Deadline check is not effective, allowing outdated slippage and allow pending transaction to be unexpected executed
Two swap paths in the protocol's spell contracts omit an effective deadline: one passes the maximum possible timestamp to the router, and the other calls the pool directly with no deadline at all. A pending swap could therefore execute much later at an outdated price, and a MEV bot could sandwich it for profit.
Source: https://github.com/sherlock-audit/2023-04-blueberry-judging/issues/145
Found by
Bauer, Breeje, ctf_sec
Summary
Deadline check is not effective, allowing outdated slippage and allow pending transaction to be unexpected executed
Vulnerability Detail
In the current implementation in CurveSpell.sol
{
// 2. Swap rewards tokens to debt token
uint256 rewards = _doCutRewardsFee(CRV);
_ensureApprove(CRV, address(swapRouter), rewards);
swapRouter.swapExactTokensForTokens(
rewards,
0,
swapPath,
address(this),
type(uint256).max
);
}
the deadline check is set to type(uint256).max, which means the deadline check is disabled!
In IChiSpell. the swap is directedly call on the pool instead of the router
SWAP_POOL.swap(
address(this),
// if withdraw token is Token0, then swap token1 -> token0 (false)
!isTokenA,
amountToSwap.toInt256(),
isTokenA
? param.sqrtRatioLimit + deltaSqrt
: param.sqrtRatioLimit - deltaSqrt, // slippaged price cap
abi.encode(address(this))
);
and it has no deadline check for the transaction when swapping
Impact
AMMs provide their users with an option to limit the execution of their pending actions, such as swaps or adding and removing liquidity. The most common solution is to include a deadline timestamp as a parameter (for example see Uniswap V2 and Uniswap V3). If such an option is not present, users can unknowingly perform bad trades:
Alice wants to swap 100 tokens for 1 ETH and later sell the 1 ETH for 1000 DAI.
The transaction is submitted to the mempool, however, Alice chose a transaction fee that is too low for miners to be interested in including her transaction in a block. The transaction stays pending in the mempool for extended periods, which could be hours, days, weeks, or even longer.
When the average gas fee dropped far enough for Alice's transaction to become interesting again for miners to include it, her swap will be executed. In the meantime, the price of ETH could have drastically changed. She will still get 1 ETH but the DAI value of that output might be significantly lower.
She has unknowingly performed a bad trade due to the pending transaction she forgot about.
An even worse way this issue can be maliciously exploited is through MEV:
The swap transaction is still pending in the mempool. Average fees are still too high for miners to be interested in it.
The price of tokens has gone up significantly since the transaction was signed, meaning Alice would receive a lot more ETH when the swap is executed. But that also means that her maximum slippage value (sqrtPriceLimitX96 and minOut in terms of the Spell contracts) is outdated and would allow for significant slippage.
A MEV bot detects the pending transaction. Since the outdated maximum slippage value now allows for high slippage, the bot sandwiches Alice, resulting in significant profit for the bot and significant loss for Alice.
Code Snippet
Tool used
Manual Review
Recommendation
We recommend the protocol use block.timstamp for swapping deadline for Uniswap V2 and swap with Unsiwap Router V3 instead of the pool directly!
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 swap calls were written without a real expiry parameter, using the maximum timestamp value in one place and calling the pool directly without any deadline in the other.
Impact
A user's swap could execute long after signing at a stale price, and a MEV bot could sandwich the pending transaction, causing a significant loss to the user.
What the attacker needed
User submits a swap transaction; transaction stays pending in mempool; price moves before inclusion
The fix
The protocol should pass a real block timestamp as the swap deadline for the router-based path and swap through the Uniswap V3 router rather than calling the pool directly.
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 normally attach an expiry time so the trade is cancelled if it sits unconfirmed for too long. Here that expiry was effectively switched off, so a trade could be confirmed hours or days later at a price you never agreed to. Someone watching pending trades could exploit that stale price to profit at the user's expense.
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.