Skip to content
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

verify block witness and proof #496

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package core

import (
"bytes"
"errors"
"fmt"

Expand Down Expand Up @@ -131,7 +132,39 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
}
// Verify that the advertised root is correct before
// In verkle mode, verify the proof.
if v.config.IsVerkle(header.Number, header.Time) {
// Check that all keys in the witness were used
keys := statedb.Witness().Keys()
var key [32]byte
for _, stemdiff := range block.ExecutionWitness().StateDiff {
copy(key[:31], stemdiff.Stem[:])
for _, suffixdiff := range stemdiff.SuffixDiffs {
key[31] = suffixdiff.Suffix

var found bool
for _, k := range keys {
if bytes.Equal(k, key[:]) {
found = true
break
}
}
if !found {
return fmt.Errorf("superfluous key %x could not be found in witness", key)
}
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only checking that the leaves from the block witness are present in the destination witness, because we are targeting state bloat. It could be that the witness does not contain all necessary leaves for stateless execution. This should be checked as well, either by execution (slow) or by just checking that there is the exact same amount of leaves.


// Open the pre-tree to prove the pre-state against
parent := v.bc.GetHeaderByNumber(header.Number.Uint64() - 1)
if parent == nil {
return fmt.Errorf("nil parent header for block %d", header.Number)
}
Comment on lines +170 to +174
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parent has most definitely already been loaded before, see if it's possible to pass it as a parameter.


// Verify the proof
trie.DeserializeAndVerifyVerkleProof(block.ExecutionWitness().VerkleProof, parent.Root.Bytes(), block.Root().Bytes(), block.ExecutionWitness().StateDiff)

} // Verify that the advertised root is correct before
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} // Verify that the advertised root is correct before
}
// Verify that the advertised root is correct before

// it can be used as an identifier for the conversion
// status.
statedb.Database().SaveTransitionState(header.Root)
Expand Down
Loading