From b408f09327a4373c04f41a3bc7caf896307b577a Mon Sep 17 00:00:00 2001 From: Guillaume Ballet <3272758+gballet@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:20:05 +0100 Subject: [PATCH] update evm tool to build the proof before computing the root Signed-off-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com> --- cmd/evm/internal/t8ntool/execution.go | 52 +++++++++++++++------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index b011a5eb2adc..85ab7d917d71 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -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 @@ -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) } } @@ -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 {