use --styleCheck:error (#2242)

* use --styleCheck:error

* rename evm/types.nim statusCode to evmStatus
This commit is contained in:
tersec 2024-05-30 09:01:07 +00:00 committed by GitHub
parent 1eb170e686
commit 6a9ca40cc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 28 deletions

View File

@ -106,7 +106,7 @@ if not defined(windows):
# for heap-usage-by-instance-type metrics and object base-type strings
--define:nimTypeNames
--styleCheck:usages
--styleCheck:hint
--styleCheck:error
--mm:refc
switch("define", "withoutPCRE")

View File

@ -235,7 +235,7 @@ proc newComputation*(vmState: BaseVMState, sysCall: bool, message: Message,
result.code = newCodeStream(
vmState.readOnlyStateDB.getCode(message.codeAddress))
proc newComputation*(vmState: BaseVMState, sysCall: bool,
func newComputation*(vmState: BaseVMState, sysCall: bool,
message: Message, code: seq[byte]): Computation =
new result
result.vmState = vmState
@ -275,25 +275,26 @@ proc dispose*(c: Computation) =
proc rollback*(c: Computation) =
c.vmState.stateDB.rollback(c.savePoint)
proc setError*(c: Computation, msg: string, burnsGas = false) =
c.error = Error(statusCode: EVMC_FAILURE, info: msg, burnsGas: burnsGas)
func setError*(c: Computation, msg: string, burnsGas = false) =
c.error = Error(evmcStatus: EVMC_FAILURE, info: msg, burnsGas: burnsGas)
proc setError*(c: Computation, code: evmc_status_code, burnsGas = false) =
c.error = Error(statusCode: code, info: $code, burnsGas: burnsGas)
func setError*(c: Computation, code: evmc_status_code, burnsGas = false) =
c.error = Error(evmcStatus: code, info: $code, burnsGas: burnsGas)
proc setError*(c: Computation, code: evmc_status_code, msg: string, burnsGas = false) =
c.error = Error(statusCode: code, info: msg, burnsGas: burnsGas)
func setError*(
c: Computation, code: evmc_status_code, msg: string, burnsGas = false) =
c.error = Error(evmcStatus: code, info: msg, burnsGas: burnsGas)
func statusCode*(c: Computation): evmc_status_code =
func evmcStatus*(c: Computation): evmc_status_code =
if c.isSuccess:
EVMC_SUCCESS
else:
c.error.statusCode
c.error.evmcStatus
func errorOpt*(c: Computation): Option[string] =
if c.isSuccess:
return none(string)
if c.error.statusCode == EVMC_REVERT:
if c.error.evmcStatus == EVMC_REVERT:
return none(string)
some(c.error.info)
@ -384,7 +385,7 @@ template asyncChainToRaise*(c: Computation,
c.continuation = nil
after
proc merge*(c, child: Computation) =
func merge*(c, child: Computation) =
c.gasMeter.refundGas(child.gasMeter.gasRefunded)
when evmc_enabled:
@ -418,22 +419,22 @@ proc execSelfDestruct*(c: Computation, beneficiary: EthAddress)
localBalance = localBalance.toString,
beneficiary = beneficiary.toHex
proc addLogEntry*(c: Computation, log: Log) =
func addLogEntry*(c: Computation, log: Log) =
c.vmState.stateDB.addLogEntry(log)
proc getGasRefund*(c: Computation): GasInt =
func getGasRefund*(c: Computation): GasInt =
if c.isSuccess:
result = c.gasMeter.gasRefunded
proc refundSelfDestruct*(c: Computation) =
func refundSelfDestruct*(c: Computation) =
let cost = gasFees[c.fork][RefundSelfDestruct]
let num = c.vmState.stateDB.selfDestructLen
c.gasMeter.refundGas(cost * num)
proc tracingEnabled*(c: Computation): bool =
func tracingEnabled*(c: Computation): bool =
c.vmState.tracingEnabled
proc traceOpCodeStarted*(c: Computation, op: Op): int {.gcsafe, raises: [].} =
func traceOpCodeStarted*(c: Computation, op: Op): int {.raises: [].} =
c.vmState.captureOpStart(
c,
c.code.pc - 1,
@ -441,7 +442,7 @@ proc traceOpCodeStarted*(c: Computation, op: Op): int {.gcsafe, raises: [].} =
c.gasMeter.gasRemaining,
c.msg.depth + 1)
proc traceOpCodeEnded*(c: Computation, op: Op, opIndex: int) {.gcsafe, raises: [].} =
func traceOpCodeEnded*(c: Computation, op: Op, opIndex: int) {.raises: [].} =
c.vmState.captureOpEnd(
c,
c.code.pc - 1,
@ -452,7 +453,7 @@ proc traceOpCodeEnded*(c: Computation, op: Op, opIndex: int) {.gcsafe, raises: [
c.msg.depth + 1,
opIndex)
proc traceError*(c: Computation) {.gcsafe, raises: [].} =
func traceError*(c: Computation) {.raises: [].} =
c.vmState.captureFault(
c,
c.code.pc - 1,
@ -463,10 +464,12 @@ proc traceError*(c: Computation) {.gcsafe, raises: [].} =
c.msg.depth + 1,
c.errorOpt)
proc prepareTracer*(c: Computation) =
func prepareTracer*(c: Computation) =
c.vmState.capturePrepare(c, c.msg.depth)
proc opcodeGastCost*(c: Computation, op: Op, gasCost: GasInt, reason: string) {.gcsafe, raises: [OutOfGas, ValueError].} =
func opcodeGastCost*(
c: Computation, op: Op, gasCost: GasInt, reason: string)
{.raises: [OutOfGas, ValueError].} =
c.vmState.captureGasCost(
c,
op,

View File

@ -96,7 +96,7 @@ type
sysCall*: bool
Error* = ref object
statusCode*: evmc_status_code
evmcStatus*: evmc_status_code
info* : string
burnsGas* : bool

View File

@ -62,7 +62,7 @@ proc evmcExecute(vm: ptr evmc_vm, hostInterface: ptr evmc_host_interface,
return evmc_result(
# Standard EVMC result, if a bit generic.
status_code: c.statusCode,
status_code: c.evmcStatus,
# Gas left is required to be zero when not `EVMC_SUCCESS` or `EVMC_REVERT`.
gas_left: if result.status_code notin {EVMC_SUCCESS, EVMC_REVERT}: 0'i64
else: c.gasMeter.gasRemaining.int64,

View File

@ -1,6 +1,6 @@
# Nimbus - Services available to EVM code that is run for a transaction
#
# 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)
@ -43,7 +43,7 @@ proc afterExecCreateEvmcNested(host: TransactionHost, child: Computation,
res.status_code = EVMC_SUCCESS
res.create_address = child.msg.contractAddress.toEvmc
else:
res.status_code = child.statusCode
res.status_code = child.evmcStatus
if child.output.len > 0:
# TODO: can we move the ownership of seq to raw pointer?
res.output_size = child.output.len.uint
@ -78,7 +78,7 @@ proc afterExecCallEvmcNested(host: TransactionHost, child: Computation,
host.computation.merge(child)
res.status_code = EVMC_SUCCESS
else:
res.status_code = child.statusCode
res.status_code = child.evmcStatus
if child.output.len > 0:
# TODO: can we move the ownership of seq to raw pointer?

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)
@ -54,7 +54,7 @@ export
vmc.traceOpCodeStarted,
vmc.tracingEnabled,
vmc.writeContract,
vmc.statusCode,
vmc.evmcStatus,
vmc.errorOpt
# End