-
Notifications
You must be signed in to change notification settings - Fork 13
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
proofs: remove post-values in Multiproof #297
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -518,7 +518,7 @@ func TestProcessVerkle(t *testing.T) { | |
//f.Write(buf.Bytes()) | ||
//fmt.Printf("root= %x\n", chain[0].Root()) | ||
// check the proof for the last block | ||
err := trie.DeserializeAndVerifyVerkleProof(proofs[1], chain[0].Root().Bytes(), keyvals[1]) | ||
err := trie.DeserializeAndVerifyVerkleProof(proofs[1], chain[0].Root().Bytes(), chain[1].Root().Bytes(), keyvals[1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The This must be true. If it's false, the block is invalid (or there's a bug in post-tree reconstruction). |
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,27 +336,16 @@ func ProveAndSerialize(pretrie, posttrie *VerkleTrie, keys [][]byte, resolver ve | |
return p, kvps, nil | ||
} | ||
|
||
type set = map[string]struct{} | ||
|
||
func addKey(s set, key []byte) { | ||
s[string(key)] = struct{}{} | ||
} | ||
|
||
func DeserializeAndVerifyVerkleProof(vp *verkle.VerkleProof, root []byte, statediff verkle.StateDiff) error { | ||
rootC := new(verkle.Point) | ||
rootC.SetBytes(root) | ||
|
||
var others set = set{} // Mark when an "other" stem has been seen | ||
func DeserializeAndVerifyVerkleProof(vp *verkle.VerkleProof, preStateRoot []byte, postStateRoot []byte, statediff verkle.StateDiff) error { | ||
// TODO: check that `OtherStems` have expected length and values. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is something that we should do. This prob needs to be done in This is unrelated with all this post-state change; just something I realized that I believe was the original idea of this deleted code in L339-349 & L356-359 (all that code wasn't doing anything). To do this extra check, we don't need that code, so I'm suggesting here to be removed (since it's currently not doing anything). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure yes we should add this, in another PR if you prefer. |
||
|
||
proof, err := verkle.DeserializeProof(vp, statediff) | ||
if err != nil { | ||
return fmt.Errorf("verkle proof deserialization error: %w", err) | ||
} | ||
|
||
for _, stem := range proof.PoaStems { | ||
addKey(others, stem) | ||
} | ||
|
||
rootC := new(verkle.Point) | ||
rootC.SetBytes(preStateRoot) | ||
pretree, err := verkle.PreStateTreeFromProof(proof, rootC) | ||
if err != nil { | ||
return fmt.Errorf("error rebuilding the pre-tree from proof: %w", err) | ||
|
@@ -385,12 +374,20 @@ func DeserializeAndVerifyVerkleProof(vp *verkle.VerkleProof, root []byte, stated | |
} | ||
} | ||
|
||
// TODO: this is necessary to verify that the post-values are the correct ones. | ||
// But all this can be avoided with a even faster way. The EVM block execution can | ||
// keep track of the written keys, and compare that list with this post-values list. | ||
// This can avoid regenerating the post-tree which is somewhat expensive. | ||
Comment on lines
+377
to
+380
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's do it, unless it makes the PR so much more complex, that it makes sense to split it? |
||
posttree, err := verkle.PostStateTreeFromStateDiff(pretree, statediff) | ||
if err != nil { | ||
return fmt.Errorf("error rebuilding the post-tree from proof: %w", err) | ||
} | ||
regeneratedPostTreeRoot := posttree.Commitment().Bytes() | ||
if !bytes.Equal(regeneratedPostTreeRoot[:], postStateRoot) { | ||
return fmt.Errorf("post tree root mismatch: %x != %x", regeneratedPostTreeRoot, postStateRoot) | ||
} | ||
Comment on lines
+377
to
+388
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I mentioned in Matrix; just re-explaining in this TODO. Something to explore in the future after doing more measurements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but wait, root computation will be performed in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's exactly what I describe in my TODO above saying:
If we do that, we can avoid it. Or maybe are you referring to something different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no that's what I meant: let's do that, so that we don't have to recompute the root |
||
|
||
return verkle.VerifyVerkleProofWithPreAndPostTrie(proof, pretree, posttree) | ||
return verkle.VerifyVerkleProofWithPreState(proof, pretree) | ||
} | ||
|
||
// ChunkedCode represents a sequence of 32-bytes chunks of code (31 bytes of which | ||
|
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.
This shouldn't be needed from the previous PR that we properly use the
resolver
in theGetElementsForProof
. Now, this is even more true since we don't do that for proof generation so this should be safe.I can't test it directly since this code path only works in real proof generation, so let's be aware the next time we update nodes in Kaustinen.
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.
well if it fails, and looking at it and the fact that it doesn't in sync mode, I'm comfortable enough merging that. If it fails, we'll figure it out fast enough after relaunch.