Skip to content
Business logic Audit finding Intermediate

Dust orders can block order posting

Maker orders can be reduced below the minimum limit without a check, leaving dust positions in the order book. When a new order tries to match such a dust order, the quote amount can round down to zero, causing a ZeroCostTrade revert that blocks the incoming order.

montecristo Follow with 0xAsen, gesha17 and 4 others

Originally disclosed on Code4rena

Submitted by montecristo, also found by 0xAsen, gesha17, gizzy, holtzzx, newspacexyz, and solhhj

clob/CLOB.sol #L807-L849

When matching incoming orders, maker orders can be reduced below the minimum limit without checks, resulting in dust positions remaining in the order book. These dust orders can block new incoming orders, as matching them may revert with a ZeroCostTrade error if the quote amount rounds down to zero.

Description

When matching an incoming order, maker order’s amount can be set below minLimitOrderAmountInBase, as there is no min amount check:

File: contracts/clob/CLOB.sol

833:@>       bool orderRemoved = matchData.baseDelta == matchedBase;
834:
835:         // Handle token accounting for maker.
836:         if (takerOrder.side == Side.BUY) {
837:             TransientMakerData.addQuoteToken(makerOrder.owner, matchData.quoteDelta);
838:
839:             if (!orderRemoved) ds.metadata().baseTokenOpenInterest -= matchData.baseDelta;
840:         } else {
841:             TransientMakerData.addBaseToken(makerOrder.owner, matchData.baseDelta);
842:
843:             if (!orderRemoved) ds.metadata().quoteTokenOpenInterest -= matchData.quoteDelta;
844:         }
845:
846:         if (orderRemoved) ds.removeOrderFromBook(makerOrder);
847:@>       else makerOrder.amount -= matchData.baseDelta;
  • In L833, order is removed only when matched amount is equal to maker order’s amount
  • In L847, maker order’s amount is decreased by matched amount. The result amount can be dust, as there is no min amount check done afterwards.

As such, maker order’s amount can be a dust amount (up to lotSizeInBase config).

This means there can be a dust position in the order book.

What happens if this dust order is matched to another incoming order?

File: contracts/clob/CLOB.sol

819:             matchData.baseDelta = (matchedBase.min(takerOrder.amount) / lotSize) * lotSize;
820:             matchData.quoteDelta = ds.getQuoteTokenAmount(matchedPrice, matchData.baseDelta);
  • In L819, matchData.baseDelta can be as small as lotSize, since makeOrder.amount can be down to lotSize
  • In L820, matchData.quoteDelta can be zero due to rounddown:

File: contracts/clob/types/Book.sol

471:     function getQuoteTokenAmount(Book storage self, uint256 price, uint256 baseAmount)
472:         internal
473:         view
474:         returns (uint256 quoteAmount)
475:     {
476:         return baseAmount * price / self.config().baseSize;
477:     }

If matchData.quoteDelta is 0, the trade(or order posting) will revert with ZeroCostTrade error:

File: contracts/clob/CLOB.sol

439: if (totalQuoteSent == 0 || totalBaseReceived == 0) revert ZeroCostTrade();

Impact

Dust positions can block incoming orders. An example is shown in the POC.

Recommended Mitigation Steps

Consider removing orders if the amount after matching is lower than minLimitOrderAmountInBase.

View detailed Proof of Concept


The original report as published on Code4rena, by montecristo. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 matching logic reduces a maker order's amount without checking whether the remainder is below the minimum limit, so dust orders stay in the book and can produce a zero quote amount on the next match.

Impact

Dust positions can block incoming orders, as matching them may revert with a ZeroCostTrade error.

What the attacker needed

A maker order partially matched; remainder below minimum limit; a new taker order matches dust

The fix

Orders should be removed if the amount after matching is lower than minLimitOrderAmountInBase.

How it was found

  1. A maker order is partially matched, leaving a remainder below the minimum limit.
  2. The remainder stays in the order book as a dust order.
  3. A new incoming order attempts to match the dust order.
  4. The base delta is as small as the lot size, and the quote delta rounds down to zero.
  5. The trade reverts with ZeroCostTrade, blocking the incoming order.

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.

In an order book, a 'maker' order waits to be matched and a 'taker' order comes in to trade against it. The code lets a maker order shrink to a tiny leftover amount (dust) without removing it. Later, when someone tries to trade against that tiny leftover, the calculated cost can round down to zero, and the system rejects the trade, so the new order cannot go through.

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.

More by montecristo

View all

10 more disclosed reports, best first.

More from GTE Spot CLOB and Router

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.