Skip to content

Commit

Permalink
update evm tool to build the proof before computing the root
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Ballet <[email protected]>
  • Loading branch information
gballet committed Jan 6, 2025
1 parent f530b6a commit b7c13cd
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,19 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
statedb.AddBalance(w.Address, amount)
statedb.Witness().TouchFullAccount(w.Address[:], true, math.MaxUint64)
}

var (
verkleProof *verkle.Proof
statelessProof *verkle.VerkleProof
keys = statedb.Witness().Keys()
proofTrie *trie.VerkleTrie
)
if chainConfig.IsVerkle(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp) {
if err := overlay.OverlayVerkleTransition(statedb, common.Hash{}, chainConfig.OverlayStride); err != nil {
return nil, nil, fmt.Errorf("error performing the transition, err=%w", err)
}
}
// Commit block
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
if err != nil {
return nil, nil, NewError(ErrorEVM, fmt.Errorf("could not commit state: %v", err))
}

// Add the witness to the execution result
var vktProof *verkle.VerkleProof
var vktStateDiff verkle.StateDiff
if chainConfig.IsVerkle(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp) {
keys := statedb.Witness().Keys()
if len(keys) > 0 && vtrpre != nil {
var proofTrie *trie.VerkleTrie
switch tr := statedb.GetTrie().(type) {
case *trie.VerkleTrie:
proofTrie = tr
Expand All @@ -371,18 +366,29 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
default:
return nil, nil, fmt.Errorf("invalid tree type in proof generation: %v", tr)
}
proof, err := trie.Proof(vtrpre, proofTrie, keys, vtrpre.FlatdbNodeResolver)
var err error
verkleProof, err = trie.Proof(vtrpre, proofTrie, keys, vtrpre.FlatdbNodeResolver)
if err != nil {
return nil, nil, fmt.Errorf("error generating verkle proof for block %d: %w", pre.Env.Number, err)
}
err = trie.AddPostValuesToProof(keys, proofTrie, proof)
if err != nil {
return nil, nil, fmt.Errorf("error adding post values to proof: %w", err)
}
vktProof, vktStateDiff, err = verkle.SerializeProof(proof)
if err != nil {
return nil, nil, fmt.Errorf("error serializing proof: %w", err)
}
}
}
// Commit block
root, err := statedb.Commit(vmContext.BlockNumber.Uint64(), chainConfig.IsEIP158(vmContext.BlockNumber))
if err != nil {
return nil, nil, NewError(ErrorEVM, fmt.Errorf("could not commit state: %v", err))
}

// Add the witness to the execution result
var statelessDiff verkle.StateDiff
if chainConfig.IsVerkle(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp) {
err = trie.AddPostValuesToProof(keys, proofTrie, verkleProof)
if err != nil {
return nil, nil, fmt.Errorf("error adding post values to proof: %w", err)
}
statelessProof, statelessDiff, err = verkle.SerializeProof(verkleProof)
if err != nil {
return nil, nil, fmt.Errorf("error serializing proof: %w", err)
}
}

Expand All @@ -397,8 +403,8 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty),
GasUsed: (math.HexOrDecimal64)(gasUsed),
BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee),
VerkleProof: vktProof,
StateDiff: vktStateDiff,
VerkleProof: statelessProof,
StateDiff: statelessDiff,
ParentRoot: parentStateRoot,
}
if pre.Env.Withdrawals != nil {
Expand Down

0 comments on commit b7c13cd

Please sign in to comment.