tests: assert the DH ratchet step in lockstep on a bidirectional burst #97

Merged
sirius merged 1 commit from wt/t_d686a78c into main 2026-09-18 00:49:29 +00:00
Owner

What

Adds bidirectional_burst_keeps_the_dh_ratchet_in_lockstep to tests/ratchet.rs.

The existing round_trip_across_two_dh_ratchet_steps only asserts that neither
sending ratchet key stayed put. It would still pass if the two peers stepped onto
unconnected epochs, and it never checks that either peer adopted the key the
other advertised in the frame header. The new test takes the ratchet key out of
the wire header (dh_pub[0..32]) and asserts the adoption per step.

Lockstep semantics the test pins

The bootstrap tie-break means one A->B / B->A round cannot step both sides: only
the lower-key (establishing) peer rotates its sending chain, and the other peer
has still only ever seen bootstrap keys. The test asserts that intermediate state
instead of assuming it, then drives the rounds that complete the lockstep:

  • round 1: a rotates, b.public() is unchanged, a.remote_pub() is b's key;
  • round 2: a's fresh key reaches b, which takes a full step and adopts exactly
    the advertised key;
  • round 3: the mirror image for a;
  • burst: three frames each way, asserting they are chain reads (not extra steps),
    skipped_len() == 0, recv_index() == 3, and that the peer which received last
    is keyed to the other's current key. The one-header lag in the other
    direction (b.remote_pub() is a's last advertised key, not the fresh key
    a's step just generated) is documented in the test rather than asserted away.

Verification

  • cargo test --locked --test ratchet -- 16 passed, 0 failed (new test included)
  • ratchet filter across targets: ratchet 16, ratchet_adversarial 5, ratchet_e2e 5,
    ratchet_wire 5 -- all 0 failed
  • cargo clippy --locked --all-targets -- -D warnings -- exit 0, no warnings
  • rustfmt --edition 2024 --check tests/ratchet.rs -- clean (exit 0)
  • Mutation check (scratch, src/ratchet.rs reverted afterwards; only
    tests/ratchet.rs is in this diff): the new test fails for each of
    1. rotate_sending_chain reusing the old keypair -> "round 1 must rotate a's
      sending ratchet key";
    2. plan_step reusing the old keypair instead of generating one -> "b must
      DH-ratchet on a's new key";
    3. decrypt treating every frame as the same chain -> fails at round 2.

No src/ change, no new dependency, one file.

## What Adds `bidirectional_burst_keeps_the_dh_ratchet_in_lockstep` to `tests/ratchet.rs`. The existing `round_trip_across_two_dh_ratchet_steps` only asserts that neither sending ratchet key stayed put. It would still pass if the two peers stepped onto *unconnected* epochs, and it never checks that either peer adopted the key the other advertised in the frame header. The new test takes the ratchet key out of the wire header (`dh_pub[0..32]`) and asserts the adoption per step. ## Lockstep semantics the test pins The bootstrap tie-break means one A->B / B->A round cannot step both sides: only the lower-key (establishing) peer rotates its sending chain, and the other peer has still only ever seen bootstrap keys. The test asserts that intermediate state instead of assuming it, then drives the rounds that complete the lockstep: - round 1: `a` rotates, `b.public()` is unchanged, `a.remote_pub()` is b's key; - round 2: `a`'s fresh key reaches `b`, which takes a full step and adopts exactly the advertised key; - round 3: the mirror image for `a`; - burst: three frames each way, asserting they are chain reads (not extra steps), `skipped_len() == 0`, `recv_index() == 3`, and that the peer which received last is keyed to the other's *current* key. The one-header lag in the other direction (`b.remote_pub()` is `a`'s last advertised key, not the fresh key `a`'s step just generated) is documented in the test rather than asserted away. ## Verification - `cargo test --locked --test ratchet` -- 16 passed, 0 failed (new test included) - ratchet filter across targets: ratchet 16, ratchet_adversarial 5, ratchet_e2e 5, ratchet_wire 5 -- all 0 failed - `cargo clippy --locked --all-targets -- -D warnings` -- exit 0, no warnings - `rustfmt --edition 2024 --check tests/ratchet.rs` -- clean (exit 0) - Mutation check (scratch, `src/ratchet.rs` reverted afterwards; only `tests/ratchet.rs` is in this diff): the new test fails for each of 1. `rotate_sending_chain` reusing the old keypair -> "round 1 must rotate a's sending ratchet key"; 2. `plan_step` reusing the old keypair instead of generating one -> "b must DH-ratchet on a's new key"; 3. `decrypt` treating every frame as the same chain -> fails at round 2. No `src/` change, no new dependency, one file.
tests: assert the DH ratchet step in lockstep on a bidirectional burst
All checks were successful
ci / test (pull_request) Successful in 4m51s
ci / sdk (pull_request) Successful in 58s
6f267a6aba
`round_trip_across_two_dh_ratchet_steps` only asserts that neither sending
ratchet key stayed put; it would still pass if the two sides stepped onto
unconnected epochs, and it never checks that either peer adopted the key the
other advertised. The new test reads dh_pub out of the wire header and pins the
adoption per step across an A->B / B->A burst:

- round 1 rotates only the lower-key (establishing) peer, so one round cannot
  lockstep both sides -- the intermediate state is asserted, not assumed;
- rounds 2 and 3 step each side in turn, asserting each receiver adopts exactly
  the key the frame advertised;
- the three-frame burst each way asserts chain reads (not extra steps), zero
  skipped keys, and that the peer that received last is keyed to the other's
  current key.

tests/ratchet.rs only; no src change, no new dependency.
sirius merged commit fa53237968 into main 2026-09-18 00:49:29 +00:00
sirius deleted branch wt/t_d686a78c 2026-09-18 00:49:29 +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!97
No description provided.