Accrued liquidity can be lost and never be recovered for a given tick period.
A boundary condition in the liquidity mining contract causes the tick tracking index not to be incremented when a user exits exactly at the next week timestamp, so accrued liquidity rewards for that tick period can be lost and never recovered.
Accrued liquidity can be lost and never be recovered for a given tick period due to not incrementing tickTrackingIndex, which sets the tick end timestamp to nextweek and will start accruing liquidity for next tick period.
Proof of Concept
LiquidityMining.accrueConcentratedPositionTimeWeightedLiquidity sets tickActiveEnd = nextWeek and doesn’t increment tickTrackingIndex, which makes current tick period to end by setting tickActiveEnd = nextWeek and moves to next tick period without incrementing tickTrackingIndex. When tick is no longer active that is tickTracking.exitTimestamp < nextWeek, it means tickTracking.exitTimestamp should be strictly less than the nextWeek to set tickActiveEnd = tickTracking.exitTimestamp and then calculate dt based on the tickActiveStart and tickActiveEnd values.
else {
// Tick is no longer active
if (tickTracking.exitTimestamp < nextWeek) {
// Exit was in this week, continue with next tick
tickActiveEnd = tickTracking.exitTimestamp;//1697068700
tickTrackingIndex++;
dt = tickActiveEnd - tickActiveStart;
} else {
// Exit was in next week, we need to consider the current tick there (i.e. not increase the index)
tickActiveEnd = nextWeek;
}
Now the issue here, is with the if statement; if (tickTracking.exitTimestamp < nextWeek) calculates dt if exitTimestamp is strictly lesser than the nextWeek. Suppose there is a condition in which user exitTimestamp = nextWeek i.e.; user exits the concentrated liquidity position with some X poolIdx with the nextWeek timestamp. Meaning when the nextWeek is about to end, the user triggers an exit and as soon as the exit triggers, this if statement will revert and tickTrackingIndex will not be incremented for that user or poolId. tickTrackingIndexAccruedUpTo_[poolIdx][posKey][i] and therefore, the accrued concentrated liquidity might be lost for a given tick period and will never be recovered due to setting tickActiveEnd = nextWeek in the else statement; which will declare the tick end and move to the next tick period to accrued liquidity .
Recommended Mitigation Steps
Edit the if statement for exitTimestamp, which increments tickTrackingIndex when tickTracking.exitTimestamp == nextWeek:
- if (tickTracking.exitTimestamp < nextWeek) {
}
+ if (tickTracking.exitTimestamp <= nextWeek) {
}
Good point, requires quite a few conditions to actually cause damage (exactly aligned exitTimestamp and even then, the accrual has to happen a few weeks later with additional ticks that were in range since then for it to cause skipping ticks), but will definitely be fixed.
The original report as published on Code4rena, by Satyam_Sharma. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the strict less-than comparison in the condition checking the exit timestamp against the next week boundary, which fails to increment the tick tracking index when the timestamps are equal.
Impact
Accrued liquidity rewards for a tick period could be permanently lost, but the issue requires exact timestamp alignment and additional conditions, making it low likelihood.
What the attacker needed
User exits exactly at nextWeek timestamp; additional ticks in range later
The fix
The condition should be changed to less-than-or-equal so that the tick tracking index is incremented when the exit timestamp equals the next week boundary.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This is a smart contract bug where a user's rewards for providing liquidity can be lost if they exit at a very specific time. The code checks if the exit time is before the next week, but if it is exactly equal, it skips updating a counter, so the rewards for that period are never recorded.
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.