Skip to content
  • Rust
  • Security · order-book verification

How Manifest went beyond “no loss of funds” with Aristotle

Manifest runs an open-source order book on Solana. Aristotle proved 28 things about its code, including that a valid swap goes through, and that every error a swap can return has a known source. It also found a rounding bug, which Manifest has since fixed.

Beyond no loss of funds

Order-book verification usually stops at checking that traders can’t lose money. Aristotle checked that too, but Manifest wanted to go further: will a valid swap actually go through, and what caused a swap to fail when one did?

Aristotle proved that a swap goes through as long as there’s enough liquidity, the accounts are funded, the amounts are in range, and the token program does its job. It also traced every error a swap can return back to where it starts. With those conditions in place, none of the errors come from Manifest’s own matching or setup code. The only ones left come from request limits or the token program, including Token-2022 transfer fees.

“The trading progress and error classification go beyond the normal proof of no loss of funds and show un-brickable. That’s what impressed me most.”

Lead developer, Manifest

A trade that hit its target, then failed

Manifest’s quote function works out how much of the base token a trader gets for a given amount of the quote token. Rounding can make a fill overshoot what’s left by a little. For example, at a price of 1.5, one base atom costs two quote atoms after rounding, even when only one quote atom was still needed.

The original code stopped early only when an order was partially filled. A complete fill went on to subtract two from one, and returned an arithmetic error after the target had already been met. The corrected code stops as soon as a fill meets or exceeds the target, and returns the base amount it has accumulated. Aristotle proved the corrected behavior, including this exact example.

The second finding was in canceling a global order. The code ran a quote conversion it never used on that path, and that conversion could fail before the order was removed. Manifest fixed it, and Aristotle proved the bounds that keep accepted bids from overflowing.

Try Aristotle

The results

Manifest Rust

28 results across the whole order book

Each result comes with a full Lean statement that Manifest’s team can read and check, from tree integrity to every error a swap can return.

  • 28

    Proved results

  • 8

    Areas covered

  • 2

    Findings, both corrected

What Aristotle proved, by area:
AreaWhat’s proved
Trading progressComplete local and global swaps succeed under explicit conditions.
Error classificationEvery error a swap returns is traced to where it came from.
Order-book integrityInserting and removing orders keeps the trees valid and leaves unrelated data untouched. Admitted bids, including global bids, stay within their arithmetic bounds.
Custody and recoveryLocal and global accounting keep their backing, and refunds can’t repeat. Canceling and withdrawing recovers funds under the stated conditions.
Cancellation authorizationA supplied hint is checked against the stored trader and sequence.
MatchingMatching obeys the price, quantity, expiration, and order-policy rules.
Reverse ordersReverse orders fit their integer ranges and charge only the funded addition.
Quotes and roundingQuotes agree with actual matching, respect input budgets, and stop once the target is reached.

Every result keeps its account, funding, arithmetic, and liquidity conditions explicit.

Built on

  • Solana

What the proof covers

  • The real Rust, unchanged

    Aristotle reasoned over Manifest’s actual Rust code, with no source changes, no simplified model, and no loops unrolled to a fixed depth.

  • Any sequence of operations

    The invariants hold across any finite sequence of operations, not just a fixed number of steps.

  • Unsafe code included

    The red-black tree at the core of the order book uses substantial unsafe Rust. Aristotle can reason about it without any issues.

  • Stated conditions and limits

    Each result states its account, funding, and arithmetic conditions. The token and system programs Manifest calls are assumed, not proved, and there’s no compute-unit bound.

Find what your tests and audits miss

  1. 01

    Point Aristotle at your Rust program.

  2. 02

    Say what must always hold, or let Aristotle propose it.

  3. 03

    Get back every property, proved or refuted, with the conditions it rests on.

Try Aristotle