Funding Mis-Accrual Due to Missing Time Normalization in _calcFundingIndex
The funding accrual in the perpetuals contract adds a per-interval funding amount without scaling by elapsed time, so the cumulative funding index depends on how often settlements occur rather than only on elapsed time and price. This can charge or credit users incorrect funding, distort PnL and insurance-fund flows, and potentially cause unintended liquidations.
Psycharis Follow with ifex445, IvanAlexandur and 1 other
Originally disclosed on Code4rena
Submitted by Psycharis, also found by ifex445, IvanAlexandur, and Manga
perps/types/FundingRateEngine.sol #L98-L117
The bug stems from missing time-proportional scaling in funding accrual.
In contracts/perps/types/FundingRateEngine.sol, the cumulativeFundingIndex is incremented as:
fundingIndex = fundingRate × indexTwap;
but without scaling by the elapsed time relative to the effective funding interval (either fundingInterval or resetInterval during clamp/reset).
- Elapsed time is used for TWAPs and interval checks via
assertFundingIntervalElapsed. - However, the accrual step ignores elapsed time.
Violation of invariants
This makes funding path-dependent:
- Performing N settlements each of length
Δtresults in ≈N × funding - A single settlement over total
N × Δtresults in much less
Mathematically, the protocol breaks the invariant:
$$ \Delta CFI(\text{10h}) \neq \sum_{i=1}^{10} \Delta CFI(\text{1h}) $$
Thus, cumulative funding no longer depends only on elapsed time and price path, but also on settlement frequency.
Impact
- Users may be charged or credited incorrect funding, leading to unfair transfers between longs and shorts.
- Errors accumulate over time, distorting PnL, accounting, insurance-fund flows, and potentially causing unintended liquidations.
- Even without malice (e.g., downtime), the protocol mis-accrues funding.
- If settlement frequency can be influenced, actors can deliberately amplify or dampen funding to their advantage.
Recommended mitigation steps
- Add time-proportional scaling — scale per-interval funding by
elapsed / baseInterval. - Unit tests for path-independence — confirm that 1×10h = 10×1h accrual.
- Monitoring — track expected vs. realized accrual and alert on deviations.
View detailed Proof of Concept
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 accrual step multiplies the funding rate by the index TWAP but omits scaling by elapsed time relative to the funding interval.
Impact
Users may be charged or credited incorrect funding, errors accumulate over time distorting PnL and insurance-fund flows, and this could cause unintended liquidations; if settlement frequency can be influenced, actors could amplify or dampen funding to their advantage.
What the attacker needed
Funding settlements occur repeatedly; settlement frequency can vary
The fix
The accrual should be scaled by elapsed time divided by the base funding interval, with tests confirming that one long settlement equals many short ones.
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 perpetual futures market, one side periodically pays the other a small fee called funding. This code adds that fee each time it settles but forgets to multiply by how much time has passed, so settling ten times in ten hours charges far more than settling once after ten hours. That makes the amounts users pay or receive depend on settlement frequency rather than real time.
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.