diff --git a/core/vm/eips.go b/core/vm/eips.go index 6bb941d5f9d7..ede00827ab9a 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -29,6 +29,7 @@ var activators = map[int]func(*JumpTable){ 2200: enable2200, 1884: enable1884, 1344: enable1344, + 3541: enable3541, } // EnableEIP enables the given EIP on the config. @@ -144,3 +145,7 @@ func enable2929(jt *JumpTable) { jt[SELFDESTRUCT].constantGas = params.SelfdestructGasEIP150 jt[SELFDESTRUCT].dynamicGas = gasSelfdestructEIP2929 } + +func enable3541(jt *JumpTable) { + // Do nothing. +} diff --git a/core/vm/errors.go b/core/vm/errors.go index c813aa36af36..fd80a89025fc 100644 --- a/core/vm/errors.go +++ b/core/vm/errors.go @@ -34,6 +34,7 @@ var ( ErrWriteProtection = errors.New("write protection") ErrReturnDataOutOfBounds = errors.New("return data out of bounds") ErrGasUintOverflow = errors.New("gas uint64 overflow") + ErrInvalidCode = errors.New("invalid code") ) // ErrStackUnderflow wraps an evm error when the items on the stack less diff --git a/core/vm/evm.go b/core/vm/evm.go index bd54e855c6b7..7e3063767885 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -417,6 +417,15 @@ func (c *codeAndHash) Hash() common.Hash { return c.hash } +func hasEIP3541(vmConfig *Config) bool { + for _, eip := range vmConfig.ExtraEips { + if eip == 3541 { + return true + } + } + return false +} + // create creates a new contract using code as deployment code. func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, value *big.Int, address common.Address) ([]byte, common.Address, uint64, error) { // Depth check execution. Fail if we're trying to execute above the @@ -468,6 +477,11 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, err = ErrMaxCodeSizeExceeded } + // Reject code starting with 0xEF if EIP-3541 is enabled. + if err == nil && len(ret) >= 1 && ret[0] == 0xEF && hasEIP3541(&evm.vmConfig) { + err = ErrInvalidCode + } + // if the contract creation ran successfully and no errors were returned // calculate the gas required to store the code. If the code could not // be stored due to not enough gas set an error and let it be handled