fix: prefix-free node hashing - #242
Merged
Merged
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).
# Conflicts: # src/tree.rs
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.
Resolves merge conflicts for #192 while preserving both the prefix-free hashing regression coverage and the structural diff tests already on main. Supersedes #192 after CI passes.