diff --git a/nimbus/transaction/evmc_host_glue.nim b/nimbus/transaction/evmc_host_glue.nim index d2aa67861..64652f1f5 100644 --- a/nimbus/transaction/evmc_host_glue.nim +++ b/nimbus/transaction/evmc_host_glue.nim @@ -108,6 +108,7 @@ proc evmcExecComputation*(host: TransactionHost): EvmcResult {.inline.} = return let hostContext = cast[evmc_host_context](host) + host.hostInterface = hostInterface.unsafeAddr # Without `{.gcsafe.}:` here, the call via `vm.execute` results in a Nim # compile-time error in a far away function. Starting here, a cascade of diff --git a/nimbus/transaction/host_call_nested.nim b/nimbus/transaction/host_call_nested.nim index 1ea5a7698..377752319 100644 --- a/nimbus/transaction/host_call_nested.nim +++ b/nimbus/transaction/host_call_nested.nim @@ -112,16 +112,25 @@ proc beforeExecEvmcNested(host: TransactionHost, msg: EvmcMessage): Computation # contribute to the stack frame of `callEvmcNested` below. {.noinline.} = host.showCallEntry(msg) - if msg.kind == EVMC_CREATE or msg.kind == EVMC_CREATE2: - return beforeExecCreateEvmcNested(host, msg) - else: - return beforeExecCallEvmcNested(host, msg) + let c = if msg.kind == EVMC_CREATE or msg.kind == EVMC_CREATE2: + beforeExecCreateEvmcNested(host, msg) + else: + beforeExecCallEvmcNested(host, msg) + when defined(evmc_enabled): + c.host.init(cast[ptr nimbus_host_interface](host.hostInterface), + cast[typeof(c.host.context)](host)) + host.saveComputation.add(host.computation) + host.computation = c + return c proc afterExecEvmcNested(host: TransactionHost, child: Computation, kind: EvmcCallKind): EvmcResult # This function must be declared with `{.noinline.}` to make sure it doesn't # contribute to the stack frame of `callEvmcNested` below. {.noinline.} = + host.computation = host.saveComputation[^1] + host.saveComputation[^1] = nil + host.saveComputation.setLen(host.saveComputation.len - 1) if kind == EVMC_CREATE or kind == EVMC_CREATE2: afterExecCreateEvmcNested(host, child, result) else: diff --git a/nimbus/transaction/host_types.nim b/nimbus/transaction/host_types.nim index 01905765e..ac898ea28 100644 --- a/nimbus/transaction/host_types.nim +++ b/nimbus/transaction/host_types.nim @@ -63,6 +63,8 @@ type touchedAccounts*: HashSet[EthAddress] selfDestructs*: HashSet[EthAddress] depth*: int + saveComputation*: seq[Computation] + hostInterface*: ptr evmc_host_interface # These versions of `toEvmc` and `fromEvmc` don't flip big/little-endian like # the older functions in `evmc_helpers`. New code only flips with _explicit_