Deadline check is not effective in the UniV2LiquidityAmo and UniV3LiquidityAmo contracts, allowing outdated slippage and allow pending transaction to be unexpected executed #1873
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-898
grade-b
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/0ea4387a4851cd6c8811dfb61da95a677f3f63ae/contracts/amo/UniV2LiquidityAmo.sol#L231
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/amo/UniV3LiquidityAmo.sol#L190
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/amo/UniV3LiquidityAmo.sol#L250
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/amo/UniV3LiquidityAmo.sol#L295
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/reLP/ReLPContract.sol#L257-L265
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/reLP/ReLPContract.sol#L277-L295
Vulnerability details
Summary
Deadline check is not effective, allowing outdated slippage and allow pending transaction to be unexpected executed.
Vulnerability Detail
In the current implementation in
UniV3LiquidityAmo.addLiquidity
:the deadline check is set to
type(uint256).max
, which means the deadline check is disabled!Others implementations like
UniV3LiquidityAmo.removeLiquidity
:UnitV3LiquidityAmo.swap
:and the last in the
UniV2LiquidityAmo.addLiquidity
:Also in the following lines in
ReLPContract
: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,DEFAULT_ADMIN_ROLE
can unknowingly perform bad trades, i made this example to illustrate the issue: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.
Tools Used
Manual review
Recommended Mitigation Steps
Fixed deadline as param, and also never set deadline to
block.timestamp
ortype(uint256).max
.This article is very helpful to try and understand this issue.
Assessed type
MEV
The text was updated successfully, but these errors were encountered: