-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add support for building merkle multiproofs #16
Conversation
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.
How come there are no tests here?
Added tests. |
New test coverage:
|
Wait for #19 before merging this. |
Thanks @zah for the review comments. I have addressed them in the latest push. |
|
Is this an already-identified regression? One reason for having this Nim devel checks is so that they can be fixed upstream before Nimbus has to wait until Nim 1.x.2 or 1.x.3 before it even builds due to not having noticed these to be fixed in time for the Nim 1.x.0 or Nim 1.x.1 releases. |
Yes, they fixed it here: nim-lang/Nim#19472 |
Re-ran CI. |
Anything still holding this PR back? |
This adds functionality for building merkle multiproofs in the same form that the Ethereum consensus specs suggest, i.e., in descending order of helper indices. Merkle multiproofs are useful for the light client sync. https://github.com/ethereum/consensus-specs/blob/v1.1.6/ssz/merkle-proofs.md#merkle-multiproofs Tested from `nimbus-eth2` root using: ``` nim c -r vendor/nim-ssz-serialization/tests/test_all.nim ```
|
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.
Looks fine to me to be merged imo.
I do have a similar remark as @zah regarding the naming of hash_tree_root
procs which are there to return the proofs rather than the final hash tree root.
I get it that each piece of the proof(s) is in its own a hash tree root, but based on the name, one could think that the final hash_tree_root
call would then return the hash tree root, instead of the proof(s).
Initially I thought that the naming was fine, but then I noticed that the proof versions of these procs are actually all separate due to the indexing logic that needs to be done, which causes of no real code re-use with the original versions in there.
Which is great from the point of view of leaving that code untouched and making merging this less impactful (Existing code touched is actually rather limited).
But then I do think that for a lot of the code related to this indexing it would be more fitting to live in proofs.nim
.
But perhaps I am missing some crucial details (I did rather skim fast over the indexing part and the new hashTreeRootAux
proc). Anyhow, not necessarily something blocking.
func build_proof*( | ||
anchor: auto, | ||
indices: static openArray[GeneralizedIndex], | ||
proof: var openArray[Digest]): Result[void, string] = |
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 there still a reason for having the function signatures with proof: var openArray[Digest]
and a returned void Result (and the same counts for the root_tree_hash
counterparts)?
When there is already the need for Result[void, string]
(or boolean for that matter), perhaps that type of return should be only provided, considering it is a safer practice (caller must verify the result to access the proofs).
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 guess it could save some copying because the result can be directly put into the destination, but semantically these two are the same.
var foo: SomeObject
? state.build_proof(5.GeneralizedIndex, foo.proof)
foo.proof = ? state.build_proof(5.GeneralizedIndex)
Alternative names could be
Yes, this is just an implementation detail though. The regular |
OK, fair enough. I guess what I was trying to say is that you can make it provided a proof by giving it the right indexes as parameter.
I was not aware of that terminology. I saw
Right, that's a good point and argument for keeping the code where it is. |
This adds functionality for building merkle multiproofs in the same form
that the Ethereum consensus specs suggest, i.e., in descending order of
helper indices. Merkle multiproofs are useful for the light client sync.
https://github.com/ethereum/consensus-specs/blob/v1.1.6/ssz/merkle-proofs.md#merkle-multiproofs