Potential 99.5% loss in emergencyWithdraw() of two Yieldbox strategies
The emergencyWithdraw function in two Yieldbox strategies calculated the minimum acceptable withdrawal amount as only 0.5% of the expected amount, instead of 99.5%. An attacker could sandwich the withdrawal transaction, causing the user to lose up to 99.5% of the funds to slippage.
Submitted by 0xfuje, also found by Madalad, paweenp, carrotsmuggler, kaden, c7e7eff, Brenzee, SaeedAlipoor01988, and Vagner
99.5% of user funds are lost to slippage in two Yieldbox strategies in case of emergencyWithdraw()
Description
Slippage is incorrectly calculated where minAmount is intended to be 99.5%, however it’s calculated to be only 0.5%, making the other 99.5% sandwichable. The usual correct minAmount slippage calculation in other Yieldbox strategy contracts is
uint256 minAmount = calcAmount - (calcAmount * 50) / 10_000;
Calculation logic
In ConvexTriCryptoStrategy and LidoEthStrategy - emergencyWithdraw() allows the owner to withdraw all funds from the external pools. the amount withdrawn from the corresponding pool is calculated to be: uint256 minAmount = (calcWithdraw * 50) / 10_000;. This is incorrect and only 0.5% of the withdrawal.
Let’s calculate with calcWithdraw = 1000 as the amount to withdrawn from the pool. uint256 incorrectMinAmount = (1000 * 50) / 10_000 = 5
The correct calculation would look like this: uint256 correctMinAmount = calcWithdraw - (calcWithdraw * 50) / 10_000 aka uint256 correctMinAmount = 1000 - (1000 * 50) / 10_000 = 995
Withdrawal logic
emergencyWithdraw() of Yieldbox Strategy contracts is meant to remove all liquidity from the corresponding strategy contract’s liquidity pool.
In the case of LidoStrategy the actual withdraw is curveStEthPool.exchange(1, 0, toWithdraw, minAmount) which directly withdraws from the Curve StEth pool.
In the case of ConvexTriCryptoStrategy it’s lpGetter.removeLiquidityWeth(lpBalance, minAmount) and lpGetter withdraws from the Curve Tri Crypto (USDT/WBTC/WETH) pool via removeLiquidityWeth() -> _removeLiquidity() -> liquidityPool.remove_liquidity_one_coin(_amount, _index, _min).
These transactions are vulnerable to front-running and sandwich attacks so the amount withdrawn is only guaranteed to withdraw the minAmount aka 0.5% from the pool which makes the other 99.5% user funds likely to be lost.
Recommended Mitigation Steps
Fix the incorrect minAmount calculation to be uint256 minAmount = calcAmount - (calcAmount * 50) / 10_000; in ConvexTriCryptoStrategy and LidoEthStrategy.
0xRektora (Tapioca) confirmed via duplicate issue 408
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The minAmount calculation used (calcWithdraw * 50) / 10_000 instead of calcWithdraw - (calcWithdraw * 50) / 10_000, making the minimum only 0.5% of the withdrawal.
Impact
An attacker could sandwich the emergencyWithdraw transaction, causing the user to lose up to 99.5% of the withdrawn funds to slippage.
What the attacker needed
EmergencyWithdraw called; attacker can sandwich transaction
The fix
The minAmount calculation should be changed to calcAmount - (calcAmount * 50) / 10_000 in both strategies.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you withdraw money from a pool, you set a minimum amount you will accept to protect against price changes. Here, the code set that minimum to just 0.5% of what you should get, so an attacker could manipulate the price and take almost everything. This is like agreeing to sell your car for at least £50 when it's worth £10,000.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.