cmd/evm/internal/t8ntool: fix eof checks

This commit is contained in:
Marius van der Wijden 2025-02-21 09:37:29 +01:00
parent a4c40781a8
commit 97bb2a5d5a
5 changed files with 14 additions and 14 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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

View File

@ -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 {

View File

@ -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())