PriceOracle has invalid checks on price staleness
The price oracle contract used two invalid checks to detect stale Chainlink prices: it only verified that the update timestamp was non-zero and that a deprecated round field was not less than the round ID. An attacker could exploit a stale price to borrow or liquidate at an incorrect value.
Submitted by oakcobalt, also found by Ch_301, bin2chen, and SpicyMeatball
There are two checks on price staleness in PriceOracle::getAssetPriceFromChainlink, but both checks are invalid.
updatedAt != 0- In chainlink aggregator, the price is updated at a set heartbeat and a threshold of deviation.updatedAtshould be used to check if the answer is within the heartbeat or acceptable time limits. See doc.answeredInRound >= roundId-answeredInRoundis deprecated and shouldn’t be used. See doc.
//src/PriceOracle.sol
/// @notice Query the price of asset from chainlink oracle
function getAssetPriceFromChainlink(address asset) public view returns (uint256) {
AggregatorV2V3Interface sourceAgg = assetChainlinkAggregators[asset];
require(address(sourceAgg) != address(0), Errors.ASSET_AGGREGATOR_NOT_EXIST);
(uint80 roundId, int256 answer, , uint256 updatedAt, uint80 answeredInRound) = sourceAgg.latestRoundData();
require(answer > 0, Errors.ASSET_PRICE_IS_ZERO);
|> require(updatedAt != 0, Errors.ORACLE_PRICE_IS_STALE);
|> require(answeredInRound >= roundId, Errors.ORACLE_PRICE_IS_STALE);
return uint256(answer);
}
Recommended Mitigation Steps
Consider using asset-specific heartbeat (e.g., ETH/USD has 1 hour heartbeat) and check against (block.timestamp - updatedAt).
Assessed type
Oracle
thorseldon (BendDAO) acknowledged and commented:
Checking the stale interval or grace period of oracle price, it’s maybe better do this as suggested, but it’s hard to set or predict the appropriate interval time.
We suggest adjust the severity level to informative.
Historically, findings like this which can have a price impact were awarded with Medium severity on C4.
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 code did not compare the price update time against a heartbeat or acceptable age, and relied on a deprecated field for round completeness.
Impact
A stale price could be used, potentially allowing borrowing or liquidation at an incorrect value, though the report does not demonstrate a concrete exploit.
What the attacker needed
A stale Chainlink price feed
The fix
The oracle should check that the price is not older than an asset-specific heartbeat by comparing the current block timestamp with the update timestamp.
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 price oracle is a service that tells a smart contract the current price of an asset. This contract tried to make sure the price was fresh, but its checks were wrong: one only checked that a timestamp existed, and the other used a field that Chainlink no longer supports. So the contract could accept an old price, and someone might use that to borrow too much or trigger unfair liquidations.