Skip to content

Instantly share code, notes, and snippets.

@dangerousfood
Created June 10, 2019 11:01
Show Gist options
  • Save dangerousfood/6c48313d05231940f5b5c4dff1ae8802 to your computer and use it in GitHub Desktop.
Save dangerousfood/6c48313d05231940f5b5c4dff1ae8802 to your computer and use it in GitHub Desktop.
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