Skip to content
DoS Audit finding Advanced

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.

hickuphh3 Follow

Originally disclosed on Code4rena

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)

  • feeGrowthGlobal initializes 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 feeGrowthOutside values 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 feeGrowthOutside of 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.

alcueca (judge) commented:

@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.

The original report as published on Code4rena, by hickuphh3. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Set up a pool at parity with a small tick spacing and positions providing liquidity.
  2. Move the price up so the nearest tick reaches 40, then create a position over uninitialised ticks below it.
  3. Move the price further to 50 and create a position whose lower tick is uninitialised and upper tick was initialised earlier.
  4. 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.

More by hickuphh3

View all

43 more disclosed reports, best first.

More from Sushi Trident contest phase 2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.