EIP-1153: completing transient storage on EVMC side
This commit is contained in:
parent
3078c207ca
commit
dd9e181acc
|
@ -200,16 +200,14 @@ template getCode*(c: Computation, address: EthAddress): seq[byte] =
|
|||
|
||||
template setTransientStorage*(c: Computation, slot, val: UInt256) =
|
||||
when evmc_enabled:
|
||||
# TODO: EIP-1153
|
||||
discard
|
||||
c.host.setTransientStorage(c.msg.contractAddress, slot, val)
|
||||
else:
|
||||
c.vmState.stateDB.
|
||||
setTransientStorage(c.msg.contractAddress, slot, val)
|
||||
|
||||
template getTransientStorage*(c: Computation, slot: UInt256): UInt256 =
|
||||
when evmc_enabled:
|
||||
# TODO: EIP-1153
|
||||
0.u256
|
||||
c.host.getTransientStorage(c.msg.contractAddress, slot)
|
||||
else:
|
||||
c.vmState.readOnlyStateDB.
|
||||
getTransientStorage(c.msg.contractAddress, slot)
|
||||
|
|
|
@ -30,7 +30,7 @@ type
|
|||
block_base_fee* : evmc_uint256be # The block base fee.
|
||||
blob_hashes* : ptr evmc_bytes32 # The array of blob hashes (EIP-4844).
|
||||
blob_hashes_count*: csize_t # The number of blob hashes (EIP-4844).
|
||||
|
||||
|
||||
nimbus_message* = object
|
||||
kind* : evmc_call_kind
|
||||
flags* : uint32
|
||||
|
@ -77,6 +77,10 @@ type
|
|||
address: EthAddress): evmc_access_status {.cdecl, gcsafe, raises: [CatchableError].}
|
||||
access_storage*: proc(context: evmc_host_context, address: EthAddress,
|
||||
key: var evmc_bytes32): evmc_access_status {.cdecl, gcsafe, raises: [CatchableError].}
|
||||
get_transient_storage*: proc(context: evmc_host_context, address: EthAddress,
|
||||
key: ptr evmc_uint256be): evmc_uint256be {.cdecl, gcsafe, raises: [CatchableError].}
|
||||
set_transient_storage*: proc(context: evmc_host_context, address: EthAddress,
|
||||
key, value: ptr evmc_uint256be) {.cdecl, gcsafe, raises: [CatchableError].}
|
||||
|
||||
proc nim_host_get_interface*(): ptr nimbus_host_interface {.importc, cdecl.}
|
||||
proc nim_host_create_context*(vmstate: pointer, msg: ptr evmc_message): evmc_host_context {.importc, cdecl.}
|
||||
|
@ -165,3 +169,16 @@ proc accessStorage*(ctx: HostContext, address: EthAddress,
|
|||
{.gcsafe, raises: [CatchableError].} =
|
||||
var key = toEvmc(key)
|
||||
ctx.host.access_storage(ctx.context, address, key)
|
||||
|
||||
proc getTransientStorage*(ctx: HostContext, address: EthAddress, key: UInt256): UInt256
|
||||
{.gcsafe, raises: [CatchableError].} =
|
||||
var key = toEvmc(key)
|
||||
UInt256.fromEvmc ctx.host.get_transient_storage(ctx.context, address, key.addr)
|
||||
|
||||
proc setTransientStorage*(ctx: HostContext, address: EthAddress,
|
||||
key, value: UInt256)
|
||||
{.gcsafe, raises: [CatchableError].} =
|
||||
var
|
||||
key = toEvmc(key)
|
||||
value = toEvmc(value)
|
||||
ctx.host.set_transient_storage(ctx.context, address, key.addr, value.addr)
|
||||
|
|
|
@ -81,6 +81,15 @@ proc accessStorage(p: evmc_host_context, address: var evmc_address,
|
|||
key: var evmc_bytes32): evmc_access_status {.cdecl.} =
|
||||
toHost(p).accessStorage(address.fromEvmc, key.flip256.fromEvmc)
|
||||
|
||||
proc getTransientStorage(p: evmc_host_context, address: var evmc_address,
|
||||
key: var evmc_bytes32): evmc_bytes32
|
||||
{.cdecl, raises: [RlpError].} =
|
||||
toHost(p).getTransientStorage(address.fromEvmc, key.flip256.fromEvmc).toEvmc.flip256
|
||||
|
||||
proc setTransientStorage(p: evmc_host_context, address: var evmc_address,
|
||||
key, value: var evmc_bytes32) {.cdecl, raises: [RlpError].} =
|
||||
toHost(p).setTransientStorage(address.fromEvmc, key.flip256.fromEvmc, value.flip256.fromEvmc)
|
||||
|
||||
let hostInterface = evmc_host_interface(
|
||||
account_exists: accountExists,
|
||||
get_storage: getStorage,
|
||||
|
@ -96,6 +105,8 @@ let hostInterface = evmc_host_interface(
|
|||
emit_log: emitLog,
|
||||
access_account: accessAccount,
|
||||
access_storage: accessStorage,
|
||||
get_transient_storage: getTransientStorage,
|
||||
set_transient_storage: setTransientStorage,
|
||||
)
|
||||
|
||||
proc evmcExecComputation*(host: TransactionHost): EvmcResult
|
||||
|
|
|
@ -286,6 +286,15 @@ proc accessStorage(host: TransactionHost, address: HostAddress,
|
|||
else:
|
||||
return EVMC_ACCESS_WARM
|
||||
|
||||
proc getTransientStorage(host: TransactionHost,
|
||||
address: HostAddress, key: HostKey): HostValue {.show.} =
|
||||
host.vmState.readOnlyStateDB.getTransientStorage(address, key)
|
||||
|
||||
proc setTransientStorage(host: TransactionHost, address: HostAddress,
|
||||
key: HostKey, newVal: HostValue) {.show.} =
|
||||
host.vmState.mutateStateDB:
|
||||
db.setTransientStorage(address, key, newVal)
|
||||
|
||||
when use_evmc_glue:
|
||||
{.pop: inline.}
|
||||
const included_from_host_services = true
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 78fb00187f19dd0306acab82a52f91ab40217f94
|
||||
Subproject commit 51bdaa5ddb488f874477afa0f4bd23b5111a3806
|
Loading…
Reference in New Issue