iroha icon indicating copy to clipboard operation
iroha copied to clipboard

feat(merkle): implement inclusion proof generation and verification

Open s8sato opened this issue 6 months ago • 0 comments

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 tree
    • sibling_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

Related

  • Closes part of #4968
  • Prepares groundwork for cross-chain interoperability: #4637

s8sato avatar Jun 16 '25 01:06 s8sato