Boost _ IDEX 34239 - [Smart Contract - Insight] Dont validate stale price in Pyth Network
Last updated
Was this helpful?
Last updated
Was this helpful?
Submitted on Wed Aug 07 2024 10:21:25 GMT-0400 (Atlantic Standard Time) by @Hoverfly9132 for
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
The get price by pyth oracle getPriceUnsafe
function:
/// @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 either
getPriceor
getPriceNoOlderThan. /// @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.
The protocol may use stale pyth price may cause users asset account error.
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.
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.
However, the getPriceUnsafe
function may return stale price as the official :