Staleness

The condition where oracle data or moving average values are outdated and no longer reflect current market conditions.

Staleness in DeFi refers to the condition where price data, oracle feeds, or moving average values have not been updated recently enough to accurately reflect current market conditions. Stale data is one of the most common sources of DeFi exploits, as protocols that rely on outdated prices may allow under-collateralized borrowing, incorrect liquidations, or mispriced trades.

How staleness occurs

  • Low trading activity: On-chain TWAP oracles only update when trades occur. Illiquid pools may go hours without an update.
  • Network congestion: High gas prices may delay oracle update transactions.
  • Oracle downtime: External oracle networks like Chainlink may experience temporary outages or delayed heartbeats.
  • Moving average lag: By design, moving averages incorporate historical data, creating inherent delay in reflecting current prices.

Security impact

Consider a lending protocol using a 24-hour moving average for collateralization ratios:

1Time T: ETH price = $2,000 | Moving average = $2,000 | Collateral healthy
2Time T+1h: ETH crashes to $1,500 | Moving average ≈ $1,980 | Protocol thinks collateral is still sufficient

The moving average hasn't caught up to the real price drop. During this window, users could take out loans against collateral that is effectively worth less than the protocol believes, creating bad debt.

Staleness checks

Protocols should implement explicit staleness validation:

1(, int256 price,, uint256 updatedAt,) = priceFeed.latestRoundData();
2require(block.timestamp - updatedAt < MAX_STALENESS, "Stale price data");
3require(price > 0, "Invalid price");

For moving averages, check that enough recent observations exist:

1require(lastObservationTimestamp + MAX_OBSERVATION_AGE > block.timestamp, "Moving average stale");

Mitigation strategies

  • Heartbeat checks: Verify oracle data was updated within an acceptable timeframe.
  • Circuit breakers: Pause operations when data freshness cannot be guaranteed.
  • Fallback oracles: Switch to alternative data sources when the primary oracle is stale.
  • Deviation checks: Compare moving average values against spot prices; large deviations may indicate staleness rather than smoothing.

Staleness is a fundamental challenge in any system that uses moving averages or time-delayed price feeds. Protocols must balance the manipulation resistance of smoothed data against the risk of operating on outdated information.

Need expert guidance on Staleness?

Our team at Zealynx has deep expertise in blockchain security and DeFi protocols. Whether you need an audit or consultation, we're here to help.

Get a Quote

oog
zealynx

Subscribe to Our Newsletter

Stay updated with our latest security insights and blog posts

© 2024 Zealynx