Skip to content

Cover data.state with integrity and bundle version 2 - #181

Merged
WiktorB2004 merged 2 commits into
mainfrom
commit-record-state
Dec 3, 2026
Merged

WiktorB2004 merged 2 commits into
mainfrom
commit-record-state

Conversation

@WiktorB2004

@WiktorB2004 WiktorB2004 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #51

Integrity now covers data.state (row state), and record_state works with AuditTrail(integrity=...).

  • state is an optional activity group: committed only on rows that have it, left out of the leaf (ERASABLE_DATA_KEYS).
  • scrub() erases it like payload and stamps state only on rows that have the key; the audit.scrubbed payload gets stamped_state_rows only when nonzero. verify() checks the erased form and counts (absent means 0).
  • The erasure journal stays v2 and accepts the three scrub groups plus state; reapply_erasures() erases and stamps it again.
  • Bundles: an export with a state row in scope is bundle_version 2 (header and manifest), decided by an EXISTS pre-scan per run of seal blocks before header.json. The reader accepts 1 and 2; a version 1 bundle with a state group or null key is malformed; a ledger bundle is always 1.
  • The writer refuses data.state = null. The guard refusing record_state with integrity is removed.
  • Specs (canonical.md, bundle-v1.md), the integrity, privacy and models guides, and new vectors (a state commitment, a leaf, a journal, five bundles).

Compatibility

  • Rows, journals, checkpoints and bundles written by 0.7 verify unchanged: no migration, no new tag, data.v, leaf and commit tags unchanged. git diff origin/main -- docs/spec/vectors shows additions only; the existing bundle vectors regenerate byte for byte.
  • An export without state rows is version 1, byte for byte as before; the released 0.7.0 CLI verifies one exported here (VALID). Given a bundle with state, 0.7.0 exits 2 with bundle version 2 is not supported.
  • A 0.7 verify() run against a database holding 0.8 state rows reports ROOT_MISMATCH/COMMITMENT_MISMATCH; upgrade every sealer and verifier to 0.8 before writing state with integrity (a 0.7 sealer does lasting damage; see below).
  • The ledger and the Go verifier (ledger only) are not affected.

Review follow-up

  • Upgrade order. CHANGELOG, the models guide and a new integrity guide section ("Before turning on row state") say: upgrade every sealer and verifier to 0.8 before turning on record_state with integrity. A 0.7 sealer hashes data.state into the leaf, so 0.8's verify() fails those blocks with ROOT_MISMATCH for good, and once a scrub erases the state they can never verify. That cannot be undone; a 0.7 verifier is only a false alarm.
  • A null state fails. check_groups (used by verify() and verify_bundle()) fails a sealed row whose data.state is present and null with COMMITMENT_MISMATCH, group state, detail stored as null, before the salt/stamp checks. No writer stores it and a scrub erases a null to the mark, so it is never legitimate. I kept an existing failure kind instead of adding a new one: it is waivable like the others and needs no new report or CLI surface. canonical.md and the bundle spec's group-check steps state the rule. payload/changes are unchanged. The Go verifier checks ledger bundles only (it refuses any bundle_version but 1 and never reads audit row groups), so it needs no change.
  • Export guard vs pre-scan. The "appeared in scope during the export; export again" guard now covers only the rows in scope, which the pre-scan reads. A scrub record fetched by a stamp (outside the scope, so not pre-scanned) that holds data.state raises its own error naming the audit.scrubbed row: no scrub writes a state, so the row was changed, and exporting again would not help. I chose this over widening the pre-scan: the scrub records are found only by the stamps read during the export, and finding them up front would need a scan of every activity row (there is no verb index), while that tampered row is already a verify() failure.
  • Pre-scan cost. The integrity guide and CHANGELOG say the EXISTS query has no index to use: one extra pass over the activity rows in scope.
  • Strict versions. bundle_version must be an integer (not a bool) in the header (both the audit and the ledger dispatch) and the manifest: true, 2.0, 1.0 and "2" are refused as unsupported versions.
  • Tests. DB: state added to a row without one, state removed, state set to null, null state added, salt removed plus a forged stamp (and with the value also put in erased form), each through verify() and through an exported bundle; the race guard (a state row after the pre-scan); a tampered scrub record outside the scope; and a 0.8 audit.scrubbed payload compared byte for byte with what 0.7.0 stores for the same scrub (checked against the 0.7.0 tag). Unit: non-integer versions, a true manifest version, a null state in a version 2 bundle, and check_groups on a null state.

data.state becomes an optional activity group: committed only on rows that
have it and left out of the leaf, erased and stamped by scrub only there,
counted in stamped_state_rows, listed in the erasure journal and re-applied
by reapply_erasures. An export with a state row in scope is bundle version
2, decided by a pre-scan before header.json; every other bundle stays
version 1. Lift the guard that refused record_state with integrity.
- Fail a sealed row whose data.state is present and null with
  COMMITMENT_MISMATCH (group state), in verify() and verify_bundle().
- Require an integer bundle_version in the header and the manifest.
- A scrub record outside the scope that holds data.state now raises
  its own error naming the row; the "export again" guard covers only
  the rows the pre-scan reads.
- Docs: upgrade every sealer and verifier to 0.8 before turning on
  record_state with integrity; the pre-scan is one extra pass over
  the activity rows in scope.
- Tests for state tampering, the export guards and the 0.7 scrub
  record bytes.
@WiktorB2004
WiktorB2004 merged commit 33cc571 into main Dec 3, 2026
15 checks passed
@WiktorB2004
WiktorB2004 deleted the commit-record-state branch December 3, 2026 19:24
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.

Opt-in row snapshots on audited models

1 participant