From 1f45af089a9f2ee9cf633c74e7f9e5fdf0f8f046 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Wed, 21 Aug 2024 14:15:40 +0800 Subject: [PATCH] core/vm: implement EIP 3541 (#22809) --- core/vm/errors.go | 3 ++- core/vm/evm.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/vm/errors.go b/core/vm/errors.go index a1e8adf49ef0..02ce2a678b34 100644 --- a/core/vm/errors.go +++ b/core/vm/errors.go @@ -35,10 +35,11 @@ var ( ErrReturnDataOutOfBounds = errors.New("return data out of bounds") ErrGasUintOverflow = errors.New("gas uint64 overflow") ErrNonceUintOverflow = errors.New("nonce uint64 overflow") + ErrInvalidCode = errors.New("invalid code: must not begin with 0xef") // errStopToken is an internal token indicating interpreter loop termination, // never returned to outside callers. - errStopToken = errors.New("stop token") + errStopToken = errors.New("stop token") ) // 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 18b132b1809b..4f61fc3c80a0 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -486,6 +486,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 && evm.chainRules.IsEIP1559 { + 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