Boost _ IDEX 34239 - [Smart Contract - Insight] Dont validate stale price in Pyth Network

Submitted on Wed Aug 07 2024 10:21:25 GMT-0400 (Atlantic Standard Time) by @Hoverfly9132 for Boost | IDEX

Report ID: #34239

Report type: Smart Contract

Report severity: Insight

Target: https://github.com/idexio/idex-contracts-ikon/blob/main/contracts/oracle-price-adapters/PythOraclePriceAdapter.sol

Impacts:

  • Protocol insolvency

Description

Bug Description

The PythOraclePriceAdapter#loadPriceForBaseAssetSymbol get price by pyth oracle getPriceUnsafe function:

function loadPriceForBaseAssetSymbol(string memory baseAssetSymbol) public view returns (uint64 price) {
    PythMarket memory market = marketsByBaseAssetSymbol[baseAssetSymbol];
    require(market.exists, "Unknown base asset symbol");

    // @audit-issue - may get stale price
    PythStructs.Price memory pythPrice = pyth.getPriceUnsafe(market.priceId);

    uint64 priceInPips = _priceToPips(pythPrice.price, pythPrice.expo, market.priceMultiplier);
    require(priceInPips > 0, "Unexpected zero price");

    return priceInPips;
  }

However, the getPriceUnsafe function may return stale price as the official describe:

/// @notice Returns the price of a price feed without any sanity checks. /// @dev This function returns the most recent price update in this contract without any recency checks. /// This function is unsafe as the returned price update may be arbitrarily far in the past. /// /// Users of this function should check the publishTimein the price to ensure that the returned price is /// sufficiently recent for their application. If you are considering using this function, it may be /// safer / easier to use eithergetPriceorgetPriceNoOlderThan. /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.

So it may return stale price but the protocol don't validate it.

Impact

The protocol may use stale pyth price may cause users asset account error.

Recommendation

Using pyth.updatePriceFeeds for updating prices, followed by pyth.getPrice for retrieval. Following the example in: https://github.com/pyth-network/pyth-sdk-solidity/blob/main/README.md#example-usage

Impact: High Likelihood: Low

So i evaluate this issue is medium.

Proof of concept

PoC

The finding is easy to understand but as boost rule we need provide PoC, so we mock the loadPriceForBaseAssetSymbol function with getPriceUnsafe function, compare the price before and after.

Last updated

Was this helpful?