iroha
iroha copied to clipboard
feat(merkle): implement inclusion proof generation and verification
I've split out the cryptographic part of the trigger execution logs (from #4968) into a separate PR: #5467
Summary
This PR introduces Merkle proof generation and verification to support inclusion checking, as a prerequisite for #4968 (and possibly #4637). It also includes a fix to the construction of the Merkle tree to ensure correct transaction indexing.
Changes
Features
- Added
MerkleProof<T>struct that includes:leaf_index: the position of the leaf in the treesibling_hashes: the list of sibling hashes from the leaf up to the root (excluding the root itself)
- Implemented
MerkleTree::get_proof(leaf_index)to generate an inclusion proof - Implemented
MerkleProof::verify(root, max_height)to verify the proof against a given root
Fixes
- Fixed the binary operation used to compute parent hashes from child hashes: it was previously commutative (addition), but has been corrected to a non-commutative (ordered) operation. The previous implementation could not preserve transaction index ordering guarantees.
Notes
max_heightis passed explicitly toverify()to avoid trusting unbounded proof data.- The Merkle proof format and verification logic follow a standard binary Merkle tree structure. See:
Related
- Closes part of #4968
- Prepares groundwork for cross-chain interoperability: #4637