Stale oracle price: when a contract trusts an old answer
A stale oracle price is an answer from a price feed that no longer matches the market, which a contract still lends, liquidates or mints against because it never checks when the answer was written. Feeds go quiet for ordinary reasons, such as a calm market, a paused feed or a rollup sequencer that stopped. Compare each answer's timestamp with that feed's own update interval, reject zero and negative answers, and decide in code what each function does while the price is stale.
How does an oracle price go stale?
A push oracle writes a new answer on chain only when it has a reason to. Chainlink's feeds update when the off-chain price moves a set distance from the last on-chain answer, or when a heartbeat interval runs out (Chainlink). Between updates the stored answer is old by design. Each read through latestRoundData() comes with startedAt and updatedAt, and Chainlink's API reference lists answeredInRound as deprecated, so updatedAt is the field to check (Chainlink). The caller decides whether it is recent enough.
An answer can be older than it should be for several reasons, and only some of them are failures:
- Nothing moved. In a calm market a feed updates only when its interval runs out, so an answer several hours old can still be right.
- The feed stopped. A feed can be paused, replaced or left without updates, and its last answer stays readable.
- The chain stopped. On a rollup, while the sequencer is down, feeds stop updating and most users can't send transactions to add collateral. When it restarts, the price can jump.
- The answer hit a limit. If a feed has a configured floor or ceiling, a crash through the floor keeps reading as the floor.
- Your own cache is old. A protocol that stores a last good price as a fallback, with no timestamp of its own, can keep serving it long after the feed died.
A contract that ignores updatedAt can't tell any of these apart from a fresh answer. Borrowers then borrow against collateral that has already fallen, liquidators seize positions on a price that has already recovered, and minters mint against yesterday's value. Prices that someone deliberately moves are a different problem, covered on the page about oracle price manipulation.
What does vulnerable code look like?
This lender reads the feed and never looks at when the answer was written.
Vulnerable: the feed's update time is never read (illustrative, not audited code) StaleFeedLender.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IAggregatorV3 {
function decimals() external view returns (uint8);
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
contract StaleFeedLender {
IAggregatorV3 public immutable feed; // USD price of the collateral token
mapping(address => uint256) public collateral; // collateral tokens, 18 decimals
mapping(address => uint256) public debt; // stablecoin owed, 18 decimals
constructor(IAggregatorV3 feed_) {
feed = feed_;
}
function depositCollateral(uint256 amount) external {
collateral[msg.sender] += amount;
// ... pull `amount` collateral tokens from msg.sender
}
// Price with 18 decimals. updatedAt is ignored, so an answer written last week
// looks the same as one written in this block.
function price() public view returns (uint256) {
(, int256 answer, , , ) = feed.latestRoundData();
return uint256(answer) * 1e18 / 10 ** feed.decimals();
}
function borrow(uint256 amount) external {
uint256 newDebt = debt[msg.sender] + amount;
uint256 value = collateral[msg.sender] * price() / 1e18;
require(newDebt * 100 <= value * 75, "undercollateralized");
debt[msg.sender] = newDebt;
// ... send `amount` of the stablecoin to msg.sender
}
}
If the collateral token falls 40% while the feed is stuck, borrow still values it at the old price, and the loan is undercollateralized from the moment it is made. Nothing reverts, so nobody notices until liquidations fail to cover the debt. In a Foundry test, this lender accepted a borrow against an answer three days old.
How do you fix it?
Fixed: a sequencer check, a per-feed age limit, checks on the whole answer, and repayments that keep working (illustrative, not audited code) FreshFeedLender.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IAggregatorV3 {
function decimals() external view returns (uint8);
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
contract FreshFeedLender {
IAggregatorV3 public immutable feed;
IAggregatorV3 public immutable sequencerFeed; // a rollup's sequencer uptime feed, or address(0) on Ethereum
uint256 public immutable maxDelay; // seconds: this feed's heartbeat on this chain, plus a margin
uint256 public constant GRACE_PERIOD = 1 hours; // after the sequencer comes back
uint256 private immutable scale; // 10 ** decimals, read once at deployment
mapping(address => uint256) public collateral;
mapping(address => uint256) public debt;
constructor(IAggregatorV3 feed_, IAggregatorV3 sequencerFeed_, uint256 maxDelay_) {
feed = feed_;
sequencerFeed = sequencerFeed_;
maxDelay = maxDelay_;
scale = 10 ** feed_.decimals();
}
// Price with 18 decimals, and whether it is fresh enough to lend against.
function price() public view returns (uint256 value, bool fresh) {
if (address(sequencerFeed) != address(0)) {
// The uptime feed answers 0 while the sequencer is up and 1 while it is down.
(, int256 status, uint256 since, , ) = sequencerFeed.latestRoundData();
if (status != 0 || since == 0 || block.timestamp - since <= GRACE_PERIOD) return (0, false);
}
try feed.latestRoundData() returns (uint80, int256 answer, uint256, uint256 updatedAt, uint80) {
if (answer <= 0 || updatedAt == 0 || updatedAt > block.timestamp) return (0, false);
// forge-lint: disable-next-line(unsafe-typecast)
value = uint256(answer) * 1e18 / scale; // answer > 0 was checked on the line above
fresh = block.timestamp - updatedAt <= maxDelay;
} catch {
return (0, false); // a feed that reverts is treated like a stale one
}
}
// Lowers risk, so it never waits for the feed.
function depositCollateral(uint256 amount) external {
collateral[msg.sender] += amount;
// ... pull `amount` collateral tokens from msg.sender
}
// Adds risk, so it needs a fresh price.
function borrow(uint256 amount) external {
(uint256 p, bool fresh) = price();
require(fresh, "stale price");
uint256 newDebt = debt[msg.sender] + amount;
require(newDebt * 100 <= collateral[msg.sender] * p / 1e18 * 75, "undercollateralized");
debt[msg.sender] = newDebt;
// ... send `amount` of the stablecoin to msg.sender
}
// Lowers risk, so it works whatever the feed is doing.
function repay(uint256 amount) external {
debt[msg.sender] -= amount;
// ... pull `amount` of the stablecoin from msg.sender
}
}
- Set the age limit per feed. Look up the update interval of the exact feed on the exact chain you use and add a margin. One constant for every feed is too long for some and too short for others, and too short turns a calm market into an outage.
- Check the whole answer. Reject a zero or negative answer and a zero or future
updatedAt, and scale by the feed's own decimals, which the fixed lender reads once at deployment. - Fail closed only where it matters. Borrowing and withdrawing collateral add risk and need a fresh price. Repaying and adding collateral lower risk, so they keep working, and users can still protect their positions while a feed is down.
- Check the sequencer first on rollups. Chainlink publishes sequencer uptime feeds for several rollups: an answer of 0 means up, 1 means down, and Chainlink's sample code refuses prices until a grace period has passed since the restart (Chainlink). The fixed lender does the same, so users can top up before risky actions resume. Chainlink has said it won't add more networks to that list, so on a rollup without a feed you need your own signal.
- Treat a revert as stale. A feed contract can be replaced or start reverting, so the fixed lender wraps the call in
tryand handles a failure the way it handles an old answer, instead of reverting every function that touches the price.
In the same Foundry test, the fixed lender refused to lend on the three-day-old answer, still accepted a repayment, refused while a mock sequencer feed reported down and for the first hour after it came back, and lent normally after that.
How has a stale price been exploited?
| Protocol | Venus Protocol and Blizz Finance |
|---|---|
| Date | 12 May 2022 |
| Chain | BNB Chain (Venus) and Avalanche (Blizz) |
| Loss | $13.5M from Venus and $8.3M from Blizz, by rekt's count |
| What happened | During the LUNA crash, the Chainlink LUNA feeds that both lending protocols read stopped following the market. According to rekt.news, the feed had a minimum price, minAnswer, hardcoded at $0.10. Blizz Finance's post-mortem says its oracle stopped updating with a final price of $0.10, that the team was unaware of Chainlink's minimum price circuit breaker, and that its oracle code, a direct fork of Aave v2, had no logic to handle that case. Venus said on 12 May 2022 that Chainlink had paused the feed, and that LUNA was last listed on Venus at about $0.107 while the market price was $0.01. Attackers bought LUNA at the market price, deposited it as collateral at the frozen price and borrowed other assets against it. |
| Sources | Venus Protocol, Blizz Finance, rekt.news |
Both protocols kept lending against an answer that had stopped moving, while the market price was about a tenth of it. An age check fires only once an answer is older than the feed's heartbeat, which can be too late in a crash, so the checklist below also asks what happens when the market moves past a feed's configured floor.
What should a contract do while the price is stale?
Decide this per function before an outage, not during one. One reasonable split:
| Action | Needs a fresh price? | Why |
|---|---|---|
| Borrow or mint against collateral | Yes | It adds debt at the current price. |
| Withdraw collateral | Yes | It lowers the collateral behind existing debt. |
| Repay debt | No | It only lowers risk, and blocking it traps users. |
| Add collateral | No | Users need it most while prices are moving. |
| Liquidate | Yes | A stale price can seize healthy positions or protect insolvent ones. After an outage, a grace period lets users act first. |
Whatever the split, expose the state, for example a view that returns whether the price is fresh, so keepers, front ends and monitoring see a deliberate pause instead of a stream of failed transactions.
What should a reviewer check?
- For every
latestRoundData()call, isupdatedAtcompared with a maximum age set for that feed on that chain? - Are a zero or negative answer and a zero
updatedAtrejected, and are the feed's decimals applied? - On a rollup, is the sequencer status read before any price, with a grace period after a restart?
- Which functions stop while the price is stale, and can users still repay and add collateral?
- Is there a cached or fallback price, and does it carry its own timestamp and age limit?
- Does the feed have a configured floor or ceiling, and what happens if the market moves past it?
- Can governance replace a feed that stops updating, and how long would that take with the timelock?
- Is there a test that warps time past the age limit and expects borrowing to revert and repaying to succeed?
How does QuillShield check for stale oracle prices?
Whether a price is too old depends on facts outside the code: which feed each asset uses, on which chain, and how often that feed updates. Before an audit you can add context such as the whitepaper, trust assumptions, privileged roles and previous audit reports, so list each feed there with the update interval you expect.
QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep. For this class, the adapter that reads a feed and every function that acts on its answer have to be reviewed together, because the age check belongs in one and the damage happens in the other.
A separate reviewer agent tries to disprove every finding before you see it, and each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, a proof of concept. It then checks every pull request on GitHub or GitLab.com against that graph. New collateral types and feed swaps tend to arrive as small pull requests long after launch, so that second check matters as much as the first audit.
Run a full audit on the contracts that read prices. Sign-up is free. New accounts get $50 in credit, good for up to half of an order. For a launch you can also request a manual audit from QuillAudits.
FAQ
How old is too old for an oracle price?
Older than that feed's update interval plus a small margin. The interval differs between feeds and between chains, so store a maximum age for each feed instead of one number for all of them.
Is checking updatedAt enough?
No. Also reject zero and negative answers, apply the feed's decimals and, on a rollup, check the sequencer status first. A fresh answer can still be wrong, which is what price bounds and a second source are for.
Can a fresh price still be the wrong price?
Yes. After Moonwell executed governance proposal MIP-X43 on 15 February 2026, one configuration priced cbETH from the cbETH/ETH rate alone, about $1.12 instead of about $2,200, and Moonwell was left with about $1.78M of bad debt, as The Block reported. An age check doesn't catch a price in the wrong unit; a bound on the expected range does.
Should a stale price make every function revert?
No. Stop the actions that add risk, such as borrowing and withdrawing collateral, and keep repayments and collateral deposits open, so a stuck feed doesn't trap users.
Can a staleness check cause an outage?
Yes. If the age limit is shorter than the feed's normal update interval, a calm market trips it. Set the limit from the feed's documented interval, and give governance a way to replace a feed that has stopped.
Sources
- What are deviation thresholds?, Chainlink checked 3 December 2026
- Data Feeds API reference, Chainlink docs checked 3 December 2026
- L2 sequencer uptime feeds, Chainlink docs checked 3 December 2026
- DeFi lending protocol Moonwell hit with $1.8 million bad debt after oracle misconfiguration, The Block checked 24 November 2026
- Oracle error leaves DeFi lender Moonwell with $1.8 million in bad debt, Decrypt checked 24 November 2026
- Venus Protocol Official Statement regarding LUNA, Venus Protocol checked 3 December 2026
- Blizz Finance Post Mortem, Blizz Finance checked 3 December 2026
- Blizz Finance, Venus Protocol REKT, rekt.news checked 3 December 2026