Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
olivmath committed Oct 19, 2024
1 parent f04f7f2 commit 4cf7972
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 8 additions & 8 deletions merkly/mtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,24 @@ def verify_proof(proof: List[Node], raw_leaf: str, root: str, **kwargs) -> bool:
"""
Verify the validity of a Merkle proof for a given leaf against the expected root hash.
This method checks whether the provided proof can reconstruct the root hash
from the given raw leaf data. It uses the specified hash function to compute
This method checks whether the provided proof can reconstruct the root hash
from the given raw leaf data. It uses the specified hash function to compute
the hashes along the proof path.
Args:
proof (List[Node]): A list of Nodes representing the Merkle proof. Each Node
proof (List[Node]): A list of Nodes representing the Merkle proof. Each Node
contains the hash of a sibling node and its position (left or right) in the tree.
raw_leaf (str): The raw leaf data (in string format) for which the proof is
raw_leaf (str): The raw leaf data (in string format) for which the proof is
being verified. This data should correspond to a leaf in the Merkle tree.
root (str): The expected root hash (in hexadecimal string format) that the
root (str): The expected root hash (in hexadecimal string format) that the
proof should reconstruct if valid.
**kwargs: Optional keyword arguments. Can include:
- hash_function (Callable[[bytes, bytes], bytes]): A custom hash function
that takes two byte inputs and returns a hash. If not provided,
- hash_function (Callable[[bytes, bytes], bytes]): A custom hash function
that takes two byte inputs and returns a hash. If not provided,
the default `keccak` function is used.
Returns:
bool: Returns True if the proof is valid and reconstructs the expected root
bool: Returns True if the proof is valid and reconstructs the expected root
hash; otherwise, returns False.
Example:
Expand Down
4 changes: 3 additions & 1 deletion test/merkle_proof/test_merkle_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def test_verify_merkle_proof_without_leaves():
assert not invalid_result, "Expected proof to be invalid for incorrect leaf"

# Test with a different root
different_root = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
different_root = (
"0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
)
different_result = MerkleTree.verify_proof(proof, leaf, different_root)
assert not different_result, "Expected proof to be invalid for different root"

0 comments on commit 4cf7972

Please sign in to comment.