This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
Emmanuel - PythOracle:if price.expo is less than 0, wrong prices will be recorded #56
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
Emmanuel
medium
PythOracle:if price.expo is less than 0, wrong prices will be recorded
Summary
In PythOracle#_recordPrice function, prices with negative exponents are not handled correctly, leading to a massive deviation in prices.
Vulnerability Detail
Here is PythOracle#_recordPrice function:
If price is 5e-5 for example, it will be recorded as 5e5
If price is 5e-6, it will be recorded as 5e6.
As we can see, there is a massive deviation in recorded price from actual price whenever price's exponent is negative
Impact
Wrong prices will be recorded.
For example,
If priceA is 5e-5, and priceB is 5e-6. But due to the wrong conversion,
Unfortunately, current payoff functions may not be able to take care of these discrepancies
Code Snippet
https://github.com/sherlock-audit/2023-07-perennial/blob/main/perennial-v2/packages/perennial-oracle/contracts/pyth/PythOracle.sol#L203
Tool used
Manual Review
Recommendation
In PythOracle.sol,
_prices
mapping should not bemapping(uint256 => Fixed6) private _prices;
Instead, it should be
mapping(uint256 => Price) private _prices;
, where Price is a struct that stores the price and expo:This way, the price exponents will be preserved, and can be used to scale the prices correctly wherever it is used.
The text was updated successfully, but these errors were encountered: