Submitted by jonah1005, also found by 0xRajeev and WatchPug
When a user tries to withdraw the token from the vault, the vault would withdraw the token from the controller if theres insufficient liquidity in the vault. However, the controller does not raise an error when theres insufficient liquidity in the controller/ strategies. The user would lose his shares while getting nothing.
An MEV searcher could apply this attack on any withdrawal. When an attacker found an unconfirmed tx that tries to withdraw 1M dai, he can do such sandwich attack.
All users would be vulnerable to MEV attackers. I consider this is a high-risk issue.
Heres web3.py script to reproduce the issue.
There are two issues involved.
First, users pay the slippage when they try to withdraw. I do not find this fair. Users have to pay extra gas to withdraw liquidity from strategy, convert the token, and still paying the slippage. I recommend writing a view function for the frontend to display how much slippage the user has to pay (Controler.sol L448-L479).
Second, the controller does not revert the transaction theres insufficient liquidity (Controller.sol#L577-L622).
Recommend to revert the transaction when _amount is not equal to zero after the loop finishes.
GainsGoblin (yAxis) acknowledged
GalloDaSballo (judge) commented:
BobbyYaxis (yAxis) noted:
