From 14a34fcc4a31e150918cefcf6fda60b821256d7e Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Wed, 21 Feb 2024 11:15:44 +0100 Subject: [PATCH] re-disable create2 following pushback --- core/vm/evm.go | 15 +++++---------- core/vm/instructions.go | 3 +++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 608cf50811..9219c7ad71 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -429,6 +429,11 @@ 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 { @@ -439,16 +444,6 @@ 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 2289c8ea70..d390650204 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -620,6 +620,9 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b } func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + if interpreter.evm.TxContext.Is5806 && (scope.Contract.CodeHash == (common.Hash{}) || scope.Contract.CodeHash == types.EmptyCodeHash) { + return nil, ErrEip5806Write + } if interpreter.readOnly { return nil, ErrWriteProtection }