-
Notifications
You must be signed in to change notification settings - Fork 998
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
Conversation
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.
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 |
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] |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this 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]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 fewPySpec 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.