fix: prefix-free node hashing — distinct (k,v) sets must not collide - #192
Closed
presempathy-awb wants to merge 1 commit into
Closed
fix: prefix-free node hashing — distinct (k,v) sets must not collide#192presempathy-awb wants to merge 1 commit into
presempathy-awb wants to merge 1 commit into
Conversation
…llide
get_hash concatenated keys.concat() ++ values.concat() with NO length
delimiters, so distinct content could produce identical hash input:
values ("ab","c") and ("a","bc") both concat to "abc" under the same
keys => identical root hash. For a content-addressed / merge-convergent
structure that is a correctness bug (false dedup, false merge
convergence).
Length-frame every element (u32 BE lengths — never usize, so the hash
is identical on 32- and 64-bit / wasm), delimit the key region from the
value region by count, and bind is_leaf + level so a leaf can't collide
with an internal node of identical bytes. Hash-function-agnostic: only
the ValueDigest::new INPUT changes, not the digest algorithm, and only
node identity changes — chunk boundaries (tree shape) are untouched, so
merge-canonicality and every existing test still hold.
Tests: mod prefix_free_collision_probe (fails on the old concat hash,
passes here).
zhangfengcdt
approved these changes
Aug 25, 2026
zhangfengcdt
left a comment
Owner
There was a problem hiding this comment.
Reviewed: implementation and tests pass; no public API surface change detected.
Owner
|
Resolved and integrated via #242 after the full CI matrix passed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
ProllyNode::get_hashhasheskeys.concat() ++ values.concat()with no length delimiters, so distinct content can produce identical hash input:k1,k2, values("ab","c")→ inputk1k2abck1,k2, values("a","bc")→ inputk1k2abc→ identical root hash. For a content-addressed / merge-convergent structure this is a correctness bug (false dedup, false merge convergence).
Repro (RED)
The added test fails on
main:Fix
Length-frame every element (u32 BE lengths — not
usize, so the hash is identical on 32/64-bit and wasm), delimit the key region from the value region by count, and bindis_leaf+levelso a leaf can't collide with an internal node of identical bytes.Hash-function-agnostic: only the
ValueDigest::newinput changes, not the digest algorithm — and only node identity changes, chunk boundaries (tree shape) are untouched, so merge-canonicality and every existing test still hold.Tests / verification
mod prefix_free_collision_probe(RED on the old concat hash, GREEN here).cargo test— 164/164 lib green, 0 regressions. Fully independent of any other change. Based onmain@373128e.