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

@ -78,7 +78,10 @@ template accountExists*(c: Computation, address: EthAddress): bool =
when evmc_enabled: when evmc_enabled:
c.host.accountExists(address) c.host.accountExists(address)
else: 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 = template getStorage*(c: Computation, slot: Uint256): Uint256 =
when evmc_enabled: when evmc_enabled:

View File

@ -23,7 +23,11 @@ proc hostGetBlockHashImpl(ctx: Computation, number: int64): evmc_bytes32 {.cdecl
ctx.vmState.getAncestorHash(number.u256).toEvmc() ctx.vmState.getAncestorHash(number.u256).toEvmc()
proc hostAccountExistsImpl(ctx: Computation, address: var evmc_address): c99bool {.cdecl.} = 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.} = proc hostGetStorageImpl(ctx: Computation, address: var evmc_address, key: var evmc_bytes32): evmc_bytes32 {.cdecl.} =
let storageAddr = fromEvmc(address) 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 (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): let (memOffset, memLength) = if calcMemSize(memInPos, memInLen) > calcMemSize(memOutPos, memOutLen):
(memInPos, memInLen) (memInPos, memInLen)
else: else:
@ -699,7 +694,7 @@ template genCall(callName: untyped, opCode: Op): untyped =
let (childGasFee, childGasLimit) = c.gasCosts[opCode].c_handler( let (childGasFee, childGasLimit) = c.gasCosts[opCode].c_handler(
value, value,
GasParams(kind: opCode, GasParams(kind: opCode,
c_isNewAccount: isNewAccount, c_isNewAccount: not c.accountExists(contractAddress),
c_gasBalance: c.gasMeter.gasRemaining, c_gasBalance: c.gasMeter.gasRemaining,
c_contractGas: gas, c_contractGas: gas,
c_currentMemSize: c.memory.len, c_currentMemSize: c.memory.len,
@ -861,8 +856,7 @@ op selfDestructEip161, inline = false:
let let
beneficiary = c.stack.popAddress() beneficiary = c.stack.popAddress()
stateDb = c.vmState.readOnlyStateDb isDead = not c.accountExists(beneficiary)
isDead = stateDb.isDeadAccount(beneficiary)
balance = c.getBalance(c.msg.contractAddress) balance = c.getBalance(c.msg.contractAddress)
let gasParams = GasParams(kind: SelfDestruct, let gasParams = GasParams(kind: SelfDestruct,