ratchet: freeze the v1 state/frame wire format with guard tests #98

Merged
sirius merged 2 commits from wt/t_0ffa68d2 into main 2026-09-18 00:50:38 +00:00
Owner

Card t_0ffa68d2 (ratchet wire freeze). Base: main.

What

Locks the Double Ratchet wire format with two guard tests, and documents it.

  • tests/ratchet.rs: ratchet_state_blob_is_frozen_at_version_v1 asserts the literal 0x01 version byte and the literal 210-byte v1 prefix length. Both are literals, not STATE_VERSION, so a version bump breaks the test instead of riding along with it.
  • tests/ratchet.rs: ratchet_state_foreign_version_is_rejected_not_misread mutates the version byte to 0x00/0x02/0x7f/0xff on a blob that carries two skipped keys (346 bytes, so the rejection cannot pass by luck) and asserts Err(Error::UnsupportedStateVersion(byte)) for each, with the untouched v1 blob still loading afterwards.
  • references/ratchet-wire-frozen.md (new): the frozen v1 state layout, the rat frame layout, the reject-before-decode behaviour, and the migration path a v2 must follow.

No change to src/ratchet.rs: the format itself is untouched.

Naming note

The card asks for a decode_state() call. There is no such function in this crate: the persisted blob is decoded by RatchetState::from_bytes, reached from ratchet_for in src/node.rs and from the Kind::Ratchet arm of Node::handle_incoming. That is what the tests exercise.

Verification

  • Guard has teeth: with STATE_VERSION = 2 both new tests fail (the frozen version byte changed: this is a wire-format break, not a refactor, and the 0x02 mutation is then accepted, so the rejection test fails too). Reverted immediately after; STATE_VERSION is 1 in the diff.
  • cargo test --locked ratchet exit 0; both new tests ok.
  • cargo clippy --locked --all-targets -- -D warnings exit 0.
  • rustfmt --edition 2024 --check tests/ratchet.rs clean (0 diffs, same count as at HEAD), so no formatting churn.

Housekeeping

The kanban card's workspace was mis-wired to the solana-meme-bot repo (/home/lancelot/projects/solana-meme-bot/.worktrees/t_0ffa68d2), which is a Python project with no Cargo workspace. OnionWire work was done in a worktree of the real repo at /home/lancelot/Projects/onionwire, branch wt/t_0ffa68d2, and nothing was committed to the solana-meme-bot branch.

Card t_0ffa68d2 (ratchet wire freeze). Base: main. ## What Locks the Double Ratchet wire format with two guard tests, and documents it. - `tests/ratchet.rs`: `ratchet_state_blob_is_frozen_at_version_v1` asserts the literal `0x01` version byte and the literal 210-byte v1 prefix length. Both are literals, not `STATE_VERSION`, so a version bump breaks the test instead of riding along with it. - `tests/ratchet.rs`: `ratchet_state_foreign_version_is_rejected_not_misread` mutates the version byte to 0x00/0x02/0x7f/0xff on a blob that carries two skipped keys (346 bytes, so the rejection cannot pass by luck) and asserts `Err(Error::UnsupportedStateVersion(byte))` for each, with the untouched v1 blob still loading afterwards. - `references/ratchet-wire-frozen.md` (new): the frozen v1 state layout, the `rat ` frame layout, the reject-before-decode behaviour, and the migration path a v2 must follow. No change to `src/ratchet.rs`: the format itself is untouched. ## Naming note The card asks for a `decode_state()` call. There is no such function in this crate: the persisted blob is decoded by `RatchetState::from_bytes`, reached from `ratchet_for` in `src/node.rs` and from the `Kind::Ratchet` arm of `Node::handle_incoming`. That is what the tests exercise. ## Verification - Guard has teeth: with `STATE_VERSION = 2` both new tests fail (`the frozen version byte changed: this is a wire-format break, not a refactor`, and the 0x02 mutation is then accepted, so the rejection test fails too). Reverted immediately after; `STATE_VERSION` is 1 in the diff. - `cargo test --locked ratchet` exit 0; both new tests ok. - `cargo clippy --locked --all-targets -- -D warnings` exit 0. - `rustfmt --edition 2024 --check tests/ratchet.rs` clean (0 diffs, same count as at HEAD), so no formatting churn. ## Housekeeping The kanban card's workspace was mis-wired to the `solana-meme-bot` repo (`/home/lancelot/projects/solana-meme-bot/.worktrees/t_0ffa68d2`), which is a Python project with no Cargo workspace. OnionWire work was done in a worktree of the real repo at `/home/lancelot/Projects/onionwire`, branch `wt/t_0ffa68d2`, and nothing was committed to the solana-meme-bot branch.
ratchet: freeze the v1 state/frame wire format with guard tests
All checks were successful
ci / test (pull_request) Successful in 4m47s
ci / sdk (pull_request) Successful in 57s
1aec007601
The persisted ratchet state had a version byte and typed errors but no
test that a format change would actually be caught. Add two dedicated
guards to tests/ratchet.rs that assert the frozen shape as literals
(0x01, 210-byte prefix) rather than via STATE_VERSION, so a bump breaks
them visibly, and pin that any foreign version byte is rejected with
Error::UnsupportedStateVersion before any field is read.

Document the frozen v1 state layout, the rat frame layout, and the
migration path a v2 must follow in references/ratchet-wire-frozen.md.

Verified by flipping STATE_VERSION to 2: both guards fail
("the frozen version byte changed"), then revert.
Merge branch 'main' into wt/t_0ffa68d2
All checks were successful
ci / test (pull_request) Successful in 4m59s
ci / sdk (pull_request) Successful in 1m7s
ba3c39cfe1
sirius merged commit 4a06d794f1 into main 2026-09-18 00:50:38 +00:00
sirius deleted branch wt/t_0ffa68d2 2026-09-18 00:50:38 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!98
No description provided.