`Chainlink.latestRoundData()` may return stale results
The Oracle.getUnderlyingPrice() function did not check whether the Chainlink price feed data was stale. An attacker could exploit stale prices to cause incorrect valuations in the InsuranceFund, MarginAccount, and AMM contracts, potentially leading to financial loss.
0x3e84fa45 Follow with 0xbepresent, 0xmuxyz and 25 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-04-hubble-exchange-judging/issues/18
Found by
0x3e84fa45, 0xbepresent, 0xmuxyz, 0xpinky, 0xvj, Bauer, Breeje, BugBusters, BugHunter101, Hama, Kaiziron, MohammedRizwan, PRAISE, Vagner, carrotsmuggler, crimson-rat-reach, darkart, dimulski, dirk_y, kutugu, lemonmon, lil.eth, minhtrng, osmanozdemir1, p-tsanev, rogue-lion-0619, shtesesamoubiq, tsvetanovv
Summary
The Oracle.getUnderlyingPrice() function is used to get the price of tokens, the problem is that the function does not check for stale results.
Vulnerability Detail
The Oracle.getUnderlyingPrice() function is used in InsuranceFund, MarginAccount and AMM contracts. The Oracle.getUnderlyingPrice() helps to determine the tokens prices managed in the contracts.
The problem is that there is not check for stale data. There are some reasons that the price feed can become stale.
Impact
Since the token prices are used in many contracts, stale data could be catastrophic for the project.
Code Snippet
The Oracle.getUnderlyingPrice() is used by the next contracts:
Tool used
Manual review
Recommendation
Read the updatedAt return value from the Chainlink.latestRoundData() function and verify that is not older than than specific time tolerance.
require(block.timestamp - udpatedData < toleranceTime, "stale price");
Discussion
asquare08
will add a tolerance time equal to the max update time of the price feed.
asquare08
Fixed in this PR. The description is in the PR.
IAm0x52
Fix looks good. chainLinkAggregatorMap now stores a struct which contains the oracle address and the heartbeat. getUnderlyingPrice will now revert if price update is outside of heartbeat window
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
Impact
Stale price data could be catastrophic for the project because token prices are used in many contracts, potentially allowing an attacker to exploit outdated prices for profit.
What the attacker needed
Stale price feed; no special access needed
The fix
The fix was to store a heartbeat per aggregator and revert if the price update is outside the heartbeat window.
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.
This report is about a smart contract that uses an external price feed (Chainlink) to get token prices. The contract did not verify that the price data was recent, so if the feed stopped updating, the contract would keep using old prices. That could let someone take advantage of outdated prices to cause financial damage.