synapse
A component of the AienOS ecosystem.
Brought by drakestapleton
synapse / docs / E0_IDENTITY_DOCUMENT.md
| 1 | # E0: Repository Identity Document |
| 2 | |
| 3 | ADR 0003 section 9 step E0 (issue aien-spark/synapse#26). Section 5.5 "Trust root": delegates and threshold live in a Synapse identity document that mirrors the Radicle `refs/rad/id` delegates and threshold; changing it, including registering executors and the server's own machine key, needs the current threshold. |
| 4 | |
| 5 | Code: `crates/synapse-radicle/src/identity.rs`. Tests: `crates/synapse-radicle/tests/e0_identity_document.rs`. Evidence: `evidence/e0-identity-document/`. |
| 6 | |
| 7 | ## 1. What the document holds |
| 8 | |
| 9 | | Field | Meaning | Consumed by | |
| 10 | | :--- | :--- | :--- | |
| 11 | | `repo_id` | The repository the document governs | every check | |
| 12 | | `revision` | 0 for genesis, each edit adds exactly 1 | chaining | |
| 13 | | `prev` | Digest of the document this one replaces; zero for genesis (and only for genesis) | chaining | |
| 14 | | `threshold` | Distinct delegate signatures an edit of *this* document needs, 1 to the delegate count | E2 (promotion quorum), M2 (erasure quorum) through `verify_quorum` | |
| 15 | | `delegates` | Ed25519 keys allowed to sign edits; strictly ascending, at most 256, at least 1 | same | |
| 16 | | `executors` | Registered executor machine keys; strictly ascending, at most 4096 | E1 (`executor_registered_at`, `admit_executor_receipt`) | |
| 17 | | `server_key` | The server's machine key, which signs derivation attestations | B5 (`server_key_at`) | |
| 18 | |
| 19 | Every key must decode to an Ed25519 point that is not of small order. All refusals use existing `RefusalCode` variants; no new code was added. |
| 20 | |
| 21 | ## 2. Rules |
| 22 | |
| 23 | * **Genesis** (`IdentityLog::genesis`): revision 0, zero `prev`, valid, and signed by at least its own threshold of its own delegates. |
| 24 | * **Edit** (`IdentityLog::apply`): the full next document plus delegate signatures. It applies only if the `WalSeq` moves forward, the next document is valid, names the same repository, has revision `current + 1`, has `prev` equal to the current document's digest, and at least the *current* threshold of *current* delegates signed it. A key the edit itself would add cannot sign it into effect. A refused edit changes nothing. |
| 25 | * **Quorum** (`RepositoryIdentityDocument::verify_quorum`): fails closed. A signer that is not a delegate: `RadicleIdentityInvalid`. A signature that does not verify (strict Ed25519): `RadicleSignatureInvalid`. Fewer distinct delegates than the threshold: `RadicleQuorumInsufficient`. A delegate signing twice counts once. |
| 26 | * **Time** (`IdentityLog::document_at`): each revision is in effect from the `WalSeq` it was applied at. The question "was executor X registered when receipt R was accepted" is answered from the document in effect at R's acceptance `WalSeq`, so a later removal refuses only later receipts and never revokes one already accepted (section 5.1, "an attestation added later never revokes a receipt already accepted"). |
| 27 | * **Receipt admission** (`IdentityLog::admit_executor_receipt`): the existing `synapse_evidence::EvidenceReceipt` is verified with its own `verify` (structure, executor `did:key`, strict signature; refusal `ReceiptRefusal::Receipt`), then its executor key must be registered in the document in effect at the acceptance `WalSeq` (refusal `ReceiptRefusal::Identity` with `RadicleIdentityInvalid`). This checks registration only; what a receipt counts toward (input root, policy, independence) is E1. |
| 28 | |
| 29 | ## 3. Byte layout (record version 1, principle P5) |
| 30 | |
| 31 | All integers little-endian, all lengths and counts fixed-width and checked against their caps and against the remaining bytes before anything is allocated. Every decode refusal is `RadicleIdentityInvalid`; a truncated record, trailing bytes, a wrong tag, or a wrong version are each refused. |
| 32 | |
| 33 | Document: |
| 34 | |
| 35 | | Field | Bytes | |
| 36 | | :--- | :--- | |
| 37 | | tag `SYNAPSE_IDENTITY_DOCUMENT_V1\0` | 29 | |
| 38 | | version (`1`) | u16 | |
| 39 | | `repo_id` length, then UTF-8 bytes (at most 4096) | u32 + n | |
| 40 | | `revision` | u64 | |
| 41 | | `prev` | 32 | |
| 42 | | `threshold` | u32 | |
| 43 | | delegate count, then each key | u32 + 32 each | |
| 44 | | executor count, then each key | u32 + 32 each | |
| 45 | | `server_key` | 32 | |
| 46 | |
| 47 | Digest: SHA-256 over `SYNAPSE_IDENTITY_DOCUMENT_DIGEST_V1\0`, the record length as u64, and the record. |
| 48 | |
| 49 | Signed bytes (domain separated): `SYNAPSE_IDENTITY_EDIT_SIGN_V1\0` followed by the 32-byte digest. Because the digest covers `repo_id`, `revision`, and `prev`, a signature cannot be replayed onto another repository, another revision, or a fork. |
| 50 | |
| 51 | Edit: |
| 52 | |
| 53 | | Field | Bytes | |
| 54 | | :--- | :--- | |
| 55 | | tag `SYNAPSE_IDENTITY_EDIT_V1\0` | 25 | |
| 56 | | version (`1`) | u16 | |
| 57 | | document length, then the document record | u32 + n | |
| 58 | | signature count (at most 256), then each 32-byte key and 64-byte signature | u32 + 96 each | |
| 59 | |
| 60 | ## 4. Acceptance |
| 61 | |
| 62 | | Acceptance (ADR 0003 section 9, row 6) | Test | Result | |
| 63 | | :--- | :--- | :--- | |
| 64 | | An edit signed by fewer than the threshold is refused | `e0_edit_signed_by_fewer_than_threshold_is_refused` (1 of threshold 2; the same delegate twice; no signature; a key the edit would add; a forged delegate signature) | pass | |
| 65 | | An edit signed by the threshold applies | `e0_edit_signed_by_threshold_applies` (2 of 3 applies, raises the threshold to 3, rotates the server key; the next edit then needs 3) | pass | |
| 66 | | A removed executor's later receipts are refused | `e0_removed_executor_later_receipts_are_refused` (real signed `EvidenceReceipt`s; removal at `WalSeq` 10; refused at 10 and 11, still admitted on replay at 5; unregistered key, pre-genesis, forged receipt refused) | pass | |
| 67 | | Radicle conformance stays 11 of 11 | `synapse-bench child --kind conformance` with the live Radicle repository, before (main 91733a3) and after | 11 of 11 both; case results identical | |
| 68 | |
| 69 | Supporting tests: `e0_edits_chain_and_cannot_be_replayed_or_reordered`, `e0_genesis_needs_its_own_threshold_and_a_valid_document`, `e0_binary_format_round_trips_and_refuses_malformed_bytes`. |
| 70 | |
| 71 | Red then green: `evidence/e0-identity-document/red-green/red.txt` (all 6 tests fail on their assertions against a fail-open stub that accepts every edit and receipt and changes nothing) and `green.txt` (all 6 pass). |
| 72 | |
| 73 | Radicle conformance reproduction: write `{"suites":["radicle"],"work_dir":"<tmp>","radicle_repo":"<radicle storage repo>"}` to a spec file and run `synapse-bench child --kind conformance --spec <spec> --result <out>`. Raw results: `evidence/e0-identity-document/radicle-conformance/`. |
| 74 | |
| 75 | ## 5. Performance |
| 76 | |
| 77 | E0 is not a hot-path step. No figure is reported, so no bound is needed. |
| 78 | |
| 79 | ## 6. Limits and disclosures |
| 80 | |
| 81 | * The document is in memory only; persisting edits in the WAL is not part of E0 (the binary record format is fixed here so that a later step can store it unchanged). |
| 82 | * The mirror between this document's delegates and threshold and Radicle `refs/rad/id` is not checked by E0; while the Git edge exists, E2 keeps the existing Radicle check and refuses disagreement as `SplitBrainDivergence`. |
| 83 | * Small-order key refusal and the `verify_quorum` signature-count cap were added beside the tested rules and have no test of their own. |
| 84 | * `synapse-radicle` now depends on `synapse-evidence` (and on `synapse-crumb` for tests only); `Cargo.lock` was regenerated by cargo. |