The vulnerable contract tfUSD owned 50M tusd at the time the issue was reported.
This exploit contract could get 15M of profit in one transaction. Similar attack pattern could be applied for several txs. With the help of flashbot, attacker could have drained all 50M TSUD in the pool.
The bug located at the old implementation of tfUSD. https://etherscan.io/address/0x27f461c698844ff51b33ecffa5dc2bd9721060b1#code.
There old implementation had an flush function that every can trigger.
function flush(uint256 currencyAmount, uint256 minMintAmount) external {
The flush function calls _curvePool.add_liquidity(amounts, minMintAmount);
. When the contract provides liquidity through add_liquidity
the curve pool mints 3crv based on the market price. When the 3crv pool is imbalanced, the contract suffers huge slippage.
The exploit steps are as follow:
- borrow TUSD and DAI from aave.
- Deposit DAI into compound to borrow TUSD.
- Mutate the TUSD price at 3crv prool (
0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51
) - trigger
flush
and force the pool to add liquidity to 3crv at bad price. - Buy back TUSD at 3crv pool (Gain profit at this step.)
- Repay TUSD to compound
- Repay DAI, TUSD to aave
- Get 15M TUSD profit.
The attack pattern is simliar to yDai incident.
The attack can do following steps:
- supply token to the pool
- exploit it. (see above steps)
- withdraw token
- repeat 1-3
npm i
npx hardhat test
Here's setting of hardhat
{
solidity: "0.6.12",
networks: {
hardhat: {
forking: {
url: "https://eth-mainnet.alchemyapi.io/v2/{}",
blockNumber: 12517300
}
},
},
mocha: {
timeout: 1200000,
}
}