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

merkle proof test generator #2629

Merged
merged 2 commits into from
Sep 27, 2021
Merged

merkle proof test generator #2629

merged 2 commits into from
Sep 27, 2021

Conversation

etan-status
Copy link
Contributor

Building merkle proofs is required functionality for implementing light
client sync. Although the spec currently only defines a function to
verify merkle proofs (is_valid_merkle_branch) there are still a few
PySpec unit tests that produce merkle proofs. This patch adds a new
generator to extract test vectors from those static unit tests, so that
light client implementations can validate their merkle proof logic.

Building merkle proofs is required functionality for implementing light
client sync. Although the spec currently only defines a function to
verify merkle proofs (`is_valid_merkle_branch`) there are still a few
PySpec unit tests that produce merkle proofs. This patch adds a new
generator to extract test vectors from those static unit tests, so that
light client implementations can validate their merkle proof logic.
@protolambda
Copy link
Contributor

Hey @etan-status, thank you for your testing contribution! I moved the test to its own package (it's not just a spec unit-test, since it outputs vectors), and updated the format to not split it into so many different files. Also, I updated it to output into a single_proof handler of the merkle runner. We can then add more types of merkle testing later. What do you think?

@etan-status
Copy link
Contributor Author

Thanks, appreciate the update! Makes this entire thing quite a bit cleaner :-)

yield "proof", {
"leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(),
"leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX,
"branch": ['0x' + root.hex() for root in next_sync_committee_branch]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is root the common name even for intermediate hashes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In remerkleable every 32-byte tree thing is a "root", (Root type). And the tree is built with PairNode and RootNode types. If you take the merkle-root of any subtree (even if just a single node) it's a Root. It's a little confusing with the "leaf/sibling" meanings, but it's the opposite of a pair, so I stuck with it. Naming is hard.

Copy link
Contributor

@protolambda protolambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@protolambda protolambda merged commit 2a98d4c into ethereum:dev Sep 27, 2021
Copy link
Contributor

@djrtwo djrtwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one minor suggestion

@@ -8,8 +8,14 @@

@with_phases([ALTAIR])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would default to doing @with_all_phases_except([PHASE0]) and if the beaconstate changes enough in subsequent phase to break this test, it will alert us to either make this more modular or to add additional merkle tests for new phase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but more of a separate issue that already existed before this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants