Skip to the content.

Design: Tree Consensus and Threshold Storage Key

Status: approved. Phases 1 to 3 are implemented and always run (no setting turns them off): Tier 1 servers order tree operations through consensus and apply them only after commit, and a Tier 1 member that joins or lags applies the replicated log. A server that holds a tree from before tree operations awaits the one-time merge commit. Tier 2 servers hold no tree (decided 2026-10-24; see A7). See Configuration for the behavior and limits, and Tree Merge Ceremony for the migration runbook. Phase 4, the storage-threshold library (crates/storage-threshold), is implemented and tested. Phase 5 (holder plans and key rotations in consensus, the unlock protocol, the StorageUnlock attestation purpose, per-epoch share refresh, and daily rotation) is implemented and always on, with no setting to turn it off; see B11 and Configuration. The external review of the unaudited library paths in B3 was not commissioned: that gate was waived on 2026-10-22, not satisfied. Phase 6 is implemented: nexus-attestd seals and unseals, and the gossip identity key and the epoch vote keys move under the seal through one-way migrations (see B6 for the binding, the migration, the upgrade path, and the limits). Phase 7 is implemented and always on (see B12); it had the same review gate, also waived. The design changes the trust model, so AGENTS.md requires review of each later phase and its migration plan before code.

Table of Contents

Summary

Two problems, one plan:

  1. Servers do not stay in sync. Each server applies only the tree changes it receives directly. Two admins who edit through two servers produce two different trees. Part A sends every tree change through the Tier 1 HotStuff consensus, so every Tier 1 server applies the same changes in the same order. Tier 2 servers hold no tree (A7).
  2. A copied disk exposes the server’s secrets. Private keys, the session secret, TLS keys, and the whole tree are on disk in plaintext, or encrypted with a key stored beside them. Part B encrypts each server’s files with a data key that only 65% of the attested servers together can unlock. The storage secret is never assembled in one place.

FROST, the epoch signing key, does not change.

Decisions Already Made

Decision Value
Storage key threshold 65% of holders, rounded up
Holders Every server that passes SEV-SNP attestation, at most 50
Re-share Every epoch (share refresh), and right away when a holder is lost or added
Key rotation Storage secret daily (rewraps data keys); each server’s data key monthly and after a suspected compromise (re-encrypts files)
Recovery No offline recovery key. Re-sharing restores full tolerance while at least the threshold stays online.
Tree versions Nodes hold their versions. The existing sync library (nexus::sync) replicates committed changes; consensus orders them.
Saving a change The API waits up to 8 s for the commit, then reports the change as pending
Re-share authority Needs 65% of the current holders, not only a consensus quorum
FROST and consensus Unchanged in role, threshold, and storage
Endpoint tiers Tier 3 = inference node, Tier 4 = client (see Security)
Holders Needed (65%) Can be offline
5 4 1
7 5 2
10 7 3
20 13 7
31 21 10
50 (cap) 33 17

Current State

Facts from the code at 37c359e (r18):

Part A: Tree Changes Through Consensus

A1. Tree operation

Every change to the tree becomes one tree operation:

TreeOp {
  version        1
  network_id     binds the op to this network
  op_id          SHA-256 of the canonical encoding without signatures
  kind           create_node | update_fields | set_assignment | delete_node | join
                 | establish_root | set_endpoint | accept_invite | move_node
                 | delete_account
  target         node id
  base_version   the target node's version the author saw
  body           kind-specific fields
  author         Ed25519 key of the signer
  signature      over the canonical encoding
  submitted_by   server that received it (for routing only, unsigned)
}

A2. Submission

  1. The API server, a Tier 1 member, validates the op statically (format, signature, size) and sends it over the backbone to the other Tier 1 servers. A Tier 2 server takes no tree request (see A7).
  2. Each Tier 1 server keeps a bounded pending pool, keyed by op_id, with per-author limits.
  3. The API answers when the op commits or is refused, waiting up to 8 s. After that it returns 202 with the op_id, the app shows the change as pending, and polls until it commits.

Phase 2 implementation: replicas trust op signatures from the block epoch’s frozen Tier 1 set only, so a Tier 2 server cannot sign an op a replica accepts. The poll route is GET /api/tree/op/{op_id}.

Finalized state names only the Tier 1 set (and, at a boundary, the eligible candidates for selection). Root-signed admission certificates are identity, not authority, so they cannot become a list of trusted submitters, and a Tier 1 server that signed a Tier 2 server’s request would assert a session it did not authenticate. A Tier 2 server therefore answers every tree route, writes and reads alike, with a plain 421 that carries no redirect and no data (A7). The earlier 503 for writes on Tier 2 is replaced by that refusal.

A3. Consensus payload

Phase 2 implementation: Proposal keeps its layout. A tree block’s transitions_digest field carries ops_digest (the digest of the batch’s canonical wire form, domain-separated from every stage digest), which enforces “never both” by construction. The batch follows the certificate in the HotStuffProposal message only, as a typed block payload (BlockPayload.hpp); commit proofs and sync replies carry the header. Blocks without a batch keep their proposal digest and wire bytes, so stored commit proofs and handoff links still decode. kMaxConsensusBlockBytes is now 48,000. New payload kinds (for example Phase 5’s StorageHolderPlan and StorageKeyRotation) add a BlockPayloadKind value and an IBlockPayloadHandler.

A4. Deterministic validation

A replica votes for a tree block only if every op validates against the tree state of the block’s parent (committed state plus the uncommitted ancestors). The checks are the current rules with the non-deterministic inputs removed:

A5. State root

proposed_state_root becomes a commitment to the tree, not only a hash chain: H(parent_root ‖ ops_digest ‖ tree_digest_after), where tree_digest_after is a deterministic digest of every node’s canonical encoding and version. Replicas recompute it and vote only on a match.

Phase 2 implementation: parent_root is the state root of the previous tree block in the chain (the tree log head, or the nearest uncommitted tree ancestor), and the proposal’s previous_state_root carries it. Phase 3 adds the committed op ids to the root: H(parent_root ‖ ops_digest ‖ tree_digest_after ‖ committed_digest_after) (domain lemonade-nexus/tree-state-root:v2, tree log format 2), so a snapshot’s ids are bound by a certified root and an edited snapshot is not used. The tree log is therefore a hash chain: a server that missed a tree block cannot match the next one, and halts instead of applying it. The first entry chains to a base root over the tree the log started from.

A6. Commit, apply, and the tree log

A7. Tier 2 and lagging servers

Decision (2026-10-24): Tier 2 servers hold no tree. They are pure proxies of end-to-end encrypted data and connections. They do not store, replicate, read, write, redirect, or forward the tree, do not serve the tree API, and do not terminate or vouch for a client tree session. Clients send every tree read and write directly to a Tier 1 server, which they verify from finalized membership (see Client SDK). The original plan, in which Tier 2 servers applied the replicated log and served the same tree, is withdrawn.

Phase 3 implementation:

A8. Effect on clients

A9. Migration of existing trees

Today each server’s tree differs.

  1. One release switches every write path to tree operations. A server that holds a tree from before awaits the merge: it serves that tree for reads, refuses tree writes (retryable 503), and votes for no tree block, so no block can take height 1 first.
  2. After the rolling update reaches every server, the root server’s operator runs one script. It collects a signed export of every current Tier 1 member’s tree, plus the root server’s own tree from its backup (a Tier 2 server deleted its tree at startup). The root server merges them by a fixed rule: the root from the root server, each device from the server it joined, each group from its creator’s record, then a documented tie-break. Nodes that share an identifier and nodes that do not reach the root are dropped and reported.
  3. The merged tree is committed as height 1, signed by the root management key inside the root server’s process, and verified by every Tier 1 server.

Implementation: the merge commit is a tree log entry of kind merge at height 1: its body is the canonical encoding of the merged nodes, its root chains to the empty base, and the root management key signs a canonical JSON preimage that names the network, height, block time, roots, and node count. A log accepts it only on top of the empty base, so it is one-shot. The root management key and the data key exist only inside the running servers, so the exports, the backup read, the merge, and the signature run there: scripts/nexus-tree-migrate only carries bytes between the root server’s control socket and the Tier 1 members’ POST /api/tree/merge/export and POST /api/tree/merge/commit routes. When the commit applies, a server’s pre-merge tree is replaced by the merged tree. nexus-tree-merge, --sign-tree-merge, and --install-tree-merge remain for plaintext test data only. See Tree Merge Ceremony.

Part B: Threshold Storage Key

B1. Keys and roles

Key Where it lives Purpose
Storage secret s Never assembled. Holder i keeps share s_i. Threshold decryption only
Storage public key S = s·G Public, recorded in the holder plan Wrapping data keys
Server data key (DEK) Wrapped on that server’s disk; unwrapped in memory Encrypts that server’s files
Boot set (gossip identity key, own share, vote-key wrapping key) Sealed by the vTPM (B6) Starting up and authenticating before unlock

The storage key is a separate key role with its own domain-separation tag (LEMONADE-NEXUS-STORAGE-V1). It never signs and never authorizes. FROST, vote keys, and the epoch chain are untouched.

B2. Why threshold decryption, not rebuilding the key

Rebuilding s on every restarting server would give each one the whole network’s storage secret. One compromised running server would then expose every server’s files. Instead:

B3. Library

No custom cryptography (AGENTS.md). A new Rust crate, storage-threshold, wraps these libraries behind a C ABI like frost-ffi; panics never cross it.

Need Library Audit
Dealerless key generation over Ristretto255 frost-ristretto255, with the internals feature of frost-core, pinned to the same version as frost-ed25519 (2.2.0) NCC Group, 2023-10-23 (v0.6.0)
Share refresh with the same holder set and threshold; removing holders frost-ristretto255 refresh_dkg_* Not audited
Enrolling a new holder at the same threshold frost-ristretto255 repair_share_* Not audited
Lagrange combination of partials frost-ristretto255 helpers Audited with key generation
DLEQ (Chaum-Pedersen) proof for each partial elastic-elgamal 0.3.1 LogEqualityProof Not audited

Both libraries use curve25519-dalek 4.1.3, so the lockfile stays on one curve implementation. Written in this repository: the C ABI wrapper, the partial and proof wrapper (about 60 lines), the combiner (about 30 lines), and key derivation and encryption in C++ with the existing primitives. The unaudited library paths get an external review before Phase 5 ships.

No audited library changes the threshold while keeping S. B5 therefore rotates the key when the threshold must change.

B4. Holder set

B5. Re-sharing

B5a. Key rotation

Key Rotates What it costs
FROST epoch signing key Every epoch (existing: each epoch runs a fresh DKG) Nothing new
Storage shares s_i Every epoch (B5), same S One re-share: about 5,000 small messages at 50 holders
Storage secret s (new S) Daily, and on demand A fresh key generation among the holders. Each server rewraps its DEK to the new S through one threshold unlock. Files are not touched.
Server data key (DEK) Monthly, and on demand after a suspected compromise The server re-encrypts its files under a new DEK in the background, then deletes the old ciphertext

B6. Sealing the boot set

A server must authenticate and hold its own share before it can unlock anything, so these two items cannot depend on the DEK:

Implemented (Phase 6).

Item Value
Policy TPM2_PolicyPCR over the SHA-256 bank of PCR 8 and 9 (kSvsmBootPcrs), the two values a qualified release approval pins. PCR 10 is not bound: it advances with the IMA log.
Seal parent ECC P-256 storage primary in the owner hierarchy, unique field LEMONADE-NEXUS-SEAL-PARENT-V1. Recreated per call. No persistent handle, no NV index. Not the EK, not the quote AK.
Sealed object Keyed-hash object holding a random 32-byte key. No USERWITHAUTH; ADMINWITHPOLICY. Sessions are salted to the parent, so the key is encrypted to and from the TPM.
Secret encryption XChaCha20-Poly1305 in the server process, under the sealed key. Associated data: purpose sealed-blob, the sealing domain, the PCR digest, and the TPM public area.
Domains One per secret role: gossip-identity, storage-share (Phase 5), and vote-key-wrap (the wrapping key of the epoch vote keys).
Files data/sealed/<domain>.sealed (running boot chain), data/sealed/<domain>.next.sealed (staged for an approved next boot chain), data/sealed/gossip-identity.state.json (migration state and the public key), data/sealed/vote-key-wrap.state.json (migration state and the key id).

The daemon creates and unseals only the 32-byte key. The server encrypts and decrypts the secret itself (SealedBlobStore with attestd_seal_backend), so neither the secret nor its ciphertext crosses the socket, and a compromised daemon does not obtain the server’s keys.

Migration of the gossip identity (identity/keypair.json):

  1. Legacy file. A host that cannot seal (no attestd client in the build, no TPM, or an older daemon) keeps keypair.json at mode 600. This is today’s protection and the documented limit for certificate-only (Tier 2) hosts.
  2. Sealed, pending. The server seals the key, unseals the sealed copy, and compares it with the file. Only then does it record the pending state and the kernel boot id. keypair.json stays.
  3. Sealed. When the sealed copy unseals in a later boot (another boot id), the server records the sealed state, then overwrites and removes keypair.json. The two-boot rule protects against a vTPM that does not keep its owner seed across reboots.

While keypair.json exists it is the fallback when the sealed copy does not unseal, and the server seals it again. After step 3 the server never creates a new identity in place of a sealed one:

Restart case Result
Sealed copy present, PCR 8/9 match Unseals; the same key.
PCR 8/9 changed, approved chain staged The staged copy unseals, is sealed again to the running PCRs, and the staged file is removed.
PCR 8/9 changed, nothing staged Startup stops with policy_mismatch. Files stay unchanged. Recovery: boot the previous boot entry.
Blob corrupt, from another TPM, or the vTPM owner seed changed Startup stops with corrupt. Recovery: restore data/sealed/ from a backup of this host.
Blob missing Startup stops. Recovery: restore the file, or remove the state file to start with a new identity, which needs new enrollment.
Daemon unreachable Retries for about 30 s, then stops.

The same rules apply before step 3, except that keypair.json is used instead of stopping.

Vote keys. Consensus votes while the DEK is locked (B8), so the vault cannot cover the epoch vote keys (B12). Each server seals one random 32-byte vote-key wrapping key under the domain vote-key-wrap and uses it only to encrypt its own vote keys (EpochStore, Security/Epoch/EpochStore.hpp). A seal or an unseal is a TPM operation and a new vote key is created every epoch, so the server seals the wrapping key once and unseals it once per start. The vote keys never reach the daemon.

Item Value
Sealed copy data/security/vote-key-<epoch>.sealed.json. EncryptedBlob version 1 (XChaCha20-Poly1305) under HKDF(wrapping key, "LEMONADE-NEXUS-VOTE-KEY-WRAP-V1", "lemonade-nexus-vote-key-file-key-v1"). Associated data: aead_aad("vote-key-at-rest", {epoch, node id, vote public key}). The file names the key id, a second HKDF output of the wrapping key.
Machine-bound copy data/security/vote-key-<epoch>.json, the format before sealing: KeyWrappingService with an empty passphrase, so the key comes from wrap_local.key and /etc/machine-id.
State data/sealed/vote-key-wrap.state.json: migration state, the boot id that sealed the key, and the key id.

The vote-key migration has the same three states and the same two-boot rule as the gossip identity:

  1. Machine-bound. A host that cannot seal keeps only the machine-bound copies. This is the protection before this change, and its limit.
  2. Sealed, pending. The server seals a new wrapping key, unseals it, and compares it. It then records the pending state and gives every existing vote key a sealed copy. Each new vote key goes to both files, machine-bound copy first.
  3. Sealed. When the wrapping key unseals in a later boot, the server gives every machine-bound copy a sealed copy, reads it back, and compares it. Then it records the sealed state, and only then overwrites and removes the machine-bound copies. A crash between two steps leaves an extra copy, never a missing key.

While the migration is pending, the machine-bound copies hold every vote key. A wrapping key that does not unseal, or that is missing, is then replaced by a new one, and the sealed copies are written again. After step 3 the restart cases of the table above apply to the wrapping key and stop startup, and a machine-bound copy is never read again. A machine-bound file that appears after step 3 does not get a sealed copy.

Upgrade path. PCR 8 records the GRUB commands and the kernel command line; PCR 9 records the files GRUB reads (kernel, initramfs, GRUB configuration). The server binary is measured into PCR 10 by IMA, not into PCR 8 or 9. On the Tier 1 mesh, releases r11 to r21 all pin the same PCR 8 and 9, so a binary-only release changes nothing that the seal binds. A release that changes the boot chain installs an approval with new expected PCR 8 and 9. At its next start on the old boot chain, the server verifies that approval against Genesis and seals each boot-set secret a second time, to the expected values (<domain>.next.sealed). After the reboot the staged copy unseals and becomes the current copy. The current copy is replaced only after the new one is durable, so booting back into the old chain still works until then. No step needs Genesis or a new enrollment.

Limits:

B7. Unlock at startup

  1. The server unseals its boot set (Phase 6, Core/BootSet.hpp). The share goes into the same SealedBlobStore under the storage-share domain and gets the same upgrade staging.
  2. It requests partials from the holders with a new security message, StorageUnlockRequest {network, epoch, R, nonce}.
  3. Each holder challenges the requester with a new attestation purpose, StorageUnlock, bound to the request nonce. Holders that are not Tier 1 may challenge for this purpose only; the router’s NotMember gate changes accordingly.
  4. On a passing verdict for the approved profile, the holder answers with StorageUnlockPartial {s_i·R, DLEQ proof}, sealed to the requester with the request digest as associated data. The holder answers only for an R that the requester’s latest finalized wrap claim names for the plan’s S (B5a). An R belongs to the first server that claimed it while its S is live, so a server that copies another server’s data-key.json gets no partial for it.
  5. With t valid partials the server unwraps its DEK and opens its files in memory. With fewer it retries with backoff and serves nothing that needs its files. An attempt waits at least for the holders’ pending window before it times out, and the partials of a timed-out request still count while a holder may answer it: the holder charges a served partial when it sends it, so a late one is used, not wasted. The server sends no new request while a holder may still hold the previous one pending.

Budgets: one pending unlock per requester per holder, and two per-epoch limits per requester, like attestation budgets. The first counts partials the holder served and bounds what one requester can extract. The second, larger one counts challenges the holder issued, served or not, and bounds the evidence verifications and remembered request digests one requester can cost a holder. A challenge whose attestation fails or expires spends only the second, so a server whose first answers fail after a restart is not locked out until the epoch changes.

B8. Cold start

B9. What the DEK encrypts

Everything in the table under Current State except the boot set: the node identity key, vote keys, JWT secret, TLS and ACME keys, ACL and DDNS keys (derived from the DEK instead of the gossip key), the tree log and snapshots, and account data. wrap_local.key is retired. B12 states what the implementation covers and which of these items stay outside the vault.

A server whose platform cannot pass the StorageUnlock attestation never unlocks a DEK: a holder answers only after a verdict that proves every claim of the Tier 1 attestation profile (StorageKeyService::on_verdict). A Tier 2 server without SEV-SNP therefore never completes the B10 round trip, and its files stay plaintext (B10 step 3). The root server of the production mesh is such a server. It still holds a share and answers other servers’ unlocks.

B10. Migration

  1. A release creates S once at least 5 holders are attested, through a dealerless key generation among them.
  2. Each server creates a DEK, wraps it to S, re-encrypts its files, verifies that it can unlock through the holders, and only then deletes the plaintext.
  3. A server that cannot reach t holders keeps its old files and retries.

B11. Phase 5 implementation

Always on, no setting (Security/Storage/):

B12. Phase 7 implementation

Always on, no setting (Security/Storage/StorageVault.hpp):

Part C: Key-Generation Race Fix

The first r17 founding split because round-2 messages that arrive before round 1 completes are dropped (DkgSession.cpp:224-226, SecurityRouter.cpp:590-601). Only the founding path re-sends; epoch-transition and adoption runs send round 1 once, so a dropped message stalls until the 300 s timeout.

This part does not change the trust model and can ship first.

Phases

Phase Content Depends on
0 Part C race fix. keypair.json mode 600. —
1 TreeOp, node versions, deterministic validation, all write paths produce ops (applied locally, behind a flag). —
2 Tree batches in consensus, TreeLog, commit-then-apply on Tier 1. 1
3 Log replication to joining and lagging Tier 1 servers with QC verification. Tree merge ceremony and switch-over (A9). Tier 2 servers hold no tree (A7, decided 2026-10-24). 2
4 storage-threshold crate: library review, key generation, re-share, share refresh, DLEQ, threshold ECIES. —
5 StorageHolderPlan in consensus, unlock protocol, StorageUnlock attestation purpose, per-epoch share refresh, daily StorageKeyRotation. 2, 4
6 nexus-attestd Seal and Unseal; boot set sealed. Implemented (B6). —
7 DEK file migration; plaintext removed; monthly DEK rotation. Implemented (B12), including the TLS and ACME private keys and coverage generation 2 (committed op ids, admission records, account data store, user credentials, legacy link token files). Vote keys are read before the unlock and are sealed through the boot set instead (B6); B12 lists every file that is not covered and the reason. 5, 6

Phases 1, 4, and 6 can run in parallel.

Tests Required

Each phase adds tests for the valid path and these rejection cases:

Open Decisions

  1. Genesis and root management keys stay on the root server for now. Revisit before Phase 7.

Decided: libraries for storage-threshold (B3), with an external review of the unaudited paths before Phase 5; a threshold change rotates the key instead of re-sharing to a new threshold (B5); no offline recovery key (B8); nodes hold per-node versions and the sync library replicates (A7); the API waits up to 8 s, then reports pending (A2); holder counts (B4, B5, B10): the storage key is created only with at least 5 eligible, attested holders; after holders are lost, Tier 1 refreshes or rotates promptly while at least 3 holders remain (a refresh when t stays the same, otherwise a rotation at the new count: 4 holders give t = 3, 3 holders give t = 2); below 3 holders the last plan stays and no rotation runs; holders are added back through rotation; the crate permits 3 to 50 holders for a refresh or rotation and 5 to 50 for the first key.