fix: in-place nodes ignored in proof verification #27
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.
Fixes #26.
Kinda relates to #7 and #9, but on the verification side only.
The current behavior of jumping to the next proof node does not work with in-place encoded child nodes, as when such nodes are encountered, it's always the last item of the proof, causing a mismatch of
key
andwalked_path
, and a verification failure.This patch fixes the issue by checking whether the branch child is encoded in-place, and if so "recursively" walk the child (in reality this cannot be more than 1 level deep as otherwise it wouldn't be in-place to begin with).
The test case added is manually crafted, without using the hash builder for proof collection. This is because currently the issue of handling small nodes exist across the whole library, meaning the hash builder is faulty too. Unfortunately I only have time to fix the verification side, and hence the manual test case.
Technically this part is also prone to the issue:
trie/src/proof/verify.rs
Lines 69 to 72 in dc77954
as you can't just assume the extension's child is a hash. It's an easy fix by just applying the same check as in this patch, but I didn't have time to build the test case for this code path, and I don't want to submit untested code.