From 3e384f764df6eb1d5f14569d7aa4b12e079aac77 Mon Sep 17 00:00:00 2001 From: andri lim Date: Fri, 17 Jan 2020 18:48:14 +0700 Subject: [PATCH] fixes evmc 'accountExists' definition --- nimbus/vm/computation.nim | 5 ++++- nimbus/vm/evmc_host.nim | 6 +++++- nimbus/vm/interpreter/opcodes_impl.nim | 10 ++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index fef6e29d3..032cdd887 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -78,7 +78,10 @@ template accountExists*(c: Computation, address: EthAddress): bool = when evmc_enabled: c.host.accountExists(address) else: - c.vmState.readOnlyStateDB.accountExists(address) + if c.fork >= FkSpurious: + not c.vmState.readOnlyStateDB.isDeadAccount(address) + else: + c.vmState.readOnlyStateDB.accountExists(address) template getStorage*(c: Computation, slot: Uint256): Uint256 = when evmc_enabled: diff --git a/nimbus/vm/evmc_host.nim b/nimbus/vm/evmc_host.nim index 2ad5cc6ac..70850a1fd 100644 --- a/nimbus/vm/evmc_host.nim +++ b/nimbus/vm/evmc_host.nim @@ -23,7 +23,11 @@ proc hostGetBlockHashImpl(ctx: Computation, number: int64): evmc_bytes32 {.cdecl ctx.vmState.getAncestorHash(number.u256).toEvmc() proc hostAccountExistsImpl(ctx: Computation, address: var evmc_address): c99bool {.cdecl.} = - ctx.vmState.readOnlyStateDB.accountExists(fromEvmc(address)) + let db = ctx.vmState.readOnlyStateDB + if ctx.fork >= FkSpurious: + not db.isDeadAccount(fromEvmc(address)) + else: + db.accountExists(fromEvmc(address)) proc hostGetStorageImpl(ctx: Computation, address: var evmc_address, key: var evmc_bytes32): evmc_bytes32 {.cdecl.} = let storageAddr = fromEvmc(address) diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index d11fe784e..71118017b 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -686,11 +686,6 @@ template genCall(callName: untyped, opCode: Op): untyped = let (memInPos, memInLen, memOutPos, memOutLen) = (memoryInputStartPosition.cleanMemRef, memoryInputSize.cleanMemRef, memoryOutputStartPosition.cleanMemRef, memoryOutputSize.cleanMemRef) - let isNewAccount = if c.fork >= FkSpurious: - c.vmState.readOnlyStateDb.isDeadAccount(contractAddress) - else: - not c.accountExists(contractAddress) - let (memOffset, memLength) = if calcMemSize(memInPos, memInLen) > calcMemSize(memOutPos, memOutLen): (memInPos, memInLen) else: @@ -699,7 +694,7 @@ template genCall(callName: untyped, opCode: Op): untyped = let (childGasFee, childGasLimit) = c.gasCosts[opCode].c_handler( value, GasParams(kind: opCode, - c_isNewAccount: isNewAccount, + c_isNewAccount: not c.accountExists(contractAddress), c_gasBalance: c.gasMeter.gasRemaining, c_contractGas: gas, c_currentMemSize: c.memory.len, @@ -861,8 +856,7 @@ op selfDestructEip161, inline = false: let beneficiary = c.stack.popAddress() - stateDb = c.vmState.readOnlyStateDb - isDead = stateDb.isDeadAccount(beneficiary) + isDead = not c.accountExists(beneficiary) balance = c.getBalance(c.msg.contractAddress) let gasParams = GasParams(kind: SelfDestruct,