Vault: The attacker can sandwich attack himself on swaps in open_position, close_position and reduce_position to make a bad debt
The Vault contract allows an attacker to set infinite slippage on swaps during open_position, close_position, and reduce_position, enabling them to sandwich their own transaction and steal funds, leaving the position undercollateralized and creating bad debt. The protocol could be drained as a result.
Source: https://github.com/sherlock-audit/2023-06-unstoppable-judging/issues/140
Found by
0xyPhilic, Tricko, n33k, ontheway, pengun, stopthecap, whiteh4t9527
Summary
The attacker could call MarginDex to open/close postions in Vault. The swap slippage is controlled by the attacker. He can set the slippage to infinite to steal from swaps and leave a bad postion/debt.
Vulnerability Detail
In open_position of Vault, max_leverage is first checked to ensure the position that is about to open will be healthy. Then token is borrowed and swapped into postion token. The attacker can set slippage to infinite and sandwich attack the swap to steal almost all of the swapped token. Then the amount swapped out is recorded in postion and the postion will be undercollateralized.
Swaps in close_position and reduce_position are also vulnerable to this sandwich attack. The attacker can attack to steal from swap and make a bad debt.
Impact
The protocol could be drained because of this sandwich attack.
Code Snippet
Tool used
Manual Review
Recommendation
Call _is_liquidatable in the end of open_position and reduce_position.
Check pool price deviation to oracle price inside close_position.
Discussion
twicek
Escalate for 10 USDC The pools used in the margin dex are whitelisted and therefore highly liquid. Using a flashloan in such a pool to manipulate the reserves would not be economically viable since the flashloans are attached with a fee. It would not even be possible to repay the loan in the scenario described in the report (it would revert).
This issue should be at most medium.
PS: Note that it is not possible to sandwich other's transactions on Arbitrum. So the above assumes that a malicious user wants to sandwich its own transaction by making several function call in one transaction. I'm no MEV expert, so correct me if I'm wrong, but Arbitrum uses a sequencer to order transactions and does not have a mempool. Instead, transactions are ordered on a first come, first served basis. Therefore, it is only possible to back-run transactions. On Arbitrum MEV bots are competing for the lowest latency to the sequencer in order to identify profitable transactions and initiate a back-run.
sherlock-admin2
Escalate for 10 USDC The pools used in the margin dex are whitelisted and therefore highly liquid. Using a flashloan in such a pool to manipulate the reserves would not be economically viable since the flashloans are attached with a fee. It would not even be possible to repay the loan in the scenario described in the report (it would revert).
This issue should be at most medium.
PS: Note that it is not possible to sandwich other's transactions on Arbitrum. So the above assumes that a malicious user wants to sandwich its own transaction by making several function call in one transaction. I'm no MEV expert, so correct me if I'm wrong, but Arbitrum uses a sequencer to order transactions and does not have a mempool. Instead, transactions are ordered on a first come, first served basis. Therefore, it is only possible to back-run transactions. On Arbitrum MEV bots are competing for the lowest latency to the sequencer in order to identify profitable transactions and initiate a back-run.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
141345
Recommendation: keep the original judging.
Escalate for 10 USDC The pools used in the margin dex are whitelisted and therefore highly liquid. Using a flashloan in such a pool to manipulate the reserves would not be economically viable since the flashloans are attached with a fee. It would not even be possible to repay the loan in the scenario described in the report (it would revert).
This issue should be at most medium.
PS: Note that it is not possible to sandwich other's transactions on Arbitrum. So the above assumes that a malicious user wants to sandwich its own transaction by making several function call in one transaction. I'm no MEV expert, so correct me if I'm wrong, but Arbitrum uses a sequencer to order transactions and does not have a mempool. Instead, transactions are ordered on a first come, first served basis. Therefore, it is only possible to back-run transactions. On Arbitrum MEV bots are competing for the lowest latency to the sequencer in order to identify profitable transactions and initiate a back-run.
The pools used in the margin dex are whitelisted
Whitelisted pool can not guarantee liquidity all the time. With flashloan, the liquidity could be manipulated. The profit is the loss from the LP here, which can cover the flashloan fee.
This vector is suitable for self sandwich, the attack is by design, abusing the delayed isLiquidatable() check.
Unstoppable-DeFi
https://github.com/Unstoppable-DeFi/unstoppable-dex-audit/pull/13
hrishibhat
Result: High Has duplicates After further discussions with the Lead judge, Agree that this could be on the border with respect to severity. Based on the points raised in issues #140, and #106, and duplicates such as #54. With all the information presented , considering this issue a valid high.
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- twicek: rejected
maarcweiss
Fixed by calling self._is_liquidatable(position_uid) after opening and reducing a position.
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
Likely the contract does not re-check the health of the position after the swap, allowing the attacker to manipulate the swap price and make the position undercollateralized.
Impact
The protocol could be drained because of this sandwich attack.
What the attacker needed
Attacker can call MarginDex; attacker controls slippage
The fix
The fix was to call _is_liquidatable after opening and reducing a position, and to check pool price deviation to oracle price inside close_position.
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 open a leveraged position, the contract borrows tokens and swaps them for the asset you want. The swap uses a slippage setting that the attacker controls. By setting slippage very high, the attacker can make the swap execute at a terrible price, effectively stealing most of the swapped tokens and leaving the position with too little collateral. This can create bad debt for the protocol.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.