Wrong slippage protection on Token -> Token trades
The token-to-token swap function computed the slippage check for the second leg using the input amount of the first leg instead of the output of the first leg. This meant the slippage limit could reject a trade that should pass or accept a trade that lost the user more than expected.
Vader Protocol contest
Originally disclosed on Code4rena
The Router.swapWithSynthsWithLimit allows trading token to token and specifying slippage protection. A token to token trade consists of two trades:
- token to base
- base to token
The slippage protection of the second trade (base to token) is computed wrong:
require(iUTILS(UTILS()).calcSwapSlip(
inputAmount, // should use outToken here from prev trade
iPOOLS(POOLS).getBaseAmount(outputToken)
) <= slipLimit
);
It compares the token input amount (of the first trade) to the base reserve of the second pair.
Slippage protection fails and either the trade is cancelled when it shouldn’t be or it is accepted even though the user suffered more losses than expected.
Recommend it should use the base output from the first trade to check for slippage protection. Note that this still just computes the slippage protection of each trade individually. An even better way would be to come up with a formula to compute the slippage on the two trades at once.
strictly-scarce (vader) confirmed:
Valid, although disagree with severity, the wrongly compute slip amount would just fail the trade or allow the second trade to go thru with no protection.
Our decision matrix for severity:
0: No-risk: Code style, clarity, off-chain monitoring (events etc), exclude gas-optimisations 1: Low Risk: UX, state handling, function incorrect as to spec 2: Funds-Not-At-Risk, but can impact the functioning of the protocol, or leak value with a hypothetical attack path with stated assumptions, but external requirements 3: Funds can be stolen/lost directly, or indirectly if a valid attack path shown that does not have handwavey hypotheticals.
Recommended: 1
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 slippage calculation for the second leg used the original input token amount rather than the base amount produced by the first leg.
Impact
The trade could be cancelled when it should not be, or accepted even though the user suffered more losses than expected; the maintainer noted the second trade could go through with no protection.
What the attacker needed
Token-to-token swap via the router
The fix
The check should use the base output from the first trade, and ideally a single formula should compute slippage across both trades at once.
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 swap one token for another through an intermediate token, the contract checks that you do not lose too much value along the way. That check is called slippage protection. Here the check for the second half of the swap used the wrong number, so the safety limit did not reflect what actually happened.
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.