Skip to content

feat(private): contiguous key epochs, burned epochs and safe maintainer changes - #64

Merged
PastaPastaPasta merged 8 commits into
masterfrom
feat/private-epochs-contiguous
Sep 27, 2026
Merged

PastaPastaPasta merged 8 commits into
masterfrom
feat/private-epochs-contiguous

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

What

This follows up #47. It makes private-repo key epochs contiguous, adds burned epochs, and tightens how anchors are chosen and how maintainers are added or removed. The spec, the conformance vectors, the Rust reference and the web's TypeScript all change together, so master stays green on both stacks.

Rules (docs/security/private-repos.md, §4.3, §5.3, §5.5, §5.6, §7, §8.1, §11)

  • Contiguous epochs.
    • Epoch e exists only if it has an anchor and e − 1 exists.
    • A current maintainer's config above a gap raises an EpochGap alert and is ignored.
    • Each anchor chains to exactly prevEpoch = e − 1.
    • A new epoch is always current + 1, so a config at a huge epoch number can no longer use up the epoch space.
  • Anchors only after their key was stated.
    • For e ≥ 1, a config counts only if its ($createdAtBlockHeight, $id) is strictly after stated(e − 1). That is the first config for e − 1, by anyone, that carries anchor(e − 1)'s commitment.
    • A config posted in advance never becomes an anchor. This covers future epochs, returning maintainers, and configs from before the epoch below existed.
    • A re-anchor after a maintainer's removal keeps the epochs above it.
    • Block height is set by consensus, and ties are broken by raw $id bytes.
  • Burned epochs (config TLV tag 11).
    • When a rotation's key for n+1 may have reached someone outside the remaining members (a crashed earlier run, a visible stray wrap, or a wrap that can't be replaced), the rotation does four things:
      1. It wraps K_{n+1} to every remaining member.
      2. It anchors n+1 burned, carrying no prevEpochKey.
      3. It confirms that its anchor won, checking both author and commitment. If it lost, it stops.
      4. It rotates to n+2, which carries prevEpochKey = K_{n+1} and a new skipEpochKey (TLV tag 12): the key of the nearest epoch below that is not burned.
    • A burned epoch has no write epoch. Content under it is Late unless a current member wrote it, and manifests under it are suspect.
    • The repair check rotates past a burned epoch, and any maintainer can finish a burn.
  • Changing maintainers.
    • Removing a maintainer re-anchors their epochs first. Each re-anchor repeats the full chain link (8, 9, 11, 12).
    • The client then checks the result without that maintainer. If anything changed, it refuses the removal and names whoever took over an anchor.
    • The leaving maintainer's unreadable top epochs are dropped only when nobody who stays holds them. Wraps written by the leaving maintainer don't count.
    • The owner can't drop their own maintainer role while they anchor an epoch.
    • Adding a maintainer is refused if it would move an anchor.
    • While a non-member holds the current key, writeEpoch is null until the rotation lands.

Implementation

  • Rust.
    • private/{epoch,tlv,doc}.rs: anchor selection with stated heights, the chain walk with skip keys, burned epochs and the late rule.
    • keyring.rs:
      • rotate makes its decision in a pure step_for, handles the burn path and uses next_link / ChainLink.
      • Removal re-anchoring and verification: reanchor_plan, wrap_held_through, confirm_removal.
      • The grant check and rotation_may_burn.
    • dg:
      • repo keys status names whoever burned the current epoch.
      • Cost estimates account for a burn, and the removal prompt names a burn it will finish.
      • Refusal messages say exactly what works.
      • Content sealed under an earlier use of an epoch number is reported as that, not as corruption.
  • TypeScript. forge-web/lib/private/{epoch,tlv,doc}.ts mirror the Rust exactly; the web agent will take these files as-is when it rebases feat(web): read private repos and manage their members #51.
  • Vectors. 181 private_* vectors, up from 146. Both harnesses pass all of them, and gen.py regenerates them byte for byte.

Reviews

  • Two independent security reviews of the burn, contiguity and anchor rules, one before the skip-key change and one after.
    • Findings fixed: an unremovable malicious maintainer (H1), no write epoch while a non-member holds the key (H2), removals that could fail forever, removal poisoning, and misleading guidance.
    • The anchor-order rule was confirmed to have no liveness gap and no ordering skew.
  • Two correctness reviews.
    • The second was APPROVED WITH SUGGESTIONS, and every suggestion is applied.
    • Fixes include the ones for C1 (only the maintainer who started a burn could finish it), C2 (an owner dropping their own maintainer role would have wiped every epoch) and M2 (a burned anchor handed out the key of the epoch below it).
  • A simplifier pass, with its findings applied.
  • Every fix has a test that failed before it.

Live e2e on devnet moutai (e017aa2 build)

  • Scenario 15:
    • create, then a sealed push, then a non-member refused;
    • a member clones byte-identical; removal rotates to epoch 1;
    • a maintainer rejoins at epoch 2; removing them re-anchors, then rotates to 3;
    • the owner reads every epoch, and status is clean.
  • Scenario 16 (new):
    • the owner's rotation dies after its self-wrap;
    • removing a writer burns epoch 1 and dies after the burned anchor;
    • the other maintainer sees the burn and repairs to epoch 2;
    • the removed writer is refused, and both maintainers read every epoch through the skip key.
    • The crash points come from DASH_FORGE_TEST_FAULT, which only debug builds honour; release builds skip the scenario.

Notes

  • Devnet repos with a burned epoch created under an intermediate commit of this branch (1ddd1f2) will show ChainBroken. The only such repos are e2e test repos, so nothing needs migrating.
  • Burn griefing by a current maintainer is bounded by removing them. It is attributable (dg repo keys status names who burned), and a removal won't pay for someone else's burn without asking.
  • Follow-ups are in the QA backlog: full keyring reload per write (M8), dg repo view hiding E306, a dg repo keys reanchor command, and CLI sealing of issues, PRs, comments and reviews.

🤖 Generated with Claude Code

PastaPastaPasta and others added 7 commits September 27, 2026 01:24
Epochs exist only contiguously from 0: a config above a missing epoch number is not an anchor (EpochGap alert), each anchor chains to exactly e-1, and a new epoch is always current+1, so a huge epoch number can no longer exhaust the space.

A rotation whose key for n+1 may have reached someone outside the remaining members anchors n+1 burned (config TLV tag 11) and rotates on to n+2, stopping if another maintainer's n+1 anchor wins. A burned epoch only links the chain: no write epoch, late content unless by a member, suspect manifests, and the repair check rotates past it.

Maintainer changes keep anchors intact: a removal re-anchors with the same key, chain pair and burned flag and verifies the post-removal resolution (dropping only unreadable top epochs), and adding a maintainer is refused when their old configs would move an anchor. dg repo keys status names who burned the current epoch; the removal's follow-up repair no longer spends on someone else's burn.

Spec §4.3/§5.3/§5.5/§5.6/§8.2 and 17 new or regenerated vectors (163 total), with the TS reference from the web branch so both stacks pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
After dropping the leaving maintainer's unreadable top epochs, the surviving current epoch must be readable by the remover; otherwise the removal is refused before any write (matches the web).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…pre-posted future configs

A maintainer removal drops unreadable top epochs only when the leaving maintainer anchored all of them and no maintainer who stays wrote or received a wrap for them (public wrap rows); staying writers who lose them are named.

Re-granting a maintainer is refused when they have a config above the current epoch, and a rotation whose anchor makes room for a pre-posted next-epoch config refuses and names its author (parity with the web).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Anchor selection (spec §5.3): for e >= 1 a config is a candidate only if its (block height, id) is strictly after stated(e-1), the first config of e-1 carrying anchor(e-1)'s commitment. Pre-posted configs (future epochs, re-granted maintainers) never become anchors; measuring from the key's first statement keeps epochs above a re-anchored one intact.

Five new vectors (168), Rust and TS. Also applies the simplifier's findings: shared reload/poll helpers, create_private_state via pending_key, burned_by returns the epoch, one still-holds check in the removal.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…hes a burn

M2: a burned anchor keeps prevEpoch but carries no prevEpochKey; the next anchor carries prevEpochKey and a new skipEpochKey (TLV tag 12), the key of the nearest epoch below the burned run, and the chain walk steps over the run. C1: the burn path wraps the burned key to every remaining member before anchoring, so any maintainer sees and finishes it.

C2: removing your own maintainer role is refused while you anchor an epoch. Security H1: the leaving maintainer's own wraps never pin an epoch. H2: no write epoch while a non-member holds the current key. M2/M3: the remover self-wraps every epoch it holds only through the leaver and the refusal names who displaced an anchor. M1: plain grant refusal; M3: a re-run removal rotates past a burned epoch. L: owner check before any fee, won judged by commitment, earlier-use classification, burn cost estimate, spec wording.

13 new vectors (181), Rust and TS; rotate's decision is the pure step_for.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Scenario 16 on moutai: the owner's rotation dies after its self-wrap, the removal burns epoch 1 and dies after the burned anchor, the other maintainer repairs to epoch 2, the removed writer is refused and both maintainers read every epoch through the skip key. Crash points via the debug-only DASH_FORGE_TEST_FAULT.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The removal refusal names only who changed a commitment; earlier-use content is judged from when the key was first stated (Anchor.stated_height), and only a tag failure on an intact pack counts as one; no_write says when a non-member holds the current key; a wrap only proves holding an epoch if it carries the resolution's key.

Burn-aware estimates for rotate and remove, the removal prompt names someone else's burn it will finish, clearer maintainer grant refusal, scenario 16 skips on release builds; spec §5.6 H2 rule, §8.1 EarlierUse and stale wording.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: e36c7de3-cd54-4d53-beb3-38824bcd9af7

📥 Commits

Reviewing files that changed from the base of the PR and between 0cec37c and cb6c1b0.

📒 Files selected for processing (59)
  • crates/dg/src/collab.rs
  • crates/dg/src/keys.rs
  • crates/forge-core/src/keyring.rs
  • crates/forge-core/src/private/conformance.rs
  • crates/forge-core/src/private/doc.rs
  • crates/forge-core/src/private/epoch.rs
  • crates/forge-core/src/private/tlv.rs
  • crates/forge-core/src/repo.rs
  • docs/security/private-repos.md
  • e2e/README.md
  • e2e/cli/run.sh
  • e2e/cli/scenarios/15-private-repo.sh
  • e2e/cli/scenarios/16-private-burn-repair.sh
  • forge-contracts/vectors/private_doc_open__config_burned_anchor.json
  • forge-contracts/vectors/private_doc_open__config_with_skip_key.json
  • forge-contracts/vectors/private_doc_open__content_under_burned_epoch_from_member_shown.json
  • forge-contracts/vectors/private_doc_open__content_under_burned_epoch_late.json
  • forge-contracts/vectors/private_doc_open__tlv_burned_bad_value.json
  • forge-contracts/vectors/private_doc_open__tlv_burned_in_epoch0.json
  • forge-contracts/vectors/private_doc_open__tlv_burned_in_issue.json
  • forge-contracts/vectors/private_doc_open__tlv_burned_two_bytes.json
  • forge-contracts/vectors/private_doc_open__tlv_burned_with_prev_key.json
  • forge-contracts/vectors/private_doc_open__tlv_burned_with_skip_key.json
  • forge-contracts/vectors/private_doc_open__tlv_reserved_tag.json
  • forge-contracts/vectors/private_doc_open__tlv_skip_key_in_epoch0.json
  • forge-contracts/vectors/private_doc_open__tlv_skip_key_in_issue.json
  • forge-contracts/vectors/private_doc_open__tlv_skip_key_length_31.json
  • forge-contracts/vectors/private_doc_seal__burned_in_epoch0.json
  • forge-contracts/vectors/private_doc_seal__burned_with_prev_key.json
  • forge-contracts/vectors/private_doc_seal__burned_with_skip_key.json
  • forge-contracts/vectors/private_doc_seal__config_anchor_epoch2_with_skip.json
  • forge-contracts/vectors/private_doc_seal__config_burned_anchor_epoch1.json
  • forge-contracts/vectors/private_epoch__anchor_tie_at_same_height_after_prev_by_id.json
  • forge-contracts/vectors/private_epoch__burned_anchor_has_no_prev_key.json
  • forge-contracts/vectors/private_epoch__burned_current_requires_rotation.json
  • forge-contracts/vectors/private_epoch__burned_epoch_chain_walks.json
  • forge-contracts/vectors/private_epoch__burned_epoch_not_writable.json
  • forge-contracts/vectors/private_epoch__burned_flag_only_on_the_anchor_counts.json
  • forge-contracts/vectors/private_epoch__chain_prev_epoch_must_be_e_minus_1.json
  • forge-contracts/vectors/private_epoch__chain_prev_epoch_without_anchor.json
  • forge-contracts/vectors/private_epoch__chain_with_skipped_epoch_number.json
  • forge-contracts/vectors/private_epoch__consecutive_burned_skip.json
  • forge-contracts/vectors/private_epoch__current_epoch_is_highest_anchored.json
  • forge-contracts/vectors/private_epoch__epoch_gap_ignored.json
  • forge-contracts/vectors/private_epoch__huge_epoch_from_current_maintainer_is_a_gap.json
  • forge-contracts/vectors/private_epoch__huge_epoch_from_removed_maintainer_ignored.json
  • forge-contracts/vectors/private_epoch__missing_skip_key_chain_broken.json
  • forge-contracts/vectors/private_epoch__preposted_after_other_key_ignored.json
  • forge-contracts/vectors/private_epoch__preposted_config_ignored_after_regrant.json
  • forge-contracts/vectors/private_epoch__preposted_future_config_ignored.json
  • forge-contracts/vectors/private_epoch__reanchor_of_middle_epoch_keeps_epochs_above.json
  • forge-contracts/vectors/private_epoch__rotation_alert_only_for_maintainers.json
  • forge-contracts/vectors/private_epoch__rotation_required_when_wrapped_non_member.json
  • forge-contracts/vectors/private_epoch__skip_key_walks_past_burned.json
  • forge-web/lib/private/conformance.test.ts
  • forge-web/lib/private/doc.ts
  • forge-web/lib/private/epoch.ts
  • forge-web/lib/private/tlv.ts
  • tools/private-repos-vectors/gen.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Keeps master's edits-are-judged-too §8.2 paragraph alongside the burned-epoch wording, and adds ForgeIds.group_owner to the keyring test fixture.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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