Incorrect underflow handling in tick::get_fee_growth_inside()
may prevent position modifications
#40
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-46
🤖_primary
AI based primary recommendation
🤖_54_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
upgraded by judge
Original issue severity upgraded from QA/Gas by judge
Lines of code
https://github.com/code-423n4/2024-08-superposition/blob/4528c9d2dbe1550d2660dac903a8246076044905/pkg/seawater/src/tick.rs#L125-L246
Vulnerability details
Impact
tick::get_fee_growth_inside()
can revert in certain situations due to not handling underflows correctly. As a result, some positions may become unmodifiable, causing users' funds to become stuck in the AMM.Proof of Concept
Uniswap's function
Tick.getFeeGrowthInside()
is responsible for calculating fee growth before any position-modifying actions. In the Uniswap v3 code (below), we see that all subtraction operations are subject to underflow (Uniswap v3 was deployed using Solidity versions prior to 0.8.0, it lacks built-in protections against overflow and underflow)In contrast, Seawater’s implementation of this function (
tick::get_fee_growth_inside()
) useschecked_sub
for these operations, which causes the execution to revert if an underflow occurs. This presents a problem because the behavior ofgetFeeGrowthInside()
relies on underflow to calculate fee growth. If underflow is prevented, as in Seawater’s version, valid fee growth calculations may revert. Consequently, some positions may become unmodifiable, potentially locking users' funds in the AMM.Tools Used
Manual Review.
Recommended Mitigation Steps
To resolve this issue, consider replacing
checked_sub
withwrapping_sub
. Additionally,positions::update()
must also be modified to properly handle fee growth values.(tick.rs)
(position.rs)
Assessed type
Under/Overflow
The text was updated successfully, but these errors were encountered: