Folding a leaf through its Merkle branch gives the root
ProvedBsv.Merkle.fold_branchbitcoindata-structuresformal-verificationmerkle-tree
Let be an arbitrary binary operation, and let root, branch and fold be as in the imported definition. Let be a list, a position, and the node of at position . Then
This is completeness of branch verification: a branch generated from the list verifies, at every position, including where odd levels pair a node with itself. It is not a soundness statement: nothing is said about branches that were not generated from .
Formalization Note The statement is about the Lean model of the tree, not about a particular program.
Preamble
import Definitions.Def_bsv_merkle_tree
Formal statement
namespace Bsv.Merkle
theorem fold_branch {α : Type} (H : α → α → α) (l : List α) (i : Nat) (x : α) (hx : l[i]? = some x) :
some (fold H x (branch H l i) i) = root H l := by sorry
end Bsv.MerkleSource
Gregory J. Ward, Bryan W. Daugherty, Shawn M. Ryan, BSV Lean proofs (Apache-2.0), theorem fold_branch. https://github.com/codenlighten/bsv-lean-proofs/blob/41c4bfdc5ce4dd9bfbf0e21c77e6586d041261de/BsvLeanProofs/MerkleVerify.lean