VaderRouter._swap performs wrong swap
The VaderRouter._swap function incorrectly passes the foreign amount as the native amount when performing a three-path swap, causing the pool's balance check to fail. As a result, all three-path swaps through the router revert, preventing users from completing such swaps.
Submitted by cmichel
The 3-path hop in VaderRouter._swap is supposed to first swap foreign assets to native assets, and then the received native assets to different foreign assets again.
The pool.swap(nativeAmountIn, foreignAmountIn) accepts the foreign amount as the second argument. The code however mixes these positional arguments up and tries to perform a pool0 foreign -> native swap by using the foreign amount as the native amount:
function _swap(
uint256 amountIn,
address[] calldata path,
address to
) private returns (uint256 amountOut) {
if (path.length == 3) {
// ...
// @audit calls this with nativeAmountIn = amountIn. but should be foreignAmountIn (second arg)
return pool1.swap(0, pool0.swap(amountIn, 0, address(pool1)), to);
}
}
// @audit should be this instead
return pool1.swap(pool0.swap(0, amountIn, address(pool1)), 0, to);
Impact
All 3-path swaps through the VaderRouter fail in the pool check when require(nativeAmountIn = amountIn <= nativeBalance - nativeReserve = 0) is checked, as foreign amount is sent but native amount is specified.
Recommended Mitigation Steps
Use return pool1.swap(pool0.swap(0, amountIn, address(pool1)), 0, to); instead.
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 arguments to the pool.swap function were swapped: the foreign amount was passed as the native amount and vice versa.
What the attacker needed
Three-path swap through VaderRouter
The fix
The arguments to the two swap calls should be corrected so that the foreign amount is passed as the second argument and the native amount as the first.
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.
A router contract is supposed to swap tokens along a path. For a three-token path, it first swaps token A for token B, then token B for token C. The code mixed up which amount goes where, so the first swap tried to use the wrong token's amount. The pool's safety check then rejected the swap, making all three-token swaps fail.
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.