@@ -25,6 +25,10 @@ import (
2525 "github.com/ethereum/go-ethereum/params"
2626)
2727
28+ // emptyCodeHash is used by create to ensure deployment is disallowed to already
29+ // deployed contract addresses (relevant after the account abstraction).
30+ var emptyCodeHash = crypto .Keccak256Hash (nil )
31+
2832type (
2933 CanTransferFunc func (StateDB , common.Address , * big.Int ) bool
3034 TransferFunc func (StateDB , common.Address , common.Address , * big.Int )
@@ -307,13 +311,17 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
307311 if ! evm .CanTransfer (evm .StateDB , caller .Address (), value ) {
308312 return nil , common.Address {}, gas , ErrInsufficientBalance
309313 }
310-
311- // Create a new account on the state
314+ // Ensure there's no existing contract already at the designated address
312315 nonce := evm .StateDB .GetNonce (caller .Address ())
313316 evm .StateDB .SetNonce (caller .Address (), nonce + 1 )
314317
315- snapshot := evm .StateDB .Snapshot ()
316318 contractAddr = crypto .CreateAddress (caller .Address (), nonce )
319+ contractHash := evm .StateDB .GetCodeHash (contractAddr )
320+ if evm .StateDB .GetNonce (contractAddr ) != 0 || (contractHash != (common.Hash {}) && contractHash != emptyCodeHash ) {
321+ return nil , common.Address {}, 0 , ErrContractAddressCollision
322+ }
323+ // Create a new account on the state
324+ snapshot := evm .StateDB .Snapshot ()
317325 evm .StateDB .CreateAccount (contractAddr )
318326 if evm .ChainConfig ().IsEIP158 (evm .BlockNumber ) {
319327 evm .StateDB .SetNonce (contractAddr , 1 )
0 commit comments