[NAZ-M1] Chainlink’s latestRoundData Might Return Stale Results
The contract only checks the updatedAt timestamp from Chainlink's latestRoundData, ignoring other staleness indicators. An attacker could exploit stale prices to cause loss of funds to end-users.
Submitted by 0xNazgul, also found by 141345, 0x1f8b, ak1, brgltd, cccz, csanuragjain, Dravee, Guardian, hyh, IllIllI, itsmeSTYJ, Jujic, Lambda, pashov, peachtea, rbserver, reassor, Sm4rty, TomJ, and zzzitron
https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L161 https://github.com/code-423n4/2022-08-olympus/blob/main/src/modules/PRICE.sol#L170
Across these contracts, you are using Chainlink’s latestRoundData API, but there is only a check on updatedAt. This could lead to stale prices according to the Chainlink documentation:
The result of latestRoundData API will be used across various functions, therefore, a stale price from Chainlink can lead to loss of funds to end-users.
Recommended Mitigation Steps
Consider adding the missing checks for stale data.
For example:
(uint80 roundID ,answer,, uint256 timestamp, uint80 answeredInRound) = AggregatorV3Interface(chainLinkAggregatorMap[underlying]).latestRoundData();
require(answer > 0, "Chainlink price <= 0");
require(answeredInRound >= roundID, "Stale price");
require(timestamp != 0, "Round not complete");
Oighty (Olympus) confirmed and commented:
Agree. We’ll add the additional checks.
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 only checks the updatedAt timestamp from latestRoundData and does not verify that the answer is positive, that answeredInRound is at least roundID, or that timestamp is non-zero.
Impact
A stale price from Chainlink could lead to loss of funds to end-users.
What the attacker needed
Chainlink price feed returns stale data
The fix
The contract should be fixed by adding checks for stale data, such as requiring answer > 0, answeredInRound >= roundID, and timestamp != 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 uses a price feed from Chainlink to get the latest price of an asset. The contract only checks when the price was last updated, but not whether the price is actually fresh according to other checks. If the price is stale, the contract might use an old price, which could be exploited to cause financial loss.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.