ConcentratedLiquidityPool : rangeFeeGrowth and secondsPerLiquidity math needs to be unchecked
The fee growth and seconds-per-liquidity calculations in a concentrated liquidity pool can legitimately produce negative intermediate values, but the code performs these subtractions with checked arithmetic. An attacker could trigger a revert by moving the price so that the computed fee growth inside a range goes negative, causing the affected position operations to fail.
Submitted by hickuphh3
Impact
The fee growth mechanism, and by extension, secondsPerLiquidity mechanism of Uniswap V3 has the ability to underflow. It is therefore a necessity for the math to (ironically) be unsafe / unchecked.
Proof of Concept
Assume the following scenario and initial conditions:
-
Price at parity (nearestTick is 0)
-
tickSpacing of 10
-
Swaps only increase the price (nearestTick moves up only)
-
feeGrowthGlobalinitializes with 0, increases by 1 for every tick moved for simplicity -
Existing positions that provide enough liquidity and enable nearestTick to be set to values in the example
-
Every tick initialized in the example is ≤ nearestTick, so that its
feeGrowthOutside=feeGrowthGlobal -
When nearestTick is at 40, Alice creates a position for uninitialised ticks [-20, 30]. The ticks are initialized, resulting in their
feeGrowthOutsidevalues to be set to 40. -
nearestTick moves to 50. Bob creates a position with ticks [20, 30] (tick 20 is uninitialised, 30 was initialized from Alice’s mint). tick 20 will therefore have a
feeGrowthOutsideof 50. -
Let us calculate
rangeFeeGrowth(20,30).-
lowerTick = 20, upperTick = 30
-
feeGrowthBelow = 50 (lowerTick’s
feeGrowthOutside) since lowerTick < currentTick -
feeGrowthAbove = 50 - 40 = 10 (feeGrowthGlobal - upperTick’s
feeGrowthOutside) since upperTick < currentTick -
feeGrowthInside
= feeGrowthGlobal - feeGrowthBelow - feeGrowthAbove
= 50 - 50 - 10
= -10
-
We therefore have negative feeGrowthInside.
This behaviour is actually acceptable, because the important thing about this mechanism is the relative values to each other, not the absolute values themselves.
Recommended Mitigation Steps
rangeFeeGrowth() and rangeSecondsInside() has to be unchecked. In addition, the subtraction of feeGrowthInside values should also be unchecked in _updatePosition() and ConcentratedLiquidityPosition#collect().
The same also applies for the subtraction of pool.rangeSecondsInside and stake.secondsInsideLast in claimReward() and getReward() of the ConcentratedLiquidityPoolManager contract.
sarangparikh22 (Sushi) disputed:
Can you give more elaborate example.
@sarangparikh22 (Sushi), I find the example quite elaborate. It shows an specific example in which underflow is desired, by comparing with other platform using similar mechanics. It explains that with your current implementation you can’t have negative
feeGrowthInside, which is a possible and acceptable scenario. Could you please elaborate on what your grounds are for disputing this finding?
sarangparikh22 (Sushi) confirmed:
@alcueca (judge) Yes this a valid issue.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the fee growth and seconds-per-liquidity subtractions use checked arithmetic, so a legitimate negative intermediate value causes a revert instead of wrapping as intended.
Impact
Positions whose fee growth inside a range goes negative could revert on update or collection, disrupting pool operations; the report does not demonstrate theft of funds.
What the attacker needed
A deployed pool with active positions; ability to trade and move the price; specific tick initialisation state
The fix
The fee growth and seconds-inside calculations, and the related subtractions in position updates, collection and reward claims, should be made unchecked.
How it was found
- Set up a pool at parity with a small tick spacing and positions providing liquidity.
- Move the price up so the nearest tick reaches 40, then create a position over uninitialised ticks below it.
- Move the price further to 50 and create a position whose lower tick is uninitialised and upper tick was initialised earlier.
- Compute the fee growth inside that range and observe it is negative, which the checked code cannot handle.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A liquidity pool tracks how much fee each price range has earned. Sometimes the correct intermediate number is negative, which is fine because only differences matter. If the code refuses to allow negative numbers, it crashes (reverts) instead of working, and someone can force that crash by trading the price into a particular state.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.