Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type (
GetHashFunc func(uint64) common.Hash
)

const emptyNonce uint64 = 0

// run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter.
func run(evm *EVM, snapshot int, contract *Contract, input []byte) ([]byte, error) {
if contract.CodeAddr != nil {
Expand Down Expand Up @@ -314,7 +316,18 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I

snapshot := evm.StateDB.Snapshot()
contractAddr = crypto.CreateAddress(caller.Address(), nonce)

// When a contract creation is on an account with non-zero nonce or non-empty code,
// the creation fails as if init code execution resulted in an exceptional halt.
// This applies to contract creation triggered by a contract creation transaction
// and by CREATE instruction.
if evm.StateDB.GetNonce(contractAddr) > emptyNonce || evm.StateDB.GetCode(contractAddr) != nil {
// In case of address collision, all gas remained will been consumed.
return nil, common.Address{}, 0, errAddressCollision
}

evm.StateDB.CreateAccount(contractAddr)

if evm.ChainConfig().IsEIP158(evm.BlockNumber) {
evm.StateDB.SetNonce(contractAddr, 1)
}
Expand Down
1 change: 1 addition & 0 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
errReturnDataOutOfBounds = errors.New("evm: return data out of bounds")
errExecutionReverted = errors.New("evm: execution reverted")
errMaxCodeSizeExceeded = errors.New("evm: max code size exceeded")
errAddressCollision = errors.New("evm: contract address collision")
)

func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
Expand Down