[UTXO-BUG] MED-2: Merkle tree second-preimage vulnerability in compute_state_root()#2071
Merged
Scottcjn merged 1 commit intoScottcjn:mainfrom Apr 5, 2026
Conversation
…e_state_root() The Merkle tree duplicates the last hash when the element count is odd (hashes.append(hashes[-1])). This is a well-known second-preimage weakness: UTXO sets [A,B,C] and [A,B,C,C] produce identical roots, meaning two nodes with different UTXO sets can agree on the state root. Fix: 1. Use domain-separated padding: SHA256(0x01 || last_hash) instead of duplicating the last element, making padding distinguishable from a real leaf. 2. Mix the UTXO count into each leaf hash so tree is bound to a specific cardinality — sets of different sizes always differ. Test added: - test_state_root_odd_count_unique All 35 tests pass. Bounty: #2819 (Medium, 50 RTC)
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
|
Great security audit work! These fixes are critical for the protocol. |
Contributor
Author
|
@Scottcjn please review |
Owner
|
✅ Merged. Solid cryptographic fix — the naive Merkle tree odd-count duplication is a well-known second-preimage weakness. Domain-separated sentinel + count-binding in leaf hashes is the correct mitigation. 50 RTC paid. Wallet: |
This was referenced Apr 6, 2026
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.
Vulnerability Class
Medium — Merkle state root manipulation (50 RTC bounty)
The Bug
The Merkle tree duplicates the last hash when the element count is odd (
hashes.append(hashes[-1])). This is a well-known second-preimage weakness:[A, B, C]pads to[H(A), H(B), H(C), H(C)][A, B, C, C]naturally produces[H(A), H(B), H(C), H(C)]Two nodes with divergent UTXO sets can agree on state root, undermining consensus verification.
Fix
SHA256(0x01 || last_hash)instead of duplicating, making padding distinguishable from a real leafTest Added
test_state_root_odd_count_unique— verifies roots differ across 3→4→5 box transitionsAll 35 tests pass.
Files Changed
node/utxo_db.py—compute_state_root()rewritten with safe paddingnode/test_utxo_db.py— 1 test addedRef: Bounty #2819
My WALLET IS aroky-x86-miner