-
Notifications
You must be signed in to change notification settings - Fork 745
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
[Merged by Bors] - Added Merkle Proof Generation for Beacon State #3674
Conversation
CC @pawanjay176 @michaelsproul please give it a quick look, i still need to work some things out and test it properly and in the meanwhile I would like a general opinion on it and if |
just kidding it just need some unit tests, do anyone knows of something already avaiable or do I have to try making the test myself? |
On second thought, I think it is not feasible to write unit tests for Beacon State as you would need something real from nimbus (Which I have no idea where to start as I never coded in Nim) and the struct itself is too big, I think it would be better if something breaks when I simulate gossip/resp req |
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've left a sketch of how I think we should proceed in a code comment.
Re: testing, the BeaconState
s are actually quite small (<100MB) and there are unit tests available from the specs repo here: https://github.com/ethereum/consensus-specs/blob/dev/tests/formats/light_client/single_merkle_proof.md.
Our code that integrates the spec tests is here: https://github.com/sigp/lighthouse/tree/stable/testing/ef_tests. To run the new tests we'd need to add a new case runner and handler.
I'm off sick this week, but can get stuck into this more with you next week.
I need to get Finality Branch EF test to work thats the one missing, all of the others are working at the first try due probably to some miracle |
Okay so this is interesting, all the tests for finality have a proof that starts with 0x0000000000000000000000000000000000000000000000000000000000000000, and then it goes on normally? also it seems that we generate the correct proof if we discard this weird thing, like the rest of the proof match. is that even possible? |
I just checked against Erigon lightclient we do not indeed get any finality branch starting with 0 hash |
I was wondering if maybe we were appending the extra node at the wrong end of the proof? The 0x0 value could be the epoch value that is the sibling of the finalized root |
okay i tried to prepend the extra leaf and now everything passed |
Consider it ready for review now |
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.
looking great on the whole, just a few minor things then we can merge
cargo fmt
is currently failing too, you can fix it up with cargo fmt --all
thanks!
I seee |
nevermind i think it was an old test |
you can run the linter locally with |
running
|
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! Will try to get this merged assuming CI cooperates
bors r+ |
🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set. |
bors retry |
Stopped waiting for PR status (GitHub check) without running due to duplicate requests to run. You may check Bors to see that this PR is included in a batch by one of the other requests. |
## Issue Addressed This PR addresses partially #3651 ## Proposed Changes This PR adds the following methods: * a new method to trait `TreeHash`, `hash_tree_leaves` which returns all the Merkle leaves of the ssz object. * a new method to `BeaconState`: `compute_merkle_proof` which generates a specific merkle proof for given depth and index by using the `hash_tree_leaves` as leaves function. ## Additional Info Now here is some rationale on why I decided to go down this route: adding a new function to commonly used trait is a pain but was necessary to make sure we have all merkle leaves for every object, that is why I just added `hash_tree_leaves` in the trait and not `compute_merkle_proof` as well. although it would make sense it gives us code duplication/harder review time and we just need it from one specific object in one specific usecase so not worth the effort YET. In my humble opinion. Co-authored-by: Michael Sproul <micsproul@gmail.com>
## Issue Addressed This PR addresses partially sigp#3651 ## Proposed Changes This PR adds the following methods: * a new method to trait `TreeHash`, `hash_tree_leaves` which returns all the Merkle leaves of the ssz object. * a new method to `BeaconState`: `compute_merkle_proof` which generates a specific merkle proof for given depth and index by using the `hash_tree_leaves` as leaves function. ## Additional Info Now here is some rationale on why I decided to go down this route: adding a new function to commonly used trait is a pain but was necessary to make sure we have all merkle leaves for every object, that is why I just added `hash_tree_leaves` in the trait and not `compute_merkle_proof` as well. although it would make sense it gives us code duplication/harder review time and we just need it from one specific object in one specific usecase so not worth the effort YET. In my humble opinion. Co-authored-by: Michael Sproul <micsproul@gmail.com>
## Issue Addressed This PR addresses partially sigp#3651 ## Proposed Changes This PR adds the following methods: * a new method to trait `TreeHash`, `hash_tree_leaves` which returns all the Merkle leaves of the ssz object. * a new method to `BeaconState`: `compute_merkle_proof` which generates a specific merkle proof for given depth and index by using the `hash_tree_leaves` as leaves function. ## Additional Info Now here is some rationale on why I decided to go down this route: adding a new function to commonly used trait is a pain but was necessary to make sure we have all merkle leaves for every object, that is why I just added `hash_tree_leaves` in the trait and not `compute_merkle_proof` as well. although it would make sense it gives us code duplication/harder review time and we just need it from one specific object in one specific usecase so not worth the effort YET. In my humble opinion. Co-authored-by: Michael Sproul <micsproul@gmail.com>
Issue Addressed
This PR addresses partially #3651
Proposed Changes
This PR adds the following methods:
TreeHash
,hash_tree_leaves
which returns all the Merkle leaves of the ssz object.BeaconState
:compute_merkle_proof
which generates a specific merkle proof for given depth and index by using thehash_tree_leaves
as leaves function.Additional Info
Now here is some rationale on why I decided to go down this route: adding a new function to commonly used trait is a pain but was necessary to make sure we have all merkle leaves for every object, that is why I just added
hash_tree_leaves
in the trait and notcompute_merkle_proof
as well. although it would make sense it gives us code duplication/harder review time and we just need it from one specific object in one specific usecase so not worth the effort YET. In my humble opinion.