Chainlink’s latestRoundData might return stale or incorrect results
The smart contract used Chainlink's latestRoundData without checking whether the returned price was stale or invalid. An attacker could exploit this to cause the protocol to use outdated or incorrect prices, potentially leading to financial loss.
Submitted by WatchPug, also found by cmichel, defsec, and ye0lde
function sync() public {
(, int256 feedPrice, , uint256 timestamp, ) = feed.latestRoundData();
Fixed18 price = Fixed18Lib.ratio(feedPrice, SafeCast.toInt256(_decimalOffset));
if (priceAtVersion.length == 0 || timestamp > timestampAtVersion[currentVersion()] + minDelay) {
priceAtVersion.push(price);
timestampAtVersion.push(timestamp);
emit Version(currentVersion(), timestamp, price);
}
}
On ChainlinkOracle.sol, we are using latestRoundData, but there is no check if the return value indicates stale data. 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
Recommendation
Consider adding missing checks for stale data.
For example:
(uint80 roundID, int256 feedPrice, , uint256 timestamp, uint80 answeredInRound) = feed.latestRoundData();
require(feedPrice > 0, "Chainlink price <= 0");
require(answeredInRound >= roundID, "Stale price");
require(timestamp != 0, "Round not complete");
kbrizzle (Perennial) confirmed
Alex the Entreprenerd (judge) commented:
Agree with the finding, while you can get started with Chainlink’s feed can be used with one line of code, in a production environment it is best to ensure that the data is fresh and within rational bounds
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
The contract failed to validate the price feed's round completeness and freshness, as recommended by Chainlink.
Impact
The protocol could operate with stale or incorrect prices, potentially leading to financial losses or unfair trades.
What the attacker needed
None
The fix
The contract should be fixed by adding checks for positive price, round completeness, and freshness as shown in the recommendation.
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.
A smart contract relied on an outside service for price data but didn't verify that the data was recent and valid. If the service returned an old or broken price, the contract would still use it, which could cause problems like wrong trades or losses.