core: addressed review comments

pull/30511/head
Marius van der Wijden 1 month ago
parent a73a8e7851
commit e027042d01
  1. 33
      cmd/evm/internal/t8ntool/transition.go
  2. 14
      core/state_transition.go

@ -288,23 +288,24 @@ func applyCancunChecks(env *stEnv, chainConfig *params.ChainConfig) error {
return nil 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 { 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) {
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) { for addr, acc := range prestate.Pre {
var ( if vm.HasEOFByte(acc.Code) {
c vm.Container var (
err error c vm.Container
) err error
err = c.UnmarshalBinary(acc.Code, false) )
if err == nil { err = c.UnmarshalBinary(acc.Code, false)
jt := vm.NewPragueEOFInstructionSetForTesting() if err == nil {
err = c.ValidateCode(&jt, false) 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 err != nil {
} return NewError(ErrorConfig, fmt.Errorf("code at %s considered invalid: %v", addr, err))
} }
} }
} }

@ -17,7 +17,6 @@
package core package core
import ( import (
"bytes"
"errors" "errors"
"fmt" "fmt"
"math" "math"
@ -303,9 +302,9 @@ func (st *StateTransition) preCheck() error {
if !msg.SkipFromEOACheck { if !msg.SkipFromEOACheck {
// Make sure the sender is an EOA // Make sure the sender is an EOA
code := st.state.GetCode(msg.From) code := st.state.GetCode(msg.From)
if 0 < len(code) && !bytes.HasPrefix(code, []byte{0xef, 0x01, 0x00}) { if len(code) > 0 {
return fmt.Errorf("%w: address %v, codehash: %s", ErrSenderNoEOA, return fmt.Errorf("%w: address %v, codeLen: %d", ErrSenderNoEOA,
msg.From.Hex(), st.state.GetCodeHash(msg.From)) msg.From.Hex(), len(code))
} }
} }
// Make sure that transaction gasFeeCap is greater than the baseFee (post london) // 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) // - reset transient storage(eip 1153)
st.state.Prepare(rules, msg.From, st.evm.Context.Coinbase, msg.To, vm.ActivePrecompiles(rules), msg.AccessList) 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 ( var (
ret []byte ret []byte
vmerr error // vm errors do not effect consensus and are therefore not assigned to err 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) st.state.SetNonce(msg.From, st.state.GetNonce(sender.Address())+1)
} }
} else { } 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) ret, st.gasRemaining, vmerr = st.evm.Call(sender, st.to(), msg.Data, st.gasRemaining, value)
} }

Loading…
Cancel
Save