# Stale fee state in liquidation checks

Liquidation or net-value math reading fee/interest accumulators not accrued to the current timestamp

_Area: DeFi oracles, liquidations and flash loans. Seen in 3 disclosed reports; latest 2026-03-09. Updated 2026-12-04._

## How it works
Liquidation and margin math assume every value it reads is current. In perp/DEX accounting, funding and borrowing fees are stored as per-market accumulators that only advance when someone interacts with the market. A position's net value or liquidation eligibility is computed from those cached accumulators, so it reflects the last interaction, not now. A position that is actually underwater still looks healthy, or collateral and debt are valued at different timestamps, so the check answers a stale question.

## Where it shows up
- Net-value or margin functions subtracting a cached `totalPosFee`, funding fee per quantity, or cumulative borrowing fee per token [E1](https://bugbountylibrary.com/r/sherlock%3A2024-05-elfi-protocol%3AH-7.md).
- Liquidation eligibility computed before `updateFundingAndBorrowingState` (or equivalent accrual) runs in the same call [E2](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AM-18.md).
- A valuation mixing a stored accumulator (assets from `unrealizedInterest`) with a freshly simulated one (debt from a borrow index advanced to now) [E3](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-14.md).
- Any `_accrueInterest`-style function whose result is only persisted on interaction, but read by liquidation paths.

## How to review
For each value feeding a liquidation or margin decision, trace it to its source and ask: is this advanced to `block.timestamp` at the moment of the check? The invariant: every term in the health/net-value formula is accrued to the same timestamp, and accrual happens before the check, not after. Check call ordering in the liquidation entrypoint [E2](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AM-18.md), and check that assets and debt use the same time basis [E3](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-14.md). If an accumulator is lazy, confirm the check path forces a refresh first.

## How finders spotted it
- Traced `totalPosFee` in `_getCrossNetValue` back to market-level accumulators refreshed only on interaction; confirmed with a PoC showing net value frozen then jumping when another user traded [E1](https://bugbountylibrary.com/r/sherlock%3A2024-05-elfi-protocol%3AH-7.md).
- Read `DecreasePositionUtils.decreasePosition` top to bottom and noticed the liquidation check preceded `updateFundingAndBorrowingState` [E2](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AM-18.md).
- Compared how `assetsAndInterest` derives assets (stored `unrealizedInterest`) versus debt (`_owedInterest` simulating the current borrow index), spotting the timestamp mismatch [E3](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-14.md).

## Variants seen
- Stale fee accumulator in cross-margin net value delaying liquidation [E1](https://bugbountylibrary.com/r/sherlock%3A2024-05-elfi-protocol%3AH-7.md).
- Wrong ordering: eligibility checked before funding/borrowing state update [E2](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AM-18.md).
- Assets and debt valued at different timestamps inside one liquidation [E3](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-14.md).

## Impact and severity
Positions that should be liquidatable are not, delaying liquidation and increasing protocol losses; in cross-margin, insolvency risk [E1](https://bugbountylibrary.com/r/sherlock%3A2024-05-elfi-protocol%3AH-7.md)[E2](https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AM-18.md). In E3 the mismatch understates liquidatee net worth and overstates protocol loss, amplified by liquidation and bonus math [E3](https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-14.md). Severity is high where the stale value gates solvency.

## Evidence
- E1: https://bugbountylibrary.com/r/sherlock%3A2024-05-elfi-protocol%3AH-7.md
- E2: https://bugbountylibrary.com/r/sherlock%3A2023-02-gmx%3AM-18.md
- E3: https://bugbountylibrary.com/r/c4%3A2025-12-panoptic-next-core%3AM-14.md
