Lucene search

K
code423n4Code4renaCODE423N4:2023-07-MOONWELL-FINDINGS-ISSUES-340
HistoryJul 31, 2023 - 12:00 a.m.

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

2023-07-3100:00:00
Code4rena
github.com
3
vulnerability
impact
proof of concept
chainlink
oracle
mitigation .

Lines of code

Vulnerability details

Impact

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&gt;
<https://solodit.xyz/issues/m-16-chainlinkadapteroracle-will-return-the-wrong-price-for-asset-if-underlying-aggregator-hits-minanswer-sherlock-blueberry-blueberry-git&gt;

if case like luna happen 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 &gt; 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 &gt; 0) {
            return uint256(answer).mul(10 ** decimalDelta);
        } else {
            return uint256(answer);
        }
    }

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

Tools Used

manual review

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 &lt; _maxPrice, "Upper price bound breached");
          require(answer &gt; _minPrice, "Lower price bound breached");

Assessed type

Oracle


The text was updated successfully, but these errors were encountered:

All reactions