sellQuote and buyQuote are missing deadline check in LamboVEthRouter
The sellQuote and buyQuote functions in LamboVEthRouter lack a deadline check, so transactions can remain in the mempool and execute later when the Uniswap pool price has changed. This makes the swaps vulnerable to sandwich attacks because the slippage parameters can become outdated.
Infect3d Follow with 0xDemon, Bryan_Conquer and 7 others
Originally disclosed on Code4rena
Submitted by Infect3d, also found by 0xDemon, Bryan_Conquer, Evo, hyuunn,SpicyMeatball, KupiaSec, NexusAudits, OpaBatyo, and pumba
https://github.com/code-423n4/2024-12-lambowin/blob/main/src/LamboVEthRouter.sol#L102-L102
https://github.com/code-423n4/2024-12-lambowin/blob/main/src/LamboVEthRouter.sol#L148-L148
sellQuote and buyQuote are missing deadline check in LamboVEthRouter.
Because of that, transactions can still be stuck in the mempool and be executed a long time after the transaction is initially called. During this time, the price in the Uniswap pool can change. In this case, the slippage parameters can become outdated and the swap will become vulnerable to sandwich attacks.
Vulnerability details
The protocol has made the choice to develop its own router to swap tokens for users, which imply calling the low level UniswapV2Pair::swap function:
// this low-level function should be called from a contract which performs important safety checks
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock {
require(amount0Out > 0 || amount1Out > 0, 'UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT');
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY');
As the comment indicates, this function require important safety checks to be performed.
A good example of safe implementation of such call can be found in the UniswapV2Router02::swapExactTokensForTokens function:
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external virtual override ensure(deadline) returns (uint[] memory amounts) {
amounts = UniswapV2Library.getAmountsOut(factory, amountIn, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
TransferHelper.safeTransferFrom(
path[0], msg.sender, UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]
);
_swap(amounts, path, to);
}
As we can see, 2 safety parameters are present here: amountOutMin and deadline.
Now, if we look at SellQuote (buyQuote having the same issue):
File: src/LamboVEthRouter.sol
148: function _buyQuote(address quoteToken, uint256 amountXIn, uint256 minReturn) internal returns (uint256 amountYOut) {
149: require(msg.value >= amountXIn, "Insufficient msg.value");
150:
...:
...: //* ---------- some code ---------- *//
...:
168: require(amountYOut >= minReturn, "Insufficient output amount");
We can see that no deadline parameter is present.
Impact
The transaction can still be stuck in the mempool and be executed a long time after the transaction is initially called. During this time, the price in the Uniswap pool can change. In this case, the slippage parameters can become outdated and the swap will become vulnerable to sandwich attacks.
Recommended Mitigation Steps
Add a deadline parameter.
Shaneson (Lambo.win) acknowledged
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 router functions call the low-level Uniswap swap without enforcing a transaction deadline, unlike the standard Uniswap router which includes a deadline parameter.
Impact
Transactions may be executed long after submission when the pool price has changed, making the swaps vulnerable to sandwich attacks.
What the attacker needed
None
The fix
Add a deadline parameter to the functions and enforce it.
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 tokens on a decentralised exchange, you set a minimum amount you will accept and a deadline. Without a deadline, a pending transaction can sit in the queue and execute much later, after the price has moved, letting someone else profit at your expense. This report says two functions forgot to include that deadline check.
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.