After trades are executed in the Perp Market, the trade order is validated to ensure that the trade conforms to the parameters set by the user, such as market price, limit price, and stop price, etc.
When the stop price is validated, the ratio of the oracle price and stop price is calculated.
The problem is that the ratio incorrectly returns 0 when oracle price == stop price, when it should actually return 1.
This leads to a problem where a valid stop price may incorrectly be invalidated, causing DoS of trades.
Lines of code
https://github.com/code-423n4/2024-05-predy/blob/main/src/markets/perp/PerpMarketV1.sol#L213-L215 https://github.com/code-423n4/2024-05-predy/blob/main/src/markets/perp/PerpMarketLib.sol#L97-L115 https://github.com/code-423n4/2024-05-predy/blob/main/src/markets/perp/PerpMarketLib.sol#L147-L153 https://github.com/code-423n4/2024-05-predy/blob/main/src/markets/perp/PerpMarketLib.sol#L178-L186
Vulnerability details
Impact
After trades are executed in the
Perp Market
, the trade order is validated to ensure that the trade conforms to the parameters set by the user, such as market price, limit price, and stop price, etc.When the
stop price
is validated, the ratio of theoracle price
andstop price
is calculated.The problem is that the ratio incorrectly returns 0 when
oracle price == stop price
, when it should actually return 1.This leads to a problem where a valid stop price may incorrectly be invalidated, causing DoS of trades.
Proof of Concept
After trades are completed, they are validated
PerpMarketV1.sol#L213-L215
The
stop price
is validated under certain conditionsPerpMarketLib.sol#L97-L115
validateStopPrice
callsdecay2
withratio(oraclePrice, stopPrice)
as thevalue
parameterPerpMarketLib.sol#L147-L153
PerpMarketLib.sol#L178-L186
Here, if
price1 == price2
the ratio returned is 0, which is incorrect. Any values that are equal have a ratio of 1 (100%) (Bps.ONE
in this case).This means that the
decayedSlippageTolerance
value will not be correct and validate stop prices may be deemed invalid, causing DoS of trades.Tools Used
Manual Review
Recommended Mitigation Steps
When prices are equal, the ratio should be 1 (100%)
Assessed type
Math