From 72975f15067ae4dadc7af3052a371cf3ec651592 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 1/9] docs(circuits): document the note model and Poseidon2 hashes Co-Authored-By: Claude Opus 5.5 --- .../docs/circuits/notes-and-hashes.mdx | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/content/docs/circuits/notes-and-hashes.mdx diff --git a/src/content/docs/circuits/notes-and-hashes.mdx b/src/content/docs/circuits/notes-and-hashes.mdx new file mode 100644 index 0000000..44cffd6 --- /dev/null +++ b/src/content/docs/circuits/notes-and-hashes.mdx @@ -0,0 +1,95 @@ +--- +title: Notes and hashes +description: "The MIST note model: Chamber ID, custody binding, owner commitment, note hash and nullifier, the two owner types, and the Poseidon2 parameters behind every hash." +sidebar: + order: 3 +--- + +A note is a commitment to an owner, an asset and an amount, held under one Chamber and one Reserve. Every hash in it is Poseidon2 over the BN254 scalar field, and the circuit, the native Go helpers and the Solidity library compute the same values. + +## Fields + +| Field | Contents | +| --- | --- | +| `chamber` | The Chamber ID, not the bare Chamber address | +| `reserve` | The Reserve contract address | +| `blinding` | A random nonce, the note's spending secret | +| `owner` | A wallet or contract address, or a MIST Address | +| `asset` | The ERC-20 contract address | +| `amount` | Below 2^120. The circuit range-checks it and `Chamber.deposit` requires it | + +Addresses enter the field as left-padded big-endian `uint160` values, with no reduction. A 160-bit value is smaller than the field, so nothing wraps. + +## Chamber ID + +Two chains can host a Chamber at the same address, so a note names its Chamber by ID: + +```text +chamber = H2(chainId, chamberAddress) +``` + +The Chamber computes it in its constructor and stores it as the immutable `chamberId`. The chain ID is frozen at deployment. + +## Note hash and nullifier + +```text +custody = H2(chamber, reserve) +ownerCommitment = H2(blinding, owner) +noteHash = H4(custody, ownerCommitment, asset, amount) +nullifier = H4(custody, H2(blinding + 1, owner), asset, amount) +``` + +- **Custody binding.** `H2(chamber, reserve)` locks the note to one Chamber and one Reserve, the only instances that can move it. In the circuit, `chamber` and `reserve` are private inputs of the whole spend, and the binding is computed once for all four notes. +- **Owner commitment.** `H2(blinding, owner)` hides the recipient. Whoever creates a note needs only the commitment, never the recipient's blinding or owner. `Chamber.deposit` takes it as an argument and requires it to be below the field order. The circuit takes each output as an owner commitment and an amount. +- **Note hash.** The leaf appended to the transactions tree. `Chamber.hashNote(chamber_, reserve_, ownerCommitment_, asset_, amount_)` computes it on-chain. A deposited note hashes the amount the Reserve actually received, not the amount requested. +- **Nullifier.** The note hash with the blinding increased by one. A spend publishes it, and the Chamber records it as spent. + +The nullifier does not use the MIST Address secret. Two consequences follow: + +- **Anyone who knows a note's fields can watch for its spend.** That person can compute the nullifier, but spending still takes the owner's secret or the owner as caller. A sender who built the owner commitment from the recipient's blinding and owner knows every field. The nullifier stays private from the sender only when the recipient picks the blinding and hands over a finished owner commitment. +- **Sequential blindings link notes.** A note's nullifier equals the hash of a note with blinding `b + 1` and otherwise the same fields. A wallet that derives blindings in sequence for repeated notes with the same owner, asset and amount links them. Derive each blinding independently. + +## Owners + +| Owner | Value | Spent with | Authorised by | +| --- | --- | --- | --- | +| Wallet or contract address | The `uint160` address | `auth_done = 0` | The Chamber, which requires the owner as caller | +| MIST Address | `H2(p, 0x6f776e6572)`, with `p` a secret | `auth_done = 1` | The proof, as knowledge of `p` | + +The keyword `0x6f776e6572` is the ASCII string "owner" (478745093490). A MIST Address is a hiding commitment, so publishing it reveals nothing about `p`. [What a spend proves](/circuits/spend/#authorisation) gives both modes in full. + +## Poseidon2 + +Every width uses the same parameters: the BN254 scalar field, 8 full rounds, 56 partial rounds and S-box exponent 5. The round counts are set in `core/circuits/gadgets/gadgets.go` and `core/circuits/lib/hash/poseidon2.go`. The exponent is gnark-crypto's fixed S-box degree for BN254. + +Each function feeds an input forward into one element of the final permutation state. The width-4 permutation serves four functions, told apart only by how the output is read: + +| Function | Width | Output | Constraints | +| --- | --- | --- | --- | +| `H2(a, b)` | 2 | `state[1] + b` | 217 | +| `H3(a, b, c)` | 3 | `state[0] + a` | 241 | +| `H4(a, b, c, d)` | 4 | `state[0] + a` | 265 | +| `HM4`, the Merkle node | 4 | `state[0] + state[1]`, over sorted children | 283, selector included | +| Keystream block | 4 | `state[j + 1] - k`, for `j = 0, 1, 2` | 265 per block | + +Constraint counts are from core's committed constraint snapshot. Reading the output differently separates the domains with no extra input, tag or round: a collision across two uses would need one permutation state element to equal an input the other use feeds forward. + +`Fold2` reduces a vector to one element by chaining `H2` from the left: `Fold2(v) = H2(... H2(H2(v0, v1), v2) ..., vn)`. + +## Where each hash is used + +| Value | Hash | +| --- | --- | +| Chamber ID | `H2(chainId, chamberAddress)` | +| Custody binding | `H2(chamber, reserve)` | +| Owner commitment | `H2(blinding, owner)` | +| Note hash, nullifier | `H4(custody, ...)` | +| MIST Address | `H2(p, 0x6f776e6572)` | +| Reserve config | `H2(keyHash, keyInputPoint)` | +| zkState leaf | `H3(reserve, reserveConfig, usersRoot)` | +| Registered-user leaf | `H2(owner, userKeyExchange)` | +| Messaging key | `H2(userKeyExchange, keyIndex)` | +| `auditor_commitments` | `Fold2([privateTxKey, c0, c1, c2, c3, c4])` | +| Merkle node | `HM4` | + +[Merkle trees](/circuits/merkle-trees/) covers `HM4`, and [Reserve messaging](/circuits/reserve-messaging/) the keystream. From c2f7726c689563034cdff8ca5981b04f70bb9666 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 2/9] docs(circuits): document the HM4 Merkle tree and its proofs Co-Authored-By: Claude Opus 5.5 --- src/content/docs/circuits/merkle-trees.mdx | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/content/docs/circuits/merkle-trees.mdx diff --git a/src/content/docs/circuits/merkle-trees.mdx b/src/content/docs/circuits/merkle-trees.mdx new file mode 100644 index 0000000..798f565 --- /dev/null +++ b/src/content/docs/circuits/merkle-trees.mdx @@ -0,0 +1,97 @@ +--- +title: Merkle trees +description: "The 4-ary HM4 Merkle tree behind the transactions, zkState and registered-users trees: the node hash, prover-ordered insertion, the 30-element proof and its cost." +sidebar: + order: 4 +--- + +import Figure from "../../../components/diagrams/Figure.astro"; +import Cell from "../../../components/diagrams/Cell.astro"; + +MIST's three Merkle trees share one shape: depth 10, four children per node, and a node hash that sorts its children. A membership proof is 30 field elements, three siblings for each level. + +## Node hash + +`HM4` hashes four children, with zero standing for a missing child. Sort them so that `a <= b <= c <= d`: + +- If `a`, `b` and `c` are all zero, the node is `d`. A node with one non-zero child passes it through unchanged, and a node with none is zero. +- Otherwise the node is one evaluation of the width-4 Poseidon2 permutation over `(a, b, c, d)`, read as `state[0] + state[1]`. + +Each node costs at most one permutation. `HM4(x, 0, 0, 0) == x`, so a tree with few leaves needs no padding levels: the levels above its height pass the value through to depth 10. An empty tree's root is zero. + +## Prover-ordered insertion + +In the circuit, each level takes the running value and three siblings `w0 <= w1 <= w2` from the proof. Three conditional swaps place the running value among them before the permutation runs. + +
+
    +
  1. +

    1 Siblings

    +
    + + + +
    +

    Three siblings from the proof, ascending. A missing child is zero.

    +
  2. +
  3. +

    2 Insert

    +
    + + + + +
    +

    Three swaps, each on a boolean the prover supplies, place the running value.

    +
  4. +
  5. +

    3 Parent

    +
    + +
    +

    One permutation, read as state 0 plus state 1. The parent is the next level's running value.

    +
  6. +
+
+ +Each swap bit comes from a solver hint that compares the running value with the sibling, so an honest prover inserts it in sorted position. The circuit constrains each bit only to be boolean. Membership still holds only for the sorted order: the Chamber, each Reserve and the native Go tree build every node over sorted children, so any other order hashes to a different parent and the fold misses the root. + +## Proof shape + +A proof has 10 levels of three siblings, ascending within each level, so 30 elements. Missing children are zero, and every level above the tree's height is all zeros. + +| Source | Returns | +| --- | --- | +| `Chamber.merkleProof(index)` | The 30-element proof for global note index `index`, against the current root of that note's transactions tree | +| `Reserve.registeredUserProof(index)` | The 30-element proof for the user at `index`, against the Reserve's users root | +| `core/circuits/lib/merkle` | The native Go tree, `NativeHM4Tree`, with `NativeHM4ProveAt(idx)` | + +The contracts return a flat array, level by level. The circuit takes the same values as `[10][3]`. + +## Properties + +- **Position independence.** Because `HM4` sorts its children, a proof shows that a leaf is in the tree, not where. Nothing in the protocol depends on a leaf's position today. A future rule that does must bind the index itself. +- **Pass-through.** A node's value is a valid leaf at any depth, the root included. This is not exploitable: spending a note needs a Poseidon2 preimage of a note hash, and the fixed 30-element proof pins the depth for the circuit. +- **Updates.** Zeroing a leaf, which is how a Reserve removes a user, recomputes its ancestors over the same zero-padded groups. The result equals a fresh tree built over the same leaves, with that one set to zero, only because `HM4` sorts. + +## The three trees + +| Tree | Held by | Leaf | Capacity | Roots a spend may use | +| --- | --- | --- | --- | --- | +| Transactions | The Chamber, one tree per `treeId` | A note hash | 4^10 = 1,048,576 per tree. When a tree fills, the next one opens | Every root any transactions tree has had | +| zkState | The Chamber | `H3(reserve, reserveConfig, usersRoot)`, one per Reserve | 4^10 Reserves | The current root, or one superseded less than 10 minutes ago | +| Registered users | Each Reserve | `H2(owner, userKeyExchange)`, one per member | 4^10 leaf slots, removed users included | Proven against the users root inside the Reserve's zkState leaf | + +Both inputs of a spend share one `transactions_root`, so two real notes in different transactions trees cannot be spent together. + +## Cost + +| Operation | Constraints | +| --- | --- | +| One node, selector included | 283 | +| One membership lookup, 10 levels | 2,821 | + +Counts are from core's committed constraint snapshot. Every spend runs four folds, whatever its inputs: one per input note, one for the Reserve's zkState leaf and one for the sender's users leaf. A dummy's fold and the users fold at a Reserve without members are computed and their results ignored, so the circuit's shape never changes. From 66b9c98915b24a8144ab832b34f425c5045cc863 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 3/9] docs(circuits): document what a spend proves Co-Authored-By: Claude Opus 5.5 --- src/content/docs/circuits/spend.mdx | 134 ++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/content/docs/circuits/spend.mdx diff --git a/src/content/docs/circuits/spend.mdx b/src/content/docs/circuits/spend.mdx new file mode 100644 index 0000000..05d1dba --- /dev/null +++ b/src/content/docs/circuits/spend.mdx @@ -0,0 +1,134 @@ +--- +title: What a spend proves +description: "The 2-in/2-out shape of a MIST spend, every rule PrimaryTransactionCircuit asserts about it, the two authorisation modes, and what the circuit leaves to the Chamber." +sidebar: + order: 1 +--- + +import Figure from "../../../components/diagrams/Figure.astro"; +import Cell from "../../../components/diagrams/Cell.astro"; + +A spend consumes two notes and creates two, with an optional public withdrawal. `PrimaryTransactionCircuit` proves that the move follows the money rules without revealing which notes were spent, who owns the new ones or how the amounts split. + +## Shape + +Every spend has the same shape: two input notes, two output notes and one optional withdrawal. A zero-amount dummy fills a slot that has no real note, so a spend with one real input or one real output looks like any other. + +
+
    +
  1. +

    1 Two inputs

    +
    + +
    +

    Two notes from one transactions tree, or one note and a zero-amount dummy. Each publishes a nullifier.

    +
  2. +
  3. +

    2 One proof

    +
      +
    • Range
    • +
    • Conservation
    • +
    • Membership
    • +
    • Authorisation
    • +
    • Reserve state
    • +
    +

    One Groth16 proof binds 14 public inputs.

    +
  4. +
  5. +

    3 Two outputs

    +
    + + + Withdrawal +
    +

    Two new note hashes, always appended, plus an optional payout to a public address.

    +
  6. +
+
+ +The circuit's private inputs, as declared in `core/circuits/src/primary.go`: + +| Group | Fields | Meaning | +| --- | --- | --- | +| Custody | `Chamber`, `Reserve` | The Chamber ID and the Reserve address. One pair for the whole spend, not one per note | +| Input notes | `In1`, `In2` | Each has `Blinding`, `Owner`, `OwnerSecret`, `Asset.Addr`, `Asset.Amount` and a `MerkleProof` of 10 levels by 3 siblings | +| Output notes | `Out1Owner`, `Out1Amt`, `Out2Owner`, `Out2Amt` | Each output is an owner commitment and an amount. The asset is the spend's asset | +| Reserve messaging | `ReserveConfig`, `UsersRoot`, `ReserveProof`, `UserKeyExchange`, `UserProof`, `KeyIndex` | The Reserve's zkState leaf and its proof, the sender's registered key exchange and its proof, and the key index. See [Reserve messaging](/circuits/reserve-messaging/) | + +## Dummy notes + +A dummy is a note with amount 0. + +- **A dummy output** is an ordinary new note with amount 0. Its hash is appended like any other. +- **A dummy input** still supplies a Merkle proof, and the circuit still folds it, but the result is discarded instead of compared with `transactions_root`. The dummy's blinding and Merkle proof are free. + +Three things about a dummy input are still pinned. Its custody is the spend's, by construction. Its asset address must equal the other input's. Its owner must pass the same authorisation rule as a real input. + +The circuit asserts that at least one input is real (`in1Dummy * in2Dummy == 0`). A dummy's nullifier is derived and published like a real one, and the Chamber marks it spent. A prover therefore picks a fresh blinding for every dummy: a dummy whose nullifier is already spent makes the spend revert. + +## The rules + +Each row is an assertion in `PrimaryTransactionCircuit.Define`. + +| Rule | What the circuit asserts | +| --- | --- | +| Range | Every amount fits in 120 bits: both input amounts, both output amounts and `withdraw_amount`. The conservation sum therefore cannot wrap around the field | +| Conservation | `In1.Amount + In2.Amount == Out1Amt + Out2Amt + withdraw_amount` | +| One asset | The second input's asset address equals the first input's. Outputs carry no asset field of their own: they are hashed with the first input's asset | +| One custody | `H2(Chamber, Reserve)` is computed once and fed into every note hash and nullifier. There is no per-note Chamber or Reserve field, so no spend crosses a Chamber or Reserve boundary. This costs no constraints | +| Membership | Each real input's Merkle fold equals `transactions_root`. Both inputs are proven against the same root, so both sit in the same transactions tree | +| Nullifiers | Each input's nullifier is derived from the note and equals the public `nullifier_1` or `nullifier_2` | +| Distinct nullifiers | `nullifier_1 != nullifier_2`, so one note cannot fill both input slots and double its value | +| New notes | `new_note_i == H4(custody, OutiOwner, asset, OutiAmt)` for both outputs | +| Authorisation | Set by `auth_done`, below | +| Withdrawal pinning | `withdraw_asset` and `withdraw_reserve` are 0 without a withdrawal and the spend's asset and Reserve with one, below | +| Reserve state | The Reserve's zkState leaf is in `state_root` on every spend. At a Reserve with registered users, the messaging rules apply. See [Reserve messaging](/circuits/reserve-messaging/) | +| Payload pinning | `withdraw_to` and `tx_payload` are each squared once, so the verifying key binds them. See [Public inputs](/circuits/public-inputs/#binding) | + +The note hash and nullifier formulas are on [Notes and hashes](/circuits/notes-and-hashes/). + +## Authorisation + +The public flag `auth_done` picks who authorises the spend: the proof itself, or the Chamber by checking the caller. The check runs on each input note, so the notes actually spent are the ones authorised. + +| | `auth_done = 1` | `auth_done = 0` | +| --- | --- | --- | +| Owner type | A MIST Address, `H2(p, 0x6f776e6572)` | A wallet or contract address | +| Circuit | Each input's `Owner` equals `H2(OwnerSecret, 0x6f776e6572)`. The two inputs may have different owners, except at a Reserve with registered users | Both inputs have the same `Owner`, and it equals the public `owner` | +| Chamber | Ignores `owner` | Requires `owner == uint160(msg.sender)`, or reverts with `only owner caller` | +| Who can submit | Anyone, for example a relayer | Only the owner, as the caller | +| What is public | `owner` is unconstrained and should not be read | `owner` is the wallet or contract address, in the clear | + +The gate is a `Select`, not a branch, so both modes have the same circuit shape and constraint count. `Select` constrains `auth_done` to be boolean, and the Chamber reverts with `invalid authDone` on any value other than 0 or 1. + +Neither mode can spend the other's notes. A wallet-owned note cannot be spent with `auth_done = 1`, because a 160-bit address is not an `H2(p, 0x6f776e6572)` image without a preimage. A MIST Address note cannot be spent with `auth_done = 0`, because the Chamber compares `owner` with a 160-bit caller address. + +Sender privacy holds only for notes owned by a MIST Address. A spend with `auth_done = 0` publishes its owner. That is how a middleware works: it owns notes as a contract, and only it can submit their spends. + +## Withdrawal binding + +A spend withdraws when `withdraw_amount` is not 0. + +| Input | Without a withdrawal | With a withdrawal | +| --- | --- | --- | +| `withdraw_amount` | 0 | Any amount that fits in 120 bits and satisfies conservation | +| `withdraw_asset` | 0, so a private payment does not reveal its asset | The spend's asset | +| `withdraw_reserve` | 0, so a private payment does not reveal its Reserve | The spend's Reserve, which the Chamber calls to pay out | +| `withdraw_to` | Free, but bound by the proof | The recipient. The prover's choice, bound by the proof | + +The circuit does not range-check `withdraw_to`. The Chamber rejects `withdraw_asset`, `withdraw_reserve` and `withdraw_to` at or above 2^160 with `address input out of range`, before it verifies the proof. Because the proof binds `withdraw_to`, a relayer that submits an `auth_done = 1` withdrawal cannot redirect it. + +## What the circuit leaves to the Chamber + +A proof is a statement about notes and roots. These checks need on-chain state, so `Chamber.handleZkp` makes them: + +- **Spent nullifiers.** The circuit cannot know whether a nullifier was already used. The Chamber reverts with `transaction is spent`. +- **Known roots.** `transactions_root` must be a root some transactions tree has had, and `state_root` must be the current zkState root or one superseded less than 10 minutes ago. +- **The caller,** when `auth_done = 0`. +- **The published commitments.** The six elements in calldata must fold to `auditor_commitments`. +- **Address width** of the three address inputs. + +[Contracts](/contracts/) covers `handleZkp` and the order of these checks. From 3afe0934fe8117f610cc14f4f8216ab86285cd69 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 4/9] docs(circuits): list the 14 public inputs with encoding and binding Co-Authored-By: Claude Opus 5.5 --- src/content/docs/circuits/public-inputs.mdx | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/content/docs/circuits/public-inputs.mdx diff --git a/src/content/docs/circuits/public-inputs.mdx b/src/content/docs/circuits/public-inputs.mdx new file mode 100644 index 0000000..d867be4 --- /dev/null +++ b/src/content/docs/circuits/public-inputs.mdx @@ -0,0 +1,63 @@ +--- +title: Public inputs +description: "The 14 public inputs of PrimaryTransactionCircuit in order, how each is encoded and bound, and what one spend reveals to observers and to a Reserve's key holder." +sidebar: + order: 2 +--- + +A proof binds 14 public inputs. `Chamber.handleZkp` passes them to the verifier as `uint256[14] input` and decodes them into its `PublicParams` struct in the same order. + +## The 14 inputs + +gnark orders public inputs by field declaration in `PrimaryTransactionCircuit`. `Withdraw` is a `note.Asset`, whose fields are `Amount` then `Addr`, so the withdrawal amount comes before its asset. The index is the position in `handleZkp`'s `input` array. + +| Index | Name | Circuit field | `PublicParams` field | Meaning | +| --- | --- | --- | --- | --- | +| 0 | `nullifier_1` | `Nullifier1` | `nullifier1` | Nullifier of the first input note | +| 1 | `nullifier_2` | `Nullifier2` | `nullifier2` | Nullifier of the second input note | +| 2 | `new_note_1` | `NewNote1` | `newNote1` | First new note hash, appended to the transactions tree | +| 3 | `new_note_2` | `NewNote2` | `newNote2` | Second new note hash, appended after the first | +| 4 | `transactions_root` | `TransactionsRoot` | `transactionsRoot` | The transactions-tree root both inputs are proven against | +| 5 | `state_root` | `StateRoot` | `stateRoot` | The zkState root holding the Reserve's leaf | +| 6 | `withdraw_amount` | `Withdraw.Amount` | `withdrawAmount` | Amount paid out on-chain, 0 for a private payment | +| 7 | `withdraw_asset` | `Withdraw.Addr` | `withdrawAsset` | The asset paid out, 0 without a withdrawal | +| 8 | `withdraw_reserve` | `WithdrawReserve` | `withdrawReserve` | The Reserve that pays out, 0 without a withdrawal | +| 9 | `withdraw_to` | `WithdrawTo` | `withdrawTo` | The public recipient of a withdrawal | +| 10 | `tx_payload` | `TxPayload` | `txPayload` | Free data for a middleware. The Chamber decodes it and does not use it | +| 11 | `owner` | `Owner` | `owner` | The owner the Chamber compares with the caller when `auth_done = 0` | +| 12 | `auth_done` | `AuthDone` | `authDone` | 1 when the proof authorised the spend, 0 when the caller must be `owner` | +| 13 | `auditor_commitments` | `AuditorCommitments` | `auditorCommitments` | The `Fold2` of the six commitment elements the spend publishes, or 0 | + +The count and order are the decoding contract between the circuit, `ChamberVerifier.sol` and `Chamber.PublicParams`. Changing either means a new circuit, a new verifier and a new `PublicParams` together. Core's `TestVerifierPublicInputCountMatchesCircuit` holds all three to 14, and a run against core `cf1413d` for these pages passed. + +## Encoding + +- **Field elements.** Every input is an element of the BN254 scalar field, passed as a `uint256` below the field order `r`. The verifier reverts with `PublicInputNotInField` on anything larger. The check matters: the EVM's scalar-multiplication precompile reduces its scalar, so without it `x` and `x + r` would verify alike and a spent nullifier could be replayed under its alias. +- **Addresses.** Addresses enter the field as left-padded big-endian `uint160` values, with no reduction. The Chamber requires inputs 7, 8 and 9 to be below 2^160, or reverts with `address input out of range`, and reads them as `address`. +- **`auth_done`** is 0 or 1. The circuit's `Select` constrains it to be boolean, and the Chamber reverts with `invalid authDone` on any other value. +- **`auditor_commitments`** comes with its preimage. `handleZkp` takes a third argument, `uint256[] auditorCommitments_`, which must be six elements below `r` that fold to input 13, or empty when input 13 is 0. + +## Binding + +Groth16 binds a public input only through a non-zero coefficient in some constraint. An input that no constraint reads drops out of the verifier's public-input sum and can be rewritten in calldata without invalidating the proof. Every input here is read by a constraint: + +| Inputs | Bound by | +| --- | --- | +| `nullifier_1`, `nullifier_2`, `new_note_1`, `new_note_2` | Equality with the hashes the circuit computes | +| `transactions_root` | The membership check of each input. For a dummy input the root is selected in place of the fold, which still reads it | +| `state_root` | The Reserve's zkState membership check, which runs on every spend | +| `withdraw_amount`, `withdraw_asset`, `withdraw_reserve` | Range check, conservation and withdrawal pinning | +| `withdraw_to`, `tx_payload` | A square, `x * x`, whose result is unused. No other constraint reads them | +| `owner`, `auth_done` | The authorisation gate | +| `auditor_commitments` | The messaging equality. It is conditional, but the conditional form keeps the coefficient non-zero even when messaging is off and the value is free | + +The squares look like dead weight and are not. A linear identity would not do the same job: its terms cancel to a zero coefficient. Core's `TestEveryPublicInputIsBound` changes each input of a real Groth16 proof in turn and requires verification to fail. + +## What one spend reveals + +| To | Learns | Does not learn | +| --- | --- | --- | +| Any observer | Both nullifiers and both new note hashes. Both roots. Whether a withdrawal happened, and its amount, asset, Reserve and recipient. `auditor_commitments` and its six-element preimage. `owner` and `auth_done`. Whatever is in `tx_payload` | Which notes were spent. The input amounts and how the outputs split them. The asset and the Reserve of a private payment. Who owns the new notes. Whether an input was a dummy | +| The key holder of a Reserve with registered users | For each member spend: which member sent it, the asset, both output owner commitments and both output amounts | Who the recipients are: they appear only as owner commitments. The two input amounts one by one | + +Every spend has the same shape and appends two notes, zero-amount outputs included, so spends look alike. A payment inside MIST hides among the notes of every Reserve, because the transactions tree is shared. A withdrawal reveals its Reserve, so it hides only among that Reserve's notes. A spend with `auth_done = 0` names its owner, so it gives up sender privacy. From 3848f35a37c1a3e95540499e3110552f7ad8de52 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 5/9] docs(circuits): document reserve messaging and the keystream Co-Authored-By: Claude Opus 5.5 --- .../docs/circuits/reserve-messaging.mdx | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/content/docs/circuits/reserve-messaging.mdx diff --git a/src/content/docs/circuits/reserve-messaging.mdx b/src/content/docs/circuits/reserve-messaging.mdx new file mode 100644 index 0000000..db4d874 --- /dev/null +++ b/src/content/docs/circuits/reserve-messaging.mdx @@ -0,0 +1,155 @@ +--- +title: Reserve messaging +description: "How the circuit binds a spend to its Reserve's state, checks that the sender is a member, and encrypts the spend's details for the key holder with the Hash-and-Add keystream." +sidebar: + order: 5 +--- + +import Figure from "../../../components/diagrams/Figure.astro"; +import Cell from "../../../components/diagrams/Cell.astro"; + +At a Reserve with registered users, every spend must come from a member and must publish its details encrypted under a key that member shares with the key holder. The primary circuit does the encryption itself. No second circuit is involved. + +## The Reserve's zkState leaf + +The Chamber keeps one zkState leaf per Reserve: + +```text +reserveConfig = H2(keyHash, keyInputPoint) +stateLeaf = H3(reserve, reserveConfig, usersRoot) +``` + +`keyHash` and `keyInputPoint` are two opaque field elements of Reserve metadata. The circuit binds `reserveConfig` into the leaf and never opens it. `usersRoot` is the root of the Reserve's registered-users tree, zero while the tree is empty. + +The circuit proves the leaf is in `state_root` on every spend, with messaging on or off. `usersRoot` is therefore read off the leaf the Chamber committed, so a prover cannot claim a zero users root to skip messaging at a Reserve that has members. + +## Messaging on and off + +Messaging is on when `usersRoot` is not zero. The rules are gated with `Select`, not by branching, so the circuit's shape and constraint count are the same either way. + +| Rule | `usersRoot == 0` | `usersRoot != 0` | +| --- | --- | --- | +| zkState leaf is in `state_root` | Checked | Checked | +| Both inputs have the same owner | Not checked | Checked | +| The sender is a member | Not checked | `H2(In1.Owner, userKeyExchange)` is in `usersRoot` | +| `KeyIndex` fits in 8 bits | Checked | Checked | +| `auditor_commitments` | Free | Equals `Fold2([privateTxKey, c0, c1, c2, c3, c4])` | + +A new Reserve's leaf is `H3(reserve, reserveConfig, 0)`, so it is spendable from its first block with no sync step. Messaging switches on when the first user registers, and from then on it applies to every note at that Reserve, notes created earlier included. It never switches off: a removal that would leave the users tree empty reverts. + +When a Reserve's users root first becomes non-zero, the Chamber stops accepting every superseded zkState root at once. Those roots hold a zero users root for that Reserve and would let a spend skip messaging. + +:::caution[Unregistered holders cannot spend at a Reserve with members] +A deposit cannot check membership, because the owner commitment hides the owner. A holder who deposited before being registered, or before the Reserve had members, cannot spend or withdraw until they are registered. An exit spend that lets any owner withdraw in public is **Planned**. +::: + +## Membership + +A member's leaf is `H2(owner, userKeyExchange)`. `owner` is the owner of the notes the member spends: a MIST Address or a wallet address. `userKeyExchange` is a value the member and the key holder agree off-chain. It never appears on-chain, and it must be a full-entropy key-exchange output, or the public leaf could be brute-forced. The protocol does not fix the exchange. + +The Reserve's registrar adds the leaf, and only this hash goes on-chain. A removed member's leaf is set to zero. A member who was removed can still prove against a zkState root that holds their leaf until that root leaves the 10-minute grace window. [Contracts](/contracts/) covers registration and removal. + +## Key and keystream + +The spend picks a `KeyIndex` from 0 to 255 and derives a fresh key: + +```text +k = H2(userKeyExchange, keyIndex) +``` + +Hash-and-Add is a stream cipher on the width-4 Poseidon2 permutation `P4`. The block at counter `s` permutes `(k, s, s + 1, s + 2)` and emits three masked elements: + +```text +e_j = P4(k, s, s + 1, s + 2)[j + 1] - k, j = 0, 1, 2 +``` + +`state[0]` and the raw lanes never leave the block, so a known plaintext reveals only a masked value. Blocks advance the counter by 3. Messaging starts the stream at `s = 0`. + +- **The identifier** is the stream's first element, `P4(k, 0, 1, 2)[1] - k`. Core calls it `privateTxKey`. It encrypts nothing. +- **The keystream** is the rest of the stream in order: the last two elements of block 0, then three per block. +- **Encryption** is `c_i = m_i + κ_i mod r`. Decryption subtracts the same keystream. + +
+
    +
  1. +

    1 Key

    +
    + + + +
    +

    The key exchange and a key index give the key. Neither is published.

    +
  2. +
  3. +

    2 Stream

    +
      +
    • Block 0
    • +
    • Block 1
    • +
    +

    Block 0 emits the identifier and two keystream elements. Block 1 emits three more.

    +
  4. +
  5. +

    3 Six published

    +
    + + + + + + +
    +

    The identifier, then five ciphertexts. Their fold is auditor_commitments.

    +
  6. +
+
+ +## The six commitments + +The plaintext is fixed by `ReservePlaintext` in `core/circuits/src/primary.go`. A spend publishes either nothing or exactly these six elements: + +| Element | Contents | +| --- | --- | +| 0 | `privateTxKey`, the identifier | +| 1 | Ciphertext of the asset address | +| 2 | Ciphertext of output 1's owner commitment | +| 3 | Ciphertext of output 1's amount | +| 4 | Ciphertext of output 2's owner commitment | +| 5 | Ciphertext of output 2's amount | + +Their fold is the public input: + +```text +auditor_commitments = H2(H2(H2(H2(H2(e0, e1), e2), e3), e4), e5) +``` + +The circuit fixes only the fold. `Chamber.handleZkp` takes the six elements as `auditorCommitments_` and requires each to be below the field order and the six to fold to input 13, or an empty array when input 13 is 0. It files the spend under element 0 in `privateTxCommitments`, reverts with `private tx key used` if that identifier was filed before, and emits `PrivateTransfer(privateTxKey, newNote1, newNote2, commitments)`. + +At a Reserve without members, `auditor_commitments` is free. A spend there may publish nothing, which leaves `auditor_commitments = 0`, or six elements of its choosing. To anyone without the key, ciphertexts and identifiers look uniformly random, so random elements look the same. + +## Decryption + +The key holder holds each member's `userKeyExchange`. For each member and each key index from 0 to 255, it derives `k`, computes the identifier and looks it up in `privateTxCommitments` or in `PrivateTransfer` events, where it is indexed. A match gives the six elements, and subtracting the keystream gives the plaintext. + +| The key holder learns | The key holder does not learn | +| --- | --- | +| Which member sent the spend, the asset, both output owner commitments and both output amounts | Who the recipients are: they appear only as owner commitments. The two input amounts one by one | + +Handing one spend's `k` to a reviewer reveals that spend only: recovering `userKeyExchange` from `k` is a preimage problem. The ciphertext is not addressed to the recipient, so a recipient cannot use it to find their note. + +## Limits + +| Limit | Effect | +| --- | --- | +| 256 identifiers per key exchange | `KeyIndex` is range-checked to 8 bits. After 256 messaging spends a member needs a new key exchange and a new registration | +| One namespace for every Reserve | The Chamber files identifiers first come, first served across all Reserves, and the record names no Reserve. Whoever holds a member's key exchange can derive that member's identifiers and file a real spend under one first. At a Reserve without members anyone can file under any identifier | +| Calldata is public | Hash-and-Add hides the plaintext only from someone without the key exchange. Hash-and-Add is symmetric, so the long-term privacy of the ciphertexts rests on the key exchange the Reserve picks | +| Sender only | The record identifies the sender. It carries no beneficiary record and no per-input record | + +Sequential, owner-bound identifiers, which remove the 256 cap and stop identifier squatting, are **Planned**. + +## Cost + +A keystream block costs 265 constraints however many of its elements are used: 265 for one or two plaintexts and 529 for three, from core's committed constraint snapshot. Messaging's identifier and five ciphertexts take two blocks. The snapshot has no entry for five plaintexts on its own. From 8dc662d45276028e3c2cc0aff0ff09a2cd576bbd Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 6/9] docs(circuits): state the constraint count and the trusted setup status Co-Authored-By: Claude Opus 5.5 --- .../docs/circuits/constraints-and-setup.mdx | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/content/docs/circuits/constraints-and-setup.mdx diff --git a/src/content/docs/circuits/constraints-and-setup.mdx b/src/content/docs/circuits/constraints-and-setup.mdx new file mode 100644 index 0000000..4ec032b --- /dev/null +++ b/src/content/docs/circuits/constraints-and-setup.mdx @@ -0,0 +1,74 @@ +--- +title: Constraints and trusted setup +description: "The measured constraint count of PrimaryTransactionCircuit, the proof system it runs on, and the status of its trusted setup: single-party keys, no multi-party ceremony." +sidebar: + order: 6 +--- + +`PrimaryTransactionCircuit` compiles to 17,318 R1CS constraints. Its proving and verifying keys come from a single-party Groth16 setup. No multi-party ceremony has been run. + +## Constraint counts + +Core commits the count of every circuit and gadget in `core/circuits/build/.constraint-snapshot`. The figures below are that file at core `cf1413d`. For these pages, core's `TestConstraintSnapshotMatchesCompile` was run against `cf1413d`: it compiles each entry that core builds and requires the committed count. It passed. + +| Circuit or gadget | Constraints | +| --- | --- | +| `PrimaryTransactionCircuit` | 17,318 | +| `Hash2` | 217 | +| `Hash3` | 241 | +| `Hash4` | 265 | +| `MerkleHash4`, one node | 283 | +| `MerkleProofVerification`, 10 levels | 2,821 | +| `HashAndAdd`, one plaintext | 265 | +| `HashAndAdd`, two plaintexts | 265 | +| `HashAndAdd`, three plaintexts | 529 | + +The count is the same for every spend. Dummy inputs, messaging on or off, and either `auth_done` mode change only witness values, never the circuit's shape. Each conditional rule is a `Select` or a conditional equality, and every Merkle fold is computed whether or not its result is used. + +The snapshot also lists circuits built in `core-deploy/experiments`: `CompliantTransactionCircuit`, `OuterGroth16Circuit`, `OuterGroth16TwoProofCircuit` and `PrimaryChamberWrappingCircuit`. None has a proving key, a verifier or a contract path. They are not part of the protocol. + +## Proof system + +| Item | Value | +| --- | --- | +| Proof system | Groth16 | +| Curve | BN254, the curve of the EVM's pairing precompiles | +| Library | gnark v0.16.4 | +| Public inputs | 14 | +| Proof on-chain | Eight `uint256` words, 256 bytes, passed to `Chamber.handleZkp` as `uint256[8] proof` | + +Groth16 over BN254 is not post-quantum. The circuit does no elliptic-curve operations of its own: the curve is the proof system's. + +## Trusted setup + +The keys come from one call to gnark's `groth16.Setup` in `core/scripts/gen`, run by one party. No multi-party computation ceremony has been run for this circuit. + +Groth16 security rests on the setup's secret randomness being destroyed. Anyone who kept it could forge a proof for any public inputs, including a withdrawal, and the Chamber would accept it. With a single-party setup, users trust that one party. + +:::caution[Single-party development keys] +The current keys are for development. The specification requires a multi-party ceremony before production. It is **Planned**, and runs once, on the final circuit version. +::: + +## Artifacts + +`core-deploy/scripts/build.sh` builds every artifact from the circuit in one pass. + +| Artifact | Path | +| --- | --- | +| Constraint system, proving key | `core-deploy/dist/prover/cs`, `core-deploy/dist/prover/pk` | +| Verifying key | `core-deploy/dist/vk.json` | +| Solidity verifier | Exported by gnark, then committed as `core/contracts/src/ChamberVerifier.sol` | +| End-to-end fixture | `core/testdata/e2e_fixture.json`, a real proof the Foundry suite verifies | +| Constraint snapshot | `core/circuits/build/.constraint-snapshot` | +| Prover WASM | `core-deploy/dist/mist.wasm`, which embeds the constraint system and proving key | + +`scripts/gen` skips the setup when the compiled constraint system matches the stored one byte for byte, and reuses the stored keys. A new setup runs only when the constraints change. + +## Changing the circuit + +- **`core/circuits/src` is frozen once deployed.** Any change to its constraints invalidates the keys, the verifier and the fixture. New circuits are built in `core-deploy/experiments`. +- **Moving Go code can invalidate the proving key.** gnark records solver-hint function paths in the serialized constraint system. Renaming the package that defines `hintShouldSwap` changes those bytes, even with identical constraints. Every hint is registered in `gadgets.InitHints()`. +- **A gnark upgrade changes the serialized constraint system, not the circuit.** The constraint system is re-serialized with the new gnark, the setup is skipped, and the verifier regenerates identically. +- **A new verifier is not live when it is generated.** Regenerating `ChamberVerifier.sol` changes nothing on-chain. The Chamber owner proposes the new verifier, and it can go live only after a 7-day timelock. See [Contracts](/contracts/). + +The specification plans three circuit changes, each its own circuit version with its own setup and verifier: exit spends, then sequential identifiers, then a relayer fee leg. All three are **Planned**. From 44e722b6855b7a8fbe04377a8980d4b1d17787d8 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 04:47:15 +0530 Subject: [PATCH 7/9] docs(circuits): link the detailed pages from the overview Co-Authored-By: Claude Opus 5.5 --- src/content/docs/circuits/index.mdx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/content/docs/circuits/index.mdx b/src/content/docs/circuits/index.mdx index 4a957f6..76b93fe 100644 --- a/src/content/docs/circuits/index.mdx +++ b/src/content/docs/circuits/index.mdx @@ -6,6 +6,8 @@ sidebar: order: 0 --- +import RuledIndex from "../../../components/RuledIndex.astro"; + Every MIST spend is one Groth16 proof of one circuit, `PrimaryTransactionCircuit`. It is written in Go with gnark and proven over BN254. The circuit enforces the money rules. Nothing is printed or destroyed: value is pooled and moved from one set of notes to another, or withdrawn on-chain. @@ -71,6 +73,19 @@ Costs are R1CS constraints, recorded in the constraint snapshot that core commit The specification describes three circuit changes that are not built: a relayer fee leg, exit spends that let any owner leave a Reserve, and sequential messaging identifiers. Each lands as its own circuit version. +## Detailed pages + + + ## Source The circuit is `core/circuits/src/primary.go`. Its Poseidon2 and Merkle gadgets are in `core/circuits/gadgets`, and the native reference implementations in `core/circuits/lib`. The [specification](https://github.com/mistcash/mist/blob/main/spec/04_circuit_architecture.md) defines each check. From 2fbe576cee35b58a824d19685d7602d1a312604f Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Thu, 26 Nov 2026 05:03:57 +0530 Subject: [PATCH 8/9] docs(circuits): correct accuracy points from an independent review Count the width-4 uses correctly, say that snapshot gadget figures include the wrapper's assertion, scope the custody rule and note that no public input carries the Chamber ID, point zkState root acceptance at the history cutoff, and describe the setup and drift checks without process claims. Co-Authored-By: Claude Opus 5.5 --- src/content/docs/circuits/constraints-and-setup.mdx | 8 +++++--- src/content/docs/circuits/merkle-trees.mdx | 4 ++-- src/content/docs/circuits/notes-and-hashes.mdx | 6 ++++-- src/content/docs/circuits/public-inputs.mdx | 2 +- src/content/docs/circuits/reserve-messaging.mdx | 2 +- src/content/docs/circuits/spend.mdx | 5 +++-- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/content/docs/circuits/constraints-and-setup.mdx b/src/content/docs/circuits/constraints-and-setup.mdx index 4ec032b..c9e2ec3 100644 --- a/src/content/docs/circuits/constraints-and-setup.mdx +++ b/src/content/docs/circuits/constraints-and-setup.mdx @@ -9,7 +9,7 @@ sidebar: ## Constraint counts -Core commits the count of every circuit and gadget in `core/circuits/build/.constraint-snapshot`. The figures below are that file at core `cf1413d`. For these pages, core's `TestConstraintSnapshotMatchesCompile` was run against `cf1413d`: it compiles each entry that core builds and requires the committed count. It passed. +Core commits the count of every circuit and gadget in `core/circuits/build/.constraint-snapshot`. The figures below are that file at core `cf1413d`. Core's `TestConstraintSnapshotMatchesCompile` compiles each entry that core builds and fails if any count differs from the committed file. | Circuit or gadget | Constraints | | --- | --- | @@ -23,6 +23,8 @@ Core commits the count of every circuit and gadget in `core/circuits/build/.cons | `HashAndAdd`, two plaintexts | 265 | | `HashAndAdd`, three plaintexts | 529 | +Each gadget is measured on a small wrapper circuit that also asserts the result equals a public input, so each gadget figure includes that one constraint. Ten Merkle levels cost 2,821, not ten times 283. + The count is the same for every spend. Dummy inputs, messaging on or off, and either `auth_done` mode change only witness values, never the circuit's shape. Each conditional rule is a `Select` or a conditional equality, and every Merkle fold is computed whether or not its result is used. The snapshot also lists circuits built in `core-deploy/experiments`: `CompliantTransactionCircuit`, `OuterGroth16Circuit`, `OuterGroth16TwoProofCircuit` and `PrimaryChamberWrappingCircuit`. None has a proving key, a verifier or a contract path. They are not part of the protocol. @@ -41,7 +43,7 @@ Groth16 over BN254 is not post-quantum. The circuit does no elliptic-curve opera ## Trusted setup -The keys come from one call to gnark's `groth16.Setup` in `core/scripts/gen`, run by one party. No multi-party computation ceremony has been run for this circuit. +The keys come from one run of gnark's BN254 Groth16 setup, `groth16_bn254.Setup` in `core/scripts/gen`. That is a single-party setup: no multi-party computation ceremony has been run for this circuit. Groth16 security rests on the setup's secret randomness being destroyed. Anyone who kept it could forge a proof for any public inputs, including a withdrawal, and the Chamber would accept it. With a single-party setup, users trust that one party. @@ -62,7 +64,7 @@ The current keys are for development. The specification requires a multi-party c | Constraint snapshot | `core/circuits/build/.constraint-snapshot` | | Prover WASM | `core-deploy/dist/mist.wasm`, which embeds the constraint system and proving key | -`scripts/gen` skips the setup when the compiled constraint system matches the stored one byte for byte, and reuses the stored keys. A new setup runs only when the constraints change. +`scripts/gen` skips the setup when the compiled constraint system matches the stored one byte for byte and the stored keys load, and reuses them. Otherwise it runs a new setup. ## Changing the circuit diff --git a/src/content/docs/circuits/merkle-trees.mdx b/src/content/docs/circuits/merkle-trees.mdx index 798f565..ac4b980 100644 --- a/src/content/docs/circuits/merkle-trees.mdx +++ b/src/content/docs/circuits/merkle-trees.mdx @@ -82,7 +82,7 @@ The contracts return a flat array, level by level. The circuit takes the same va | Tree | Held by | Leaf | Capacity | Roots a spend may use | | --- | --- | --- | --- | --- | | Transactions | The Chamber, one tree per `treeId` | A note hash | 4^10 = 1,048,576 per tree. When a tree fills, the next one opens | Every root any transactions tree has had | -| zkState | The Chamber | `H3(reserve, reserveConfig, usersRoot)`, one per Reserve | 4^10 Reserves | The current root, or one superseded less than 10 minutes ago | +| zkState | The Chamber | `H3(reserve, reserveConfig, usersRoot)`, one per Reserve | 4^10 Reserves | The current root, or one superseded less than 10 minutes ago and not retired by a Reserve's first registration | | Registered users | Each Reserve | `H2(owner, userKeyExchange)`, one per member | 4^10 leaf slots, removed users included | Proven against the users root inside the Reserve's zkState leaf | Both inputs of a spend share one `transactions_root`, so two real notes in different transactions trees cannot be spent together. @@ -94,4 +94,4 @@ Both inputs of a spend share one `transactions_root`, so two real notes in diffe | One node, selector included | 283 | | One membership lookup, 10 levels | 2,821 | -Counts are from core's committed constraint snapshot. Every spend runs four folds, whatever its inputs: one per input note, one for the Reserve's zkState leaf and one for the sender's users leaf. A dummy's fold and the users fold at a Reserve without members are computed and their results ignored, so the circuit's shape never changes. +Counts are from core's committed constraint snapshot. Each is measured on a wrapper circuit that also asserts the result equals a public input, so each includes that one constraint: ten levels cost 2,821, not ten times 283. Every spend runs four folds, whatever its inputs: one per input note, one for the Reserve's zkState leaf and one for the sender's users leaf. A dummy's fold and the users fold at a Reserve without members are computed and their results ignored, so the circuit's shape never changes. diff --git a/src/content/docs/circuits/notes-and-hashes.mdx b/src/content/docs/circuits/notes-and-hashes.mdx index 44cffd6..f332be5 100644 --- a/src/content/docs/circuits/notes-and-hashes.mdx +++ b/src/content/docs/circuits/notes-and-hashes.mdx @@ -62,7 +62,7 @@ The keyword `0x6f776e6572` is the ASCII string "owner" (478745093490). A MIST Ad Every width uses the same parameters: the BN254 scalar field, 8 full rounds, 56 partial rounds and S-box exponent 5. The round counts are set in `core/circuits/gadgets/gadgets.go` and `core/circuits/lib/hash/poseidon2.go`. The exponent is gnark-crypto's fixed S-box degree for BN254. -Each function feeds an input forward into one element of the final permutation state. The width-4 permutation serves four functions, told apart only by how the output is read: +Each function feeds an input forward into one element of the final permutation state. The width-4 permutation serves three of them, `H4`, `HM4` and the keystream, told apart only by how the output is read: | Function | Width | Output | Constraints | | --- | --- | --- | --- | @@ -72,7 +72,9 @@ Each function feeds an input forward into one element of the final permutation s | `HM4`, the Merkle node | 4 | `state[0] + state[1]`, over sorted children | 283, selector included | | Keystream block | 4 | `state[j + 1] - k`, for `j = 0, 1, 2` | 265 per block | -Constraint counts are from core's committed constraint snapshot. Reading the output differently separates the domains with no extra input, tag or round: a collision across two uses would need one permutation state element to equal an input the other use feeds forward. +Constraint counts are from core's committed constraint snapshot. Each is measured on a small wrapper circuit that also asserts the result equals a public input, so each figure includes that one constraint. + +The output read is the only thing that separates the three width-4 uses: there is no extra input, domain tag or round. The [specification](https://github.com/mistcash/mist/blob/main/spec/01_system_overview.md) gives the argument for why that is enough. `Fold2` reduces a vector to one element by chaining `H2` from the left: `Fold2(v) = H2(... H2(H2(v0, v1), v2) ..., vn)`. diff --git a/src/content/docs/circuits/public-inputs.mdx b/src/content/docs/circuits/public-inputs.mdx index d867be4..65db372 100644 --- a/src/content/docs/circuits/public-inputs.mdx +++ b/src/content/docs/circuits/public-inputs.mdx @@ -28,7 +28,7 @@ gnark orders public inputs by field declaration in `PrimaryTransactionCircuit`. | 12 | `auth_done` | `AuthDone` | `authDone` | 1 when the proof authorised the spend, 0 when the caller must be `owner` | | 13 | `auditor_commitments` | `AuditorCommitments` | `auditorCommitments` | The `Fold2` of the six commitment elements the spend publishes, or 0 | -The count and order are the decoding contract between the circuit, `ChamberVerifier.sol` and `Chamber.PublicParams`. Changing either means a new circuit, a new verifier and a new `PublicParams` together. Core's `TestVerifierPublicInputCountMatchesCircuit` holds all three to 14, and a run against core `cf1413d` for these pages passed. +The count and order are the decoding contract between the circuit, `ChamberVerifier.sol` and `Chamber.PublicParams`. Changing either means a new circuit, a new verifier and a new `PublicParams` together. Core's `TestVerifierPublicInputCountMatchesCircuit` holds all three to 14. No check compares the order field by field: it is held by the circuit's declaration order matching `PublicParams`, and the Foundry suite replays a real proof through `handleZkp`. ## Encoding diff --git a/src/content/docs/circuits/reserve-messaging.mdx b/src/content/docs/circuits/reserve-messaging.mdx index db4d874..52288bc 100644 --- a/src/content/docs/circuits/reserve-messaging.mdx +++ b/src/content/docs/circuits/reserve-messaging.mdx @@ -152,4 +152,4 @@ Sequential, owner-bound identifiers, which remove the 256 cap and stop identifie ## Cost -A keystream block costs 265 constraints however many of its elements are used: 265 for one or two plaintexts and 529 for three, from core's committed constraint snapshot. Messaging's identifier and five ciphertexts take two blocks. The snapshot has no entry for five plaintexts on its own. +A keystream block costs the same however many of its elements are used. Core's committed constraint snapshot records 265 constraints for one or two plaintexts and 529 for three, each measured on a wrapper circuit that adds one equality assertion. Messaging's identifier and five ciphertexts take two blocks. The snapshot has no entry for five plaintexts on its own. diff --git a/src/content/docs/circuits/spend.mdx b/src/content/docs/circuits/spend.mdx index 05d1dba..4c301a9 100644 --- a/src/content/docs/circuits/spend.mdx +++ b/src/content/docs/circuits/spend.mdx @@ -78,7 +78,7 @@ Each row is an assertion in `PrimaryTransactionCircuit.Define`. | Range | Every amount fits in 120 bits: both input amounts, both output amounts and `withdraw_amount`. The conservation sum therefore cannot wrap around the field | | Conservation | `In1.Amount + In2.Amount == Out1Amt + Out2Amt + withdraw_amount` | | One asset | The second input's asset address equals the first input's. Outputs carry no asset field of their own: they are hashed with the first input's asset | -| One custody | `H2(Chamber, Reserve)` is computed once and fed into every note hash and nullifier. There is no per-note Chamber or Reserve field, so no spend crosses a Chamber or Reserve boundary. This costs no constraints | +| One custody | `H2(Chamber, Reserve)` is computed once and fed into every note hash and nullifier. There is no per-note Chamber or Reserve field, so every note in a spend has the same custody. Beyond that one `H2`, the rule costs no constraints | | Membership | Each real input's Merkle fold equals `transactions_root`. Both inputs are proven against the same root, so both sit in the same transactions tree | | Nullifiers | Each input's nullifier is derived from the note and equals the public `nullifier_1` or `nullifier_2` | | Distinct nullifiers | `nullifier_1 != nullifier_2`, so one note cannot fill both input slots and double its value | @@ -126,7 +126,8 @@ The circuit does not range-check `withdraw_to`. The Chamber rejects `withdraw_as A proof is a statement about notes and roots. These checks need on-chain state, so `Chamber.handleZkp` makes them: - **Spent nullifiers.** The circuit cannot know whether a nullifier was already used. The Chamber reverts with `transaction is spent`. -- **Known roots.** `transactions_root` must be a root some transactions tree has had, and `state_root` must be the current zkState root or one superseded less than 10 minutes ago. +- **Known roots.** `transactions_root` must be a root some transactions tree has had, and `state_root` must be the current zkState root or one superseded less than 10 minutes ago. A Reserve's first registration retires superseded roots at once: see [Reserve messaging](/circuits/reserve-messaging/#messaging-on-and-off). +- **The Chamber itself.** No public input carries the Chamber ID: `Chamber` is a private input. Two Chambers that shared a verifier would be kept apart only by their roots, since `transactions_root` must be in this Chamber's history and `state_root` names this Chamber's Reserves. - **The caller,** when `auth_done = 0`. - **The published commitments.** The six elements in calldata must fold to `auditor_commitments`. - **Address width** of the three address inputs. From edea7735ab8063a60780e42fcbbf82ad44c24641 Mon Sep 17 00:00:00 2001 From: Shramee Srivastav <11048263+shramee@users.noreply.github.com> Date: Fri, 27 Nov 2026 09:18:02 +0530 Subject: [PATCH 9/9] docs(circuits): follow core fa7b92d The circuit changed by one comment, so the constraint figures stand: the snapshot matches a fresh compile at fa7b92d. The messaging page now says a removed member is frozen like an unregistered holder, and that the Chamber refuses a users root returning to zero. Co-Authored-By: Claude Opus 5.5 --- src/content/docs/circuits/constraints-and-setup.mdx | 2 +- src/content/docs/circuits/reserve-messaging.mdx | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/content/docs/circuits/constraints-and-setup.mdx b/src/content/docs/circuits/constraints-and-setup.mdx index c9e2ec3..c1c77d0 100644 --- a/src/content/docs/circuits/constraints-and-setup.mdx +++ b/src/content/docs/circuits/constraints-and-setup.mdx @@ -9,7 +9,7 @@ sidebar: ## Constraint counts -Core commits the count of every circuit and gadget in `core/circuits/build/.constraint-snapshot`. The figures below are that file at core `cf1413d`. Core's `TestConstraintSnapshotMatchesCompile` compiles each entry that core builds and fails if any count differs from the committed file. +Core commits the count of every circuit and gadget in `core/circuits/build/.constraint-snapshot`. The figures below are that file at core `fa7b92d`, unchanged since `cf1413d`. Core's `TestConstraintSnapshotMatchesCompile` compiles each entry that core builds and fails if any count differs from the committed file. | Circuit or gadget | Constraints | | --- | --- | diff --git a/src/content/docs/circuits/reserve-messaging.mdx b/src/content/docs/circuits/reserve-messaging.mdx index 52288bc..dce8166 100644 --- a/src/content/docs/circuits/reserve-messaging.mdx +++ b/src/content/docs/circuits/reserve-messaging.mdx @@ -35,19 +35,19 @@ Messaging is on when `usersRoot` is not zero. The rules are gated with `Select`, | `KeyIndex` fits in 8 bits | Checked | Checked | | `auditor_commitments` | Free | Equals `Fold2([privateTxKey, c0, c1, c2, c3, c4])` | -A new Reserve's leaf is `H3(reserve, reserveConfig, 0)`, so it is spendable from its first block with no sync step. Messaging switches on when the first user registers, and from then on it applies to every note at that Reserve, notes created earlier included. It never switches off: a removal that would leave the users tree empty reverts. +A new Reserve's leaf is `H3(reserve, reserveConfig, 0)`, so it is spendable from its first block with no sync step. Messaging switches on when the first user registers, and from then on it applies to every note at that Reserve, notes created earlier included. It never switches off: a removal that would leave the users tree empty reverts, and the Chamber refuses a users root that returns to zero. When a Reserve's users root first becomes non-zero, the Chamber stops accepting every superseded zkState root at once. Those roots hold a zero users root for that Reserve and would let a spend skip messaging. -:::caution[Unregistered holders cannot spend at a Reserve with members] -A deposit cannot check membership, because the owner commitment hides the owner. A holder who deposited before being registered, or before the Reserve had members, cannot spend or withdraw until they are registered. An exit spend that lets any owner withdraw in public is **Planned**. +:::caution[Unregistered and removed holders cannot spend at a Reserve with members] +A deposit cannot check membership, because the owner commitment hides the owner. A holder who deposited before being registered, or before the Reserve had members, cannot spend or withdraw until they are registered. A removed member is in the same position once the 10-minute grace window has passed. An exit spend that lets any owner withdraw in public is **Planned**. ::: ## Membership A member's leaf is `H2(owner, userKeyExchange)`. `owner` is the owner of the notes the member spends: a MIST Address or a wallet address. `userKeyExchange` is a value the member and the key holder agree off-chain. It never appears on-chain, and it must be a full-entropy key-exchange output, or the public leaf could be brute-forced. The protocol does not fix the exchange. -The Reserve's registrar adds the leaf, and only this hash goes on-chain. A removed member's leaf is set to zero. A member who was removed can still prove against a zkState root that holds their leaf until that root leaves the 10-minute grace window. [Contracts](/contracts/) covers registration and removal. +The Reserve's registrar adds the leaf, and only this hash goes on-chain. A removed member's leaf is set to zero. A member who was removed can still prove against a zkState root that holds their leaf until that root leaves the 10-minute grace window. After that, their notes at the Reserve are frozen until they are registered again. [Contracts](/contracts/) covers registration and removal. ## Key and keystream