Closed c4-bot-6 closed 4 months ago
This report describes how the protocol's PriceFeed
contract performs dangerous multiplication with Q96 = 2^96 twice.
First instance: uint256 price = uint256(int256(basePrice.price)) * Constants.Q96 / uint256(quoteAnswer);
.
Next instance: price = price * Constants.Q96 / _decimalsDiff;
First, the price is calculated with multiplication by Constants.Q96
, which will result in price
to have units in 2^96. There is another direct multiplcation with Constants.Q96
in the second line, which can overflow, as displayed in the report using chisel
.
There are also similar findings on solodit: #1, #2, #3
Therefore, I believe this should be a valid medium severity finding.
Lines of code
https://github.com/code-423n4/2024-05-predy/blob/main/src/PriceFeed.sol#L45-L58 https://github.com/code-423n4/2024-05-predy/blob/main/src/libraries/Constants.sol#L19
Vulnerability details
Impact
PriceFeed::getSqrtPrice
provides the square root price of the base token in terms of the quote token.There is a problem where direct multiplication is performed with
Constants.Q96 (2^96)
twice. This can cause overflow in some cases resulting in DoS.Proof of Concept
PriceFeed.sol#L45-L58
Here
price
is multiplied byConstants.Q96
directly, which is defined as the following:Constants.sol#L19
This is a case that may cause DoS due to overflow, and it is also handled by Uniswap's Oracle Library
Here's an example of how easily overflow can occur due to direct multiplication with Q96 using chisel:
Tools Used
Manual Review.
Recommended Mitigation Steps
Utilize Uniswap's FullMath library to perform this calculation
Assessed type
Under/Overflow