This is a demo to replay the beanstalk exploit happened on Apr-17-2022
https://etherscan.io/tx/0xcd314668aaa9bbfebaf1a0bd2b6553d01dd58899c508d4729fa7311dc5d33ad7
npm install
npx hardhat run scripts/execute.js
From the analysis of the following transactions
https://etherscan.io/tx/0xfdd9acbc3fae083d572a2b178c8ca74a63915841a8af572a10d0055dbe91d219
https://etherscan.io/tx/0xf5a698984485d01e09744e8d7b8ca15cd29aa430a0137349c8c9e19e60c0bb9d
https://etherscan.io/tx/0x68cdec0ac76454c3b0f7af0b8a3895db00adf6daaf3b50a99716858c4fa54c6f
https://etherscan.io/tx/0xcd314668aaa9bbfebaf1a0bd2b6553d01dd58899c508d4729fa7311dc5d33ad7
The following steps were executed
- swap 73 ETH worth of beans and deposit the beans to Beanstalk in order to create a proposal.
- submit proposal to Beanstalk (at this time the malicious proposal contract is not created yet the exploiter use create2 to control the future created contract so that nobody will find the what the contract actually does after he submit the proposal)
- After 1 day of goverance period, create malicious proposal contract in step 2
- flash loan 350,000,000 DAI , 500,000,000 USDC, 150,000,000 USDT from AAVE
- flash loan 32,100,950 from Uni Beans pool
- flash loan 11,643,065 LUSD from Sushi LUSD-OHM pair
- add 350,000,000 DAI , 500,000,000 USDC, 150,000,000 USDT to 3CRV pool
- exchange 15,000,000 3crv token for 15,251,318 LUSD
- add 964,691,328 3crv to Beans3Crv
- add 32,100,950 Beans & 26,894,383 LUSd to BeansLusd Curve pool
- deposit 795,425,740 Beans3Crv token to Beanstalk protocol for voting power
- deposit 58,924,887 BeanLusd token Beanstalk protocol for voting power
- vote for the proposal created on step 4
- execute emergencyCommit
- remove 874,663,982 Beans3Crv liqudity for 1,007,734,729 3Crv
- remove 60,562,844 BeansLusd liquidity for 28,149,504 LUSD
- return 11,678,100 to Sushi Lusd-Ohm Pair
- return 32,197,543 to Uni beans pool
- exchange 16,184,690 LUSD to 16,184,690 3crv
- remove 511,959,710 3Crv for 522,487,380 USDC
- remove 358,371,797 3Crv for 365,758,059 DAI
- remove 153,587,913 3Crv for 156,732,232 USDT
- return AAVE DAI, USDC & USDT flashloan
- remove Beans-WETH 540,716,100,968 liquidity for 10,883 ETH and 32,511,085 Beans
- swap 15,443,059 DAI for 15,441,256 USDC
- swap 37,228,637 USDC for 11,822 ETH
- swap 6,597,232 USDT for 2,124 ETH
There are several reasons that make this exploit possible.
- This is a governance and flashloan attack. Beanstalk allow emergency commit to a proposal that has a majority of voting (2/3) after a one day of period.
- Majority of voting power can be accquired by flashloan stable assets and stake on Beans Curve pool.
This codebase is for demonstration purposes only