From 375901f0928304b77eab559a022f4c16fb4f2aaf Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 19 Feb 2024 11:10:16 +0100 Subject: [PATCH] re-enable create2 in delegate transactions --- core/vm/evm.go | 15 ++++++++++----- core/vm/instructions.go | 5 ----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 9219c7ad71..608cf50811 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -429,11 +429,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, if !evm.Context.CanTransfer(evm.StateDB, caller.Address(), value) { return nil, common.Address{}, gas, ErrInsufficientBalance } - nonce := evm.StateDB.GetNonce(caller.Address()) - if nonce+1 < nonce { - return nil, common.Address{}, gas, ErrNonceUintOverflow - } - evm.StateDB.SetNonce(caller.Address(), nonce+1) // We add this to the access list _before_ taking a snapshot. Even if the creation fails, // the access-list change should not be rolled back if evm.chainRules.IsBerlin { @@ -444,6 +439,16 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) { return nil, common.Address{}, 0, ErrContractAddressCollision } + // Increment caller's nonce (unless specific case) + if evm.TxContext.Is5806 && (contractHash == (common.Hash{}) || contractHash == types.EmptyCodeHash) && typ == CREATE2 { + // skip nonce increment + } else { + nonce := evm.StateDB.GetNonce(caller.Address()) + if nonce+1 < nonce { + return nil, common.Address{}, gas, ErrNonceUintOverflow + } + evm.StateDB.SetNonce(caller.Address(), nonce+1) + } // Create a new account on the state snapshot := evm.StateDB.Snapshot() evm.StateDB.CreateAccount(address) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 27c9e0fb38..73af956dbe 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -624,11 +624,6 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b } func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { - if interpreter.evm.TxContext.Is5806 { - if scope.Contract.CodeHash == types.EmptyCodeHash || scope.Contract.CodeHash == (common.Hash{}) { - return nil, ErrEip5806Write - } - } if interpreter.readOnly { return nil, ErrWriteProtection }