Skip to content
Audit finding Intermediate

SHOULD CHECK RETURN DATA FROM CHAINLINK AGGREGATORS

The TwapOracle contract's consult function fetches asset prices from a Chainlink aggregator using latestRoundData but does not check the updatedAt timestamp, so it may use stale prices. If Chainlink fails to start a new round or reach consensus, consumers could continue using outdated data.

defsec Follow

Originally disclosed on Code4rena

Submitted by defsec

Impact

The consult function in the contract TwapOracle.sol fetches the asset price from a Chainlink aggregator using the latestRoundData function. However, there are no checks on timeStamp, resulting in stale prices. The oracle wrapper calls out to a chainlink oracle receiving the latestRoundData(). It then checks freshness by verifying that the answer is indeed for the last known round. The returned updatedAt timestamp is not checked.

If there is a problem with chainlink starting a new round and finding consensus on the new value for the oracle (e.g. chainlink nodes abandon the oracle, chain congestion, vulnerability/attacks on the chainlink system) consumers of this contract may continue using outdated stale data (if oracles are unable to submit no new round is started)

Proof of Concept

  1. Navigate to ”https://github.com/code-423n4/2021-11-vader/blob/607d2b9e253d59c782e921bfc2951184d3f65825/contracts/twap/TwapOracle.sol#L141” contract.
  2. consult function does not check timestamp on the latestRoundData.

Tools Used

None

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(timeStamp != 0, "...");

Consider checking the oracle responses updatedAt value after calling out to chainlinkOracle.latestRoundData() verifying that the result is within an allowed margin of freshness.

SamSteinGG (Vader) confirmed

The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.

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

The contract fails to validate the freshness of the price data returned by Chainlink's latestRoundData, specifically by not checking the updatedAt timestamp.

Impact

If Chainlink fails to start a new round or reach consensus, consumers of this contract may continue using outdated stale data.

What the attacker needed

Chainlink oracle fails to update; Contract uses TwapOracle for pricing

The fix

The TWAP oracle module was completely removed and redesigned from scratch as LBTwap, which is subject to a new audit.

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 uses an outside service (Chainlink) to get the current price of an asset. The contract asks for the latest price but never checks how old that price is. If the outside service stops updating, the contract keeps using an old price, which could lead to wrong trades or calculations.

More by defsec

View all

16 more disclosed reports, best first.

More from Vader Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.