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