From c7efbf466e7ac03aa2244a385c531e16dce9ebd0 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Sat, 14 Sep 2024 16:00:46 -0600 Subject: [PATCH] create transaction Some corner cases for create * Don't consume all gas with an invalid EOF contract * don't allow CREATE/CREATE2 opcodes to create EOF --- core/state_transition.go | 2 +- core/vm/evm.go | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 48c082ec65..ed909e7558 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -517,7 +517,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { // invalid, the tx is considered valid (so update nonce), but // is to be treated as an exceptional abort (so burn all gas). if errors.Is(vmerr, vm.ErrInvalidEOFInitcode) { - st.gasRemaining = 0 + //st.gasRemaining = 0 st.state.SetNonce(msg.From, st.state.GetNonce(sender.Address())+1) } } else { diff --git a/core/vm/evm.go b/core/vm/evm.go index d75bec157c..7499991536 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -482,11 +482,8 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // Validate initcode per EOF rules. If caller is EOF and initcode is legacy, fail. isInitcodeEOF := hasEOFMagic(codeAndHash.code) - if evm.chainRules.IsPrague { - if isInitcodeEOF { - if !allowEOF { - return nil, common.Address{}, gas, fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, ErrLegacyCode) - } + if isInitcodeEOF { + if allowEOF { // If the initcode is EOF, verify it is well-formed. var c Container if err := c.UnmarshalBinary(codeAndHash.code, isInitcodeEOF); err != nil { @@ -496,7 +493,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, return nil, common.Address{}, gas, fmt.Errorf("%w: %v", ErrInvalidEOFInitcode, err) } contract.Container = &c - } else if allowEOF { + } else { // Don't allow EOF contract to execute legacy initcode. return nil, common.Address{}, gas, ErrLegacyCode } @@ -573,7 +570,8 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // Reject code starting with 0xEF if EIP-3541 is enabled. if err == nil && len(ret) >= 1 && HasEOFByte(ret) { - if evm.chainRules.IsShanghai { + if evm.chainRules.IsPrague && isInitcodeEOF { + fmt.Printf("FIXME - valid EOF deployment\n") // Don't reject EOF contracts after Shanghai } else if evm.chainRules.IsLondon { err = ErrInvalidCode