From ca6eb0cb3891c7310d1bc2b721d8eb76c7c7d303 Mon Sep 17 00:00:00 2001 From: coffeepots Date: Tue, 4 Sep 2018 17:15:46 +0100 Subject: [PATCH] Don't touch nonce until after address in-use check --- nimbus/vm/interpreter/opcodes_impl.nim | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 8a760c4d8..4f160ffca 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -546,22 +546,21 @@ op create, inline = false, value, startPosition, size: ## TODO dynamic gas that depends on remaining gas - var - contractAddress: EthAddress - isCollision: bool - - computation.vmState.mutateStateDB: - let creationNonce = db.getNonce(computation.msg.storageAddress) - db.setNonce(computation.msg.storageAddress, creationNonce + 1) - + let + readOnlyState = computation.vmState.readOnlyStateDB + creationNonce = readOnlyState.getNonce(computation.msg.storageAddress) contractAddress = generateAddress(computation.msg.storageAddress, creationNonce) - # Regarding collisions, see: https://github.com/status-im/nimbus/issues/133 - isCollision = db.hasCodeOrNonce(contractAddress) + isCollision = readOnlyState.hasCodeOrNonce(contractAddress) - if isCollision: + # Regarding collisions, see: https://github.com/status-im/nimbus/issues/133 + # See: https://github.com/ethereum/EIPs/issues/684 + if not isCollision: + computation.vmState.mutateStateDB: + db.setNonce(computation.msg.storageAddress, creationNonce + 1) + else: debug("Address collision while creating contract", address = contractAddress.toHex) push: 0 - return + raise newException(ValidationError, "Contract address already exists and is in use") let childMsg = prepareChildMessage( computation,