Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_merkle_proof returning too many values #3729

Open
nerolation opened this issue Apr 26, 2024 · 0 comments
Open

get_merkle_proof returning too many values #3729

nerolation opened this issue Apr 26, 2024 · 0 comments

Comments

@nerolation
Copy link

nerolation commented Apr 26, 2024

The get_merkle_proof function in utils/merkle_minimal.py returns too many values when tree_len is not explicitly set.

One might think the last value is the root but that's not the case. It's the root being mixed together with the zero_hash value of the respective layer.
Specifying the tree_len at len(tree) -1 circumvents it.

Not sure if there are edge cases to consider but having len(tree) -1 fixes it.

Sample Code:

from eth2spec.utils.merkle_minimal import (
    get_merkle_proof,
    calc_merkle_tree_from_leaves,
)


def run():
    nodes = [i.to_bytes(32, byteorder="little") for i in range(16)]
    tree = calc_merkle_tree_from_leaves(nodes, layer_count=32)
    print(len(tree))
    proof = get_merkle_proof(tree, 3)
    print(proof)
    print(len(proof)) # logs "33"


if __name__ == "__main__":
    run()

The expected result would be len(proof) = 32 (not including the root).

@ralexstokes ralexstokes changed the title get_merkle_proof returing two many values get_merkle_proof returning too many values Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant