ratchet: freeze the v1 state/frame wire format with guard tests #98
Loading…
Reference in a new issue
No description provided.
Delete branch "wt/t_0ffa68d2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_v1asserts the literal0x01version byte and the literal 210-byte v1 prefix length. Both are literals, notSTATE_VERSION, so a version bump breaks the test instead of riding along with it.tests/ratchet.rs:ratchet_state_foreign_version_is_rejected_not_misreadmutates 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 assertsErr(Error::UnsupportedStateVersion(byte))for each, with the untouched v1 blob still loading afterwards.references/ratchet-wire-frozen.md(new): the frozen v1 state layout, theratframe 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 byRatchetState::from_bytes, reached fromratchet_forinsrc/node.rsand from theKind::Ratchetarm ofNode::handle_incoming. That is what the tests exercise.Verification
STATE_VERSION = 2both 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_VERSIONis 1 in the diff.cargo test --locked ratchetexit 0; both new tests ok.cargo clippy --locked --all-targets -- -D warningsexit 0.rustfmt --edition 2024 --check tests/ratchet.rsclean (0 diffs, same count as at HEAD), so no formatting churn.Housekeeping
The kanban card's workspace was mis-wired to the
solana-meme-botrepo (/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, branchwt/t_0ffa68d2, and nothing was committed to the solana-meme-bot branch.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.