move create contract incNonce to 'applyMessage'

This commit is contained in:
andri lim 2020-01-20 19:32:01 +07:00 committed by zah
parent ec8abf40e4
commit ea4f851f80
4 changed files with 10 additions and 15 deletions

View File

@ -34,7 +34,6 @@ proc processTransaction*(tx: Transaction, sender: EthAddress, vmState: BaseVMSta
break
vmState.mutateStateDB:
db.incNonce(sender)
db.subBalance(sender, upfrontGasCost)
execComputation(c)

View File

@ -243,6 +243,10 @@ proc postExecuteVM(c: Computation, opCode: static[Op]) {.gcsafe.} =
proc executeOpcodes*(c: Computation) {.gcsafe.}
proc applyMessage*(c: Computation, opCode: static[Op]) =
when opCode == Create:
c.vmState.mutateStateDB:
db.incNonce(c.msg.sender)
c.snapshot()
defer:
c.dispose()

View File

@ -588,24 +588,14 @@ proc setupCreate(c: Computation, memPos, len: int, value: Uint256, opCode: stati
# Consume gas here that will be passed to child
c.gasMeter.consumeGas(createMsgGas, reason="CREATE")
# Generate new address and check for collisions
var
contractAddress: EthAddress
isCollision: bool
when opCode == Create:
const callKind = evmcCreate
c.vmState.mutateStateDB:
let creationNonce = db.getNonce(c.msg.contractAddress)
db.setNonce(c.msg.contractAddress, creationNonce + 1)
contractAddress = generateAddress(c.msg.contractAddress, creationNonce)
let creationNonce = c.vmState.readOnlyStateDb().getNonce(c.msg.contractAddress)
let contractAddress = generateAddress(c.msg.contractAddress, creationNonce)
else:
const callKind = evmcCreate2
c.vmState.mutateStateDB:
db.incNonce(c.msg.contractAddress)
let salt = c.stack.popInt()
contractAddress = generateSafeAddress(c.msg.contractAddress, salt, callData)
let salt = c.stack.popInt()
let contractAddress = generateSafeAddress(c.msg.contractAddress, salt, callData)
let childMsg = Message(
kind: callKind,

View File

@ -69,6 +69,8 @@ proc execComputation*(c: Computation) =
if c.msg.isCreate:
c.applyMessage(Create)
else:
c.vmState.mutateStateDB:
db.incNonce(c.msg.sender)
c.applyMessage(Call)
if c.fork >= FkSpurious: