integrate evmc 'accountExists'
This commit is contained in:
parent
1813579bc4
commit
a4a1148a45
|
@ -74,6 +74,12 @@ template getBlockHash*(c: Computation, blockNumber: Uint256): Hash256 =
|
|||
else:
|
||||
c.vmState.getAncestorHash(blockNumber.vmWordToBlockNumber)
|
||||
|
||||
template accountExists*(c: Computation, address: EthAddress): bool =
|
||||
when evmc_enabled:
|
||||
c.host.accountExists(address)
|
||||
else:
|
||||
c.vmState.readOnlyStateDB.accountExists(address)
|
||||
|
||||
proc newComputation*(vmState: BaseVMState, message: Message): Computation =
|
||||
new result
|
||||
result.vmState = vmState
|
||||
|
|
|
@ -29,7 +29,6 @@ proc getTxContext*(ctx: HostContext): evmc_tx_context =
|
|||
ctx.host.get_tx_context(ctx.context)
|
||||
|
||||
proc getBlockHash*(ctx: HostContext, number: Uint256): Hash256 =
|
||||
{.gcsafe.}:
|
||||
let
|
||||
blockNumber = ctx.getTxContext().block_number.u256
|
||||
ancestorDepth = blockNumber - number - 1
|
||||
|
@ -37,10 +36,12 @@ proc getBlockHash*(ctx: HostContext, number: Uint256): Hash256 =
|
|||
return
|
||||
if number >= blockNumber:
|
||||
return
|
||||
{.gcsafe.}:
|
||||
Hash256.fromEvmc ctx.host.get_block_hash(ctx.context, number.truncate(int64))
|
||||
|
||||
proc accountExists*(ctx: HostContext, address: EthAddress): bool =
|
||||
var address = toEvmc(address)
|
||||
{.gcsafe.}:
|
||||
ctx.host.account_exists(ctx.context, address.addr).bool
|
||||
|
||||
proc getStorage*(ctx: HostContext, address: EthAddress, key: Uint256): Uint256 =
|
||||
|
|
|
@ -695,7 +695,7 @@ template genCall(callName: untyped, opCode: Op): untyped =
|
|||
let isNewAccount = if c.fork >= FkSpurious:
|
||||
c.vmState.readOnlyStateDb.isDeadAccount(contractAddress)
|
||||
else:
|
||||
not c.vmState.readOnlyStateDb.accountExists(contractAddress)
|
||||
not c.accountExists(contractAddress)
|
||||
|
||||
let (memOffset, memLength) = if calcMemSize(memInPos, memInLen) > calcMemSize(memOutPos, memOutLen):
|
||||
(memInPos, memInLen)
|
||||
|
@ -855,7 +855,7 @@ op selfDestructEip150, inline = false:
|
|||
let beneficiary = c.stack.popAddress()
|
||||
|
||||
let gasParams = GasParams(kind: SelfDestruct,
|
||||
sd_condition: not c.vmState.readOnlyStateDb.accountExists(beneficiary)
|
||||
sd_condition: not c.accountExists(beneficiary)
|
||||
)
|
||||
|
||||
let gasCost = c.gasCosts[SelfDestruct].c_handler(0.u256, gasParams).gasCost
|
||||
|
@ -913,7 +913,7 @@ op extCodeHash, inline = true:
|
|||
# this is very inefficient, it calls underlying
|
||||
# database too much, we can reduce it by implementing accounts
|
||||
# cache
|
||||
if not c.vmState.readOnlyStateDB.accountExists(address):
|
||||
if not c.accountExists(address):
|
||||
push: 0
|
||||
return
|
||||
|
||||
|
|
Loading…
Reference in New Issue