IllIllI - Negative prices will cause old orders to be canceled #177
Description
IllIllI
medium
Negative prices will cause old orders to be canceled
Summary
In most cases where orders are submitted using invalid oracle prices, the check for isEmptyPriceError()
returns true, and the order execution is allowed to revert, rather than canceling the order.
Vulnerability Detail
Negative Chainlink oracle prices (think negative interest rates in Europe) result in a plain revert(<string>)
, which isn't counted as one of these errors, and so if the price becomes negative, any outstanding order will be canceled, even if the order was submitted prior to the price going negative.
Impact
Orders to close positions will be canceled, leading to losses.
Code Snippet
Chainlink prices are converted to positive numbers:
// File: gmx-synthetics/contracts/oracle/Oracle.sol : Oracle._setPricesFromPriceFeeds() #1
577 ) = priceFeed.latestRoundData();
578
579:@> uint256 price = SafeCast.toUint256(_price);
And if they're negative, the code reverts:
// File: gmx-synthetics/node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol : SafeCast.toUint256() #2
558 function toUint256(int256 value) internal pure returns (uint256) {
559 require(value >= 0, "SafeCast: value must be positive");
560 return uint256(value);
561: }
Orders that revert get frozen or canceled
Tool used
Manual Review
Recommendation
Create a new error type, and include it in the list of OracleUtils.isEmptyPriceError()
errors