> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inkwell.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Matching mechanism

> How Dagon finds a clearing price through ciphertext alone. Walrasian tâtonnement, evaluated entirely on encrypted values.

> **CONFIDENTIAL & PROPRIETARY © 2026 Inkwell Finance, Inc. All Rights Reserved.**
>
> This document is for informational purposes only and does not constitute legal, tax, or investment advice, nor an offer to sell or a solicitation to buy any security or other financial instrument. Any examples, structures, or flows described here are design intent only and may change.

How do you find a fair price when no one — not the operator, not a
matcher, not an observer — is allowed to see anyone else's order?

## The problem

At clearing, the engine needs to find a single price *p* such that
aggregate demand at *p* equals aggregate supply at *p*. In a normal
order book this is done by sorting and matching quotes. In Dagon
nothing can be sorted because nothing can be decrypted. The orders
are encrypted curves, not encrypted quotes.

## The answer

Walrasian tâtonnement: the engine bisects over a price range,
evaluates aggregate demand and supply at each midpoint, narrows the
range toward whichever side is heavier, and repeats. After a small,
fixed number of iterations the remaining price range is tight enough to
use as the clearing price for the batch.

Every step is evaluated on ciphertexts. The engine never learns whether
demand exceeded supply at any given midpoint — it computes both
aggregates as encrypted values and uses encrypted comparisons to steer
the next iteration.

## Why bisection

The search is a fixed-depth algorithm: no branching on plaintext, no
early exit. That makes it compile cleanly into a straight-line FHE
circuit with predictable multiplicative depth, deterministic runtime,
and no side-channel leakage from iteration count. A batch takes the
same wall-clock regardless of which bracket the true clearing price
falls in.

In principle a closed-form clearing price exists at the crossing.
Computing it directly would require division by encrypted unknowns
(numerically fragile) and branches on encrypted sign tests (expensive).
Fixed-depth bisection trades optimality per iteration for determinism
and predictability — the right trade for an FHE circuit.

## Output semantics

At the final iteration the graph emits an encrypted clearing price, a
per-lane encrypted fill for each side, and a one-bit convergence flag.
The clearing price becomes public once the operator's re-encryption
step releases it. The per-lane fills remain private to each
participant, decryptable only through a proxy re-encryption from the
participant's session key.

Nothing in the graph exposes who matched with whom, at what size, or
against which curve shape. The book stays encrypted from submit
through clearing through settlement.

## Two views of the same search

The interactive walkthrough at
[dagon.so/how-it-works#mechanism ↗](https://dagon.so/how-it-works#mechanism)
shows the bisection through two complementary visualizations:

* **Rail view** — the price range narrowing toward a single point across
  iterations.
* **Merge view** — demand and supply curves approaching a single
  crossing.

Both views animate against the same trace. Drag the scrubber in the
header to step through the search.

## See also

<CardGroup cols={2}>
  <Card title="SIMD packing" icon="layer-group" href="/dagon/architecture/simd-packing">
    How the engine fits a whole batch's curves into a compact FHE layout
    before the search runs.
  </Card>

  <Card title="Interactive scrubber ↗" icon="arrow-up-right-from-square" href="https://dagon.so/how-it-works#mechanism">
    Step through the bisection at your own pace. Rail + merge views
    animate together.
  </Card>
</CardGroup>
