Refactor EVM raises to reduce compiler warnings (#2040)

* Fix style check when EVMC enabled

* Refactor EVM raises to reduce compiler warnings

* Fix EVM handler raises when EVMC enabled

* Workaround stupid style checker false complaints

* Fix Windows/clang linking error due to function pointer incompatibility
This commit is contained in:
andri lim 2024-02-20 14:16:12 +07:00 committed by GitHub
parent 7c1af9a78f
commit b09fba0b49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 101 additions and 65 deletions

View File

@ -73,7 +73,7 @@ template getTimestamp*(c: Computation): uint64 =
template getBlockNumber*(c: Computation): UInt256 =
when evmc_enabled:
c.host.getTxContext().blockNumber.u256
c.host.getBlockNumber()
else:
c.vmState.blockNumber.blockNumberToVmWord
@ -95,11 +95,11 @@ template getBaseFee*(c: Computation): UInt256 =
else:
c.vmState.blockCtx.fee.get(0.u256)
template getChainId*(c: Computation): uint =
template getChainId*(c: Computation): uint64 =
when evmc_enabled:
UInt256.fromEvmc(c.host.getTxContext().chainId).truncate(uint)
c.host.getChainId()
else:
c.vmState.com.chainId.uint
c.vmState.com.chainId.uint64
template getOrigin*(c: Computation): EthAddress =
when evmc_enabled:
@ -351,24 +351,49 @@ proc writeContract*(c: Computation)
# The account already has zero-length code to handle nested calls.
withExtra trace, "New contract given empty code by pre-Homestead rules"
template chainTo*(c: Computation, toChild: typeof(c.child), after: untyped) =
template chainTo*(c: Computation,
toChild: typeof(c.child),
shouldRaise: static[bool],
after: untyped) =
when shouldRaise:
{.pragma: chainToPragma, gcsafe, raises: [CatchableError].}
else:
{.pragma: chainToPragma, gcsafe, raises: [].}
c.child = toChild
c.continuation = proc() =
c.continuation = proc() {.chainToPragma.} =
c.continuation = nil
after
# Register an async operation to be performed before the continuation is called.
template asyncChainTo*(c: Computation, asyncOperation: Future[void], after: untyped) =
template asyncChainTo*(c: Computation,
asyncOperation: Future[void],
after: untyped) =
c.pendingAsyncOperation = asyncOperation
c.continuation = proc() =
c.continuation = proc() {.gcsafe, raises: [].} =
c.continuation = nil
after
template asyncChainToRaise*(c: Computation,
asyncOperation: Future[void],
RaisesTypes: untyped,
after: untyped) =
c.pendingAsyncOperation = asyncOperation
c.continuation = proc() {.gcsafe, raises: RaisesTypes.} =
c.continuation = nil
after
proc merge*(c, child: Computation) =
c.gasMeter.refundGas(child.gasMeter.gasRefunded)
when evmc_enabled:
{.pragma: selfDesructPragma, gcsafe, raises: [CatchableError].}
else:
{.pragma: selfDesructPragma, gcsafe, raises: [].}
proc execSelfDestruct*(c: Computation, beneficiary: EthAddress)
{.gcsafe, raises: [CatchableError].} =
{.selfDesructPragma.} =
c.vmState.mutateStateDB:
let localBalance = c.getBalance(c.msg.contractAddress)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2019 Status Research & Development GmbH
# Copyright (c) 2019-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
@ -146,7 +146,7 @@ proc copyCode*(ctx: HostContext, address: EthAddress, codeOffset: int = 0): seq[
codeOffset, result[0].addr, result.len)
doAssert(read == result.len)
proc selfdestruct*(ctx: HostContext, address, beneficiary: EthAddress)
proc selfDestruct*(ctx: HostContext, address, beneficiary: EthAddress)
{.gcsafe, raises: [CatchableError].} =
ctx.host.selfdestruct(ctx.context, address, beneficiary)
@ -183,3 +183,12 @@ proc setTransientStorage*(ctx: HostContext, address: EthAddress,
key = toEvmc(key)
value = toEvmc(value)
ctx.host.set_transient_storage(ctx.context, address, key.addr, value.addr)
# The following two templates put here because the stupid style checker
# complaints about block_number vs blockNumber and chain_id vs chainId
# if they are written directly in computation.nim
template getBlockNumber*(ctx: HostContext): UInt256 =
ctx.getTxContext().block_number.u256
template getChainId*(ctx: HostContext): uint64 =
UInt256.fromEvmc(ctx.getTxContext().chain_id).truncate(uint64)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
@ -198,7 +198,7 @@ when defined(evmc_enabled):
e[EVMC_STORAGE_ADDED_DELETED] = StorageStoreCost(gasCost: c.warmAccess,
gasRefund: c.sset - c.warmAccess)
e[EVMC_STORAGE_MODIFIED_RESTORED] = StorageStoreCost(gasCost: c.warmAccess,
gasRefund: c.reset - c.warm_access)
gasRefund: c.reset - c.warmAccess)
proc storageStoreCost(): array[EVMFork, array[evmc_storage_status, StorageStoreCost]] {.compileTime.} =
const tbl = storageCostSpec()
@ -313,7 +313,7 @@ template gasCosts(fork: EVMFork, prefix, ResultGasCostsName: untyped) =
func `prefix gasSstore`(value: UInt256, gasParams: GasParams): GasResult {.nimcall.} =
## Value is word to save
when defined(evmc_enabled):
const c = SStoreCost[fork]
const c = SstoreCost[fork]
let sc = c[gasParams.s_status]
result.gasCost = sc.gasCost
result.gasRefund = sc.gasRefund

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -35,7 +35,7 @@ const
## 0x40, Get the hash of one of the 256 most recent complete blocks.
let cpt = k.cpt
let (blockNumber) = cpt.stack.popInt(1)
cpt.asyncChainTo(ifNecessaryGetBlockHeaderByNumber(cpt.vmState, blockNumber)):
cpt.asyncChainToRaise(ifNecessaryGetBlockHeaderByNumber(cpt.vmState, blockNumber), [CatchableError]):
cpt.stack.push:
cpt.getBlockHash(blockNumber)
@ -69,10 +69,10 @@ const
k.cpt.stack.push:
k.cpt.getChainId
selfBalanceOp: Vm2OpFn = proc (k: var Vm2Ctx) =
selfBalanceOp: Vm2OpFn = proc (k: var Vm2Ctx) {.gcsafe, raises:[].} =
## 0x47, Get current contract's balance.
let cpt = k.cpt
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, cpt.msg.contractAddress)):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, cpt.msg.contractAddress), [CatchableError]):
cpt.stack.push:
cpt.getBalance(cpt.msg.contractAddress)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -149,8 +149,8 @@ proc staticCallParams(c: Computation): LocalParams =
when evmc_enabled:
template execSubCall(c: Computation; msg: ref nimbus_message; p: LocalParams) =
c.chainTo(msg):
c.returnData = @(makeOpenArray(c.res.outputData, c.res.outputSize.int))
c.chainTo(msg, shouldRaise = true):
c.returnData = @(makeOpenArray(c.res.output_data, c.res.output_size.int))
let actualOutputSize = min(p.memOutLen, c.returnData.len)
if actualOutputSize > 0:
@ -166,7 +166,7 @@ when evmc_enabled:
c.res.release(c.res)
else:
proc execSubCall(c: Computation; childMsg: Message; memPos, memLen: int) =
proc execSubCall(c: Computation; childMsg: Message; memPos, memLen: int) {.raises: [].} =
## Call new VM -- helper for `Call`-like operations
# need to provide explicit <c> and <child> for capturing in chainTo proc()
@ -174,7 +174,7 @@ else:
var
child = newComputation(c.vmState, false, childMsg)
c.chainTo(child):
c.chainTo(child, shouldRaise = true):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
@ -205,7 +205,7 @@ const
p = cpt.callParams
cpt.asyncChainTo(ifNecessaryGetAccounts(cpt.vmState, @[p.sender])):
cpt.asyncChainTo(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress])):
cpt.asyncChainToRaise(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress]), [CatchableError]):
var (gasCost, childGasLimit) = cpt.gasCosts[Call].c_handler(
p.value,
GasParams(
@ -284,7 +284,7 @@ const
p = cpt.callCodeParams
cpt.asyncChainTo(ifNecessaryGetAccounts(cpt.vmState, @[p.sender])):
cpt.asyncChainTo(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress])):
cpt.asyncChainToRaise(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress]), [CatchableError]):
var (gasCost, childGasLimit) = cpt.gasCosts[CallCode].c_handler(
p.value,
GasParams(
@ -364,7 +364,7 @@ const
p = cpt.delegateCallParams
cpt.asyncChainTo(ifNecessaryGetAccounts(cpt.vmState, @[p.sender])):
cpt.asyncChainTo(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress])):
cpt.asyncChainToRaise(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress]), [CatchableError]):
var (gasCost, childGasLimit) = cpt.gasCosts[DelegateCall].c_handler(
p.value,
GasParams(
@ -438,7 +438,7 @@ const
p = cpt.staticCallParams
cpt.asyncChainTo(ifNecessaryGetAccounts(cpt.vmState, @[p.sender])):
cpt.asyncChainTo(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress])):
cpt.asyncChainToRaise(ifNecessaryGetCodeForAccounts(cpt.vmState, @[p.contractAddress, p.codeAddress]), [CatchableError]):
var (gasCost, childGasLimit) = cpt.gasCosts[StaticCall].c_handler(
p.value,
GasParams(

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -46,26 +46,26 @@ when not defined(evmc_enabled):
when evmc_enabled:
template execSubCreate(c: Computation; msg: ref nimbus_message) =
c.chainTo(msg):
c.chainTo(msg, shouldRaise = true):
c.gasMeter.returnGas(c.res.gas_left)
if c.res.status_code == EVMC_SUCCESS:
c.stack.top(c.res.create_address)
elif c.res.status_code == EVMC_REVERT:
# From create, only use `outputData` if child returned with `REVERT`.
c.returnData = @(makeOpenArray(c.res.outputData, c.res.outputSize.int))
c.returnData = @(makeOpenArray(c.res.output_data, c.res.output_size.int))
if not c.res.release.isNil:
c.res.release(c.res)
else:
proc execSubCreate(c: Computation; childMsg: Message;
salt: ContractSalt = ZERO_CONTRACTSALT) =
salt: ContractSalt = ZERO_CONTRACTSALT) {.raises: [].} =
## Create new VM -- helper for `Create`-like operations
# need to provide explicit <c> and <child> for capturing in chainTo proc()
var
child = newComputation(c.vmState, false, childMsg, salt)
c.chainTo(child):
c.chainTo(child, shouldRaise = false):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -49,7 +49,7 @@ const
## 0x31, Get balance of the given account.
let cpt = k.cpt
let address = cpt.stack.popAddress
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, address), [CatchableError]):
cpt.stack.push:
cpt.getBalance(address)
@ -58,7 +58,7 @@ const
let cpt = k.cpt
let address = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, address), [CatchableError]):
let gasCost = cpt.gasEip2929AccountCheck(address)
cpt.opcodeGastCost(Balance, gasCost, reason = "Balance EIP2929")
cpt.stack.push:
@ -123,18 +123,18 @@ const
k.cpt.memory.writePadded(k.cpt.msg.data, memPos, copyPos, len)
codeSizeOp: Vm2OpFn = proc (k: var Vm2Ctx) =
codeSizeOp: Vm2OpFn = proc (k: var Vm2Ctx) {.gcsafe, raises:[].} =
## 0x38, Get size of code running in current environment.
let cpt = k.cpt
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, cpt.msg.contractAddress)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, cpt.msg.contractAddress), [FullStack]):
cpt.stack.push:
cpt.code.len
codeCopyOp: Vm2OpFn = proc (k: var Vm2Ctx) =
codeCopyOp: Vm2OpFn = proc (k: var Vm2Ctx) {.gcsafe, raises:[].} =
## 0x39, Copy code running in current environment to memory.
let cpt = k.cpt
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, cpt.msg.contractAddress)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, cpt.msg.contractAddress), [CatchableError]):
let (memStartPos, copyStartPos, size) = cpt.stack.popInt(3)
# TODO tests: https://github.com/status-im/nimbus/issues/67
@ -147,7 +147,6 @@ const
cpt.memory.writePadded(cpt.code.bytes, memPos, copyPos, len)
gasPriceOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x3A, Get price of gas in current environment.
k.cpt.stack.push:
@ -159,7 +158,7 @@ const
## 0x3b, Get size of an account's code
let cpt = k.cpt
let address = k.cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, address), [CatchableError]):
cpt.stack.push:
cpt.getCodeSize(address)
@ -168,7 +167,7 @@ const
let cpt = k.cpt
let address = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, address), [CatchableError]):
let gasCost = cpt.gasEip2929AccountCheck(address)
cpt.opcodeGastCost(ExtCodeSize, gasCost, reason = "ExtCodeSize EIP2929")
cpt.stack.push:
@ -181,7 +180,7 @@ const
let cpt = k.cpt
let address = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, address), [CatchableError]):
let (memStartPos, codeStartPos, size) = cpt.stack.popInt(3)
let (memPos, codePos, len) =
(memStartPos.cleanMemRef, codeStartPos.cleanMemRef, size.cleanMemRef)
@ -199,7 +198,7 @@ const
let cpt = k.cpt
let address = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, address), [CatchableError]):
let (memStartPos, codeStartPos, size) = cpt.stack.popInt(3)
let (memPos, codePos, len) = (memStartPos.cleanMemRef,
codeStartPos.cleanMemRef, size.cleanMemRef)
@ -246,7 +245,7 @@ const
## 0x3f, Returns the keccak256 hash of a contracts code
let cpt = k.cpt
let address = k.cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, address), [CatchableError]):
cpt.stack.push:
cpt.getCodeHash(address)
@ -255,7 +254,7 @@ const
let cpt = k.cpt
let address = k.cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetCode(cpt.vmState, address)):
cpt.asyncChainToRaise(ifNecessaryGetCode(cpt.vmState, address), [CatchableError]):
let gasCost = cpt.gasEip2929AccountCheck(address)
cpt.opcodeGastCost(ExtCodeHash, gasCost, reason = "ExtCodeHash EIP2929")

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -43,7 +43,6 @@ when not defined(evmc_enabled):
when evmc_enabled:
proc sstoreEvmc(c: Computation, slot, newValue: UInt256, coldAccess = 0.GasInt) =
let
currentValue = c.getStorage(slot)
status = c.host.setStorage(c.msg.contractAddress, slot, newValue)
gasParam = GasParams(kind: Op.Sstore, s_status: status)
gasCost = c.gasCosts[Sstore].c_handler(newValue, gasParam)[0] + coldAccess
@ -172,7 +171,7 @@ const
## 0x54, Load word from storage.
let cpt = k.cpt # so it can safely be captured by the asyncChainTo closure below
let (slot) = cpt.stack.popInt(1)
cpt.asyncChainTo(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot)):
cpt.asyncChainToRaise(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot), [CatchableError]):
cpt.stack.push:
cpt.getStorage(slot)
@ -181,7 +180,7 @@ const
let cpt = k.cpt
let (slot) = cpt.stack.popInt(1)
cpt.asyncChainTo(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot)):
cpt.asyncChainToRaise(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot), [CatchableError]):
let gasCost = cpt.gasEip2929AccountCheck(cpt.msg.contractAddress, slot)
cpt.opcodeGastCost(Sload, gasCost, reason = "sloadEIP2929")
cpt.stack.push:
@ -195,7 +194,7 @@ const
let (slot, newValue) = cpt.stack.popInt(2)
checkInStaticContext(cpt)
cpt.asyncChainTo(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot)):
cpt.asyncChainToRaise(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot), [CatchableError]):
sstoreEvmcOrSstore(cpt, slot, newValue)
@ -205,7 +204,7 @@ const
let (slot, newValue) = cpt.stack.popInt(2)
checkInStaticContext(cpt)
cpt.asyncChainTo(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot)):
cpt.asyncChainToRaise(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot), [CatchableError]):
sstoreEvmcOrNetGasMetering(cpt, slot, newValue)
@ -222,7 +221,7 @@ const
OutOfGas,
"Gas not enough to perform EIP2200 SSTORE")
cpt.asyncChainTo(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot)):
cpt.asyncChainToRaise(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot), [CatchableError]):
sstoreEvmcOrNetGasMetering(cpt, slot, newValue)
@ -238,7 +237,7 @@ const
if cpt.gasMeter.gasRemaining <= SentryGasEIP2200:
raise newException(OutOfGas, "Gas not enough to perform EIP2200 SSTORE")
cpt.asyncChainTo(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot)):
cpt.asyncChainToRaise(ifNecessaryGetSlot(cpt.vmState, cpt.msg.contractAddress, slot), [CatchableError]):
var coldAccessGas = 0.GasInt
when evmc_enabled:
if cpt.host.accessStorage(cpt.msg.contractAddress, slot) == EVMC_ACCESS_COLD:
@ -281,7 +280,7 @@ const
k.cpt.stack.push:
k.cpt.gasMeter.gasRemaining
jumpDestOp: Vm2OpFn = proc (k: var Vm2Ctx) =
jumpDestOp: Vm2OpFn = proc (k: var Vm2Ctx) {.gcsafe, raises:[].} =
## 0x5b, Mark a valid destination for jumps. This operation has no effect
## on machine state during execution.
discard

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -79,15 +79,19 @@ const
## 0xff, Halt execution and register account for later deletion.
let cpt = k.cpt
let beneficiary = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, beneficiary)):
cpt.selfDestruct(beneficiary)
when defined(evmc_enabled):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, beneficiary), [CatchableError]):
cpt.selfDestruct(beneficiary)
else:
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, beneficiary)):
cpt.selfDestruct(beneficiary)
selfDestructEIP150Op: Vm2OpFn = proc(k: var Vm2Ctx) =
## selfDestructEip150 (auto generated comment)
let cpt = k.cpt
let beneficiary = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, beneficiary)):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, beneficiary), [CatchableError]):
let gasParams = GasParams(
kind: SelfDestruct,
sd_condition: not cpt.accountExists(beneficiary))
@ -105,7 +109,7 @@ const
checkInStaticContext(cpt)
let beneficiary = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, beneficiary)):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, beneficiary), [CatchableError]):
let
isDead = not cpt.accountExists(beneficiary)
balance = cpt.getBalance(cpt.msg.contractAddress)
@ -127,7 +131,7 @@ const
checkInStaticContext(cpt)
let beneficiary = cpt.stack.popAddress()
cpt.asyncChainTo(ifNecessaryGetAccount(cpt.vmState, beneficiary)):
cpt.asyncChainToRaise(ifNecessaryGetAccount(cpt.vmState, beneficiary), [CatchableError]):
let
isDead = not cpt.accountExists(beneficiary)
balance = cpt.getBalance(cpt.msg.contractAddress)

View File

@ -1,6 +1,6 @@
# Nimbus - Dynamic loader for EVM modules as shared libraries / DLLs
#
# Copyright (c) 2019-2021 Status Research & Development GmbH
# Copyright (c) 2019-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
@ -71,7 +71,7 @@ proc evmcLoadVMGetCreateFn(): (evmc_create_vm_name_fn, string) =
# Search for the built function name.
symbolName = "evmc_create_" & symbolName
var sym = symAddr(lib, symbolName)
var sym = symAddr(lib, symbolName.cstring)
if sym.isNil:
const fallback = "evmc_create"
sym = symAddr(lib, fallback)

View File

@ -274,7 +274,7 @@ proc emitLog(host: TransactionHost, address: HostAddress,
copyMem(log.data[0].addr, data, data_size.int)
log.address = address
host.vmState.stateDB.addlogEntry(log)
host.vmState.stateDB.addLogEntry(log)
proc accessAccount(host: TransactionHost, address: HostAddress): EvmcAccessStatus {.show.} =
host.vmState.mutateStateDB:
@ -304,7 +304,7 @@ proc setTransientStorage(host: TransactionHost, address: HostAddress,
when use_evmc_glue:
{.pop: inline.}
const included_from_host_services = true
const included_from_host_services {.used.} = true
include ./evmc_host_glue
else:
export