Write-up and exploit of tfUSD (TrueFi ) 50M worth of bug.
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:
0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51
)flush
and force the pool to add liquidity to 3crv at bad price.The attack pattern is simliar to yDai incident.
The attack can do following steps:
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,
}
}