Skip to content
Business logic Audit finding Advanced

ConcentratedLiquidityPool : secondsPerLiquidity should be modified whenever pool liquidity changes

The secondsPerLiquidity value is not updated when pool liquidity changes in the mint and burn functions, so it becomes stale. An attacker could exploit this to cause incorrect accounting of time-weighted liquidity, potentially leading to unfair distribution of rewards or other financial discrepancies.

hickuphh3 Follow

Originally disclosed on Code4rena

Submitted by hickuphh3

Impact

secondsPerLiquidity is updated as such: secondsPerLiquidity += uint160((diff << 128) / liquidity); where diff = timestamp - uint256(lastObservation). Hence, whenever liquidity changes, secondsPerLiquidity should be updated prior to the change.

In particular, this affects the mint() and burn() functions, in the case where liquidity changes when lowerTick <= currentTick < upperTick.

In fact, the latest secondsPerLiquidity value should be calculated and used in Ticks.insert(). For comparison, notice how UniswapV3 fetches the latest value by calling observations.observeSingle() in its _updatePosition() function.

Recommended Mitigation Steps

The secondsPerLiquidity increment logic should be applied prior to liquidity addition in mint() and removal in burn().

// insert logic before these lines in mint()
unchecked {
  if (priceLower < currentPrice && currentPrice < priceUpper) liquidity += uint128(_liquidity);
}

nearestTick = Ticks.insert(
ticks,
feeGrowthGlobal0,
feeGrowthGlobal1,
secondsPerLiquidity, // should calculate and use latest secondsPerLiquidity value
    ...
);

// insert logic before before these lines in burn()
unchecked {
  if (priceLower < currentPrice && currentPrice < priceUpper) liquidity -= amount;
}

sarangparikh22 (Sushi) disputed:

The secondsPerLiquidity is same, changing the order of that will not affect anything, since it is not getting calculated at the mint or burn function.

alcueca (judge) commented:

@sarangparikh22 (Sushi), could you please elaborate on why this isn’t an issue?

sarangparikh22 (Sushi) confirmed:

@alcueca (judge) my apologies, this is an issue. I could confirm this.

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

Impact

This could lead to incorrect secondsPerLiquidity values, potentially causing unfair reward distribution or accounting errors.

What the attacker needed

Liquidity change within tick range

The fix

The secondsPerLiquidity increment logic should be applied before liquidity addition in mint() and removal in burn().

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, secondsPerLiquidity tracks how long liquidity has been provided, weighted by the amount. If the pool's liquidity changes without updating this value first, the record becomes wrong. This could let someone manipulate the system to get more rewards than they deserve.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.