core: addressed review comments
This commit is contained in:
parent
a73a8e7851
commit
e027042d01
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue