Skip to content

Commit

Permalink
use --styleCheck:error (#2242)
Browse files Browse the repository at this point in the history
* use --styleCheck:error

* rename evm/types.nim statusCode to evmStatus
  • Loading branch information
tersec committed May 30, 2024
1 parent 1eb170e commit 6a9ca40
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
43 changes: 23 additions & 20 deletions nimbus/evm/computation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -418,30 +419,30 @@ 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,
op,
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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion nimbus/evm/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type
sysCall*: bool

Error* = ref object
statusCode*: evmc_status_code
evmcStatus*: evmc_status_code
info* : string
burnsGas* : bool

Expand Down
2 changes: 1 addition & 1 deletion nimbus/transaction/evmc_vm_glue.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions nimbus/transaction/host_call_nested.nim
Original file line number Diff line number Diff line change
@@ -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:https://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http:https://opensource.org/licenses/MIT)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions nimbus/vm_computation.nim
Original file line number Diff line number Diff line change
@@ -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:https://www.apache.org/licenses/LICENSE-2.0)
Expand Down Expand Up @@ -54,7 +54,7 @@ export
vmc.traceOpCodeStarted,
vmc.tracingEnabled,
vmc.writeContract,
vmc.statusCode,
vmc.evmcStatus,
vmc.errorOpt

# End

0 comments on commit 6a9ca40

Please sign in to comment.