diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 24997def03..6ad598f063 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -270,11 +270,11 @@ func applyCancunChecks(env *stEnv, chainConfig *params.ChainConfig) error { // 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 { - if !chainConfig.IsShanghai(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) { + if !chainConfig.IsOsaka(big.NewInt(int64(prestate.Env.Number)), prestate.Env.Timestamp) { return nil } for addr, acc := range prestate.Pre { - if vm.HasEOFByte(acc.Code) { + if vm.HasEOFMagic(acc.Code) { var ( c vm.Container err error diff --git a/core/vm/eof.go b/core/vm/eof.go index 5a7d104aeb..b100d0f962 100644 --- a/core/vm/eof.go +++ b/core/vm/eof.go @@ -48,13 +48,13 @@ const ( var eofMagic = []byte{0xef, 0x00} -// HasEOFByte returns true if code starts with 0xEF byte -func HasEOFByte(code []byte) bool { +// hasEOFByte returns true if code starts with 0xEF byte +func hasEOFByte(code []byte) bool { return len(code) != 0 && code[0] == eofFormatByte } -// hasEOFMagic returns true if code starts with magic defined by EIP-3540 -func hasEOFMagic(code []byte) bool { +// HasEOFMagic returns true if code starts with magic defined by EIP-3540 +func HasEOFMagic(code []byte) bool { return len(eofMagic) <= len(code) && bytes.Equal(eofMagic, code[0:len(eofMagic)]) } @@ -196,7 +196,7 @@ func (c *Container) UnmarshalSubContainer(b []byte, isInitcode bool) error { } func (c *Container) unmarshalContainer(b []byte, isInitcode bool, topLevel bool) error { - if !hasEOFMagic(b) { + if !HasEOFMagic(b) { return fmt.Errorf("%w: want %x", errInvalidMagic, eofMagic) } if len(b) < 14 { diff --git a/core/vm/eof_instructions.go b/core/vm/eof_instructions.go index 32149da9c8..acaf8ec134 100644 --- a/core/vm/eof_instructions.go +++ b/core/vm/eof_instructions.go @@ -387,7 +387,7 @@ func opExtDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeCont returnGas uint64 ) code := interpreter.evm.StateDB.GetCode(toAddr) - if !hasEOFMagic(code) { + if !HasEOFMagic(code) { // Delegate-calling a non-eof contract should return 1 err = ErrExecutionReverted ret = nil diff --git a/core/vm/evm.go b/core/vm/evm.go index 9541f676e4..5b1d38e7df 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -339,7 +339,7 @@ func (evm *EVM) DelegateCall(originCaller common.Address, caller common.Address, ret, gas, err = RunPrecompiledContract(p, input, gas, evm.Config.Tracer) } else { code := evm.StateDB.GetCode(addr) - if fromEOF && !hasEOFMagic(code) { + if fromEOF && !HasEOFMagic(code) { return nil, gas, errors.New("extDelegateCall to non-eof contract") } // Initialise a new contract and make initialise the delegate values @@ -442,7 +442,7 @@ func (evm *EVM) create(caller common.Address, code []byte, gas uint64, value *ui contract.IsDeployment = true // Validate initcode per EOF rules. If caller is EOF and initcode is legacy, fail. - isInitcodeEOF := hasEOFMagic(code) + isInitcodeEOF := HasEOFMagic(code) if isInitcodeEOF { if allowEOF { // If the initcode is EOF, verify it is well-formed. @@ -556,16 +556,16 @@ func (evm *EVM) initNewContract(contract *Contract, address common.Address, isIn } // Reject legacy contract deployment from EOF. - if isInitcodeEOF && !hasEOFMagic(ret) { + if isInitcodeEOF && !HasEOFMagic(ret) { return ret, fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, ErrLegacyCode) } // Reject EOF deployment from legacy. - if !isInitcodeEOF && hasEOFMagic(ret) { + if !isInitcodeEOF && HasEOFMagic(ret) { return ret, ErrLegacyCode } // Reject code starting with 0xEF if EIP-3541 is enabled. - if len(ret) >= 1 && HasEOFByte(ret) { + if len(ret) >= 1 && hasEOFByte(ret) { if evm.chainRules.IsOsaka && isInitcodeEOF { // Don't reject EOF contracts after Osaka } else if evm.chainRules.IsLondon { diff --git a/core/vm/instructions.go b/core/vm/instructions.go index c2cad4cbcc..23a4374de4 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -442,7 +442,7 @@ func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) } else { // TODO this should not need to pull up the whole code code := interpreter.evm.StateDB.GetCode(address) - if HasEOFByte(code) { + if HasEOFMagic(code) { slot.SetFromHex("0x9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5") } else { slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(address).Bytes())