Skip to content
DoS Audit finding Advanced

range fee growth underflow

The RangeFeeGrowth function in a concentrated liquidity pool can revert when calculating fees because the sum of feeGrowthBelow and feeGrowthAbove can exceed the global fee growth. This prevents users from adding or removing liquidity, locking funds in the contract.

broccoli Follow

Originally disclosed on Code4rena

Submitted by broccoli

Impact

The function RangeFeeGrowth (ConcentratedLiquidityPool.sol#L601-L633) would revert the transaction in some cases.

When a pool cross a tick, it only updates either feeGrowthOutside0 or feeGrowthOutside1. Ticks.sol#L23-L53

RangeFeeGrowth calculates the fee as follow:

    feeGrowthInside0 = _feeGrowthGlobal0 - feeGrowthBelow0 - feeGrowthAbove0;
    feeGrowthInside1 = _feeGrowthGlobal1 - feeGrowthBelow1 - feeGrowthAbove1;

feeGrowthBelow + feeGrowthAbove is not necessary smaller than _feeGrowthGlobal. Please see POC.

Users can not provide liquidity or burn liquidity. Fund will get stocked in the contract. I consider this is a high-risk issue.

Proof of Concept

    # This is the wrapper.
    # def add_liquidity(pool, amount, lower, upper)
    # def swap(pool, buy, amount)

    add_liquidity(pool, deposit_amount, -800, 500)
    add_liquidity(pool, deposit_amount, 400, 700)
    # We cross the tick here to trigger the bug.

    swap(pool, False, deposit_amount)
    # Only tick 700's feeGrowthOutside1 is updated

    swap(pool, True, deposit_amount)
    # Only tick 500's feeGrowthOutside0 is updated

    # current tick at -800

    # this would revert
    # feeGrowthBelow1 = feeGrowthGlobal1
    # feeGrowthGlobal1 - feeGrowthBelow1 - feeGrowthAbove1 would revert
    # user would not be able to mint/withdraw/cross this tick. The pool is broken
    add_liquidity(pool, deposit_amount, 400, 700)

Tools Used

Hardhat

Recommended Mitigation Steps

It’s either modify the tick’s algo or RangeFeeGrowth. The quick-fix I come up with is to deal with the fee in RangeFeeGrowth. However, I recommend the team to go through tick’s logic again.

sarangparikh22 (Sushi) disputed:

The example is wrong, you can’t add use upper tick as odd, correct the example and resubmit please.

alcueca (judge) commented:

@sarangparikh22 (Sushi), is the example invalid, or the whole issue? Is this something that you would consider fixing?

sarangparikh22 (Sushi) confirmed:

@alcueca (judge) The example is invalid, but the issue is valid, the fix is to swap the condition of feeGrowthGlobal

The original report as published on Code4rena, by broccoli. 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 calculation in RangeFeeGrowth does not account for the case where the sum of feeGrowthBelow and feeGrowthAbove exceeds the global fee growth, leading to an underflow revert.

Impact

Users cannot provide or burn liquidity, and funds may become stuck in the contract.

What the attacker needed

A deployed concentrated liquidity pool; ability to add liquidity and swap

The fix

The fix is to swap the condition of feeGrowthGlobal, as confirmed by the team.

How it was found

  1. Add liquidity to a pool with a lower tick of -800 and an upper tick of 500.
  2. Add liquidity to the same pool with a lower tick of 400 and an upper tick of 700.
  3. Perform a swap that crosses the tick to trigger the bug.
  4. Perform another swap in the opposite direction.
  5. Attempt to add liquidity again with the same range (400 to 700), which reverts.

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.

In a liquidity pool, fees accumulate over time and are tracked with numbers that should only increase. A calculation subtracts two of these numbers from a third, but sometimes the two subtracted numbers add up to more than the third, causing the subtraction to fail and the transaction to be rejected. This means users cannot add or remove their funds from the pool.

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 broccoli

View all

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