Skip to content

Commit 9d0c51f

Browse files
authored
Merge pull request #15039 from karalabe/metropolis-contract-clash
core, tests: implement Metropolis EIP 684
2 parents 27a5622 + 08f2742 commit 9d0c51f

5 files changed

Lines changed: 18 additions & 12 deletions

File tree

‎core/vm/errors.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package vm
1919
import "errors"
2020

2121
var (
22-
ErrOutOfGas = errors.New("out of gas")
23-
ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas")
24-
ErrDepth = errors.New("max call depth exceeded")
25-
ErrTraceLimitReached = errors.New("the number of logs reached the specified limit")
26-
ErrInsufficientBalance = errors.New("insufficient balance for transfer")
22+
ErrOutOfGas = errors.New("out of gas")
23+
ErrCodeStoreOutOfGas = errors.New("contract creation code storage out of gas")
24+
ErrDepth = errors.New("max call depth exceeded")
25+
ErrTraceLimitReached = errors.New("the number of logs reached the specified limit")
26+
ErrInsufficientBalance = errors.New("insufficient balance for transfer")
27+
ErrContractAddressCollision = errors.New("contract address collision")
2728
)

‎core/vm/evm.go‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2832
type (
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)

‎tests/state_test.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ func TestState(t *testing.T) {
3737
// Expected failures:
3838
st.fails(`^stCodeSizeLimit/codesizeOOGInvalidSize\.json/(Frontier|Homestead|EIP150)`,
3939
"code size limit implementation is not conditional on fork")
40-
st.fails(`^stRevertTest/RevertDepthCreateAddressCollision\.json/EIP15[08]/[67]`, "bug in test")
4140
st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/EIP158`, "bug in test")
4241
st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/EIP158`, "bug in test")
43-
st.fails(`^stRevertTest/RevertDepthCreateAddressCollision\.json/Byzantium/[67]`, "bug in test")
4442
st.fails(`^stRevertTest/RevertPrecompiledTouch\.json/Byzantium`, "bug in test")
4543
st.fails(`^stRevertTest/RevertPrefoundEmptyOOG\.json/Byzantium`, "bug in test")
4644

‎tests/vm_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func TestVM(t *testing.T) {
2727
vmt := new(testMatcher)
2828
vmt.fails("^vmSystemOperationsTest.json/createNameRegistrator$", "fails without parallel execution")
2929

30-
vmt.skipLoad(`^vmPerformanceTest.json`) // log format broken
3130
vmt.skipLoad(`^vmInputLimits(Light)?.json`) // log format broken
3231

3332
vmt.skipShortMode("^vmPerformanceTest.json")

0 commit comments

Comments
 (0)