Missing sqrt_price
validation during pool creation/update may render all swaps with MAX price_limit
inexecutable
#6
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
edited-by-warden
🤖_primary
AI based primary recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-10-superposition/blob/7ad51104a8514d46e5c3d756264564426f2927fe/pkg/seawater/src/pool.rs#L48-L58
https://github.com/code-423n4/2024-10-superposition/blob/7ad51104a8514d46e5c3d756264564426f2927fe/pkg/seawater/src/pool.rs#L238-L257
Vulnerability details
Proof of Concept
In the current implementation of the
swap()
function, there is a potential vulnerability that arises from the handling of theprice_limit
parameter, particularly whenprice_limit
is set toU256::MAX
. This vulnerability can lead to unexpected reverts due to double validation checks that can invalidate theadjusted price limit
after it is set.Current implementation of the
swap()
:Issue Scenario:
A pool is initialized with a
price
value equal totick_math::MIN_SQRT_RATIO + U256::one()
ortick_math::MAX_SQRT_RATIO - U256::one()
. But since there is no validation done on theprice
parameter,sqrt_price
is set to theprice
provided:swap
withprice_limit == U256::MAX
andzero_for_one == true
.price_limit
is adjusted totick_math::MIN_SQRT_RATIO + U256::one()
, but immediately after, it gets validated again.sqrt_price
was set to a value equal totick_math::MIN_SQRT_RATIO + U256::one()
, this will trigger the conditionprice_limit >= self.sqrt_price.get()
to betrue
, leading to theErr(Error::PriceLimitTooLow)?
revert.The same revert goes for the case when
price_limit == U256::MAX
,zero_for_one == false
andsqrt_price
is equal totick_math::MAX_SQRT_RATIO - U256::one()
Impact
Users attempting to perform a valid swap might face unexpected reverts. This is because the inbuilt mechanism for price adjustment will be flawed therefore rendering all swaps with MAX
price_limit
inexecutable.Recommended Mitigation Steps
Ensure that
sqrt_price
is not set totick_math::MIN_SQRT_RATIO + U256::one()
ortick_math::MAX_SQRT_RATIO - U256::one()
:Modify
set_sqrt_price()
with the above checks as well:Assessed type
DoS
The text was updated successfully, but these errors were encountered: