Skip to content
Audit finding Intermediate

Missing check for the max/min price in the chainlinkOracle.sol contract

The Chainlink oracle adapter in Moonwell did not check the aggregator's minimum and maximum answer bounds, so if a feed's price crashed towards the floor (as with LUNA) the oracle would keep returning the floor price rather than reverting. An attacker could then borrow or liquidate against a stale, frozen price.

0xkazim Follow with BRONZEDISC, markus_ether and 9 others

Originally disclosed on Code4rena

Submitted by 0xkazim, also found by BRONZEDISC, markus_ether, Auditwolf, Hama, okolicodes, R-Nemes, kodyvim, nadin, MohammedRizwan, dacian, and niki

The chainlinkOracle.sol contract specially the getChainlinkPrice function using the aggregator v2 and v3 to get/call the latestRoundData. the function should check for the min and max amount return to prevent some case happen, something like this:

https://solodit.xyz/issues/missing-checks-for-chainlink-oracle-spearbit-connext-pdf

https://solodit.xyz/issues/m-16-chainlinkadapteroracle-will-return-the-wrong-price-for-asset-if-underlying-aggregator-hits-minanswer-sherlock-blueberry-blueberry-git

If a case like LUNA happens then the oracle will return the minimum price and not the crashed price.

Proof of Concept

The function getChainlinkPrice:

function getChainlinkPrice(
        AggregatorV3Interface feed
    ) internal view returns (uint256) {
        (, int256 answer, , uint256 updatedAt, ) = AggregatorV3Interface(feed)
            .latestRoundData();
        require(answer > 0, "Chainlink price cannot be lower than 0");
        require(updatedAt != 0, "Round is in incompleted state");

        // Chainlink USD-denominated feeds store answers at 8 decimals
        uint256 decimalDelta = uint256(18).sub(feed.decimals());
        // Ensure that we don't multiply the result by 0
        if (decimalDelta > 0) {
            return uint256(answer).mul(10 ** decimalDelta);
        } else {
            return uint256(answer);
        }
    }

The function did not check for the min and max price.

Recommended Mitigation Steps

Some check like this can be added to avoid returning of the min price or the max price in case of the price crashes.

          require(answer < _maxPrice, "Upper price bound breached");
          require(answer > _minPrice, "Lower price bound breached");

sorrynotsorry (Lookout) commented:

The implementation does not set a min/max value by design. Also Chainlink does not return min/max price as per the AggregatorV3 docs HERE contrary to the reported below;

ChainlinkAggregators have minPrice and maxPrice circuit breakers built into them.

Further proof required as per the context.

alcueca (Judge) commented:

The warden is actually right. It is a bit difficult to find, but the minAnswer and maxAnswer can be retrieved from the Chainlink Aggregator, one step through the proxy. A circuit breaker should be implemented on the Moonwell oracle so that when the price edges close to minAnswer or maxAnswer it starts reverting, to avoid consuming stale prices when Chainlink freezes.

ElliotFriedman (Moonwell) acknowledged


The original report as published on Code4rena, by 0xkazim. 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 oracle adapter read latestRoundData without comparing the answer against the aggregator's minAnswer and maxAnswer circuit breakers, so a frozen feed price was accepted as valid.

Impact

When a feed's price approaches its floor or ceiling, the oracle could consume a stale frozen price, which may let users borrow or be liquidated at an incorrect value; the report does not demonstrate an exploit.

What the attacker needed

A Chainlink feed whose price hits its floor or ceiling

The fix

The oracle should revert when the answer nears the aggregator's minAnswer or maxAnswer, so stale frozen prices are not consumed; the project acknowledged the issue.

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 price oracle is a contract that tells a lending app what an asset is worth. Chainlink feeds have a floor and a ceiling value they will report; if the real price falls below the floor, the feed keeps reporting the floor instead of the true price. This code never checked those limits, so the app could keep trusting a price that no longer reflects reality.

More from Moonwell

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.