Submitted by 0xfuje, also found by Madalad, paweenp, carrotsmuggler, kaden, c7e7eff, Brenzee, SaeedAlipoor01988, and Vagner
https://github.com/Tapioca-DAO/tapioca-yieldbox-strategies-audit/blob/05ba7108a83c66dada98bc5bc75cf18004f2a49b/contracts/lido/LidoEthStrategy.sol#L108 
https://github.com/Tapioca-DAO/tapioca-yieldbox-strategies-audit/blob/05ba7108a83c66dada98bc5bc75cf18004f2a49b/contracts/convex/ConvexTricryptoStrategy.sol#L154
99.5% of user funds are lost to slippage in two Yieldbox strategies in case of emergencyWithdraw()
Slippage is incorrectly calculated where minAmount is intended to be 99.5%, however its 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;
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.
Lets 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
emergencyWithdraw() of Yieldbox Strategy contracts is meant to remove all liquidity from the corresponding strategy contracts 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 its 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.
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
