From 5e6f04c7749f40d7ccba308fecb7b7a3072317b8 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Mon, 29 Sep 2025 12:22:10 +0200 Subject: [PATCH] cmd/evm/t8ntool: add error handling for state.New() in MakePreState The function was previously ignoring the error returned by state.New(), which could silently fail and cause panics later when the statedb is used. This change adds proper error checking and panics with a descriptive error message if state creation fails. While unlikely in normal operation, this can occur if there are database corruption issues or if invalid root hashes are provided, making debugging significantly easier when such issues do occur. This issue was encountered and fixed in https://github.com/gballet/go-ethereum/pull/552 where the error handling proved essential for debugging. --- cmd/evm/internal/t8ntool/execution.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index f1e65afe9c..1a123df83a 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -374,7 +374,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB { tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true}) sdb := state.NewDatabase(tdb, nil) - statedb, _ := state.New(types.EmptyRootHash, sdb) + statedb, err := state.New(types.EmptyRootHash, sdb) + if err != nil { + panic(fmt.Errorf("failed to create initial state: %v", err)) + } for addr, a := range accounts { statedb.SetCode(addr, a.Code, tracing.CodeChangeUnspecified) statedb.SetNonce(addr, a.Nonce, tracing.NonceChangeGenesis)