From 46b7e78cc02f36e4c472f7196316a73f3c069cad Mon Sep 17 00:00:00 2001 From: CPerezz <37264926+CPerezz@users.noreply.github.com> Date: Mon, 29 Sep 2025 12:51:46 +0200 Subject: [PATCH] cmd/evm/internal/t8ntool: panic on database corruption (#32776) These functions were previously ignoring the error returned by both `statedb.Commit()` and the subsequent `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 cc: @gballet as this was discussed in a call already. --- cmd/evm/internal/t8ntool/execution.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index f1e65afe9c..5303d432fb 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) @@ -384,8 +387,14 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB } } // Commit and re-open to start with a clean state. - root, _ := statedb.Commit(0, false, false) - statedb, _ = state.New(root, sdb) + root, err := statedb.Commit(0, false, false) + if err != nil { + panic(fmt.Errorf("failed to commit initial state: %v", err)) + } + statedb, err = state.New(root, sdb) + if err != nil { + panic(fmt.Errorf("failed to reopen state after commit: %v", err)) + } return statedb }