Different Oracle issues can return outdated prices
The oracle contract's timestamp check only verifies that the timestamp is not zero, so it accepts prices that are years old. An attacker could exploit this to use outdated prices, potentially causing economic losses.
Submitted by 0x1f8b, also found by 0x4non, ak1, async, Chom, cryptphi, csanuragjain, datapunk, hyh, JC, Jeiwan, ladboy233, Lambda, leosathya, nalus, pashov, PwnPatrol, Rolezn, scaraven, and unforgiven
Impact
Different problems have been found with the use of the oracle that can incur economic losses when the oracle is not consumed in a completely safe way.
Proof of Concept
The problems found are:
- The
timeStampcheck is not correct since in both cases it is done against 0, which would mean that a date of 2 years ago would be valid, so old prices can be taken.
function getLatestPrice(address _token)
public
view
returns (int256 nowPrice)
{
...
if(timeStamp == 0)
revert TimestampZero();
return price;
}
- Oracle price 1 can be outdated:
The latestRoundData method of the PegOracle contract calls priceFeed1.latestRoundData(); directly, but does not perform the necessary round or timestamp checks, and delegates them to the caller, but these checks are performed on price2 because it calls getOracle2_Price in this case, this inconsistency between how it take the price1 and price2 behaves favors human errors when consuming the oracle.
Recommended Mitigation Steps
For the timestamp issue, it should be checked like this:
+ uint constant observationFrequency = 1 hours;
function getLatestPrice(address _token)
public
view
returns (int256 nowPrice)
{
...
(
uint80 roundID,
int256 price,
,
uint256 timeStamp,
uint80 answeredInRound
) = priceFeed.latestRoundData();
uint256 decimals = 10**(18-(priceFeed.decimals()));
price = price * int256(decimals);
if(price <= 0)
revert OraclePriceZero();
if(answeredInRound < roundID)
revert RoundIDOutdated();
- if(timeStamp == 0)
+ if(timeStamp < block.timestamp - uint256(observationFrequency))
revert TimestampZero();
return price;
}
MiguelBits (Y2K Finance) confirmed
HickupHH3 (judge) decreased severity to Medium and commented:
Agree with the issue, but disagree with severity given. Checking for stale prices have historically been given a Medium severity rating; there isn’t a compelling argument made IMO to increase it to High.
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 timestamp check only compares against zero instead of checking for staleness relative to the current block time.
Impact
Old prices can be taken, which can incur economic losses when the oracle is not consumed in a completely safe way.
What the attacker needed
Oracle used without additional checks
The fix
The timestamp check should be changed to reject prices older than a set observation frequency, such as one hour.
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.
An oracle is a service that feeds outside data, like prices, into a smart contract. This contract only checked that the price's timestamp was not zero, so it would accept a price from two years ago as if it were current. That could let someone take advantage of old prices to cause financial harm.