Skip to content

refactor(core,net,remote,proto): one definition each for fork descendants, recovery lineage, refusals, listings, capabilities and login refs - #366

Merged
kitlangton merged 8 commits into
devfrom
core-net-proto-ssot
Dec 2, 2026
Merged

kitlangton merged 8 commits into
devfrom
core-net-proto-ssot

Conversation

@kitlangton

@kitlangton kitlangton commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Four places where the same rule was written twice now have one definition each, with no change to anything sent between devices, to a remote, or to the browser extension.
Protocol versions stay at 38 (daemon) and 3 (browser). No new dependencies.

❌ Before

  1. Membership: finding the frames under a fork rescanned every frame for every forked author; the rule for handing the recovery kit on lived in two functions that had to agree; and a fraud proof (two signatures showing one device wrote two different frames at the same position) had both signatures checked again on every resolve and again by the remote planner, although it can't exist unverified.
  2. Remote stores: the listing contract (under a prefix, after a name, sorted) was written three times, because the shared version was only compiled with the HTTP backends.
  3. Device-to-device connections: a refusal arrived as free text, and pairing decided whether to retry by comparing it to "busy" and "not pairing". Sync and pairing each had their own copy of "wait for the peer to read the refusal, then close".
  4. Extension: capability names were bare strings, so a misspelt one silently turned a feature off. A login's <vault>:<item> text was built by hand in six files and parsed in two, including the macOS AutoFill paths and the Swift bridge.

✅ After

  1. One pass over each frame's causal past finds everything under a fork; the recovery lineage is worked out once and read everywhere; a fraud proof keeps the result of its own verification.
  2. Every store's listing ends in the same function.
  3. A refusal is a named value that also writes the close, so the code and reason bytes have one home. One shared close helper.
  4. The generated bindings carry the capability list and a Capability type, so a typo fails tsc. A login ref writes and parses itself, and every one of those sites goes through it.

🟰 Behavior change: none on the wire or in any consensus rule. Two edge cases read differently, both only for input no shipped build sends: a pairing refusal with an unrecognised reason is now treated as "not pairing" instead of passing the text through, and the extension drops capability names it doesn't know from hello instead of keeping strings it never used (now covered by a test).

- for each frame, for each forked author: scan all frames for a void ancestor
+ per forked author: a bitmask of its void frames; a frame is under the fork iff its past meets the mask

- resolve: verify both signatures of every fraud proof again
+ resolve: read what the proof verified when it was built or decoded

- Err(Rejected(reason)) if reason == "busy"
+ Err(Rejected(Refusal::PairingBusy))

- host.capabilities.includes("save-from")   // compiles, feature silently off
+ host.capabilities.includes("save-from")   // tsc error: not a Capability

📊 Proof

Case Before After
Refusal close codes and reason bytes implicit in string literals pinned by a test (9 "too many connections", 3 "not pairing", 3 "busy", 3 "expired")
Misspelt capability in the extension compiles tsc error (checked by hand with a scratch file)
A forked author's data citing a frame under another author's fork counts, untested counts, pinned by a new test
Login ref grammar (lowercase hex only, exact lengths) tested in the host tested where it is defined, same cases plus more
hello naming a capability the extension doesn't know, or a non-string untested dropped, pinned by a test

Speed was not measured: the fork pass and the skipped signature checks are less work by construction, but there is no benchmark here. New tests: 5 (two core, two net, one proto); 1,561 Rust tests and 1,035 extension tests pass.

Two things this PR deliberately did not do:

  • The fork set is not flattened to one set of frames. Whether a forked author's data counts depends on its own fork, not anyone's, so a flat set would change a consensus rule. It is stored by frame with the forked authors under each, which makes "is this frame void" a single lookup and keeps the per-author answer.
  • VaultCreated / RecoveryRotated were not collapsed onto CreatedVault: they are built and destructured in files other open PRs own.

👀 Read: crates/core/src/v2/membership.rs, recovery_lineage and the RotateRecovery arm of authorize. The arm used to re-derive the handoff rule and now asks "is this the frame that retired this root"; that is only equal because a recovery root is never the target of a removal and is admitted exactly once, so removals can't change the lineage. The existing reference-model property tests cover it. The rest is routine.

🔍 Found in a code audit · no user reports · speed not measured

Checks run

On the rebased branch (onto dev with #370), after the review fixes:

  • bun run gen:proto, then the the_extension_bindings_are_current test: pass, no diff
  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo clippy -p deadbolt-core -p deadbolt-net --features sim --all-targets -- -D warnings: clean
  • bun run check:wasm: clean
  • cargo test --workspace --no-fail-fast locally: 1,558 passed, 3 failed, 5 ignored. The three (codes_do_not_hold_off_the_idle_lock, browser_lookups_do_not_hold_off_the_idle_lock, init_vaults_and_locking) are not from this PR: since feat(enclave,daemon): add With this Mac quick unlock, passphrase cadence, and native macOS watcher #355 a test daemon reads the real Mac's keyboard and mouse idle time, and input in the last 5 seconds resets its idle lock, so they fail on a Mac someone is typing on. They fail the same way with this PR's review fixes stashed, and pass on CI's headless runners.
  • cd extension && bun run typecheck: clean
  • cd extension && bun test: 1,035 pass, 0 fail
  • bash scripts/file-size.sh: 0 errors, 28 warnings, none new
  • CI on the pushed commit: every job green on the second attempt, including the three idle-lock tests on the macOS runner. The first attempt failed two jobs that a rerun with no changes passed: a crates/os test that reads a child process's arguments (a crate this PR doesn't touch) and a browser e2e passkeys step that lost its page mid-click. Neither cause is diagnosed.

…overy lineage, and proofs that keep their verification

- fork descendants come from one pass over each node's causal past instead of
  rescanning every node per fork, stored by frame so `is_fork_void` is a lookup
- the class-0 recovery lineage is derived once and read by every pass, instead
  of the handoff rule living in two functions
- a `FraudProof` keeps what verifying it established, so a resolve and the
  remote planner stop re-checking both signatures of a proof already verified
- one "above the frontier" predicate and one frame selection for a checkpoint's
  two commitments
- `counted_through` is one expression

No consensus rule changes: a forked author's data is still judged against its
own fork only, which a new test pins.
`finish_listing` was compiled only with the HTTP backends, so the in-memory
store and the faulty store each had their own copy of the listing contract.
`Error::Rejected` carried the close reason as a string, and pairing decided
whether to retry by comparing it to "busy" and "not pairing". It now carries a
`Refusal`, which is also what writes the close, so the code and reason bytes
have one definition. The bytes on the wire are unchanged, and a test pins them.

Sync and pairing also shared two copies of "wait for the peer to read the
refusal, then close with the right code"; there is one now.
…gin ref one grammar

- the bindings carry `CAPABILITIES` and a `Capability` union, and `hello` and the
  backend are typed with it, so a misspelt capability no longer compiles
- `LoginRef` writes and parses its own `<vault>:<item>` text; the host, the
  engine's fill history and the browser bindings all go through it

Nothing on the wire changes.
…proven fork frames in a list

A `FraudProof` can't exist unverified, so `verify()` only repeated what
`verified()` already holds. Its last callers read `verified()` now.

The frames a proof names were collected into a map of sets that is empty for
every vault without a fork; a list of `(frame, author)` pairs says the same
with no allocation in that case.
…call

The gate asked "is there a refusal?" and then looked the slot up again,
with a fallback for a case the first answer had ruled out. `pairing()`
returns the open slot or the close to send, so admitting and routing a
pairing connection are one line each.
…f everywhere

`format_ref` and `filled_key` were one-line wrappers around `to_string()`,
and the macOS AutoFill paths and the Swift bridge still built and read the
`<vault>:<item>` text by hand. They all go through `LoginRef` now, and the
fill history takes the ref itself rather than its text.

The Swift bridge still reads a record identifier in either case, by
lowercasing it first.
…on doesn't know

`hello` drops them, and non-strings with them. The tests that set a fake
host's capabilities no longer cast around the `Capability` type.
@kitlangton
kitlangton merged commit f6be3ed into dev Dec 2, 2026
24 of 26 checks passed
@kitlangton
kitlangton deleted the core-net-proto-ssot branch December 2, 2026 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant