`Leverager::deposit`, does not support multi-hop swaps with `exactOutput`
The Leverager contract's deposit function fails to support multi-hop swaps because the internal function _getTokenIn does not update the path variable when skipping tokens, causing an infinite loop. This prevents users from performing multi-hop swaps as intended.
000000 Follow with 0x73696d616f, AlexCzm and 10 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-02-yieldoor-judging/issues/577
Found by
000000, 0x73696d616f, AlexCzm, Foundation, JohnTPark24, Pelz, Uddercover, bladeee, elolpuer, future2_22, iamnmt, roccomania, yotov721
Summary
When depositing into the leverager, if the borrowed token is not token0 or token1, the function has to perform an exactOutput swap, to receive the borrowed token0/token1.
function openLeveragedPosition(LeverageParams calldata lp) external nonReentrant returns (uint256 _id) {
...
{
// we first borrow the maximum amount the user is willing to borrow. Any unused within the swaps is later repaid.
ILendingPool(lendingPool).borrow(lp.denomination, lp.maxBorrowAmount);
IMainnetRouter.ExactOutputParams memory swapParams;
if (a0 > lp.amount0In && up.token0 != lp.denomination) {
swapParams = abi.decode(lp.swapParams1, (IMainnetRouter.ExactOutputParams));
address tokenIn = _getTokenIn(swapParams.path);
require(tokenIn == lp.denomination, "token should be denomination");
IERC20(tokenIn).forceApprove(swapRouter, swapParams.amountInMaximum);
swapParams.amountOut = a0 - lp.amount0In;
IMainnetRouter(swapRouter).exactOutput(swapParams);
IERC20(tokenIn).forceApprove(swapRouter, 0);
}
if (a1 > lp.amount1In && up.token1 != lp.denomination) {
swapParams = abi.decode(lp.swapParams2, (IMainnetRouter.ExactOutputParams));
address tokenIn = _getTokenIn(swapParams.path);
require(tokenIn == lp.denomination, "token should be denomination 2 ");
IERC20(tokenIn).forceApprove(swapRouter, swapParams.amountInMaximum);
swapParams.amountOut = a1 - lp.amount1In;
IMainnetRouter(swapRouter).exactOutput(swapParams);
IERC20(tokenIn).forceApprove(swapRouter, 0);
}
}
if (delta0 > 0) ILendingPool(lendingPool).pushFunds(up.token0, delta0);
if (delta1 > 0) ILendingPool(lendingPool).pushFunds(up.token1, delta1);
...
}
In order to validate that the denomination token is the tokenIn, we call the internal _getTokenIn.
function _getTokenIn(bytes memory path) internal pure returns (address) {
while (path.hasMultiplePools()) {
path.skipToken();
}
(, address tokenIn,) = path.decodeFirstPool();
return tokenIn;
}
The function intends to skip, the pools until only the initial one is available, to get the tokenIn.
However, path is never changed which causes an infinite loop when the user is trying to do a multi-hop swaps.
Root Cause
When, skipping tokens, path is never changed, causing an infinite loop, for users trying to do multihop swaps.
Internal Pre-conditions
None
External Pre-conditions
- User tries to do a multi-hop swaps
Attack Path
None
Impact
The Leverager::deposit function fails to support multi-hop swaps as intended
PoC
No response
Mitigation
Consider overwriting the path when calling skipToken
while (path.hasMultiplePools()) {
- path.skipToken();
+ path = path.skipToken();
}
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 function _getTokenIn calls path.skipToken() without assigning the result back to path, so the loop condition never changes and the loop never terminates.
Impact
The Leverager::deposit function fails to support multi-hop swaps as intended, causing transactions to revert or hang.
What the attacker needed
User attempts a multi-hop swap
The fix
The path should be updated by assigning the result of skipToken back to path, as shown in the mitigation diff.
How it was found
- User calls openLeveragedPosition with swap parameters that specify a multi-hop swap path.
- The contract calls _getTokenIn to validate the tokenIn.
- _getTokenIn enters a while loop that calls path.skipToken() but does not update path.
- The loop never exits because path.hasMultiplePools() remains true, causing an infinite loop.
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 deposit into a leveraged position, the contract sometimes needs to swap tokens. If the swap involves more than one trading pair (a multi-hop swap), the contract tries to check the starting token by skipping through the path. But it forgets to actually move along the path, so it gets stuck in an endless loop and the deposit fails.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.