SHOULD CHECK RETURN DATA FROM CHAINLINK AGGREGATORS
The TwapOracle contract's consult function fetches asset prices from a Chainlink aggregator using latestRoundData but does not check the updatedAt timestamp, so it may use stale prices. If Chainlink fails to start a new round or reach consensus, consumers could continue using outdated data.
Submitted by defsec
Impact
The consult function in the contract TwapOracle.sol fetches the asset price from a Chainlink aggregator using the latestRoundData function. However, there are no checks on timeStamp, resulting in stale prices. The oracle wrapper calls out to a chainlink oracle receiving the latestRoundData(). It then checks freshness by verifying that the answer is indeed for the last known round. The returned updatedAt timestamp is not checked.
If there is a problem with chainlink starting a new round and finding consensus on the new value for the oracle (e.g. chainlink nodes abandon the oracle, chain congestion, vulnerability/attacks on the chainlink system) consumers of this contract may continue using outdated stale data (if oracles are unable to submit no new round is started)
Proof of Concept
- Navigate to ”https://github.com/code-423n4/2021-11-vader/blob/607d2b9e253d59c782e921bfc2951184d3f65825/contracts/twap/TwapOracle.sol#L141” contract.
- consult function does not check timestamp on the latestRoundData.
Tools Used
None
Recommended Mitigation Steps
Consider to add checks on the return data with proper revert messages if the price is stale or the round is incomplete, for example:
(uint80 roundID, int256 price, , uint256 timeStamp, uint80 answeredInRound) = ETH_CHAINLINK.latestRoundData();
require(timeStamp != 0, "...");
Consider checking the oracle responses updatedAt value after calling out to chainlinkOracle.latestRoundData() verifying that the result is within an allowed margin of freshness.
- https://docs.chain.link/docs/faq/#how-can-i-check-if-the-answer-to-a-round-is-being-carried-over-from-a-previous-round
- https://blog.openzeppelin.com/secure-smart-contract-guidelines-the-dangers-of-price-oracles/
The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.
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 fails to validate the freshness of the price data returned by Chainlink's latestRoundData, specifically by not checking the updatedAt timestamp.
Impact
If Chainlink fails to start a new round or reach consensus, consumers of this contract may continue using outdated stale data.
What the attacker needed
Chainlink oracle fails to update; Contract uses TwapOracle for pricing
The fix
The TWAP oracle module was completely removed and redesigned from scratch as LBTwap, which is subject to a new audit.
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 an outside service (Chainlink) to get the current price of an asset. The contract asks for the latest price but never checks how old that price is. If the outside service stops updating, the contract keeps using an old price, which could lead to wrong trades or calculations.