Chainlink’s latestRoundData might return stale or incorrect results
The Chainlink price oracle contract reads the latest round data without checking whether the returned price is stale or from an incomplete round. An attacker could exploit stale or incorrect prices to manipulate the protocol's valuation of assets.
Submitted by cccz, also found by 0xDjango, 0xkatana, berndartmueller, defsec, Dravee, fatimanaz, IllIllI, jah, kebabsec, kenta, pedroais, peritoflores, rayn, reassor, tabish, and WatchPug_
On ChainlinkPriceOracle.sol, we are using latestRoundData, but there is no check if the return value indicates stale data.
(, int basePrice, , , ) = baseAggregator.latestRoundData();
(, int quotePrice, , , ) = assetInfo.aggregator.latestRoundData();
This could lead to stale prices according to the Chainlink documentation:
https://docs.chain.link/docs/historical-price-data/#historical-rounds https://docs.chain.link/docs/faq/#how-can-i-check-if-the-answer-to-a-round-is-being-carried-over-from-a-previous-round
Proof of Concept
ChainlinkPriceOracle.sol#L83-L84
Recommended Mitigation Steps
Consider adding missing checks for stale data.
For example:
(uint80 baseRoundID, int256 basePrice, , uint256 baseTimestamp, uint80 BaseAnsweredInRound) = baseAggregator.latestRoundData();
(uint80 quoteRoundID, int256 quotePrice, , uint256 quoteTimestamp, uint80 quoteAnsweredInRound) = assetInfo.aggregator.latestRoundData();
require(BaseAnsweredInRound >= baseRoundID && quoteAnsweredInRound >= quoteRoundID, "Stale price");
require(baseTimestamp != 0 && quoteTimestamp != 0 ,"Round not complete");
require(basePrice > 0 && quotePrice > 0,"Chainlink answer reporting 0");
olivermehr (Phuture Finance) confirmed
Confirming medium issue across the board.
Context
Phuture is a DeFi protocol whose contracts include a price oracle built on Chainlink. The contract in question, ChainlinkPriceOracle.sol, reads prices from Chainlink aggregators and uses them to value assets. Chainlink aggregators expose their data through latestRoundData(), which returns the round ID, the answer (price), the started-at timestamp, the updated-at timestamp and the answered-in-round value. A consumer is expected to inspect those fields to decide whether the answer is fresh and complete before trusting it.
Setup
The finding comes from a Code4rena audit of the Phuture codebase. The relevant code is in contracts/ChainlinkPriceOracle.sol, specifically lines 83 and 84. No special accounts, roles or tooling are needed to see the issue: it is a source-level review of how the oracle consumes Chainlink data.
Finding it
The researcher noticed that the oracle calls latestRoundData() on two aggregators, one for a base asset and one for a quote asset, and destructures only the price field from each result:
(, int basePrice, , , ) = baseAggregator.latestRoundData();
(, int quotePrice, , , ) = assetInfo.aggregator.latestRoundData();
Every other return value is discarded. In particular, the round ID, the timestamps and the answered-in-round value are never examined, so there is no check that the returned price is current. According to the Chainlink documentation, a round can be carried over from a previous round, and a consumer that ignores the metadata cannot tell a fresh answer from a stale one. The researcher cites two Chainlink documentation pages on historical price data and on how to check whether a round's answer is being carried over from a previous round.
The proof of concept is simply the location of the calls: ChainlinkPriceOracle.sol#L83-L84 in the 2022-04-phuture repository.
Exploitation
The report does not describe an exploitation procedure, only the code path that produces the risk. The steps below follow the code as shown.
Step 1: Read the base price
The first call fetches the base asset price from baseAggregator:
(, int basePrice, , , ) = baseAggregator.latestRoundData();
Only basePrice is kept. The round ID, timestamps and answered-in-round value returned alongside it are dropped.
Step 2: Read the quote price
The second call does the same for the quote asset through assetInfo.aggregator:
(, int quotePrice, , , ) = assetInfo.aggregator.latestRoundData();
Again, only the price is retained.
Step 3: Use the prices
Because neither call validates its metadata, the two prices are used as if they were fresh and complete. If Chainlink is carrying an answer over from a previous round, or a round has not completed, the oracle has no way to detect it and will return a stale or otherwise incorrect price.
Root cause
The mistake is that the contract trusts the answer from latestRoundData() without validating the fields that describe the round. Chainlink's own documentation states that consumers should check whether the answer is being carried over from a previous round, and the oracle here does not. The existing code has no defence against this because it never reads the values that would allow such a check: the destructuring pattern discards them at the point of the call.
Impact
The oracle can return stale or incorrect prices. The report does not go further into which downstream functions consume the price or what an attacker could gain from manipulating it; it states the risk as stale prices leading to incorrect results. The judge confirmed the issue as medium across the board, and the finding was reported by cccz and also found by 0xDjango, 0xkatana, berndartmueller, defsec, Dravee, fatima*naz, IllIllI, jah, kebabsec, kenta, pedroais, peritoflores, rayn, reassor, tabish and WatchPug.
Fix
The recommendation is to add the missing checks for stale data. The report gives this example:
(uint80 baseRoundID, int256 basePrice, , uint256 baseTimestamp, uint80 BaseAnsweredInRound) = baseAggregator.latestRoundData();
(uint80 quoteRoundID, int256 quotePrice, , uint256 quoteTimestamp, uint80 quoteAnsweredInRound) = assetInfo.aggregator.latestRoundData();
require(BaseAnsweredInRound >= baseRoundID && quoteAnsweredInRound >= quoteRoundID, "Stale price");
require(baseTimestamp != 0 && quoteTimestamp != 0 ,"Round not complete");
require(basePrice > 0 && quotePrice > 0,"Chainlink answer reporting 0");
The first require rejects answers carried over from a previous round by comparing the answered-in-round value with the round ID. The second rejects rounds that have not completed, detected by a zero timestamp. The third rejects zero or negative answers. The report does not state whether the fix was applied; the Phuture contact olivermehr confirmed the finding.
Variants to test
- Search for
latestRoundData()calls that destructure only the price, as here. A positive result is a call where the round ID, timestamps or answered-in-round values are discarded and never checked elsewhere. - Look for checks that compare only the timestamp against
block.timestampwithout the answered-in-round comparison. A positive result is a consumer that would still accept an answer carried over from a previous round. - Look for consumers that do not reject zero or negative answers. A positive result is a price of zero or below flowing into valuation or liquidation logic.
- Look for the same pattern in derived or wrapper oracles that call other oracles. A positive result is a wrapper that passes through a price without revalidating the underlying round metadata.
Hunting notes
This kind of bug hides in oracle adapter contracts, price feed wrappers and any code that consumes Chainlink aggregators. During recon, grep the codebase for latestRoundData and getRoundData and inspect how the return tuple is destructured; a tuple with empty slots where the round ID or timestamps should be is the signal. The researcher tied the missing checks to Chainlink's documented behaviour around carried-over rounds and pointed to the exact lines, and the judge confirmed it as medium across the board.
What happened, in plain words
Phuture is a DeFi protocol. DeFi stands for decentralised finance: software that runs on a blockchain and lets people trade, lend or hold financial products without a traditional bank in the middle. Like any financial system, Phuture needs to know what things are worth. It gets those prices from Chainlink.
Chainlink is a service that delivers real-world data, such as the price of an asset, onto a blockchain. It does this through pieces of software called aggregators. Each aggregator collects prices from many places and publishes a single agreed answer. A contract that wants a price asks the aggregator for it.
The contract in this report, ChainlinkPriceOracle.sol, is Phuture's price oracle. An oracle is simply a bridge between the outside world and the blockchain: the blockchain cannot look up a price on the internet by itself, so it asks an oracle. This oracle reads prices from Chainlink aggregators and uses them to value assets.
The problem is that the oracle asks Chainlink for a price and then throws away almost everything Chainlink sends back. Chainlink does not just send a number. It sends a number plus information about that number: which round it came from, when the round started, when it was last updated, and whether the answer was actually produced in that round or carried over from an earlier one. A careful consumer of Chainlink data is supposed to look at that extra information and decide whether the price is fresh and complete before trusting it. Phuture's oracle does not. It takes the number and ignores the rest, so it cannot tell a current price from an old one.
That is the whole finding. It is a missing check, not a break-in. The researcher who reported it, cccz, was not alone: the same issue was also found by 0xDjango, 0xkatana, berndartmueller, defsec, Dravee, fatima*naz, IllIllI, jah, kebabsec, kenta, pedroais, peritoflores, rayn, reassor, tabish and WatchPug. The judge rated it medium severity, and Phuture's contact olivermehr confirmed it.
Context
To follow the rest of this article you only need a few ideas.
A smart contract is a program that lives on a blockchain. Once deployed, it runs exactly as written, and anyone can call the functions it exposes. ChainlinkPriceOracle.sol is one such contract. The .sol ending means it is written in Solidity, the most common language for smart contracts.
Chainlink aggregators expose their data through a function called latestRoundData(). A function is a named block of code you can call, and it can hand back several values at once. latestRoundData() hands back five values, in this order:
- the round ID, a number identifying which update round the answer belongs to;
- the answer itself, which in this case is the price;
- the started-at timestamp, when that round began;
- the updated-at timestamp, when the answer was last written;
- the answered-in-round value, which records the round in which the answer was actually produced.
A timestamp is a moment in time recorded as a number. A consumer of Chainlink data is expected to inspect these fields to decide whether the answer is fresh and complete before trusting it. Think of a milk carton: the price is the milk, and the round data is the date stamp. If you only look at the milk and never at the date, you have no idea whether it is still good.
Setup
The finding comes from a Code4rena audit of the Phuture codebase. Code4rena is a platform where many independent researchers review the same code and submit findings, and a judge then decides which findings are valid and how serious they are.
The relevant code is in contracts/ChainlinkPriceOracle.sol, specifically lines 83 and 84. No special accounts, roles or tooling are needed to see the issue. It is a source-level review: you read the code and reason about what it does. There is nothing to install and nothing to run.
Finding it
The researcher noticed that the oracle calls latestRoundData() on two aggregators, one for a base asset and one for a quote asset, and keeps only the price field from each result:
(, int basePrice, , , ) = baseAggregator.latestRoundData();
(, int quotePrice, , , ) = assetInfo.aggregator.latestRoundData();
Line by line:
(, int basePrice, , , )is a pattern for receiving several values at once while naming only some of them. The commas with nothing between them are empty slots. The first slot, the round ID, is left empty. The second slot is namedbasePriceand declared as anint, a whole number that can be negative. The third, fourth and fifth slots, the two timestamps and the answered-in-round value, are also left empty.= baseAggregator.latestRoundData();calls the aggregator stored under the namebaseAggregatorand asks it for its latest round data. The five returned values are placed into the five slots, and the four unnamed ones are simply discarded.- The second line does exactly the same for the quote asset, through
assetInfo.aggregator, keeping onlyquotePrice.
So every other return value is thrown away. In particular, the round ID, the timestamps and the answered-in-round value are never examined, which means there is no check that the returned price is current. According to the Chainlink documentation, a round can be carried over from a previous round. In plain terms, Chainlink may keep serving the last known answer when a new one has not arrived yet, and it flags this in the round data. A consumer that ignores the metadata cannot tell a fresh answer from a stale one, just as someone reading only the milk and not the date cannot tell whether it is still drinkable.
The researcher cites two Chainlink documentation pages: one on historical price data and one on how to check whether a round's answer is being carried over from a previous round.
The proof of concept is simply the location of the calls: ChainlinkPriceOracle.sol#L83-L84 in the 2022-04-phuture repository. A proof of concept is normally a demonstration that a problem is real; here it is just the pointer to the exact lines, because the problem is visible by reading them.
Exploitation
The report does not describe an exploitation procedure, only the code path that produces the risk. In other words, it does not walk through an attacker taking money or breaking the protocol. It shows where the unsafe read happens and explains what could go wrong as a result. The steps below follow the code as shown.
Step 1: Read the base price
The first call fetches the base asset price from baseAggregator:
(, int basePrice, , , ) = baseAggregator.latestRoundData();
Only basePrice is kept. The round ID, timestamps and answered-in-round value returned alongside it are dropped. This step matters because it is the moment the safety information is lost: after this line, the contract has no way to ask itself whether the price it just received was fresh.
Step 2: Read the quote price
The second call does the same for the quote asset through assetInfo.aggregator:
(, int quotePrice, , , ) = assetInfo.aggregator.latestRoundData();
Again, only the price is retained. A base asset and a quote asset are the two sides of a price pair: if you want the value of one asset expressed in another, you need both prices. Both reads suffer from the same omission, so the problem is not limited to one side of the pair.
Step 3: Use the prices
Because neither call validates its metadata, the two prices are used as if they were fresh and complete. If Chainlink is carrying an answer over from a previous round, or a round has not completed, the oracle has no way to detect it and will return a stale or otherwise incorrect price. Stale here means old: a price that was correct at some earlier moment but may no longer reflect the market. The oracle passes it on regardless, and whatever uses that price downstream is working from a number nobody checked.
Root cause
The mistake is that the contract trusts the answer from latestRoundData() without validating the fields that describe the round. Chainlink's own documentation states that consumers should check whether the answer is being carried over from a previous round, and the oracle here does not. The existing code has no defence against this because it never reads the values that would allow such a check: the destructuring pattern discards them at the point of the call. Once a value has been dropped, no later line can inspect it.
Impact
The oracle can return stale or incorrect prices. The report does not go further into which downstream functions consume the price or what an attacker could gain from manipulating it; it states the risk as stale prices leading to incorrect results. The judge confirmed the issue as medium across the board. The judge rated it medium severity. The finding was reported by cccz and also found by 0xDjango, 0xkatana, berndartmueller, defsec, Dravee, fatima*naz, IllIllI, jah, kebabsec, kenta, pedroais, peritoflores, rayn, reassor, tabish and WatchPug.
Fix
The recommendation is to add the missing checks for stale data. The report gives this example:
(uint80 baseRoundID, int256 basePrice, , uint256 baseTimestamp, uint80 BaseAnsweredInRound) = baseAggregator.latestRoundData();
(uint80 quoteRoundID, int256 quotePrice, , uint256 quoteTimestamp, uint80 quoteAnsweredInRound) = assetInfo.aggregator.latestRoundData();
require(BaseAnsweredInRound >= baseRoundID && quoteAnsweredInRound >= quoteRoundID, "Stale price");
require(baseTimestamp != 0 && quoteTimestamp != 0 ,"Round not complete");
require(basePrice > 0 && quotePrice > 0,"Chainlink answer reporting 0");
Line by line:
- The first line calls
latestRoundData()onbaseAggregatoragain, but this time it names four of the five values:baseRoundID(auint80, an unsigned whole number that cannot be negative),basePrice(anint256, a signed whole number),baseTimestamp(auint256) andBaseAnsweredInRound(auint80). Only the third slot, the started-at timestamp, is still left empty. Nothing is thrown away that the checks below need. - The second line does the same for the quote asset, naming
quoteRoundID,quotePrice,quoteTimestampandquoteAnsweredInRound. - The third line is a
require, a statement that stops the whole call with an error message if its condition is false. It checks thatBaseAnsweredInRound >= baseRoundIDand thatquoteAnsweredInRound >= quoteRoundID. If either fails, the call reverts with the message"Stale price". This rejects answers carried over from a previous round, because the answered-in-round value would then be lower than the round ID. - The fourth line requires both timestamps to be non-zero, reverting with
"Round not complete". A zero timestamp means the round has not finished, so there is no settled answer to use. - The fifth line requires both prices to be greater than zero, reverting with
"Chainlink answer reporting 0". This rejects zero or negative answers, which are not usable prices.
The report does not state whether the fix was applied. The Phuture contact olivermehr confirmed the finding.
Variants to test
If you were reviewing other code for the same mistake, these are the shapes to look for.
- Search for
latestRoundData()calls that keep only the price, as here. A positive result is a call where the round ID, timestamps or answered-in-round values are discarded and never checked elsewhere. - Look for checks that compare only the timestamp against
block.timestampwithout the answered-in-round comparison.block.timestampis the current time according to the blockchain. A positive result is a consumer that would still accept an answer carried over from a previous round. - Look for consumers that do not reject zero or negative answers. A positive result is a price of zero or below flowing into valuation or liquidation logic. Valuation means working out what something is worth; liquidation means forcibly closing a position.
- Look for the same pattern in derived or wrapper oracles that call other oracles. A wrapper is a contract that sits in front of another one and passes its results through, perhaps with adjustments. A positive result is a wrapper that passes through a price without revalidating the underlying round metadata.
Hunting notes
This kind of bug hides in oracle adapter contracts, price feed wrappers and any code that consumes Chainlink aggregators. During recon, meaning the early phase where you map out a codebase before testing, grep the codebase for latestRoundData and getRoundData and inspect how the return tuple is destructured. A tuple is simply an ordered group of values, and destructuring is the act of unpacking it into named variables. A tuple with empty slots where the round ID or timestamps should be is the signal. The researcher tied the missing checks to Chainlink's documented behaviour around carried-over rounds and pointed to the exact lines, and the judge confirmed it as medium across the board.
Glossary
- Aggregator: a Chainlink component that collects prices from many sources and publishes one agreed answer.
- Blockchain: a shared, append-only record of transactions maintained by many computers, on which smart contracts run.
block.timestamp: the current time according to the blockchain, available to contracts.- Chainlink: a service that delivers outside data, such as asset prices, to blockchains.
- Code4rena: a platform where many researchers audit the same code and a judge rates the submitted findings.
- Consumer (of an oracle): a contract that reads data from an oracle and uses it.
- DeFi: decentralised finance, financial software running on a blockchain without a traditional intermediary.
- Destructuring: unpacking a group of returned values into named variables, optionally leaving some slots empty.
- Function: a named block of code that can be called and can return values.
getRoundData: a Chainlink function that returns the data for a specific round, as opposed to the latest one.int/int256: a signed whole number in Solidity, which may be negative.latestRoundData(): a Chainlink function that returns the latest round's ID, answer, started-at timestamp, updated-at timestamp and answered-in-round value.- Liquidation: forcibly closing a position, typically because it no longer meets required collateral.
- Medium severity: an audit rating for a real issue that should be fixed but is not described as an immediate direct loss of funds.
- Oracle: a bridge that brings outside data, such as prices, onto a blockchain.
- Phuture: the DeFi protocol whose code was audited here.
- Proof of concept: a demonstration that a reported problem is real; here, the pointer to the exact lines.
- Recon: the early phase of mapping out a codebase before testing it.
require: a Solidity statement that stops execution with an error message if its condition is false.- Revert: to abort a contract call and undo its changes, usually because a
requirefailed. - Round (Chainlink): one update cycle of an aggregator, identified by a round ID and carrying its own timestamps.
- Round ID: the number identifying which Chainlink update round an answer belongs to.
- Answered-in-round: the round in which an answer was actually produced; if it is lower than the round ID, the answer was carried over.
- Smart contract: a program deployed on a blockchain that runs as written and can be called by anyone.
- Solidity: the main programming language for smart contracts; files end in
.sol. - Stale price: an old price that was correct earlier but may no longer reflect the market.
- Timestamp: a moment in time recorded as a number.
- Tuple: an ordered group of values, such as the five values returned by
latestRoundData(). uint80/uint256: unsigned whole numbers in Solidity, which cannot be negative.- Valuation: working out what an asset or position is worth.
- Wrapper (oracle): a contract that sits in front of another oracle and passes its results through, possibly with adjustments.