|
| 1 | +--- |
| 2 | +title: Architecture |
| 3 | +sidebar_position: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +# Architecture |
| 7 | + |
| 8 | +Guardian sits between Miden clients and the Miden network, providing an off-chain coordination layer for private account state. |
| 9 | + |
| 10 | +## System overview |
| 11 | + |
| 12 | +```mermaid |
| 13 | +graph LR |
| 14 | + A["Miden Client A<br/>(Desktop)"] <-->|"gRPC / HTTP"| Guardian["Guardian Server"] |
| 15 | + B["Miden Client B<br/>(Mobile)"] <-->|"gRPC / HTTP"| Guardian |
| 16 | + Guardian <-->|"Validates state"| Node["Miden Node"] |
| 17 | +``` |
| 18 | + |
| 19 | +- **Miden Client** handles transaction execution, proving, and local state management. |
| 20 | +- **Guardian Server** stores state snapshots and deltas, authenticates requests, validates changes against the network, and coordinates multi-party workflows. |
| 21 | +- **Miden Node** is the network's RPC endpoint that Guardian validates state against. |
| 22 | + |
| 23 | +Each account is independently configured on Guardian with its own authentication policy and storage. Clients interact with Guardian through either gRPC or HTTP — both interfaces expose the same semantics. |
| 24 | + |
| 25 | +## End-to-end transaction flow |
| 26 | + |
| 27 | +Transactions proceed through a step-by-step process to ensure consistency and verifiability: |
| 28 | + |
| 29 | +```mermaid |
| 30 | +sequenceDiagram |
| 31 | + participant Client as Miden Client |
| 32 | + participant Guardian as Guardian Server |
| 33 | + participant Chain as Miden Network |
| 34 | +
|
| 35 | + Client->>Client: 1. Execute transaction locally<br/>Generate delta |
| 36 | + Client->>Guardian: 2. Submit delta for acknowledgment |
| 37 | + Guardian->>Guardian: 3. Validate delta against policies |
| 38 | + Guardian->>Guardian: Co-sign as "candidate" |
| 39 | + Guardian-->>Client: Return ack signature |
| 40 | + Client->>Chain: 4. Submit ZK proof + state update |
| 41 | + Chain-->>Guardian: 5. Guardian monitors on-chain commitment |
| 42 | + alt Commitment matches candidate |
| 43 | + Guardian->>Guardian: Promote to "canonical" |
| 44 | + Guardian-->>Client: Propagate confirmed delta |
| 45 | + else Commitment mismatch |
| 46 | + Guardian->>Guardian: Mark as "discarded" |
| 47 | + Guardian-->>Client: Signal resync needed |
| 48 | + end |
| 49 | +``` |
| 50 | + |
| 51 | +1. **Local execution**: The user computes a transaction locally, generating a delta (state change). |
| 52 | +2. **Delta submission**: The user sends the delta to Guardian for acknowledgment. |
| 53 | +3. **Guardian acknowledgment**: Guardian validates the delta and co-signs it, designating it as a "candidate" state. |
| 54 | +4. **Proof submission**: The user generates the ZK proof and submits it to the chain. |
| 55 | +5. **Canonical confirmation**: Guardian monitors the chain. If the on-chain commitment matches the candidate, the state becomes "canonical" and is propagated to other devices or signers. |
| 56 | + |
| 57 | +## Multi-device sync |
| 58 | + |
| 59 | +For users with multiple devices, Guardian keeps state synchronized seamlessly: |
| 60 | + |
| 61 | +```mermaid |
| 62 | +sequenceDiagram |
| 63 | + participant Desktop as Desktop |
| 64 | + participant Guardian as Guardian Server |
| 65 | + participant Mobile as Mobile |
| 66 | +
|
| 67 | + Desktop->>Desktop: Execute transaction |
| 68 | + Desktop->>Guardian: Push delta |
| 69 | + Guardian->>Guardian: Validate & acknowledge |
| 70 | + Desktop->>Desktop: Submit proof to chain |
| 71 | + Guardian->>Guardian: Confirm canonical |
| 72 | + Mobile->>Guardian: Get state |
| 73 | + Guardian-->>Mobile: Return latest state |
| 74 | + Mobile->>Mobile: Replay delta locally |
| 75 | + Note over Mobile: State now matches Desktop |
| 76 | +``` |
| 77 | + |
| 78 | +The desktop executes a transaction and pushes the delta to Guardian. After on-chain confirmation, Guardian propagates the canonical delta to the mobile device, which replays it locally — all without querying the chain directly. |
| 79 | + |
| 80 | +## Account management |
| 81 | + |
| 82 | +Accounts are configured with per-account authentication based on public keys (commitments). During setup, Guardian records which keys are authorized to manage the account. |
| 83 | + |
| 84 | +For each request, the client signs a payload with one of those keys and the server verifies the signature against the account's authorized keys. See [Components](./components.md) for details on the auth model. |
| 85 | + |
| 86 | +## Canonicalization |
| 87 | + |
| 88 | +Canonicalization is the process of validating that a state transition (delta) is valid against the on-chain commitment. It is optional and mainly used in multi-user setups. |
| 89 | + |
| 90 | +```mermaid |
| 91 | +stateDiagram-v2 |
| 92 | + [*] --> candidate : push_delta |
| 93 | + candidate --> canonical : On-chain commitment matches |
| 94 | + candidate --> discarded : On-chain commitment mismatch |
| 95 | + canonical --> [*] |
| 96 | + discarded --> [*] |
| 97 | +``` |
| 98 | + |
| 99 | +- **Candidate mode** (default): A background worker promotes or discards deltas after a configurable delay and network verification. |
| 100 | +- **Optimistic mode**: Deltas become canonical immediately, skipping the verification window. |
| 101 | + |
| 102 | +| Parameter | Default | Description | |
| 103 | +|---|---|---| |
| 104 | +| `delay_seconds` | 900 (15 min) | How long a candidate waits before the worker checks it. | |
| 105 | +| `check_interval_seconds` | 60 (1 min) | How often the worker runs. | |
| 106 | + |
| 107 | +## Common use cases |
| 108 | + |
| 109 | +- **Single-user accounts**: Back up and sync state securely. If a device is lost, recover state from Guardian. |
| 110 | +- **Multi-user accounts**: Coordinate state and transactions between participants. Guardian helps keep everyone on the latest canonical state. |
0 commit comments