From 45558282f788d4101140c530fc2f2df45432690e Mon Sep 17 00:00:00 2001 From: Jordan Hrycaj Date: Fri, 23 Apr 2021 11:15:38 +0100 Subject: [PATCH] merged oph_*_kludge.nim sources => single oph_kludge.nim --- .../vm2/interpreter/op_handlers/oph_call.nim | 3 +- .../interpreter/op_handlers/oph_create.nim | 3 +- .../vm2/interpreter/op_handlers/oph_defs.nim | 4 +- .../op_handlers/oph_defs_kludge.nim | 121 ------------------ .../interpreter/op_handlers/oph_helpers.nim | 4 +- ...{oph_helpers_kludge.nim => oph_kludge.nim} | 95 +++++++++++++- nimbus/vm2/state_transactions.nim | 2 +- 7 files changed, 98 insertions(+), 134 deletions(-) delete mode 100644 nimbus/vm2/interpreter/op_handlers/oph_defs_kludge.nim rename nimbus/vm2/interpreter/op_handlers/{oph_helpers_kludge.nim => oph_kludge.nim} (64%) diff --git a/nimbus/vm2/interpreter/op_handlers/oph_call.nim b/nimbus/vm2/interpreter/op_handlers/oph_call.nim index 5c06322d7..0b546b0da 100644 --- a/nimbus/vm2/interpreter/op_handlers/oph_call.nim +++ b/nimbus/vm2/interpreter/op_handlers/oph_call.nim @@ -46,8 +46,7 @@ when not breakCircularDependency: else: import - ./oph_defs_kludge, - ./oph_helpers_kludge + ./oph_kludge # ------------------------------------------------------------------------------ # Kludge END diff --git a/nimbus/vm2/interpreter/op_handlers/oph_create.nim b/nimbus/vm2/interpreter/op_handlers/oph_create.nim index 67a4574de..68dbf7877 100644 --- a/nimbus/vm2/interpreter/op_handlers/oph_create.nim +++ b/nimbus/vm2/interpreter/op_handlers/oph_create.nim @@ -47,8 +47,7 @@ when not breakCircularDependency: else: import - ./oph_defs_kludge, - ./oph_helpers_kludge + ./oph_kludge # ------------------------------------------------------------------------------ # Kludge END diff --git a/nimbus/vm2/interpreter/op_handlers/oph_defs.nim b/nimbus/vm2/interpreter/op_handlers/oph_defs.nim index 199ecb862..b4d8768b7 100644 --- a/nimbus/vm2/interpreter/op_handlers/oph_defs.nim +++ b/nimbus/vm2/interpreter/op_handlers/oph_defs.nim @@ -13,10 +13,10 @@ ## # Including types.nim needed unless included (not imported) into -# oph_defs_kludge.nim +# oph_kludge.nim # # Note that the nim compiler will distinguish tuples defined -# here when imported and from oph_defs_kludge.nim. This is so due to the +# here when imported and from oph_kludge.nim. This is so due to the # duplicate/different Computation definitions. # when not declared(Computation): diff --git a/nimbus/vm2/interpreter/op_handlers/oph_defs_kludge.nim b/nimbus/vm2/interpreter/op_handlers/oph_defs_kludge.nim deleted file mode 100644 index 5b0d66a96..000000000 --- a/nimbus/vm2/interpreter/op_handlers/oph_defs_kludge.nim +++ /dev/null @@ -1,121 +0,0 @@ -# Nimbus -# Copyright (c) 2018 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) -# at your option. This file may not be copied, modified, or distributed except -# according to those terms. - -## EVM Opcodes, Definitions -- Kludge Version -## ========================================== -## - -{.warning: "Circular dependency breaker kludge -- no production code".} - -import - ../forks_list, - ../op_codes, - ../../memory, - ../../stack, - eth/common/eth_types, - sets - -# ------------------------------------------------------------------------------ -# Kludge BEGIN -# ------------------------------------------------------------------------------ - -type - MsgFlags* = enum - emvcNoFlags = 0 - emvcStatic = 1 - - CallKind* = enum - evmcCall = 0 # CALL - evmcDelegateCall = 1 # DELEGATECALL - evmcCallCode = 2 # CALLCODE - evmcCreate = 3 # CREATE - evmcCreate2 = 4 # CREATE2 - - ReadOnlyStateDB* = - seq[byte] - - GasMeter* = object - gasRefunded*: GasInt - gasRemaining*: GasInt - - CodeStream* = ref object - bytes*: seq[byte] - pc*: int - - ChainId* = uint # distinct uint - - ChainConfig* = object - chainId*: ChainId - homesteadBlock*: BlockNumber - daoForkBlock*: BlockNumber - daoForkSupport*: bool - - AccountsCache* = ref object - isDirty: bool - - BaseChainDB* = ref object - pruneTrie*: bool - config*: ChainConfig - - GasCost* = object - opaq: int - - GasCosts* = array[Op, GasCost] - - BaseVMState* = ref object of RootObj - chaindb* : BaseChainDB - blockHeader* : BlockHeader - logEntries* : seq[Log] - accountDb* : AccountsCache - touchedAccounts*: HashSet[EthAddress] - suicides* : HashSet[EthAddress] - txOrigin* : EthAddress - txGasPrice* : GasInt - gasCosts* : GasCosts - fork* : Fork - - Message* = ref object - kind*: CallKind - depth*: int - gas*: GasInt - contractAddress*: EthAddress - codeAddress*: EthAddress - sender*: EthAddress - value*: UInt256 - data*: seq[byte] - flags*: MsgFlags - - Computation* = ref object - returnStack*: seq[int] - output*: seq[byte] - vmState*: BaseVMState - gasMeter*: GasMeter - stack*: Stack - memory*: Memory - msg*: Message - code*: CodeStream - returnData*: seq[byte] - fork*: Fork - parent*, child*: Computation - continuation*: proc() {.gcsafe.} - touchedAccounts*: HashSet[EthAddress] - suicides*: HashSet[EthAddress] - logEntries*: seq[Log] - -# ------------------------------------------------------------------------------ -# Kludge END -# ------------------------------------------------------------------------------ - -include - ./oph_defs - -# ------------------------------------------------------------------------------ -# End -# ------------------------------------------------------------------------------ diff --git a/nimbus/vm2/interpreter/op_handlers/oph_helpers.nim b/nimbus/vm2/interpreter/op_handlers/oph_helpers.nim index 9719ec68f..cc025a4c6 100644 --- a/nimbus/vm2/interpreter/op_handlers/oph_helpers.nim +++ b/nimbus/vm2/interpreter/op_handlers/oph_helpers.nim @@ -13,9 +13,9 @@ ## # Including types.nim and others unless included (not imported) into -# oph_helpes_kludge.nim +# oph_kludge.nim # -when not declared(consumeGas): +when not declared(Computation): import ../../../db/accounts_cache, ../../state, diff --git a/nimbus/vm2/interpreter/op_handlers/oph_helpers_kludge.nim b/nimbus/vm2/interpreter/op_handlers/oph_kludge.nim similarity index 64% rename from nimbus/vm2/interpreter/op_handlers/oph_helpers_kludge.nim rename to nimbus/vm2/interpreter/op_handlers/oph_kludge.nim index 73c1bb62e..bd1c190c7 100644 --- a/nimbus/vm2/interpreter/op_handlers/oph_helpers_kludge.nim +++ b/nimbus/vm2/interpreter/op_handlers/oph_kludge.nim @@ -8,17 +8,21 @@ # at your option. This file may not be copied, modified, or distributed except # according to those terms. -## EVM Opcode Handlers: Helper Functions -- Kludge Version -## ======================================================= +## EVM Opcodes, Definitions -- Kludge Version +## ========================================== ## +{.warning: "Circular dependency breaker kludge -- no production code".} + import ../../../errors, + ../../memory, + ../../stack, ../forks_list, ../op_codes, - ./oph_defs_kludge, eth/common/eth_types, macros, + sets, stint, strutils @@ -26,6 +30,89 @@ import # Kludge BEGIN # ------------------------------------------------------------------------------ +type + MsgFlags* = enum + emvcNoFlags = 0 + emvcStatic = 1 + + CallKind* = enum + evmcCall = 0 # CALL + evmcDelegateCall = 1 # DELEGATECALL + evmcCallCode = 2 # CALLCODE + evmcCreate = 3 # CREATE + evmcCreate2 = 4 # CREATE2 + + ReadOnlyStateDB* = + seq[byte] + + GasMeter* = object + gasRefunded*: GasInt + gasRemaining*: GasInt + + CodeStream* = ref object + bytes*: seq[byte] + pc*: int + + ChainId* = uint # distinct uint + + ChainConfig* = object + chainId*: ChainId + homesteadBlock*: BlockNumber + daoForkBlock*: BlockNumber + daoForkSupport*: bool + + AccountsCache* = ref object + isDirty: bool + + BaseChainDB* = ref object + pruneTrie*: bool + config*: ChainConfig + + GasCost* = object + opaq: int + + GasCosts* = array[Op, GasCost] + + BaseVMState* = ref object of RootObj + chaindb* : BaseChainDB + blockHeader* : BlockHeader + logEntries* : seq[Log] + accountDb* : AccountsCache + touchedAccounts*: HashSet[EthAddress] + suicides* : HashSet[EthAddress] + txOrigin* : EthAddress + txGasPrice* : GasInt + gasCosts* : GasCosts + fork* : Fork + + Message* = ref object + kind*: CallKind + depth*: int + gas*: GasInt + contractAddress*: EthAddress + codeAddress*: EthAddress + sender*: EthAddress + value*: UInt256 + data*: seq[byte] + flags*: MsgFlags + + Computation* = ref object + returnStack*: seq[int] + output*: seq[byte] + vmState*: BaseVMState + gasMeter*: GasMeter + stack*: Stack + memory*: Memory + msg*: Message + code*: CodeStream + returnData*: seq[byte] + fork*: Fork + parent*, child*: Computation + continuation*: proc() {.gcsafe.} + touchedAccounts*: HashSet[EthAddress] + suicides*: HashSet[EthAddress] + logEntries*: seq[Log] + const ColdAccountAccessCost* = 2 WarmStorageReadCost* = 3 @@ -99,9 +186,9 @@ proc isCreate*(message: Message): bool = result # ------------------------------------------------------------------------------ include + ./oph_defs, ./oph_helpers # ------------------------------------------------------------------------------ # End # ------------------------------------------------------------------------------ - diff --git a/nimbus/vm2/state_transactions.nim b/nimbus/vm2/state_transactions.nim index fb6a9bc42..9ce7240ea 100644 --- a/nimbus/vm2/state_transactions.nim +++ b/nimbus/vm2/state_transactions.nim @@ -38,7 +38,7 @@ when not breakCircularDependency: else: import - ./interpreter/op_handlers/[oph_defs_kludge, oph_helpers_kludge] + ./interpreter/op_handlers/oph_kludge # ------------------------------------------------------------------------------ # Kludge END