Closed sherlock-admin2 closed 1 year ago
2 comment(s) were left on this issue during the judging contest.
141345 commented:
d
YakuzaKiawe commented:
The protocol needs to convert the expo to uint256 and when you divide it with 10**expo i.e. negative value of expo it could be converted to 0 by floor division
minhtrng
high
Incorrect price calculation in PythOracle
Summary
The price calculation in PythOracle is incorrect and can lead to prices being many orders of magnitudes higher than their actual price.
Vulnerability Detail
PythOracle._recordPrice
performs the following calculation:The problem is that if the exponent is negative a division by 10^(abs(expo)) should be performed rather than a multiplication. See PythNetwork-docs
Impact
prices used for calculation in the protocol differ hugely from the prices reported by the oracle.
Code Snippet
https://github.com/sherlock-audit/2023-07-perennial/blob/c2f6141c231d3952898ea47793872cac69a1d2af/perennial-v2/packages/perennial-oracle/contracts/pyth/PythOracle.sol#L203
Tool used
Manual Review
Recommendation
Perform a division by 10^(abs(expo)) if expo is negative
Duplicate of #56