diff --git a/nimbus/vm/computation.nim b/nimbus/vm/computation.nim index 87e2e8130..6fe607208 100644 --- a/nimbus/vm/computation.nim +++ b/nimbus/vm/computation.nim @@ -80,6 +80,12 @@ template accountExists*(c: Computation, address: EthAddress): bool = else: c.vmState.readOnlyStateDB.accountExists(address) +template getStorage*(c: Computation, slot: Uint256): Uint256 = + when evmc_enabled: + c.host.getStorage(c.msg.contractAddress, slot) + else: + c.vmState.readOnlyStateDB.getStorage(c.msg.contractAddress, slot)[0] + proc newComputation*(vmState: BaseVMState, message: Message): Computation = new result result.vmState = vmState diff --git a/nimbus/vm/evmc_api.nim b/nimbus/vm/evmc_api.nim index ac387f008..909ef084b 100644 --- a/nimbus/vm/evmc_api.nim +++ b/nimbus/vm/evmc_api.nim @@ -48,7 +48,8 @@ proc getStorage*(ctx: HostContext, address: EthAddress, key: Uint256): Uint256 = var address = toEvmc(address) key = toEvmc(key) - Uint256.fromEvmc ctx.host.get_storage(ctx.context, address.addr, key.addr) + {.gcsafe.}: + Uint256.fromEvmc ctx.host.get_storage(ctx.context, address.addr, key.addr) proc setStorage*(ctx: HostContext, address: EthAddress, key, value: Uint256): evmc_storage_status = diff --git a/nimbus/vm/interpreter/opcodes_impl.nim b/nimbus/vm/interpreter/opcodes_impl.nim index 3fe5019d3..d6a42943d 100644 --- a/nimbus/vm/interpreter/opcodes_impl.nim +++ b/nimbus/vm/interpreter/opcodes_impl.nim @@ -426,15 +426,13 @@ op mstore8, inline = true, memStartPos, value: op sload, inline = true, slot: ## 0x54, Load word from storage. - - let (value, _) = c.vmState.readOnlyStateDB.getStorage(c.msg.contractAddress, slot) - push(value) + push: c.getStorage(slot) op sstore, inline = false, slot, value: ## 0x55, Save word to storage. checkInStaticContext(c) - let (currentValue, existing) = c.vmState.readOnlyStateDB.getStorage(c.msg.contractAddress, slot) + let currentValue = c.getStorage(slot) let gasParam = GasParams(kind: Op.Sstore, s_isStorageEmpty: currentValue.isZero) @@ -930,7 +928,7 @@ op sstoreEIP2200, inline = false, slot, value: raise newException(OutOfGas, "Gas not enough to perform EIP2200 SSTORE") let stateDB = c.vmState.readOnlyStateDB - let (currentValue, existing) = stateDB.getStorage(c.msg.contractAddress, slot) + let currentValue = c.getStorage(slot) let gasParam = GasParams(kind: Op.Sstore,