Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upVIP: Merkle Proof Function #1391
Open
Labels
Projects
Comments
This comment has been minimized.
This comment has been minimized.
@jacqueswww @pipermerriam @davesque If you all agree with this proposed Specification, we can move this VIP to Approved and start implementation, since previous (#806) was already approved (but was under-specified) |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
I abstain, haven't spent time understanding this and am focused elsewhere at the moment. |
This comment has been minimized.
This comment has been minimized.
I'll also abstain from this for the same reasons as @pipermerriam . |
This comment has been minimized.
This comment has been minimized.
Notes:
|
This comment has been minimized.
This comment has been minimized.
Not necessary to add documentation since this algorithm does not allow one to control |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple Summary
Built in function to generate and validate merkle proofs for vanilla Sparse Merkle Tree implementations.
Abstract
Implement a built-in function for computing merkle roots from uncompressed merkle proofs for the sparse merkle tree (SMT) data structure, such as those commonly employed for Plasma and Plasma Cash constructions.
Motivation
Merkle proofs are useful and awesome, and can be difficult to implement due to many considerations and different possible optimizations. Having a built in function similar to
ecrecover
would greatly simplify in generating these proofs in a gas-efficient way.Specification
where
N
:constant
corresponding to the size of the trie.key
:bitand(key, 2**k) == 0
) or right (bitand(key, 2**k) > 0
) at thek
-th node in the tree.N
bits in size (uint256
works by default, but future datatypes may be added, e.g.uint32
for 32-depth trie)key
.N
ofkey
(the depth of the trie).leaf_hash
:bytes32
hash corresponding to the hash of the leaf node, typically with the same hashing function that the proof generation process uses.leaf
can be any arbitrary data structure. By convention, the data structure would be hashed according to it's ABI encoding, although that is not strictly required.proof[N]
:N
) where each array element corresponds to the sibling of the node at depthk
in the trie.proof
is in root to leaf order. Element 0 corresponds to the root level sibling (root_hash := hash(left_node, right_node)
), and ElementN
corresponds to the leaf level sibling.Additional considerations:
self.root = calc_smt_root(...)
orassert self.root == calc_smt_root(...), "Proof does not validate"
)calc_smt_root(..., function=hash_function)
wherehash_function
is one ofkeccak256
,sha256
, or any other built-in hash function that produces at 32-byte output)EMPTY_BRANCH: bytes32[N] = generate_empty_proof(empty_leaf_hash, N, function=hash_function)
where)py-trie
(by the author)An example of using this would be
Backwards Compatibility
New feature
Copyright
Copyright and related rights waived via CC0