fixes evmc 'accountExists' definition

This commit is contained in:
andri lim 2020-01-17 18:48:14 +07:00 committed by zah
parent 64f0e59487
commit 3e384f764d
3 changed files with 11 additions and 10 deletions

View File

@ -77,6 +77,9 @@ template getBlockHash*(c: Computation, blockNumber: Uint256): Hash256 =
template accountExists*(c: Computation, address: EthAddress): bool =
when evmc_enabled:
c.host.accountExists(address)
else:
if c.fork >= FkSpurious:
not c.vmState.readOnlyStateDB.isDeadAccount(address)
else:
c.vmState.readOnlyStateDB.accountExists(address)

View File

@ -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)

View File

@ -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,