diff --git a/doc/2026-11-01_design_id2804.md b/doc/2026-11-01_design_id2804.md new file mode 100644 index 0000000000..42477d95e9 --- /dev/null +++ b/doc/2026-11-01_design_id2804.md @@ -0,0 +1,494 @@ +# Design: Issuer key rotation and compromise recovery + +- Date: 2026-11-01 +- Status: **proposed** — the protocol recommendation is ready for #2043 to + adopt or amend. One policy question for Drew remains in §10. +- Issue: [#2804](https://github.com/developing-today/code/issues/2804), from + #2041; consumers include #2030, #2062, #2251 and #2043. +- Scope: design only. This record does not change implementation code or open + downstream implementation issues; the latest #2804 task note says to wait + for the gated #2043 synthesis before filing build packets. + +## The decision + +Define how a currency issuer changes signing keys without changing the +currency's identity, how a counting view decides which generation signed an +issuance, and who can make a compromise recovery authoritative. The same +signed object must be usable in both the anchored registry/gateway path and a +graph-native path with no central enforcer. + +**Recommendation in one sentence:** use an application-level, versioned +rotation event with a generation chain and successor proof; preserve each +currency definition and its identity; require a separately precommitted +recovery key for authoritative compromise recovery; make views report their +observed frontier and separate settled from disputed history. + +```text +issuer account key (generation g) + └─ signs rotation event ─ successor key countersigns + ├─ anchored: signed registry write → gateway admission cutoff + └─ graph-native: views verify locally; no network-wide stop + +recovery key (committed in the currency definition) + └─ signs recovery rotation → generation g+1 + ├─ old-generation activity after cutoff: not accepted / not counted + └─ activity in an asserted earlier compromise window: disputed +``` + +The outer `Event` has one envelope signer, not two. “Dual-signed” below means +the ordinary rotation event is signed by its current issuer key and includes +an application-level signature from the successor key. Compromise recovery is +a distinct authorization mode: it is signed by the precommitted recovery key +and countersigned by the successor, without requiring the possibly stolen +issuer key. + +## 1. Context and evidence + +### What is already decided + +- The #2041 investigation calls stolen issuer-key use the catastrophic case; + supply caps bound mint damage, a rotation names a successor, pre-rotation + currency definitions keep their identity, and views/registries pin the key + generation they count. It routes the mechanics to this issue and the + adoption decision to #2043 (see [investigation §10 case 7 and §11–12](2026-10-30T19-18-00Z_investigation_token_issuance_id_graph/2026-10-30T19-18-00Z_investigation_token_issuance_id_graph.md#L440)). +- The latest #2804 comment recommends old-key + successor signatures, linear + generations, per-currency view pinning, a recovery-key commitment, and + separate anchored and graph-native behavior. It explicitly leaves Drew the + recovery-key policy question. This note expands that recommendation; it is + not an already-adopted #2043 decision. +- #2251's design currently marks issuer-key rotation as unsolved and has a + closed currency-definition schema. Its identity calculation includes the + issuer public key and definition hash ([§1.1](2026-10-30T13-25-00Z_design_graph_token_formats_snapshot_anchoring.md#L63), + [§6–7](2026-10-30T13-25-00Z_design_graph_token_formats_snapshot_anchoring.md#L637)). + Therefore any recovery-key commitment belongs in the definition from + creation; it cannot be bolted on later without changing that definition's + identity. The design recommendation is to update the still-unimplemented + format before currencies v1 is finalized. +- #2030 separates signed-event validity, evidence storage and view counting. + A view names its set version and frontier; history changes require explicit + handling rather than silently rewriting counts ([trust/visibility + investigation §§1–3](2026-10-30T19-11-04Z_investigation_trust_visibility_model/2026-10-30T19-11-04Z_investigation_trust_visibility_model.md#L54), + [§2](2026-10-30T19-11-04Z_investigation_trust_visibility_model/2026-10-30T19-11-04Z_investigation_trust_visibility_model.md#L100)). +- #2062 makes registry writes signed graph operations and the registry a + rebuildable index. It uses issuer account-key authority (not device-key + authority) and separately permits issuer/platform-operator freeze or + sunset ([control-plane design §§2.4–2.5](2026-10-29T12-42-21Z_design_currency_control_plane/2026-10-29T12-42-21Z_design_currency_control_plane.md#L190), + [§§4.1b–4.2](2026-10-29T12-42-21Z_design_currency_control_plane/2026-10-29T12-42-21Z_design_currency_control_plane.md#L313)). + That operational freeze is not itself proof that a new issuer key is + authoritative. + +### What `pkgs/id` does and does not provide + +The rotation protocol must be layered above the generic event envelope; these +are current-code constraints, not issuer behavior already implemented: + +- `chain::sign` takes one `SigningKey` and signs one event header + (`pkgs/id/src/chain.rs:271-307`). The header commits to an optional body by + hash; `Event` bytes and the event ID are based on the signed header + (`chain.rs:259-268, 273-307`). A successor proof can be carried as typed + application data, but the generic header verifier does not validate its + meaning or signature. +- `ChainExt` is a closed schema with `deny_unknown_fields` + (`chain.rs:120-135`); generic validation/decode has no issuer, currency, + generation or successor-proof rules (`chain.rs:172-255, 311-341`). A + versioned rotation extension therefore needs an explicit schema change and + verifier; it cannot be smuggled through as an unknown field. +- The event-store persists the signed header bytes, not an arbitrary body + (`pkgs/id/src/event_store/mod.rs:1211-1229`). The recommendation puts the + compact, signed rotation record in a typed event extension, rather than + making recovery depend on a body blob that this store does not retain. +- Events form a per-author sequence through the backlink. `after` is a + separate causal reference set, capped at 32 hashes; validation checks the + cap/uniqueness but does not prove it is a complete global frontier + (`chain.rs:32-33, 93-107, 178-193, 271-294`). It is not a timestamp or a + globally total order. A successor key starts a separate author chain, so + its first event must explicitly reference the rotation in `after` if the + view is to establish that causal link (`local_events.rs:442-492`). +- The event store detects and freezes a fork in one author's chain at its fork + point (`pkgs/id/src/event_store/ingest.rs:12-16, 747-801`), but it does not + map keys to issuer generations or decide which currency view counts. The + existing `AuthId` is not a stable issuer-identity type + (`pkgs/id/src/membership/mod.rs:35-47`). + +Consequently, the “effective frontier” is **not** a claimed globally ordered +position in the ID graph. Graph-native validity uses causal relations to the +rotation event and reports incomparable events as unresolved/disputed. The +anchored path has a distinct, ordered gateway admission point: the registry +write that installs the rotation is the linearization point for that gateway. + +## 2. Viable options and trade-offs + +| Decision | Option | Trade-off | +| --- | --- | --- | +| Rotation representation | Replace the issuer key in the currency definition | Smallest model, but mutates the identity-bearing object and makes historical verification depend on today's key. Rejected by the #2041 identity requirement. | +| | Separate generation-linked rotation event | Keeps definitions stable and gives views an auditable key history. Requires an application-level schema, verifier and storage/query support; recommended. | +| Successor proof | Old key alone names a new key | Simple, but cannot prove the successor key is controlled or even available. | +| | Old key signs and successor countersigns | Proves control of both keys for routine rotation. It does **not** make a compromised old key safe; the recovery key remains necessary. Recommended. | +| Generation conflict | Pick by wall-clock timestamp or local arrival | Not trustworthy or reproducible across views. Rejected. | +| | Follow explicit predecessor links and causal evidence; report forks | Deterministic where events are ordered, fail-closed where they are not, and consistent with the existing author-chain fork rule. Recommended. | +| Compromise authority | Let the current issuer key declare its own compromise | The thief has that key too; the declaration cannot distinguish issuer from attacker. At most advisory. | +| | Precommitted recovery key authorizes recovery | Adds a cold credential and definition-time schema commitment, but supplies an authority independent of the stolen mint key. Recommended; anchored/graph-native requirement is Drew's question (§10). | +| Counting | Trust only the current key | Breaks historical verification and pre-rotation identity. | +| | Count each generation only in its effective interval, pinned at a named view frontier | Preserves valid history, makes compromise effects inspectable, and allows uncertainty to remain visible. Recommended. | +| Issuer-wide rotation | One wildcard that means “all currencies, including future ones” | Ambiguous in a graph without a complete issuer-currency registry and can silently affect future definitions. | +| | One currency per rotation; issuer-wide action expands to an explicit batch at a named set/registry version | Slightly more events, but scope is finite and auditable. Recommended. | + +## 3. Recommended protocol + +### 3.1 Stable identity and definition commitment + +- Treat `issuer_id` (the issuer account identity from the #2062 control plane) + and `currency_id` (the immutable currency-definition identity) as distinct + from a signing key and its generation. A rotation changes only the key + history; it never edits or re-hashes an existing definition. +- The definition's original issuer identity/key remains the stable identity + anchor. A v1 definition also commits to an optional `recovery_key_hash` + before its definition hash is finalized. For a definition with that field, + the commitment is part of its identity from inception, not an amendment. +- An anchored currency that requires authoritative recovery must have this + commitment at creation. If it is absent, a later key rotation cannot add it + without changing currency identity; such a currency can have routine + rotations, but has no cryptographically authoritative compromise recovery. + This is why the commitment belongs in #2251 before the format is finalized. +- The recovery key is a cold account-level recovery credential, never a + minting/device key. It is separate from #2062's normal account-key and + platform freeze/sunset controls. Rotation of the recovery credential itself + is not part of v1; loss or compromise of that credential requires a + separately governed freeze/re-issuance path and must not be represented as + successful cryptographic recovery. + +### 3.2 Rotation event format and signatures + +Add a versioned `issuer-rotation-v1` variant to the signed event extension. +The exact Rust names belong in #2251, but the wire contract is: + +```text +IssuerRotationV1 { + issuer_id + currency_id // one currency; no open-ended wildcard + mode // routine | compromise-recovery + from_generation: u64 + to_generation: u64 // exactly from_generation + 1 + previous_rotation: EventId? // absent only for the initial transition + successor_key: PublicKey + successor_proof: Signature // domain-separated canonical rotation fields + asserted_compromise_from: EventId? // recovery mode only; never a timestamp +} +``` + +Rules: + +1. Generation `0` is the key committed by the original definition. Every + transition increments exactly once and references the prior rotation + event. For an issuer-wide operator action, emit one currency-scoped event + per currency from an explicit currency-set/registry snapshot and bind the + set version in the batch; do not encode a wildcard that includes future + currencies. +2. A routine event's envelope author is the generation-`g` issuer account + key. The successor proof signs the same canonical, domain-separated + rotation fields, excluding signature fields. The envelope signature + commits to the full extension including that proof. Missing/invalid + successor proof, wrong scope, stale predecessor or nonconsecutive + generation makes the transition invalid. +3. A compromise-recovery event's envelope author is the recovery key whose + hash is committed by the currency definition. The issuer key being + replaced need not sign. The successor still proves possession. This is not + an exception that lets an old issuer key self-authorize its own compromise. +4. Do not use self-authored timestamps to order rotations. The transition + event ID is the stable reference; the event's causal position is assessed + against the view's named frontier. A successor key's first event must + include the transition event ID in `after`; because the key begins a + separate author chain, the old key's backlink alone cannot establish this + relation. +5. If two transitions claim the same predecessor, a view may treat the first + transition in its *causally ordered observed frontier* as provisional, + but must flag the conflict. It must not settle both paths. If the events + are concurrent/incomparable, or are branches of an author-chain fork, + neither branch is a globally authoritative “first”: apply #2251's rule + that both branches are void from the fork point and keep subsequent + activity disputed until recovery resolves the issuer head. This preserves + the latest #2804 recommendation (“first in frontier order”) only where a + real causal order exists, without inventing a total order absent from + `after`. + +The header extension is preferred over an optional body because the event +store persists the signed header but not arbitrary body content. The format +must nevertheless be explicitly added to the closed extension schema and +validated by issuer-level code; generic `chain::decode` alone is insufficient. + +### 3.3 Event validity, view pinning and counts + +For every currency, a counting view pins a snapshot containing: + +- the `issuer_id` and `currency_id`; +- the highest rotation event(s) it has observed, plus its observed graph + frontier (or anchored registry version); +- the generation-to-key mapping and each transition's status; and +- the compromised generation's effective cutoff and any earlier asserted + compromise frontier. + +Default policy is to count all verified generations in their valid intervals, +not only the newest key. On a view frontier, a normal rotation makes the +successor eligible only for events causally after that rotation; the prior +generation is eligible only for events causally before it. If a candidate +event is incomparable with the transition, its temporal validity is +unresolved: retain it as evidence, exclude it from settled counts, and show +it as disputed rather than guessing from timestamps or local arrival order. + +A compromise recovery has two different frontiers: + +- **Recovery cutoff:** the recovery event's causal position in graph-native + views, or the registry version/admission barrier in an anchored gateway. + From this point, the compromised generation is invalid for new issuance and + conversion. +- **Asserted compromise start:** optional. If it predates the recovery cutoff, + activity signed by the compromised generation from that asserted point to + the cutoff is `disputed`, excluded from settled counts, and still visible + for review. The signature alone cannot prove when the key was stolen. + +An ordinary rotation does not rescind earlier valid history. A recovery +declaration likewise does not delete event evidence or silently subtract +history; it changes the view's classification. This follows #2030's +validity/storage/counting separation. A view must label every balance with the +frontier and generation set used to calculate it. + +### 3.4 Compromise declaration and freeze authority + +- **Authoritative recovery:** only a valid recovery-key-signed recovery + rotation can supersede a compromised minting generation and authorize its + successor. The operation includes the issuer, currency, generation, + successor key/proof and optional asserted compromise start. +- **Advisory warning:** a declaration signed only by the current minting key + is not evidence of compromise, because the attacker may possess that key. + A gateway or view may apply a protective freeze on policy grounds, but it + must label the reason `unproven`; it cannot promote a successor or + retroactively alter settled history. Only recovery proof clears an + issuer-compromise status. #2062's platform/operator freeze remains a + separate control-plane action, not issuer-key recovery. +- **No recovery commitment:** the view/gateway may retain and display an + advisory warning and an operator may freeze/sunset under #2062, but no + issuer-signed declaration can claim authoritative compromise recovery. + This is the consequence of making the commitment optional on the + graph-native path. + +### 3.5 Anchored registry and gateway + +The issuer publishes the rotation event; the registry records a signed write +that references its event ID and updates that currency's minter generation +using the #2062 registry-write pattern. A gateway applies that write +atomically and assigns its ordered registry version as the enforcement +barrier. The gateway must not treat an arbitrary graph event's `after` list +as a global ordering primitive. + +At the barrier: + +- requests admitted and durably committed to the gateway/ledger before the + registry update may settle; +- requests merely signed or submitted but still pending at the barrier are + rejected, not queued for later execution; +- requests admitted after the barrier must use the active generation; +- already executed/posted transfers are not rewritten or deleted; if an + earlier compromise start covers them, views mark them disputed and + reconciliation uses explicit compensating operations, not a fabricated + rollback; and +- a rejected old-generation mint/conversion is not silently retried under + the new key. + +This selects a single linearization point for in-flight work: durable gateway +admission relative to the signed registry version. A request signed before a +rotation but not admitted before the barrier is not grandfathered. A +recovery-key event freezes the compromised generation at its applied +registry barrier. The platform operator may separately freeze sooner under +#2062, but that does not by itself select a successor key. + +### 3.6 Graph-native path + +There is no gateway to stop an issuer from signing or publishing more events. +Each wallet and counting view applies the same generation chain locally: + +- a view that has seen a valid rotation stops counting old-generation events + causally after it; +- a view that has not seen it reports the frontier it has evaluated; it must + not claim that the generation is globally current; +- forks and events concurrent with a transition remain visibly unresolved; +- a recovery event changes the local view once observed, but cannot stop + activity elsewhere; and +- wallet balances display at least `current`, `rotated`, + `compromised/disputed` or `forked/unresolved`, plus the frontier used. + +Because `after` is bounded and not a complete global frontier, graph-native +views can only make claims relative to their observed causal graph. The +protocol does not promise instantaneous or universal compromise awareness. + +## 4. Compromise walkthrough + +1. An attacker steals issuer generation `g` and mints or signs conversions. + The currency supply cap remains the damage bound identified by #2041, but + it does not identify the thief or guarantee that already transferred value + can be recovered. +2. Until a rotation or freeze is observed, graph-native peers may accept + activity under `g`; an anchored gateway continues only until it applies a + registry/control-plane freeze or recovery barrier. +3. The issuer uses the cold recovery key committed in the currency definition + to publish a recovery rotation to generation `g+1`, with the successor's + proof. The registry write references this event and atomically closes + admission under `g`; graph-native views apply it when they observe it. +4. Activity under `g` before the recovery cutoff remains valid unless it falls + in an earlier asserted compromise interval. Such an interval is disputed, + not silently erased or counted as settled. Pending anchored requests are + rejected at the barrier; previously executed transfers remain ledger + records and require explicit reconciliation if disputed. +5. Exposure remains for the interval between the actual theft and the + authoritative recovery/freeze. The actual theft time is not derivable from + signatures. An earlier asserted start makes affected records disputed; it + does not prove theft or automatically claw back spent proceeds. + +If there is no precommitted recovery key, step 3 cannot be authoritative. A +current-key declaration is advisory and an operator may freeze the anchored +currency, but there is no cryptographic issuer-continuity claim to make. + +## 5. Invariants + +1. A rotation never changes an existing currency definition or its identity. +2. A routine generation transition is consecutive, predecessor-linked, + signed by the current key and countersigned by the successor. +3. A compromised minting key cannot authoritatively declare its own + compromise or choose its recovery successor. +4. No wall-clock timestamp or local arrival order is used as a global graph + ordering rule; unresolved causality is visible as unresolved/disputed. +5. Every count names its view frontier, issuer generation set and compromise + classification. Historical evidence is retained. +6. Disputed issuance is excluded from settled totals but never silently + discarded; ledger transfers are not rewritten by a view decision. +7. An anchored admission barrier is ordered by the applied signed registry + version. Pending work at the barrier is rejected; executed work is not + erased. +8. Supply caps remain mandatory and load-bearing; rotation reduces the + exposure window but cannot make a stolen key harmless retroactively. +9. Graph-native recovery is local to each observer until that observer sees + the recovery event; the design never claims a network-wide stop without an + enforcer. + +## 6. Acceptance criteria for implementation + +- [ ] #2251 specifies the versioned extension, canonical signed fields, + signature domain, generation zero and transition rule, explicit currency + scope, recovery-key commitment, and unsupported-version behavior. +- [ ] The outer event signature and successor proof are both verified; + malformed, missing, stale, wrong-scope, or nonconsecutive transitions fail + closed. Recovery verifies against the committed recovery key, not the + compromised mint key. +- [ ] A successor's first event must causally reference its rotation event; + an unlinked event is not treated as authorized by that rotation. +- [ ] Tests cover a single routine rotation, two sequential rotations, + missing successor proof, stale generation, duplicate predecessor, same-key + author-chain fork, concurrent rotations, and event/rotation causality that + cannot be established. +- [ ] A definition's identity remains unchanged by later rotation. A + recovery-key commitment is present from definition creation or is absent; + no post-creation amendment silently changes identity. +- [ ] A counting-view snapshot identifies its observed frontier, accepted + generation set and compromise cutoff. It counts valid pre-rotation history, + rejects post-cutoff old-generation activity, and exposes an asserted + earlier window as disputed rather than settled or erased. +- [ ] Anchored tests race rotation/freeze against pending, executed and + rejected intents. Pending work not durably admitted by the barrier is + rejected; previously executed transfers remain and disputed ones require + explicit reconciliation. +- [ ] A compromised-key-only warning may trigger an explicitly unproven + freeze, but cannot select a successor or change authoritative generation + state. +- [ ] Graph-native tests demonstrate that a peer with a stale frontier can + report only what it has observed, and that wallets show generation status + and the frontier used for every displayed balance. +- [ ] The attacker walkthrough demonstrates the cap bound, the anchored + cutoff, the graph-native delay, what stays valid, what is disputed and what + cannot be clawed back automatically. + +## 7. Phased implementation plan + +Each phase is a separately mergeable slice. Runtime activation stays gated +until the preceding verifier/consumer is deployed; no phase silently changes +the meaning of currencies that have no rotation event. + +1. **Wire contract and conformance vectors (#2251).** Amend the closed + definition schema and add the versioned rotation/recovery extension, + signature bytes/domain, generation and predecessor semantics, stable + identity rule, explicit batch scope and vectors. Include malformed and + forked cases. This phase is specification-only and can merge without + changing runtime behavior. +2. **ID event verification and persistence.** Add typed extension decoding, + outer and successor/recovery signature verification, issuer-generation + mapping, successor causal-link validation and fork status. Keep generic + event decoding strict; do not interpret unrecognized issuer versions as + valid. Deploy as read/verify capability before allowing new rotation + events. +3. **Counting-view pinning (#2030).** Add per-currency snapshot metadata, + generation-interval validation, named frontier output, and separate + settled/disputed totals. Existing no-rotation currencies retain their + current behavior; turn on key-aware counting only for views that understand + the new format. +4. **Anchored registry and gateway enforcement (#2062).** Add a signed + registry write referencing the rotation event, ordered registry version, + atomic admission barrier, old-generation rejection and pending/executed/ + rejected race handling. Gate activation per currency until its views and + gateway enforce the same version. +5. **Compromise recovery and reconciliation.** Add the committed recovery-key + check, recovery rotation, optional asserted start, immediate anchored + freeze, disputed-history presentation and explicit ledger reconciliation. + Keep advisory freezes visibly distinct; never auto-reverse an executed + transfer. +6. **Graph-native wallet adoption.** Apply the same verifier without a + gateway, expose observed frontier and generation status in balances, and + test delayed/out-of-order event discovery. Do not imply that local + recovery stops remote signing. + +These are implementation-sized seams, not newly filed issues. The #2804 +latest task note defers filing build packets until #2043 has adopted or +amended this design; the parent/synthesis issue owns downstream issue +sequencing. + +## 8. Non-goals and limits + +- No mechanism can infer the actual time a private key was stolen from its + signatures alone. +- No automatic ledger rollback, universal clawback or recovery of already + spent proceeds is designed here. The trust/counting view and anchored + ledger reconciliation are separate concerns. +- Recovery-key loss/compromise and a governance/quorum replacement policy are + not solved by v1. The safe default is freeze, not pretending the old mint + key is trustworthy. +- This design does not change device-key revocation or replace #2062's + issuer/platform freeze and sunset controls. +- It does not claim graph-native peers learn a rotation at the same time. + +## 10. Question for Drew + +**Q1 — Must anchored currencies precommit a recovery key?** + +- **Option A (recommended):** require a recovery-key hash in every + registry-anchored currency definition; allow it to be absent for + graph-native currencies, with the explicit consequence that compromise + recovery there is advisory only. +- **Option B:** make the recovery-key commitment optional everywhere. An + anchored currency that omits it can still be frozen by the platform + operator, but cannot claim issuer-authoritative recovery or key continuity. + +Default this design and #2251 to Option A unless Drew rules otherwise. This +is the only question here that needs Drew; the remaining choices are +recommendations or explicit v1 limits. The format amendment must happen +before currency definitions are created because the commitment changes the +definition hash if added later. + +## 11. References + +- [Issue #2804 and its latest recommendation/comment](https://github.com/developing-today/code/issues/2804) +- [#2041 token-issuance investigation, §10 case 7 and §11–12](2026-10-30T19-18-00Z_investigation_token_issuance_id_graph/2026-10-30T19-18-00Z_investigation_token_issuance_id_graph.md#L440) +- [#2251 graph token formats, §1.1 and §§6–7](2026-10-30T13-25-00Z_design_graph_token_formats_snapshot_anchoring.md#L63) +- [#2030 trust/visibility model, §§1–3](2026-10-30T19-11-04Z_investigation_trust_visibility_model/2026-10-30T19-11-04Z_investigation_trust_visibility_model.md#L54) +- [#2062 currency control-plane design, §§2.4–2.5 and 4](2026-10-29T12-42-21Z_design_currency_control_plane/2026-10-29T12-42-21Z_design_currency_control_plane.md#L190) +- `pkgs/id/src/chain.rs:120-135, 172-255, 259-307, 311-341` +- `pkgs/id/src/local_events.rs:442-492` +- `pkgs/id/src/event_store/ingest.rs:747-801` +- `pkgs/id/src/event_store/mod.rs:1211-1229` +- `pkgs/id/src/membership/mod.rs:35-47`