Open fubuloubu opened 5 years ago
@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)
:+1: from me.
I abstain, haven't spent time understanding this and am focused elsewhere at the moment.
I'll also abstain from this for the same reasons as @pipermerriam .
Notes:
leaf_hash
if necessarykey
must be at least 2**N
(not strictly uint256
)Not necessary to add documentation since this algorithm does not allow one to control N
(the depth of the tree), which is a necessary condition to perpetuate this attack (since we control how many iterations are done).
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