Skip to content
Audit finding Intermediate

Should check return data from Chainlink aggregators

The PriceFeed contract fetches asset prices from a Chainlink aggregator but does not check the round ID or whether the answer is carried over from a previous round. An attacker could exploit stale or incomplete price data to manipulate the system, potentially putting funds at risk.

defsec Follow

Originally disclosed on Code4rena

Submitted by defsec, also found by hyh and WatchPug

Impact

The latestRoundData function in the contract PriceFeed.sol fetches the asset price from a Chainlink aggregator using the latestRoundData function. However, there are no checks on roundID.

Stale prices could put funds at risk. According to Chainlink’s documentation, This function does not error if no answer has been reached but returns 0, causing an incorrect price fed to the PriceOracle. The external Chainlink oracle, which provides index price information to the system, introduces risk inherent to any dependency on third-party data sources. For example, the oracle could fall behind or otherwise fail to be maintained, resulting in outdated data being fed to the index price calculations of the liquidity.

Example Medium Issue : https://github.com/code-423n4/2021-08-notional-findings/issues/18

Proof of Concept

  1. Navigate to the following contract.

https://github.com/code-423n4/2021-12-yetifinance/blob/1da782328ce4067f9654c3594a34014b0329130a/packages/contracts/contracts/PriceFeed.sol#L578

  1. Only the following checks are implemented.
    if (!_response.success) {return true;}
    // Check for an invalid roundId that is 0
    if (_response.roundId == 0) {return true;}
    // Check for an invalid timeStamp that is 0, or in the future
    if (_response.timestamp == 0 || _response.timestamp > block.timestamp) {return true;}
    // Check for non-positive price
    if (_response.answer <= 0) {return true;}

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(price > 0, "Chainlink price <= 0");
require(answeredInRound >= roundID, "...");
require(timeStamp != 0, "...");

kingyetifinance (Yeti finance) confirmed:

@LilYeti:

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://github.com/code-423n4/2021-08-notional-findings/issues/92

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

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 contract fails to validate that the Chainlink price answer is from the latest round and that the round is complete, allowing stale or zero prices to be used.

Impact

Stale or incomplete price data could be fed to the system, potentially putting funds at risk.

What the attacker needed

The contract uses Chainlink price feeds; The price feed returns stale or zero data

The fix

The contract should be fixed by adding checks on the return data, such as ensuring the price is positive, the answered round is not older than the round ID, and the timestamp is not zero.

How it was found

  1. Navigate to the PriceFeed contract on GitHub.
  2. Observe that only checks for success, roundId zero, timestamp zero or future, and non-positive price are implemented.

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 relies on an outside service (Chainlink) to get the price of an asset. The contract does not verify that the price is fresh and from the current round. If the price is old or zero, the contract may use a wrong value, which could let someone take advantage of the system.

More by defsec

View all

16 more disclosed reports, best first.

More from Yeti Finance contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.