> For the complete documentation index, see [llms.txt](https://plabs.gitbook.io/plabs-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://plabs.gitbook.io/plabs-docs/privacy-core/state-machine.md).

# Note state machine (OrchardVerifier)

`OrchardVerifier` is the **on-chain state machine** for Privacy Core. All applications (pERC20, pSWAP, …) share this execution semantics.

## Scope

```
OrchardVerifier DOES:              DOES NOT:
✓ Groth16 verification             ✗ ERC-20 metadata
✓ Merkle append                    ✗ totalSupply accounting
✓ nullifier anti double-spend      ✗ external ERC-20/ETH custody
✓ binding + spendAuth sigs         ✗ swap / HTLC logic
✓ frozenRoot binding
```

Each pool instance has its **own** tree, nullifier set, verifier ref, and `cmxFrozenRoot`.\
**Asset identity = contract address** (same bytecode on different chains = different state).

## State

| State                 | Description                                |
| --------------------- | ------------------------------------------ |
| `_tree`               | depth-32 Poseidon incremental Merkle tree  |
| `_isSpent[nf]`        | Spent nullifiers                           |
| `cmxExists[cmx]`      | Inserted commitments (no duplicate leaves) |
| `_allRootsEver[root]` | Permanent historical roots                 |
| `_frozenRoot`         | Compliance IMT root                        |
| `groth16Verifier`     | Groth16 verifier reference                 |
| `admin`               | Compliance / config authority              |

## Bundle execution order

```
1. For each BundleAction:
   a. pubFields[8] canonicality (< Fr)
   b. pubFields ↔ calldata equality
   c. Groth16 verifyAction
   d. spendAuthSig verify
2. bindingSig verify (before state writes)
3. For each action:
   a. mark nfOld spent
   b. insert cmx (reject zero / duplicate)
   c. emit NoteAdded / NoteConfirmed
```

**Invariant**: no public `bundle()` entrypoint — only app-layer `mint`/`burn`/`transfer` call `_executeBundle` (audit C-1).

## Views

| Method                | Meaning             |
| --------------------- | ------------------- |
| `cmxRoot()`           | Latest tree root    |
| `isValidAnchor(root)` | Root was ever valid |
| `isSpent(nf)`         | Nullifier spent     |
| `treeSize()`          | Commitment count    |

## Next

* [Groth16 action circuit](/plabs-docs/privacy-core/groth16-action-circuit.md)
* [Universal call format](/plabs-docs/privacy-core/universal-call-format.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://plabs.gitbook.io/plabs-docs/privacy-core/state-machine.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
