Skip to content
Smart contracts Audit finding Intermediate

outdated variable is not effective to check price feed timeliness

The ChainlinkOraclePivot contract used a single 'outdated' variable to check the timeliness of two price feeds with different heartbeat intervals, making the check ineffective. An attacker could exploit stale prices from one feed or cause the other feed to always revert, potentially affecting rebalancing.

0x007 Follow with 0x52, 0xg0 and 7 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/83

Found by

0x007, 0x52, 0xg0, BenRai, Jeiwan, ast3ros, cergyk, elephant_coral, rvierdiiev, vnavascues

Summary

In ChainlinkOraclePivot, it uses one outdated variable to check if the two price feeds are outdated. However, this is not effective because the price feeds have different update frequencies.

Vulnerability Detail

Let's have an example:

In Polygon mainnet, ChainlinkOraclePivot uses two Chainlink price feeds: MATIC/ETH and ETH/USD.

The setup can be the same in this test case: https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/test/foundry/ChainLinkOraclePivotWrapper.t.sol#L49-L63

We can see that

In function _getLatestRoundData, both price feeds use the same outdated variable.

  • If we set the outdated variable to 27s, the priceFeedA will revert most of the time since it is too short for the 86400s heartbeat.
  • If we set the outdated variable to 86400s, the priceFeedB can have a very outdated value without revert.
JavaScript
        try priceFeedA.latestRoundData() returns (
            uint80,
            int256 price,
            uint256,
            uint256 updatedAt,
            uint80
        ) {
            require(
                block.timestamp - updatedAt <= outdated, // solhint-disable-line not-rely-on-time
                "ChainLinkOracle: priceFeedA outdated."
            );

            priceA = SafeCast.toUint256(price);
        } catch {
            revert("ChainLinkOracle: price feed A call failed.");
        }

        try priceFeedB.latestRoundData() returns (
            uint80,
            int256 price,
            uint256,
            uint256 updatedAt,
            uint80
        ) {
            require(
                block.timestamp - updatedAt <= outdated, // solhint-disable-line not-rely-on-time
                "ChainLinkOracle: priceFeedB outdated."
            );

            priceB = SafeCast.toUint256(price);
        } catch {
            revert("ChainLinkOracle: price feed B call failed.");
        }

https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/oracles/ChainLinkOraclePivot.sol#L239-L271

Impact

The outdated variable is not effective to check the timeliness of prices. It can allow stale prices in one price feed or always revert in another price feed.

Code Snippet

https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/oracles/ChainLinkOraclePivot.sol#L31 https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/oracles/ChainLinkOraclePivot.sol#L239-L271

Tool used

Manual Review

Recommendation

Having two outdated values for each price feed A and B.

Discussion

Gevarist

oracle price check will always revert for few specific feeds. Should not result in fund loss, we are not considering the issue as medium level.

ctf-sec

I think this regular revert impact the rebalance...

#249 describes the issue well as well

recommend maintaining severity level

Gevarist

Yes that can impact rebalance but should not result in fund loss.

Gevarist

You can find the fix here on v2-manager-template repository, we now have two "outdated" variables to check individually if price feeds are outdated.

IAm0x52

Fix looks good. Oracle now has two separate outdated variables to accommodate feeds with different heartbeats

The original report as published on Sherlock, by 0x007. 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

Root cause

Likely the contract used a single 'outdated' threshold for two price feeds with different heartbeat intervals, so the check could not correctly validate both feeds.

Impact

The outdated variable is not effective to check the timeliness of prices. It can allow stale prices in one price feed or always revert in another price feed.

What the attacker needed

None

The fix

The fix was to use two separate 'outdated' variables, one for each price feed, to check individually if they are outdated.

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 used two price sources to calculate values, but checked both with the same time limit. Since one source updates every 27 seconds and the other every 24 hours, the check either rejected the slow source too often or accepted stale data from the fast source. This could lead to incorrect prices being used.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 0x007

View all

25 more disclosed reports, best first.

More from Arrakis Valantis SOT Audit

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.