Skip to content

test(matching): add ZSO-1 acceptance tests for bithash prefilter - #4621

Merged
oferchen merged 1 commit into
masterfrom
test/matching-zsync-bithash-acceptance-zso1
May 20, 2026
Merged

oferchen merged 1 commit into
masterfrom
test/matching-zsync-bithash-acceptance-zso1

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Adds the two ZSO-1 acceptance tests that complement the bithash prefilter implementation already merged via PR #3737. The production code (insert at index build, probe before the CompactLookup walk, clear on rebuild) is in place on master; this PR pins the acceptance contract from the ZSO-1 brief in unit tests so future refactors can't silently regress the prefilter behaviour.

  • bithash_rejects_at_least_seven_eighths_of_known_misses — builds a filter with N=1000 inserted rsums and probes with N=1000 disjoint known-miss rsums, asserting at least 87% reject at the bithash gate. Measured rate locally: 97.2%, comfortably above the 7/8 zsync density bound.
  • bithash_state_does_not_leak_between_independent_indexes — builds two DeltaSignatureIndex values from distinct basis bytes and confirms a probe for blocks indexed in one never matches in the other, pinning the per-NDX lifecycle relied on by the ZSO-7 audit at docs/audits/zso-7-inc-recurse-per-segment-state-2026-05-21.md.

Background

ZSO-1 (#2509) is the first of four zsync-inspired in-memory speedups for the matching pipeline. The bithash prefilter is a one-sided, 8x-oversized bit array probed between the tag_table[sum1] gate and the CompactLookup walk in find_match_*. It rejects ~7/8 of post-tag misses in O(1) using the full 32-bit rolling sum, all without touching the wire format.

Production sites verified against the audit citations:

  • Field on DeltaSignatureIndex at crates/matching/src/index/mod.rs:70
  • Probe sites at crates/matching/src/index/mod.rs:155 (find_match_bytes_filtered) and :211 (find_match_slices_filtered)
  • Insert + clear wired through populate_index and rebuild in crates/matching/src/index/builder.rs:32,127

The line numbers cited in the ZSO-1 brief have drifted slightly since the audit (the field sits at mod.rs:70, not :44; probes are at :155/:211, not :165; clear is at builder.rs:127 as cited). Behaviour matches the design exactly.

Wire-byte parity

No protocol or serialisation surface is touched. cargo nextest run -p protocol --all-features -E 'test(golden)' passes unchanged (407 tests).

Acknowledgement

Bithash design follows zsync 0.6.2 librcksum (Colin Phipps, http://zsync.moria.org.uk/), per the README acknowledgement landed in PR #4597.

Test plan

  • cargo nextest run -p matching --all-features — 320 tests pass.
  • cargo nextest run -p protocol --all-features -E 'test(golden)' — 407 tests pass, no golden-byte drift.
  • cargo fmt --all -- --check — clean.
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings — clean.

Adds the two ZSO-1 acceptance tests that complement the bithash
prefilter implementation already merged in PR #3737:

- bithash_rejects_at_least_seven_eighths_of_known_misses: builds a
  filter with N=1000 inserted rsums and probes with N=1000 disjoint
  known-miss rsums, asserting at least 87% reject at the bithash
  gate. Measured rate on this run: 97.2%.
- bithash_state_does_not_leak_between_independent_indexes: builds
  two DeltaSignatureIndex values from distinct basis bytes and
  confirms a probe for blocks indexed in one never matches in the
  other, pinning the per-NDX lifecycle relied on by the ZSO-7
  audit (docs/audits/zso-7-inc-recurse-per-segment-state-2026-05-21.md).

No production code changes. Wire-byte parity is unaffected; golden
tests stay green. Bithash design follows zsync 0.6.2 librcksum
(Colin Phipps, http://zsync.moria.org.uk/, README acknowledgement
added in PR #4597).
@github-actions github-actions Bot added the test label May 20, 2026
@oferchen
oferchen merged commit 93dd4c9 into master May 20, 2026
50 of 55 checks passed
@oferchen
oferchen deleted the test/matching-zsync-bithash-acceptance-zso1 branch May 20, 2026 23:13
oferchen added a commit that referenced this pull request Aug 24, 2026
Adds the two ZSO-1 acceptance tests that complement the bithash
prefilter implementation already merged in PR #3737:

- bithash_rejects_at_least_seven_eighths_of_known_misses: builds a
  filter with N=1000 inserted rsums and probes with N=1000 disjoint
  known-miss rsums, asserting at least 87% reject at the bithash
  gate. Measured rate on this run: 97.2%.
- bithash_state_does_not_leak_between_independent_indexes: builds
  two DeltaSignatureIndex values from distinct basis bytes and
  confirms a probe for blocks indexed in one never matches in the
  other, pinning the per-NDX lifecycle relied on by the ZSO-7
  audit (docs/audits/zso-7-inc-recurse-per-segment-state-2026-05-21.md).

No production code changes. Wire-byte parity is unaffected; golden
tests stay green. Bithash design follows zsync 0.6.2 librcksum
(Colin Phipps, http://zsync.moria.org.uk/, README acknowledgement
added in PR #4597).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant