Skip to content
DoS Audit finding Intermediate

MixedPriceOracleV4.sol :: getUnderlyingPrice()/getPirce() will not work for some tokens because API3 and EO oracles return prices using different decimals, causing DOS scenario

The price oracle contract compares prices from two oracles that use different decimal precisions, so the difference is always huge and the contract always falls back to the second oracle. If that second oracle's price is stale, the price lookup reverts, causing a denial of service.

0xEkko Follow with 0xfocusNode, 10ap17 and 12 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-07-malda-judging/issues/945

Found by

0xEkko, 0xfocusNode, 10ap17, Cybrid, HeckerTrieuTien, IvanFitro, KiroBrejka, PeterSR, SafetyBytes, ZanyBonzy, Ziusz, axelot, dan__vinci, elolpuer, pashap9990

Summary

getUnderlyingPrice()/getPrice() are used to obtain the price of the assets in USD. It does this by querying two different oracles, in this case, API3 and EO oracles. The problem is that these oracles return prices with different decimals, causing the function to always end up using the EO oracle’s price.

Root Cause

getUnderlyingPrice() calls _getPriceUSD(), which in turn calls _getLatestPrice(), implemented as follows:

Solidity
function _getLatestPrice(string memory symbol, PriceConfig memory config)
        internal
        view
        returns (uint256, uint256)
    {
        if (config.api3Feed == address(0) || config.eOracleFeed == address(0)) revert MixedPriceOracle_MissingFeed();

        //get both prices
@>      (, int256 apiV3Price,, uint256 apiV3UpdatedAt,) = IDefaultAdapter(config.api3Feed).latestRoundData();
@>      (, int256 eOraclePrice,, uint256 eOracleUpdatedAt,) = IDefaultAdapter(config.eOracleFeed).latestRoundData(); 
        // check if ApiV3 price is up to date
        uint256 _staleness = _getStaleness(symbol);
        bool apiV3Fresh = block.timestamp - apiV3UpdatedAt <= _staleness;

        // check delta
@>      uint256 delta = _absDiff(apiV3Price, eOraclePrice);
        uint256 deltaBps = (delta * PRICE_DELTA_EXP) / uint256(eOraclePrice < 0 ? -eOraclePrice : eOraclePrice);

        uint256 deltaSymbol = deltaPerSymbol[symbol];
        if (deltaSymbol == 0) {
            deltaSymbol = maxPriceDelta;
        }

        uint256 decimals;
        uint256 uPrice;
@>        if (!apiV3Fresh || deltaBps > deltaSymbol) {
            require(block.timestamp - eOracleUpdatedAt < _staleness, MixedPriceOracle_eOracleStalePrice());
            decimals = IDefaultAdapter(config.eOracleFeed).decimals();
            uPrice = uint256(eOraclePrice);
         } else {
            require(block.timestamp - apiV3UpdatedAt < _staleness, MixedPriceOracle_ApiV3StalePrice());
            decimals = IDefaultAdapter(config.api3Feed).decimals();
            uPrice = uint256(apiV3Price);
        }

        return (uPrice, decimals);
    }

As you can see, it obtains the price from both oracles and calculates the absolute difference using _absDiff():

Solidity
 function _absDiff(int256 a, int256 b) internal pure returns (uint256) {
        return uint256(a >= b ? a - b : b - a);
    }

The problem is that the oracles do not return prices with the same decimals. According to the documentation, API3 always returns prices with 18 decimals, while the EO oracle almost always returns prices with 8 decimals.

As a result, _absDiff() ends up calculating the difference between an 18-decimal price and an 8-decimal price, producing an incorrect delta. This delta will be disproportionately large—essentially because 18 decimals - 8 decimals ≈ 18 decimals—causing the first if condition to be triggered almost every time (because _delta is capped by PRICE_DELTA_EXP = 1e5). This leads to always selecting the EO oracle’s price, effectively making the dual-oracle setup useless.

Always entering the first if is problematic because if apiV3Fresh = true (meaning the API3 price is not stale) but the EO oracle price is stale, the transaction will still revert with MixedPriceOracle_eOracleStalePrice(). This happens even when the prices themselves are correct, simply because deltaBps > deltaSymbol is true due to the decimal mismatch. As a result, it creates a DOS for obtaining the price, when in reality the price could be retrieved using API3 orcale if the decimals from both oracles were adjusted correctly.

Internal Pre-conditions

None.

External Pre-conditions

API decimals > EO decimals or vice versa. API price is fresh, and EO price is stale.

Attack Path

None.

Impact

ThThe price obtained using getUnderlyingPrice() will always come from the EO oracle. If the EO price is stale while the API3 price is fresh, the price cannot be obtained, creating a denial-of-service (DoS) scenario.

PoC

To illustrate the problem, let’s use the wBTC / USD pair on the Linea chain, which is in scope for the contest. In the EO oracle, the price is returned with 8 decimals, while in API3 it’s returned with 18 decimals.

  1. getUnderlyingPrice() is called for an mToken whose underlying asset is wBTC.
  2. The EO oracle price is 120000000000 (8 decimals), and the API3 oracle price is 120000000000000000000000 (18 decimals). The API3 price is fresh, while the EO oracle price is stale.
  3. _absDiff() is calculated as 120000000000000000000000 - 120000000000 ≈ 120000000000000000000000, producing a very large delta.
  4. Because deltaBps is much greater than deltaSymbol, the first if condition is triggered, selecting the EO oracle’s price. However, this reverts because the EO price is stale.

If deltaBps were calculated correctly, the else branch would be taken, and the fresh API3 price would be used. In the current implementation, this creates a denial of service (DoS) scenario where the price cannot be obtained.

Mitigation

To solve the problem, normalize the decimals from both oracles before calculating _absDiff(), ensuring the deltaBps is computed correctly.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/malda-protocol/malda-lending/pull/134

CergyK

Fix looks good, as already mentioned in #1305

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

The contract calculates the absolute difference between two oracle prices without first converting them to the same number of decimals.

Impact

The price lookup always uses the EO oracle and reverts when that oracle is stale, even if the API3 price is fresh, causing a denial of service.

What the attacker needed

API3 and EO oracles use different decimals; EO oracle price is stale while API3 price is fresh

The fix

The decimals from both oracles should be normalised before calculating the difference, and the protocol team fixed this issue in a pull request.

How it was found

  1. Call getUnderlyingPrice() for a token whose underlying asset is wBTC.
  2. The EO oracle returns a price with 8 decimals and the API3 oracle returns a price with 18 decimals.
  3. The contract subtracts the two raw numbers, producing a huge delta.
  4. The delta exceeds the allowed threshold, so the contract selects the EO oracle's price.
  5. Because the EO oracle's price is stale, the transaction reverts.

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 needs to know the price of an asset. It asks two different price services and compares their answers. But one service gives numbers with 18 decimal places and the other with 8, so the comparison is meaningless and the contract always trusts the second service. If that second service's answer is out of date, the contract refuses to give any price at all.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 0xEkko

View all

10 more disclosed reports, best first.

More from Malda

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.