Skip to content

Commit 8d16201

Browse files
core/vm: reject contract creation if the storage is non-empty ethereum#28912 (#1569)
This change implements EIP-7610, which rejects the contract deployment if the destination has non-empty storage. Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
1 parent fd07811 commit 8d16201

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

core/vm/evm.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,19 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
442442
if evm.chainRules.IsEIP1559 {
443443
evm.StateDB.AddAddressToAccessList(address)
444444
}
445-
// Ensure there's no existing contract already at the designated address
445+
// Ensure there's no existing contract already at the designated address.
446+
// Account is regarded as existent if any of these three conditions is met:
447+
// - the nonce is nonzero
448+
// - the code is non-empty
449+
// - the storage is non-empty
446450
contractHash := evm.StateDB.GetCodeHash(address)
447-
if evm.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) {
451+
storageRoot := evm.StateDB.GetStorageRoot(address)
452+
if evm.StateDB.GetNonce(address) != 0 ||
453+
(contractHash != (common.Hash{}) && contractHash != types.EmptyCodeHash) || // non-empty code
454+
(storageRoot != (common.Hash{}) && storageRoot != types.EmptyRootHash) { // non-empty storage
448455
if evm.Config.Tracer != nil && evm.Config.Tracer.OnGasChange != nil {
449456
evm.Config.Tracer.OnGasChange(gas, 0, tracing.GasChangeCallFailedExecution)
450457
}
451-
452458
return nil, common.Address{}, 0, ErrContractAddressCollision
453459
}
454460
// Create a new account on the state

core/vm/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type StateDB interface {
4848
GetCommittedState(common.Address, common.Hash) common.Hash
4949
GetState(common.Address, common.Hash) common.Hash
5050
SetState(common.Address, common.Hash, common.Hash)
51+
GetStorageRoot(addr common.Address) common.Hash
5152

5253
GetTransientState(addr common.Address, key common.Hash) common.Hash
5354
SetTransientState(addr common.Address, key, value common.Hash)

0 commit comments

Comments
 (0)