Inductive Merkle Trees #
This file implements Merkle Trees. In contrast to the other Merkle tree implementation in
VCVio.CryptoFoundations.MerkleTree, this one is defined inductively.
Implementation Notes #
This works with trees that are indexed inductive binary trees,
(i.e. indexed in that their definitions and methods carry parameters regarding their structure)
as defined in ToMathlib.Data.IndexedBinaryTree.
- We found that the inductive definition seems likely to be convenient for a few reasons:
- It allows us to handle non-perfect trees.
- It can allow us to use trees of arbitrary structure in the extractor.
- I considered the indexed type useful because the completeness theorem and extractibility theorems take indices or sets of indices as parameters, and because we are working with trees of arbitrary structure, this lets us avoid having to check that these indices are valid.
Plan/TODOs #
- Basic Merkle tree API
- Completeness theorem
- Collision Lemma (See SNARGs book 18.3)
- (this is really not a lemma about oracles, so it could go with the binary tree API)
- Extractibility (See SNARGs book 18.5)
- Multi-leaf proofs
- Arbirary arity trees
- Multi-instance
Build the full Merkle tree, returning the tree populated with data on all its nodes
Instances For
A functional form of merkle tree construction, that doesn't depend on the monad. This receives an explicit hash function
Instances For
Running the monadic version of buildMerkleTree with an oracle function f
is equivalent to running the functional version of buildMerkleTreeWithHash
with the same oracle function.
Generate a Merkle proof for a leaf at a given idx The proof consists of the sibling hashes needed to recompute the root. Its length is indexed by the leaf depth, so malformed extra hashes are unrepresentable.
TODO rename this to copath and move to BinaryTree?
Instances For
Given a leaf index, a leaf value at that index, and a proof of the corresponding depth, returns the hash that would be the root of the tree if the proof was valid. i.e. the hash obtained by combining the leaf in sequence with each member of the proof, according to its index.
Instances For
A functional version of getPutativeRoot that does not depend on the monad.
It receives an explicit hash function hashFn that combines two hashes into one.
And recursively calls itself down the tree.
Instances For
Running the monadic version of getPutativeRoot with an oracle function f,
it is equivalent to running the functional version of getPutativeRootWithHash
Verify a Merkle proof proof that a given leaf at index i is in the Merkle tree with given
root.
Works by computing the putative root based on the branch, and comparing that to the actual root.
Outputs failure if the proof is invalid.
Instances For
A functional form of the completeness theorem for Merkle trees.
This references the functional versions of getPutativeRoot and buildMerkleTreeWithHash
Completeness theorem for Merkle trees.
The proof proceeds by reducing to the functional completeness theorem by a theorem about the OracleComp monad, and then applying the functional version of the completeness theorem.