A one-price batch exchange for Ethereum traders

Orders collect for a set time, then clear together at one price the contract computes. A recorded pool sandwich made the attacker 0.00809 ETH; in a batch the attacker netted 0 TKN and -1 wei.

Recorded on a local Anvil chain, 2026-11-18, commit dedf5c5

Batch clearing in three steps

Each step is one call to the AnyOrder contract; clear and claim can come from any account.

Orders collect for a set time

placeBuy and placeSell add your order to the open batch and lock its funds.

One price clears the batch

Anyone calls clear once the batch ends; it picks the price that trades the most volume.

Fills and refunds reach balances

claim credits each order's fill at that price and returns what its lock did not spend.

One sandwich, pool against batch

The same orders ran on a local Anvil chain through a constant-product pool and through one AnyOrder batch.

The victim's fill stays identical when the attacker's buy and sell are the same size and priced outside every other order: condition C.

Outside it, a one-sided buy moves the batch price from 0.011 ETH/TKN to 0.012 ETH/TKN, and the attacker pays that price too: market power, not ordering.

Pool against batchrecorded

Recorded on a local Anvil chain, 2026-11-18, commit dedf5c5

Same ordersConstant-product poolAnyOrder batch
Victim gets13.7733 TKN (alone: 14.4578 TKN)15 TKN for 0.165 ETH (alone: the same)
Clearing pricemoves with every trade0.011 ETH/TKN (alone: 0.011 ETH/TKN)
Attacker nets0.00809 ETH profit0 TKN and -1 wei, rounding the contract keeps

Anvil dev accounts. Test funds, no real value.

Arrival order

Transaction order cannot change your fill. A closed batch clears by limit price, and every filled order in it trades at one price set by the contract.

Only two exchange handlers hold Call

Only deposit_token and withdraw hold Call, so only they can call another contract or send ether. Clearing has no Ctx or caller effect; the only identity it reads is each order's recorded owner, used only for the final tie-breaks (owner address, then the owner's own order sequence), which decide at most 1 base unit per order.

Evidence for the batch claims

Run each from the repository root; a check fails when its claim does not hold.

Terminalrepository root
  • $ fe test --filter sandwich

    The pool sandwich profits; under condition C the batch attacker nets 0 TKN and -1 wei; a one-sided buy moves the price.

  • $ fe test --filter permutation

    Shuffled arrival orders, in the clearing library and across owners on the contract, keep the price and every owner's totals.

  • $ python ref/clearing_ref.py --check

    The exact Python reference regenerates the test vectors and fails if the committed ones differ.

  • $ pnpm -C web local

    Starts Anvil, builds and deploys the contracts, seeds a cleared and an open batch, and serves the app.