Fix(multiproofs verification): don't skip visiting intermediate hashes #173
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the logic of the function
VerifyMultiproof
which doesn't visit the intermediate hashes calculated while traversing the tree, resulting in the errorproof is missing required nodes
when verifying Merkle Multiproofs.In more detail, what I've noticed is that when adding the intermediate generalised indices in the
keys
array to be visited later, they are added to the end of the array but the latter is not sorted again, which mean those indices will actually never be read. This results in skipping some required steps of calculating intermediate hashes leading to a failure of the verification.fastssz/proof.go
Lines 80 to 91 in c98805c
The solution proposed avoids a 1-line change to add sorting after every insertion due to its inefficiency but relies instead on a auxiliary array to keep track of these additional indices