Mint function does not update LiquidityPosition state of caller before minting LP tokens. This
The mint function in the pool contract fails to update the caller's liquidity position state before minting new LP tokens, leaving fee growth and fee levels inconsistent with global values. This can cause liquidity providers to receive incorrect (lower) fees when they later burn their tokens.
Submitted by 0Kage
Impact
When a LP mints V2 Pool tokens, mint function in PoolLibrary gets called. Inside this function updateDurationWeightBeforeMaturity updates global short, long0 and long1 fee growth.
Change in global fee growth necessitates an update to LiquidityPosition state of caller (specifically updating fees & fee growth rates) when there are state changes made to that position (in this case, increasing liquidity). This principle is followed in functions such as burn, transferLiquidity, transferFees. However when calling mint, this update is missing. As a result, growth & fee levels in liquidity position of caller are inconsistent with global fee growth rates.
Inconsistent state leads to incorrect calculations of long0/long1 and short fees of LP holders which in turn can lead to loss of fees. Since this impacts actual rewards for users, I’ve marked it as MEDIUM risk.
Proof of Concept
Let’s say, Bob has following sequence of events
- MINT at T0: Bob is a LP who mints N pool tokens at T0
- MINT at T1: Bob mints another M pool tokens at T1. At this point, had the protocol correctly updated fees before minting new pool tokens, Bob’s fees & growth rate would be a function of current liquidity (N), global updated short fee growth rate at t1 (s*t1) and Bob’s previous growth rate at t*0 (b_t0)
- BURN at T2: Bob burns N + M tokens at T2. At this point, Bob’s fees should be a function of previous liquidity (N+M), global short fee growth rate (st2) and Bob’s previous growth rate at t*1(bt1) -> since this update never happened, Bob’s previous growth rate is wrongly referenced b*t0 instead of b_t1.
Bob could collect a lower fees because of this state inconsistency.
Recommended Mitigation Steps
Update the liquidity position state right before minting.
After line 302 of Pool.sol, update the LiquidityPosition by adding
liquidityPosition.update(pool.long0FeeGrowth, pool.long1FeeGrowth, pool.shortFeeGrowth);
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
The mint function does not call the liquidity position update routine before increasing liquidity, unlike other functions such as burn and transferLiquidity.
Impact
Bob could collect lower fees because of this state inconsistency.
What the attacker needed
User is a liquidity provider; Multiple mint operations over time
The fix
The liquidity position state should be updated right before minting, by calling the update function with the current global fee growth values.
How it was found
- Bob mints N pool tokens at time T0.
- Bob mints another M pool tokens at time T1 without his liquidity position being updated.
- Bob burns N + M tokens at time T2, but his previous growth rate is still from T0 instead of T1.
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.
When you add money to a pool, the system should update your personal record of fees earned. Here, it forgets to do that, so later when you take your money out, your fee calculation is based on old data and you might get less than you should.
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.