Ensure Slippage and Deadline Checks in UniswapV3 Swap #33
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-24
edited-by-warden
insufficient quality report
This report is not of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-01-decent/blob/main/src/swappers/UniSwapper.sol#L130
https://github.com/code-423n4/2024-01-decent/blob/main/src/swappers/UniSwapper.sol#L150
https://github.com/Uniswap/v3-periphery/blob/697c2474757ea89fec12a4e6db16a574fe259610/contracts/base/PeripheryValidation.sol#L8
Vulnerability details
Impact
missing zero check:
The
amountOutMinimum
is intended to be set toswapParams.amountOut
, but it is crucial to verify that it is not checked with a zero value. AllowingamountOutMinimum = 0
informs the swap that the caller is willing to accept a minimum amount of 0 output tokens, exposing the user to a potential catastrophic loss of funds through MEV bot sandwich attacks.missing deadline:
The
deadline
parameter allows the caller to specify a time limit by which the transaction must be executed. Without a deadline parameter, the transaction may linger in the mempool and be executed at a later time, potentially resulting in a worse price for the user.uniswap deadline checks
It is also important to include an expiration deadline to prevent slippage attacks. If the
deadline
parameter is commented out, it can lead to a zero start for thedeadline
parameter, preventing any transaction from occurring. This is becauseSwapRouter.sol
inUniswapV3
has acheckDeadline
modifier that verifies ifblock.timestamp >= deadline;
otherwise, it reverts.Proof of Concept
The missing
zero check
and the absence of a setdeadline
can be identified in the following:https://github.com/code-423n4/2024-01-decent/blob/main/src/swappers/UniSwapper.sol#L130
https://github.com/code-423n4/2024-01-decent/blob/main/src/swappers/UniSwapper.sol#L150
https://github.com/Uniswap/v3-periphery/blob/697c2474757ea89fec12a4e6db16a574fe259610/contracts/base/PeripheryValidation.sol#L8
Tools Used
Manual
Recommended Mitigation Steps
Check whether
swapParams.amountOut
is zero or not, and set the correctdeadline
.Assessed type
Uniswap
The text was updated successfully, but these errors were encountered: