Chainlink’s latestRoundData may return a stale or incorrect result
The contract reads price feed data from Chainlink's latestRoundData without checking the timestamp of the last update, so it may use an outdated price. An attacker could exploit this stale price to cause functions to misbehave or to cause loss of funds.
Madalad Follow with MohammedRizwan, turvy_fuzz and 22 others
Originally disclosed on Code4rena
Submitted by Madalad, also found by MohammedRizwan, turvy_fuzz, Breeje, etherhood, dwward3n, Aymen0909, LaScaloneta, erictee, tallo, DadeKuma, bin2chen, peanuts, Bauchibred, Bauchibred, Bauchibred, Bauchibred, whimints, whimints, piyushshukla, rvierdiiev, saneryee, Hama, Madalad, and kutugu
https://github.com/code-423n4/2023-06-stader/blob/main/contracts/StaderOracle.sol#L646 https://github.com/code-423n4/2023-06-stader/blob/main/contracts/StaderOracle.sol#L648
Chainlink’s latestRoundData is used here to retrieve price feed data; however, there is insufficient protection against price staleness.
Return arguments other than int256 answer are necessary to determine the validity of the returned price, as it is possible for an outdated price to be received. See here for reasons why a price feed might stop updating.
The return value updatedAt contains the timestamp at which the received price was last updated, and can be used to ensure that the price is not outdated. See more information about latestRoundID in the Chainlink docs. Inaccurate price data can lead to functions not working as expected and/or loss of funds.
Proof of Concept
function getPORFeedData()
internal
view
returns (
uint256,
uint256,
uint256
)
{
(, int256 totalETHBalanceInInt, , , ) = AggregatorV3Interface(staderConfig.getETHBalancePORFeedProxy())
.latestRoundData();
(, int256 totalETHXSupplyInInt, , , ) = AggregatorV3Interface(staderConfig.getETHXSupplyPORFeedProxy())
.latestRoundData();
return (uint256(totalETHBalanceInInt), uint256(totalETHXSupplyInInt), block.number);
}
Recommended Mitigation Steps
Add a check for the updatedAt returned value from latestRoundData.
function getPORFeedData()
internal
view
returns (
uint256,
uint256,
uint256
)
{
- (, int256 totalETHBalanceInInt, , , ) = AggregatorV3Interface(staderConfig.getETHBalancePORFeedProxy())
+ (, int256 totalETHBalanceInInt, , uint256 balanceUpdatedAt, ) = AggregatorV3Interface(staderConfig.getETHBalancePORFeedProxy())
.latestRoundData();
+ require(block.timestamp - balanceUpdatedAt <= MAX_DELAY, "stale price");
- (, int256 totalETHXSupplyInInt, , , ) = AggregatorV3Interface(staderConfig.getETHXSupplyPORFeedProxy())
+ (, int256 totalETHXSupplyInInt, , uint256 supplyUpdatedAt, ) = AggregatorV3Interface(staderConfig.getETHXSupplyPORFeedProxy())
.latestRoundData();
+ require(block.timestamp - supplyUpdatedAt <= MAX_DELAY, "stale price");
return (uint256(totalETHBalanceInInt), uint256(totalETHXSupplyInInt), block.number);
}
Assessed type
Oracle
manoj9april (Stader) acknowledged and commented:
Solution with chainlink is not finalized.
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 code calls latestRoundData but ignores the updatedAt timestamp, so it cannot tell whether the returned price is stale.
Impact
Inaccurate price data could lead to functions not working as expected and/or loss of funds.
What the attacker needed
Chainlink feed stops updating
The fix
The contract should check the updatedAt value returned by latestRoundData and reject prices older than a maximum delay.
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 gets price information from an outside service called an oracle. If that service stops updating, the contract might keep using an old price. This report says the contract should check how old the price is before using it.