Reduce-only orders can be used to inflate quoteOI and DoS the orderbook
Reduce-only orders are counted towards the market's quote open interest even though they create no real exposure, so an attacker can place a tiny reduce-only buy at an extremely high price and push quoteOI towards its maximum. Once that value is near the limit, other users' buy orders overflow and revert, blocking the order book.
VinciGearHead Follow with HighKingMargo and udogodwin
Originally disclosed on Code4rena
Submitted by VinciGearHead, also found by HighKingMargo and udogodwin
perps/types/Book.sol #L391-L403
A malicious user may place a reduce-only order with a tiny amount but an arbitrarily large price. The book code unconditionally increases metadata.quoteOI (for BUY) when the order is added to the book.
The addOrderToBook in book.sol library is called when adding order to a book. It manages the data structure and also calculates the new open interest of the market.
function addOrderToBook(Book storage self, Order memory order) internal {
if (order.reduceOnly) {
StorageLib.loadMarket(self.config.asset).linkReduceOnlyOrder(
order.owner, order.subaccount, order.id.unwrap(), self.config.bookType
);
}
Limit storage limit = _updateBookPostOrder(self, order);
_updateLimitPostOrder(self, limit, order);
self.orders[order.id] = order;
}
The calculation of the new open interest of the BUY side is a function of the order’s price and amount, for reduce-only order no collateral is involved in setting up the order as a result an attacker can craft a price so close (type(uint256).max) to cause other user’s BUY order to overflow.
function _updateBookPostOrder(Book storage self, Order memory order) private returns (Limit storage limit) {
if (order.side == Side.BUY) {
limit = self.bidLimits[order.price];
if (limit.numOrders == 0) self.bidTree.insert(order.price);
self.metadata.numBids++;
@>> we can push this to type(uint256).max arbitrarily
@>> self.metadata.quoteOI += order.amount.fullMulDiv(order.price, 1e18);
} else {
limit = self.askLimits[order.price];
if (limit.numOrders == 0) self.askTree.insert(order.price);
self.metadata.numAsks++;
self.metadata.baseOI += order.amount;
}
}
Because reduce-only orders are meant to reduce exposure (not create it), counting them toward open interest lets the attacker pump quoteOI without meaningful risk and cause other users’ placeOrder calls to revert.
Impact
This bug allows an attacker to DOS the order book by placing reduce-only order with tiny size and an arbitrarily large price to massively inflate metadata.quoteOI causing other users’ BUY Order to revert.
Recommended mitigation steps
Skip updating quoteOI/baseOI for reduce-only orders or enforce notional and price caps relative to mark price so attackers cannot inflate open interest with extreme values.
View detailed Proof of Concept
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the book update adds the notional value of every buy order to quoteOI without excluding reduce-only orders or capping the price, so an extreme price times a small amount can saturate the counter.
Impact
An attacker can deny service to the order book, causing other users' buy orders to revert; the text does not mention any defence that limits this.
What the attacker needed
Ability to place orders on the market; no meaningful collateral needed
The fix
The book should skip updating quoteOI and baseOI for reduce-only orders, or enforce notional and price caps relative to the mark price.
How it was found
- Place a reduce-only buy order with a very small amount and an extremely large price.
- The order is added to the book and its notional value is added to quoteOI.
- quoteOI is pushed close to its maximum value.
- Other users' buy orders then overflow and revert.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A perpetuals exchange keeps a running total of how much buying interest exists in its order book, called open interest. Reduce-only orders are supposed to only shrink a trader's position, so they should not add to that total, but the code adds them anyway. By submitting a tiny order at an absurdly high price, an attacker makes that total jump to near its maximum, and then normal buy orders fail because the number cannot grow any further.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.