Settlement and verification

Fills settle on Elysium in numbered batches. Each batch is checked in full by the exchange and linked to the engine's public log.

batch 41prevRootkeccak(digests, fills)logHeadrootlog h[1200]batch 42prevRootkeccak(digests, fills)logHeadrootlog h[1237]batch 43prevRootkeccak(digests, fills)logHeadlog h[1274]
stateRoot = keccak(prevRoot, batchId, keccak(digests, fills), logHead). Each batch commits to the engine's log at that point.

What settle checks

Only the operator key may post settle(batchId, orders, fills, logHead). Batch ids are consecutive. A batch is all-or-nothing. For every fill, the contract checks:

  • Each order's signature: ECDSA with low-s, or EIP-1271 for contract traders.
  • The nonce is not cancelled, the order has not expired, and the market matches.
  • Maker and taker are on opposite sides and their limits cross.
  • Filled size never exceeds the order's size, tracked per order digest across batches.
  • IOC is never a maker, ALO is never a taker, a trader is never on both sides.
  • Reduce-only orders only reduce.
  • Every account that added risk is above initial margin after the batch, at the mark.

The state root

stateRoot[n] = keccak256(stateRoot[n-1], batchId, keccak256(digests, fills), logHead)

logHead is the engine's event-log hash when it cut the batch. The exchange emits BatchSettled(batchId, batchHash, stateRoot, logHead, fills), and /v1/batches lists the same values with their transactions.

Replay the log

Each market's log is a hash chain:

h[0] = keccak256("EL-3 log" || market as u32 big-endian)
h[n] = keccak256(h[n-1] || encode(seq, command, events))

The encoding is fixed-width big-endian, so any language can recompute it. To verify:

# download the log for market 1, 1000 records at a time
curl "https://<this site>/api/engine/v1/log/1?from=1&limit=1000" > log-1.json
# list the batches and their log heads
curl "https://<this site>/api/engine/v1/batches?limit=50"
  1. Start from an empty book and apply each record's command in sequence.
  2. Check that your book produces the same events, and that your running hash equals each record's hash.
  3. Check that the logHead in each BatchSettled event appears in the chain. One changed fill anywhere breaks the match.