Reversion of getSqrtPrice Function Due to getPriceNoOlderThan Oracle Call #97
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-31
edited-by-warden
🤖_09_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-05-predy/blob/a9246db5f874a91fb71c296aac6a66902289306a/src/PriceFeed.sol#L48
Vulnerability details
Impact
The issue with the
getSqrtPrice
function is that it reverts when callinggetPriceNoOlderThan
from the Pyth oracle for various price feeds on multiple chains, including Optimism and Base ,Arbitrum.Proof of Concept
Consider a scenario where a user tries to execute a trade involving the
WBTC/USD
pair on theOptimism chain
,Base chain
. ThegetSqrtPrice
function is called to fetch the price data, but it reverts due to the inability to retrieve data from the Pyth oracle.User Action: A user submits a transaction to trade WBTC for USD.
Function Call: The
getSqrtPrice
function is called to fetch the price data.Oracle Query: The function calls getPriceNoOlderThan on the Pyth oracle with the
WBTC/USD
price ID and an age of300 seconds
.Error: The Pyth oracle reverts, indicating that it cannot provide the requested data.
Transaction Revert: The entire transaction reverts, leading to wasted gas fees and a failed trade.
Here is the corrected text with proper grammar:
Please test the following by yourself. You can find the Price ID of WBTC/USD, which is
0xc9d8b075a5c69303365ae23633d4e085199bf5c520a3b90fed1322a0342ffc33
.Go to the price feed contract address on Optimism and Base.
Go to the contract section, select "Read as Proxy," and then call the
getPriceNoOlderThan
function with the price ID and 300.You will observe that it always reverts.
Using
getPriceNoOlderThan
to retrieve prices is not a good practice. Some of the price IDs revert on certain chains, likeUSDC/USD
, which reverts on Optimism and Base, andDAI/USDC
, which reverts on all supported chains.ETH/USD
also reverts on Optimism and Base.Tools Used
Manual Review
Recommended Mitigation Steps
Use getPriceUnsafe instead of
getPriceNoOlderThan
.Assessed type
Oracle
The text was updated successfully, but these errors were encountered: