Skip to content

Commit

Permalink
core: addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Oct 11, 2024
1 parent a73a8e7 commit e027042
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
33 changes: 17 additions & 16 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
14 changes: 5 additions & 9 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package core

import (
"bytes"
"errors"
"fmt"
"math"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit e027042

Please sign in to comment.