integrate evmc 'getCodeHash'
This commit is contained in:
parent
5507e80b63
commit
8a9d9114e7
|
@ -96,7 +96,17 @@ template getCodeSize*(c: Computation, address: EthAddress): uint =
|
||||||
when evmc_enabled:
|
when evmc_enabled:
|
||||||
c.host.getCodeSize(address)
|
c.host.getCodeSize(address)
|
||||||
else:
|
else:
|
||||||
uint(c.vmState.readOnlyStateDB.getCode(account).len)
|
uint(c.vmState.readOnlyStateDB.getCode(address).len)
|
||||||
|
|
||||||
|
template getCodeHash*(c: Computation, address: EthAddress): Hash256 =
|
||||||
|
when evmc_enabled:
|
||||||
|
c.host.getCodeHash(address)
|
||||||
|
else:
|
||||||
|
let db = c.vmState.readOnlyStateDB
|
||||||
|
if not db.accountExists(address) or db.isEmptyAccount(address):
|
||||||
|
default(Hash256)
|
||||||
|
else:
|
||||||
|
db.getCodeHash(address)
|
||||||
|
|
||||||
proc newComputation*(vmState: BaseVMState, message: Message): Computation =
|
proc newComputation*(vmState: BaseVMState, message: Message): Computation =
|
||||||
new result
|
new result
|
||||||
|
|
|
@ -71,7 +71,8 @@ proc getCodeSize*(ctx: HostContext, address: EthAddress): uint =
|
||||||
|
|
||||||
proc getCodeHash*(ctx: HostContext, address: EthAddress): Hash256 =
|
proc getCodeHash*(ctx: HostContext, address: EthAddress): Hash256 =
|
||||||
var address = toEvmc(address)
|
var address = toEvmc(address)
|
||||||
Hash256.fromEvmc ctx.host.get_code_hash(ctx.context, address.addr)
|
{.gcsafe.}:
|
||||||
|
Hash256.fromEvmc ctx.host.get_code_hash(ctx.context, address.addr)
|
||||||
|
|
||||||
proc copyCode*(ctx: HostContext, address: EthAddress, codeOffset: int = 0): seq[byte] =
|
proc copyCode*(ctx: HostContext, address: EthAddress, codeOffset: int = 0): seq[byte] =
|
||||||
let size = ctx.getCodeSize(address).int
|
let size = ctx.getCodeSize(address).int
|
||||||
|
|
|
@ -80,7 +80,17 @@ proc hostGetCodeSizeImpl(ctx: Computation, address: var evmc_address): uint {.cd
|
||||||
ctx.vmState.readOnlyStateDB.getCode(fromEvmc(address)).len.uint
|
ctx.vmState.readOnlyStateDB.getCode(fromEvmc(address)).len.uint
|
||||||
|
|
||||||
proc hostGetCodeHashImpl(ctx: Computation, address: var evmc_address): evmc_bytes32 {.cdecl.} =
|
proc hostGetCodeHashImpl(ctx: Computation, address: var evmc_address): evmc_bytes32 {.cdecl.} =
|
||||||
ctx.vmstate.readOnlyStateDB.getCodeHash(fromEvmc(address)).toEvmc()
|
let
|
||||||
|
db = ctx.vmstate.readOnlyStateDB
|
||||||
|
address = fromEvmc(address)
|
||||||
|
|
||||||
|
if not db.accountExists(address):
|
||||||
|
return
|
||||||
|
|
||||||
|
if db.isEmptyAccount(address):
|
||||||
|
return
|
||||||
|
|
||||||
|
db.getCodeHash(address).toEvmc()
|
||||||
|
|
||||||
proc hostCopyCodeImpl(ctx: Computation, address: var evmc_address,
|
proc hostCopyCodeImpl(ctx: Computation, address: var evmc_address,
|
||||||
codeOffset: uint, bufferData: ptr byte,
|
codeOffset: uint, bufferData: ptr byte,
|
||||||
|
|
|
@ -904,17 +904,7 @@ op sarOp, inline = true:
|
||||||
|
|
||||||
op extCodeHash, inline = true:
|
op extCodeHash, inline = true:
|
||||||
let address = c.stack.popAddress()
|
let address = c.stack.popAddress()
|
||||||
# this is very inefficient, it calls underlying
|
push: c.getCodeHash(address)
|
||||||
# database too much, we can reduce it by implementing accounts
|
|
||||||
# cache
|
|
||||||
if not c.accountExists(address):
|
|
||||||
push: 0
|
|
||||||
return
|
|
||||||
|
|
||||||
if c.vmState.readOnlyStateDB.isEmptyAccount(address):
|
|
||||||
push: 0
|
|
||||||
else:
|
|
||||||
push: c.vmState.readOnlyStateDB.getCodeHash(address)
|
|
||||||
|
|
||||||
op sstoreEIP2200, inline = false, slot, value:
|
op sstoreEIP2200, inline = false, slot, value:
|
||||||
checkInStaticContext(c)
|
checkInStaticContext(c)
|
||||||
|
|
Loading…
Reference in New Issue