The L2TokenReceiver.swap()
function utilizes a stored sqrtPriceLimitX96
for each swap, potentially resulting in failed token swaps due to an outdated or out-of-range sqrtPriceLimitX96. The vulnerability arises from passing a previously stored sqrtPriceLimitX96
instead of obtaining the current pool's sqrtPriceLimitX96 for the UniswapV3 pool trade.
https://github.com/Cyfrin/2024-01-Morpheus/blob/main/contracts/L2TokenReceiver.sol#L57
The swap()
function swaps the params.tokenIn
for params.tokenOut
using UniswapV3 pool's exactInputSingle()
. Instead of providing the current pool's sqrtPriceLimitX96 for the trade, it passes the params_.sqrtPriceLimitX96
value, which is the previously stored sqrtPriceLimitX96 that doesn't depend on the swap pools condition.
https://github.com/Uniswap/v3-core/blob/main/contracts/UniswapV3Pool.sol#L608
Additionally, the UniswapV3 swap()
function verifies the provided sqrtPriceLimitX96
against the current pool conditions, making it susceptible to variations through flash loan attacks and other methods.
This inconsistency may result in failed swap()
transactions or suboptimal execution.
swap failed
Manual
Consider using the TWAP function to get the value of sqrtPriceX96
.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.