MorpheusAI

MorpheusAI
Foundry
22,500 USDC
View results
Submission Details
Severity: medium
Invalid

Misuse of `sqrtPriceLimitX96` in `L2TokenReceiver.swap`

Summary

Incorrect implementation of sqrtPriceLimitX96 in L2TokenReceiver.swap

Vulnerability Details

The swap function within the L2TokenReceiver contract employs a single sqrtPriceLimitX96 parameter for executing swaps, which is a critical parameter for determining price limits within Uniswap V3's swapping mechanism. The usage of this parameter is intended to specify a price limit to prevent swaps from occurring at undesirable rates. However, the function's current implementation does not account for the variability and uniqueness of each pool's conditions in Uniswap V3, where multiple pools can exist for each token pair, each potentially requiring a different sqrtPriceLimitX96 value:

function swap(uint256 amountIn_, uint256 amountOutMinimum_) external onlyOwner returns (uint256) {
...
ISwapRouter.ExactInputSingleParams memory swapParams_ = ISwapRouter.ExactInputSingleParams({
tokenIn: params_.tokenIn,
tokenOut: params_.tokenOut,
fee: params_.fee,
recipient: address(this),
deadline: block.timestamp,
amountIn: amountIn_,
amountOutMinimum: amountOutMinimum_,
sqrtPriceLimitX96: params_.sqrtPriceLimitX96
});
...
}

In swap function sqrtPriceLimitX96 is used twice to fetch price limit for swapping

Given Uniswap V3's(here) introduction of multiple fee tiers and pools for each token pair, using a single sqrtPriceLimitX96 value for all potential pools may not always be appropriate. This approach disregards the complexity of choosing an optimal pool based on the current state of the pools available for the token pair in question.

Furthermore, the emphasis on sqrtPriceLimitX96 could be redundant given that amountOutMinimum is also checked, serving as a safeguard to ensure that the swap does not result in an output amount lower than expected by the user.

Also, I think it's not mandatory to check a sqrtPriceLimitX96 as it checks amountOutMinimum already. (It checks amountOutMinimum)

Impact

This misuse could cause the swap function to revert or fail under circumstances where it would otherwise succeed if an appropriate sqrtPriceLimitX96 were utilized for the specific pool conditions.

Tools Used

Manual

Recommendations

It is advisable to remove the sqrtPriceLimitX96 parameter from the swap function's implementation if its inclusion does not add value beyond what is already ensured by the amountOutMinimum check. This change simplifies the swapping logic, reduces potential for errors due to misconfiguration of sqrtPriceLimitX96, and enhances the contract's flexibility in interacting with multiple pools

Updates

Lead Judging Commences

inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.