Created
June 10, 2019 11:01
-
-
Save dangerousfood/6c48313d05231940f5b5c4dff1ae8802 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def verify_merkle_branch(leaf: Bytes32, proof: List[Bytes32], depth: int, index: int, root: Bytes32) -> bool: | |
""" | |
Verify that the given ``leaf`` is on the merkle branch ``proof`` | |
starting with the given ``root``. | |
""" | |
value = leaf | |
for i in range(depth): | |
if index // (2**i) % 2: | |
value = hash(proof[i] + value) | |
else: | |
value = hash(value + proof[i]) | |
return value == root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment