From e027042d01a7903f126fef15b088029721b0a0d4 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 11 Oct 2024 12:41:09 +0200 Subject: [PATCH] core: addressed review comments --- cmd/evm/internal/t8ntool/transition.go | 33 +++++++++++++------------- core/state_transition.go | 14 ++++------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 793539c1da..b1fb8e4c7c 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -288,23 +288,24 @@ func applyCancunChecks(env *stEnv, chainConfig *params.ChainConfig) error { return nil } +// applyEOFChecks does a sanity check of the prestate EOF code validity, to avoid panic during state transition. 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)) - } + if !chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) { + return nil + } + 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)) } } } diff --git a/core/state_transition.go b/core/state_transition.go index bd9ba179e1..ad1248a574 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -17,7 +17,6 @@ package core import ( - "bytes" "errors" "fmt" "math" @@ -303,9 +302,9 @@ func (st *StateTransition) preCheck() error { if !msg.SkipFromEOACheck { // Make sure the sender is an EOA code := st.state.GetCode(msg.From) - if 0 < len(code) && !bytes.HasPrefix(code, []byte{0xef, 0x01, 0x00}) { - return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA, - msg.From.Hex(), st.state.GetCodeHash(msg.From)) + if len(code) > 0 { + return fmt.Errorf("%w: address %v, codeLen: %d", ErrSenderNoEOA, + msg.From.Hex(), len(code)) } } // Make sure that transaction gasFeeCap is greater than the baseFee (post london) @@ -441,11 +440,6 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { // - reset transient storage(eip 1153) st.state.Prepare(rules, msg.From, st.evm.Context.Coinbase, msg.To, vm.ActivePrecompiles(rules), msg.AccessList) - if !contractCreation { - // Increment the nonce for the next transaction - st.state.SetNonce(msg.From, st.state.GetNonce(sender.Address())+1) - } - var ( ret []byte vmerr error // vm errors do not effect consensus and are therefore not assigned to err @@ -460,6 +454,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { st.state.SetNonce(msg.From, st.state.GetNonce(sender.Address())+1) } } else { + // Increment the nonce for the next transaction + st.state.SetNonce(msg.From, st.state.GetNonce(sender.Address())+1) ret, st.gasRemaining, vmerr = st.evm.Call(sender, st.to(), msg.Data, st.gasRemaining, value) }