Liquidation stalls when top-of-book is outside divergence band (STANDARD & BACKSTOP), allowing under-margined positions to persist
Liquidation orders on both the STANDARD and BACKSTOP order books are blocked whenever the best quote on the needed side lies outside the divergence band around the mark price. An attacker or ordinary market stress can therefore prevent under-margined positions from being liquidated, letting losses grow into bad debt.
Submitted by 4Nescient, also found by 0xShitgem, BenRai, and nikhil840096
During liquidation, the protocol submits a reduce-only IOC order via Market.liquidate(...). Matching is gated by divergence bands around the mark:
Long liquidation (SELL into bids) must see bestBid ≥ mark × (1 − cap).
function _matchIncomingBid(
Book storage ds,
Order memory incomingOrder,
bool baseDenominated
) internal returns (uint256 quoteSent, uint256 baseReceived) {
uint256 bestAsk = ds.getBestAsk();
uint256 maxAsk = StorageLib
.loadMarket(ds.config.asset)
.getMaxDivergingAskPrice();
while (bestAsk <= incomingOrder.price && incomingOrder.amount > 0) {
if (bestAsk == type(uint256).max) break;
@> if (bestAsk > maxAsk) break;
Limit storage limit = ds.askLimits[bestAsk];
Order storage bestAskOrder = ds.orders[limit.headOrder];
if (bestAskOrder.isExpired()) {
_removeUnfillableOrder(ds, bestAskOrder);
bestAsk = ds.getBestAsk();
continue;
}
__TradeData__ memory data = _matchIncomingOrder(
ds,
bestAskOrder,
incomingOrder,
baseDenominated
);
incomingOrder.amount -= data.filledAmount;
baseReceived += data.baseTraded;
quoteSent += data.quoteTraded;
if (limit.numOrders == 0) bestAsk = ds.getBestAsk();
}
}
Short liquidation (BUY into asks) must see bestAsk ≤ mark × (1 + cap).
function _matchIncomingAsk(
Book storage ds,
Order memory incomingOrder,
bool baseDenominated
)
internal
returns (uint256 totalQuoteTokenReceived, uint256 totalBaseTokenSent)
{
uint256 bestBid = ds.getBestBid();
uint256 minBid = StorageLib
.loadMarket(ds.config.asset)
.getMaxDivergingBidPrice();
while (bestBid >= incomingOrder.price && incomingOrder.amount > 0) {
if (bestBid == 0) break;
@> if (bestBid < minBid) break;
Limit storage limit = ds.bidLimits[bestBid];
Order storage bestBidOrder = ds.orders[limit.headOrder];
if (bestBidOrder.isExpired()) {
_removeUnfillableOrder(ds, bestBidOrder);
bestBid = ds.getBestBid();
continue;
}
__TradeData__ memory data = _matchIncomingOrder(
ds,
bestBidOrder,
incomingOrder,
baseDenominated
);
incomingOrder.amount -= data.filledAmount;
totalQuoteTokenReceived += data.quoteTraded;
totalBaseTokenSent += data.baseTraded;
if (limit.numOrders == 0) bestBid = ds.getBestBid();
}
}
If the top-of-book quote is outside its allowed band (which implies no in-band quotes exist on that side), the matcher halts immediately and executes no trades. Because the order is IOC (not postable), the matcher returns zero effect, causing a ZeroOrder() revert and the liquidation aborts.
Shared gate across books. This divergence gate is applied identically to both the STANDARD and BACKSTOP order books. While enforcing a divergence cap on STANDARD is reasonable (maker price protection / slippage control), applying the same gate on BACKSTOP is problematic: Backstop’s job is risk reduction, not price protection. Sharing the STANDARD divergence band means the system can refuse to liquidate even on the backstop, whenever there are no in-band quotes on the relevant side (i.e., all asks > mark × (1 + cap) for BUY liquidation, or all bids < mark × (1 − cap) for SELL liquidation). That is exactly when you most need the backstop to trade.
Impact (why it matters)
- Denial of liquidation: If there are no quotes within the divergence band on the relevant side, liquidation cannot proceed even on BACKSTOP.
- Backstop availability failure: The “last-resort” venue becomes unavailable under stress whenever its side of book is entirely out of band or empty, defeating its risk-reduction purpose.
- Escalating loss: The account can accrue further losses and go negative equity (bad debt).
- Systemic impact: Losses hit the Insurance Fund; if insufficient, the system may auto-deleverage (ADL) solvent traders.
- Realistic stress/grief condition: In thin/volatile markets, in-band liquidity can disappear (market makers widen or pull quotes), leaving only out-of-band quotes. An attacker doesn’t need to post a special quote; it’s enough that no one maintains an in-band quote on BACKSTOP, which predictably blocks liquidation during critical windows.
Recommended mitigation steps
Any of the below (individually sufficient):
- Bypass divergence checks for BACKSTOP liquidation orders.
- Execute at the band boundary (e.g.,
clamp to mark×(1±cap)) with an explicit liquidation penalty. - Provide a non-CLOB backstop (e.g., system LP) that always fills liquidation within bounded slippage when divergence gating blocks the book.
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
The same divergence-band gate is applied to both the STANDARD and BACKSTOP books, so the backstop cannot trade when no in-band quotes exist on the relevant side.
Impact
Liquidation can be blocked during thin or volatile markets, allowing under-margined positions to persist and accrue losses that hit the Insurance Fund and may trigger auto-deleveraging of solvent traders.
What the attacker needed
No in-band quotes on the needed side; thin or volatile market conditions
The fix
The report recommends bypassing divergence checks for BACKSTOP liquidation orders, executing at the band boundary with a penalty, or providing a non-CLOB backstop that always fills within bounded slippage.
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 perpetual exchange lets traders bet on prices and must force-close (liquidate) positions that run out of collateral. Here, the code refuses to match a liquidation order if the only available prices are too far from the reference 'mark' price, even on the emergency backstop book meant to guarantee a fill. So a position that should be closed stays open and can lose more money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.