Unprotected slippage tolerance can lead to user/protocol loss of funds
The rebalanceXChain() function allows any user to set the slippage tolerance for cross-chain swaps, and an attacker can front-run the transaction to set it to 100%. This could cause the protocol or users to lose funds due to unfavourable swap rates.
Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/54
Found by
Ch_301, c7e7eff, cergyk, ff, tives, wzrdk3lly
Summary
Slippage is the difference between the expected price of an order and the price when the order actually executes. If the slippage tolerance is set too low, a transaction will not execute. If the slippage tolerance is set too high, users will lose money for paying more per token than intended during swaps. When a rebalance is ready to take place on Derby, any user can front run the rebalancXChain() call setting the slippage tolerance to be 100% for the xChain swap.
Vulnerability Detail
- Any external user/attacker invokes the
rebalanceXChain()by frontrunning the transaction when it hits the mempool
- When the
homechainis not equal to thecontrollerChainxTransfer()is called with the_slippagetolerance
- This XCall will cause the rebalance to be performed, making the proper XChain swaps with the unprotected slippage tolerance.
Impact
Fulfilled swaps where the actual slippage is significantly higher than the standard tolerance of 30 (.03%) would result in loss of funds.
Code Snippet
The entrypoint for this attack occurs in the rebalanceXChain() function below
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L307-L320
Tool used
Manual Review
Recommendation
Require minimum and maximum values that the protocol is willing to accept for a slippage tolerance that will not cause significant fund loss during Connext XChain swaps. Alternatively the rebalancXChain() call can leverage onlyDao or onlyKeeper modifiers to ensure that these are the only two trusted entities allowed to make this call as intended per the Derby Documentation.
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
Impact
Swaps could execute with slippage far above the standard 0.03%, leading to loss of funds for users or the protocol.
What the attacker needed
Attacker can front-run transactions; rebalanceXChain() is callable by anyone
The fix
The function should enforce minimum and maximum slippage bounds, or restrict callers to onlyDao or onlyKeeper.
How it was found
- An attacker sees a rebalanceXChain() transaction in the mempool and front-runs it with their own call.
- The attacker sets the slippage tolerance to 100% in their transaction.
- The attacker's transaction triggers xTransfer() with the high slippage tolerance.
- The cross-chain swap executes with the unprotected slippage, potentially at a very unfavourable rate.
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.
Slippage is the difference between the expected price of a trade and the price at which it actually executes. If someone can set the allowed slippage to a very high value, a trade might go through at a much worse price, causing a loss. Here, any user can set that high slippage by jumping ahead of the legitimate rebalance transaction.
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.