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.
This commit is contained in:
CPerezz 2025-09-29 12:22:10 +02:00
parent 265db06242
commit 5e6f04c774
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -374,7 +374,10 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB { func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB {
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true}) tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true})
sdb := state.NewDatabase(tdb, nil) 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 { for addr, a := range accounts {
statedb.SetCode(addr, a.Code, tracing.CodeChangeUnspecified) statedb.SetCode(addr, a.Code, tracing.CodeChangeUnspecified)
statedb.SetNonce(addr, a.Nonce, tracing.NonceChangeGenesis) statedb.SetNonce(addr, a.Nonce, tracing.NonceChangeGenesis)