Chainlink’s latestRoundData might return stale or incorrect results
The smart contracts used Chainlink's latestRoundData without checking whether the returned price was stale or from an incomplete round. An attacker could exploit stale prices to cause incorrect valuations, potentially leading to financial loss.
Submitted by cccz, also found by 0x1f8b, 0xDjango, 0xkatana, berndartmueller, defsec, Dravee, horsefacts, hyh, IllIllI, kenta, rayn, reassor, sorrynotsorry, and WatchPug
On ChainlinkOracleProvider.sol and ChainlinkUsdWrapper.sol , we are using latestRoundData, but there is no check if the return value indicates stale data.
function _ethPrice() private view returns (int256) {
(, int256 answer, , , ) = _ethOracle.latestRoundData();
return answer;
}
...
function getPriceUSD(address asset) public view override returns (uint256) {
address feed = feeds[asset];
require(feed != address(0), Error.ASSET_NOT_SUPPORTED);
(, int256 answer, , uint256 updatedAt, ) = AggregatorV2V3Interface(feed).latestRoundData();
require(block.timestamp <= updatedAt + stalePriceDelay, Error.STALE_PRICE);
require(answer >= 0, Error.NEGATIVE_PRICE);
uint256 price = uint256(answer);
uint8 decimals = AggregatorV2V3Interface(feed).decimals();
return price.scaleFrom(decimals);
}
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
ChainlinkOracleProvider.sol#L55 ChainlinkUsdWrapper.sol#L64
Recommended Mitigation Steps
function _ethPrice() private view returns (int256) {
(uint80 roundID, int256 answer, , uint256 timestamp, uint80 answeredInRound) = _ethOracle.latestRoundData();
require(answeredInRound >= roundID, "Stale price");
require(timestamp != 0,"Round not complete");
require(answer > 0,"Chainlink answer reporting 0");
return answer;
}
...
function getPriceUSD(address asset) public view override returns (uint256) {
address feed = feeds[asset];
require(feed != address(0), Error.ASSET_NOT_SUPPORTED);
(uint80 roundID, int256 answer, , uint256 updatedAt, uint80 answeredInRound) = AggregatorV2V3Interface(feed).latestRoundData();
require(answeredInRound >= roundID, "Stale price");
require(answer > 0," Error.NEGATIVE_PRICE");
require(block.timestamp <= updatedAt + stalePriceDelay, Error.STALE_PRICE);
uint256 price = uint256(answer);
uint8 decimals = AggregatorV2V3Interface(feed).decimals();
return price.scaleFrom(decimals);
}
chase-manning (Backd) confirmed and resolved
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
Likely the contract did not validate the round completeness and staleness of the price data returned by Chainlink's latestRoundData.
Impact
This could lead to stale prices being used, potentially causing incorrect financial decisions in the protocol.
What the attacker needed
None
The fix
The contracts were fixed by adding checks for answeredInRound >= roundID, timestamp != 0, and answer > 0.
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 relies on an external price feed (Chainlink) to get the value of assets. If the price feed returns an old or invalid price, the contract might use it without noticing, which could let someone take advantage of the wrong price.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.