fix: verify combine_hash for empty trees in proof result set#631
Conversation
In KVValueHash/KVValueHashFeatureType proof nodes, the value bytes are NOT part of the merk hash computation. For non-empty trees with lower layer proofs, GroveDB's combine_hash(H(value), child_root) check catches value tampering. However, empty trees in the result set had no such verification — an attacker could swap tree types (e.g. SumTree → Tree) without detection. Add combine_hash(H(value_bytes), NULL_HASH) verification for empty trees in both V0 and V1 proof verifiers before adding them to the result set. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThe PR adds validation to V1 proof verification to prevent empty-tree type swapping exploits. When a tree element lacks a lower-layer proof, the verifier now asserts that the value_hash matches the combined hash of the value and NULL_HASH. A corresponding test validates this protection by attempting to tamper with empty tree types in proofs. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #631 +/- ##
============================================
+ Coverage 59.95% 90.72% +30.77%
============================================
Files 182 182
Lines 51082 51118 +36
============================================
+ Hits 30624 46378 +15754
+ Misses 20458 4740 -15718
🚀 New features to boost your workflow:
|
Summary
combine_hash(H(value_bytes), NULL_HASH) == proof_hashverification for empty trees in the proof result set (both V0 and V1 verifiers)KVValueHash/KVValueHashFeatureTypeproof nodes, where the value bytes are not part of the merk hash computationempty_tree_type_swap_is_detectedregression test that proves aSumTree→Treeswap in the proof is now caughtContext
In
KVValueHashnodes, the tree hash iskv_digest_to_kv_hash(key, value_hash)— the value bytes are NOT incorporated into the hash. For non-empty trees with lower layer proofs, GroveDB already catches value tampering viacombine_hash(H(value), child_root). However, empty trees in the result set (no lower layer) had no such verification, allowing an attacker to swap serialized Element types without detection.This is a companion fix to PR #553 (which blocks KV→KVValueHash substitution for items at the merk level).
Test plan
empty_tree_type_swap_is_detectedtest — tampers a KVValueHash node's value bytes from SumTree to Tree, verifies rejectionfullandverifyfeatures🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests