diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index fa052f5954..793539c1da 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -196,6 +196,9 @@ func Transition(ctx *cli.Context) error { if err := applyCancunChecks(&prestate.Env, chainConfig); err != nil { return err } + if err := applyEOFChecks(&prestate, chainConfig); err != nil { + return err + } // Run the test and aggregate the result s, result, body, err := prestate.Apply(vmConfig, chainConfig, txIt, ctx.Int64(RewardFlag.Name), getTracer) if err != nil { @@ -285,6 +288,29 @@ func applyCancunChecks(env *stEnv, chainConfig *params.ChainConfig) error { return nil } +func applyEOFChecks(prestate *Prestate, chainConfig *params.ChainConfig) error { + // Sanity check pre-allocated EOF code to not panic in state transition. + if chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) { + for addr, acc := range prestate.Pre { + if vm.HasEOFByte(acc.Code) { + var ( + c vm.Container + err error + ) + err = c.UnmarshalBinary(acc.Code, false) + if err == nil { + jt := vm.NewPragueEOFInstructionSetForTesting() + err = c.ValidateCode(&jt, false) + } + if err != nil { + return NewError(ErrorConfig, fmt.Errorf("code at %s considered invalid: %v", addr, err)) + } + } + } + } + return nil +} + type Alloc map[common.Address]types.Account func (g Alloc) OnRoot(common.Hash) {} diff --git a/tests/state_test_util.go b/tests/state_test_util.go index cf0ce9777f..a03a622ead 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -298,6 +298,13 @@ func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapsh if tracer := vmconfig.Tracer; tracer != nil && tracer.OnTxStart != nil { tracer.OnTxStart(evm.GetVMContext(), nil, msg.From) } + + if config.IsPrague(new(big.Int), 0) { + for i := int(block.Number().Uint64() - 1); i >= 0; i-- { + core.ProcessParentBlockHash(vmTestBlockHash(uint64(i)), evm, st.StateDB) + } + } + // Execute the message. snapshot := st.StateDB.Snapshot() gaspool := new(core.GasPool)