interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / docs / B5_DERIVATION_ATTESTATION.md

72 lines · 13327 bytes Raw Blame History Source

B5: DerivationAttestation for Server-Derived Revisions

ADR 0003 section 9 step B5 (issue aien-dev/synapse#29), row 9. Sections 5.1 (AdmissionWitness, DerivationAttestation), 5.3 (lazy rebase), 5.5 (promotion merges) and 5.8 (every admitted mutation is signed): a revision the server produces rather than an agent carries a DerivationAttestation signed by the server machine key that the repository identity document (E0) registers as server_key. It names the inputs and the rule; every rule is deterministic, so a replica recomputes the output and refuses an attestation that does not match. No derived revision claims an agent signature it does not have.

Code: crates/synapse-core/src/derivation.rs (types, codecs, the one recomputation derive_revision_output), crates/synapse-core/src/revision.rs (witness signer tag 2), crates/synapse-store/src/revision.rs (check_derivation, admit_derived_revision, verify_revision_log), crates/synapse-store/src/{lib,codec}.rs (WAL kind 11, replay, checkpoint, state root), crates/synapse-radicle/src/identity.rs (IdentityLog as ServerKeyRegistry), crates/synapse-api/src/derivation.rs (tree store as DerivationTrees, derive_revision, admit_derived_revision, verify_revision_records, verify_revision_log). Tests: crates/synapse-api/tests/b5_derivation_attestation.rs, crates/synapse-store/tests/b5_derived_record.rs, unit tests in crates/synapse-core/src/derivation.rs. Evidence: evidence/b5-derivation-attestation/.

1. Model and invariants

2. Checks, in order

At admission (SynapseStore::admit_derived_revision, sequence at = the next WalSeq) and at replay (verify_revision_log, sequence = the record's own):

CheckRefusal
Content rules; attestation names this content; input count 1..=256; server key is a valid Ed25519 point and the strict signature verifiesDerivationSignatureInvalid (count: DerivationInputMismatch)
The identity documents checked belong to the attestation's repositoryDerivationIdentityRepoMismatch
Server key equals the identity document's server_key at the sequenceDerivationServerKeyUnregistered
Attestation digest not already admitted in this repositoryDerivationAttestationReplayed
Inputs fit the rule's shape and order; every named revision is admitted; every named tree is heldDerivationInputMismatch
The rule applies (rebase target differs from the base, no path conflict, merge revisions share the base) and the recomputed ChangesetId and TreeDigest equal the attested onesDerivationRecomputeMismatch

Admission then applies B1's checks: path-count limit, join rule under the asking or proposing chain (AuthChangeOutOfScope), parents (ParentChangesetNotFound), and every upserted blob already visible (BlobNotFound); nothing is written on any refusal. The record must then be written at exactly the sequence at it was checked at: a writer whose next sequence differs is refused before anything is written, and a frame that lands at another sequence anyway is not applied and poisons the store until it is reopened (WalSequenceGap in both cases, a real check in every build profile). The API also refuses an attestation for another repository (AuthCrossRepoDenied).

Replay verification walks the revision records in sequence order with a fresh ledger: kind 7 records are checked with ChangesetEnvelopeV2::validate (so a derived revision dressed in a borrowed agent attestation is AuthSignatureInvalid), kind 8 with ObsolescenceMarker::validate, kind 11 with the checks above; sequences must strictly ascend (WalSequenceGap) and any other kind is WalRecordMalformed. Refusals keep their code and prefix the message with the record's sequence.

3. Canonical binary layout (principle P5)

Conventions as in B1 (little-endian, str = u32 len | UTF-8, lengths checked before allocation, trailing bytes refused, core decoders refuse with EnvelopeMalformed).

4. Acceptance

Acceptance (issue #29)Test
A replica recomputes every derived revision from the inputs and rule its attestation names and gets the same digestsb5_replica_recomputes_every_derived_revision_and_gets_the_same_digests (rebase and T0 merge equal independently built trees; reopen from the WAL and after a checkpoint; recomputation on the replica is byte-identical)
An attestation naming different inputs is refused at admission and at replayb5_attestation_naming_different_inputs_is_refused_at_admission_and_replay (another real revision, an unknown revision, an unknown tree)
An attestation naming a different rule is refused at admission and at replayb5_attestation_naming_a_different_rule_is_refused_at_admission_and_replay
An attestation by an unregistered server key is refused at admission and at replayb5_unregistered_server_key_is_refused_at_admission_and_replay (a rogue key, a delegate's key, the old key after a rotation; the earlier derivation still verifies)
A derived revision presented with an agent signature it does not have is refusedb5_derived_revision_presented_with_an_agent_signature_it_does_not_have_is_refused (the input's attestation as is and re-pointed, at admission and as a replayed kind 7 record)

Also: b5_attestation_signed_by_another_key_is_refused_at_admission_and_replay, b5_identity_log_of_another_repository_is_refused_at_admission_and_replay (same server key, same delegates, other repository: refused at admission and at replay), b5_derivation_written_at_another_sequence_than_it_was_checked_at_is_refused (typed refusal, not applied, store poisoned), b5_replayed_attestation_is_refused_at_admission_and_replay, b5_recomputation_that_disagrees_is_refused_at_admission_and_replay, b5_derived_revision_records_round_trip_and_malformed_bytes_are_refused_typed, and the core unit tests (codec, signature binding, server witness, path collision). Test keys and identifiers are derived from labels by SHA-256; no literal is used as key material.

Red before green: each acceptance test was run against the B5 commit with one mutation that removes the behaviour it proves (evidence/b5-derivation-attestation/red-green/red.txt, 11 cases), and fails; green.txt holds the passing runs. The two review fixes (repository-bound key lookup, release-mode sequence check) were written test first: review-fixes.txt holds their red runs (the other repository's log was accepted; the misplaced record panicked in a debug build and was admitted in a release build) and green runs.

5. Limits and deviations