Position's fee growth can revert resulting in funds permanently locked #142
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-46
🤖_54_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-08-superposition/blob/4528c9d2dbe1550d2660dac903a8246076044905/pkg/seawater/src/tick.rs#L125-L246
Vulnerability details
Impact
To determine the fee growth for a position, a function similar to the one used by Uniswap V3 is used. The new logic differs from the original logic, as it does not allow underflows.
Due to this, certain operations that depend on fee growth calculations may not execute properly and could revert (removing and adding liquidity), resulting in locked funds.
Context
Similar to
Position's owed fees should allow underflow but it reverts instead, resulting in locked funds
but with a different function/root cause, both issues must be fixed separately.Proof of Concept
In
tick.get_fee_growth_inside
, Superposition's fee logic does not allow underflows:https://github.com/code-423n4/2024-08-superposition/blob/4528c9d2dbe1550d2660dac903a8246076044905/pkg/seawater/src/tick.rs#L125-L246
while the original Uniswap version allows underflows:
https://github.com/Uniswap/v3-core/blob/d8b1c635c275d2a9450bd6a78f3fa2484fef73eb/contracts/libraries/Tick.sol#L60-L95
The issue is that negative fees are expected due to how the formula works. It is explained in detail in this Uniswap's issue:
Uniswap/v3-core#573
This function is used every time a position is updated, so it will be impossible to remove funds from it when the underflow happens, resulting in locked funds.
Tools Used
Manual Review
Recommended Mitigation Steps
Use
wrapping_sub
instead, or a simple-
operation, as it natively allows underflow in Rustrelease
mode:Assessed type
Uniswap
The text was updated successfully, but these errors were encountered: