Skip to content
Audit finding Intermediate

Chainlink's `latestRoundData` might return stale or incorrect results

The smart contract uses Chainlink's latestRoundData() to fetch prices but does not check whether the returned data is stale. An attacker could exploit stale prices to cause incorrect valuations.

jayphbee Follow with hansfriese, 0xNazgul and 15 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-09-knox-judging/issues/137

Found by

jayphbee, hansfriese, 0xNazgul, GalloDaSballo, minhquanym, __141345__, csanuragjain, Olivierdem, joestakey, Ruhum, ctf_sec, cccz, Jeiwan, Trumpero, ArbitraryExecution, ak1, ali_shehab, berndartmueller

Summary

Chainlink's latestRoundData() is used but there is no check if the return value indicates stale data. This could lead to stale prices according to the Chainlink documentation:

Vulnerability Detail

The PricerInternal._latestAnswer64x64 function uses Chainlink's latestRoundData() to get the latest price. However, there is no check if the return value indicates stale data.

Impact

The PricerInternal could return stale price data for the underlying asset.

Code Snippet

PricerInternal._latestAnswer64x64

Solidity
/**
  * @notice gets the latest price of the underlying denominated in the base
  * @return price of underlying asset as 64x64 fixed point number
  */
function _latestAnswer64x64() internal view returns (int128) {
    (, int256 basePrice, , , ) = BaseSpotOracle.latestRoundData();
    (, int256 underlyingPrice, , , ) =
        UnderlyingSpotOracle.latestRoundData();

    return ABDKMath64x64.divi(underlyingPrice, basePrice);
}

Tool Used

Manual review

Recommendation

Consider adding checks for stale data. e.g

Solidity
(uint80 roundId, int256 basePrice, , uint256 updatedAt, uint80 answeredInRound) = BaseSpotOracle.latestRoundData();

require(answeredInRound >= roundId, "Price stale");
require(block.timestamp - updatedAt < PRICE_ORACLE_STALE_THRESHOLD, "Price round incomplete");

Discussion

0xCourtney

https://github.com/KnoxFinance/knox-contracts/pull/85

rcstanciu

Reply from @arbitrary-CodeBeholder


looks good to me

The original report as published on Sherlock, by jayphbee. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

The contract could return stale price data for the underlying asset, potentially leading to incorrect financial decisions.

What the attacker needed

None

The fix

The contract should be fixed by adding checks for stale data, such as verifying that the round is complete and the price is not too old.

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, which can be wrong. This report says the contract should check that the price is recent.

More by jayphbee

View all

2 more disclosed reports, best first.

More from Knox Finance

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.