Skip to content
Audit finding Intermediate

Lacking Validation Of Chainlink’ Oracle Queries

The TwapOracle.consult() function casts a signed integer price to unsigned without checking for negative values, which could cause an underflow and return an unexpected price. Additionally, the GasThrottle.validateGas() modifier uses Chainlink's latestAnswer() without checking for stale data, so it may act on outdated prices.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

Impact

TwapOracle.consult() is missing additional validations to ensure that the round is complete and has returned a valid/expected price. The consult() improperly casts an int256 price to uint256 without first checking the value. As a result, the variable may underflow and return an unexpected result, potentially causing further issues in other areas of the protocol that rely on this function.

Additionally, the GasThrottle.validateGas() modifier utilises Chainlink’s latestAnswer() function which lacks additional checks for stale data. The latestRoundData() function facilitates additional checks and should be used over latestAnswer().

Proof of Concept

Tools Used

Manual code review. Chainlink best practices.

Recommended Mitigation Steps

Consider validating the output of latestRoundData() to match the following code snippet:

     (
        uint80 roundID,
        int256 price,
        ,
        uint256 updateTime,
        uint80 answeredInRound
      ) = ETH_CHAINLINK.latestRoundData();
      require(
          answeredInRound >= roundID,
          "Chainlink Price Stale"
      );
      require(price > 0, "Chainlink Malfunction");
      require(updateTime != 0, "Incomplete round");

This needs to be updated in TwapOracle.consult() and in GasThrottle.validateGas(). The latter instance should have the latestAnswer() function replaced with latestRoundData() in order to avoid stale data.

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 leastwood. 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 code failed to validate the price returned by Chainlink before using it, missing checks for positive value, round completeness, and staleness.

Impact

The incorrect price could cause further issues in other parts of the protocol that rely on this function, and stale data could lead to decisions based on outdated prices.

What the attacker needed

None

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 reads price data from an outside service called Chainlink. The code did not check that the price was a positive number or that the data was recent. If the price was negative or old, the contract could make decisions based on wrong information.

More by leastwood

View all

70 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.