isolate vm_types as import/export wrapper

details:
  moved original vm_types.nim => vm/nvm_types.nim
This commit is contained in:
Jordan Hrycaj 2021-03-31 09:21:27 +01:00
parent a3db0f41d8
commit ed59f602d5
No known key found for this signature in database
GPG Key ID: 4101B9BC5A0DB080
10 changed files with 171 additions and 112 deletions

View File

@ -8,7 +8,7 @@
import
chronicles, strformat, macros, options, times,
sets, eth/[common, keys],
constants, errors, vm_state, vm_types,
constants, errors, vm_state, vm/nvm_types,
vm/interpreter/[opcode_values, gas_meter, gas_costs, vm_forks],
vm/code_stream, vm/memory, vm/message, vm/stack, db/[accounts_cache, db_chain],
utils/header, precompiles,

View File

@ -7,7 +7,7 @@
import
chronicles, strformat, eth/common, # GasInt
errors, vm_types
errors, vm/nvm_types
logScope:
topics = "vm gas"

View File

@ -11,7 +11,7 @@ import
vm/interpreter/utils/[macros_procs_opcodes, utils_numeric],
vm/interpreter/[gas_meter, gas_costs, opcode_values, vm_forks],
vm/[memory, stack, code_stream, computation],
vm_state, errors, constants, vm_types,
vm_state, errors, constants, vm/nvm_types,
db/[db_chain, accounts_cache]
when defined(evmc_enabled):

View File

@ -11,7 +11,7 @@
import
macros, strformat, stint, eth/common,
vm/[computation, stack, code_stream, memory],
vm_types, errors, vm/interpreter/[gas_meter, opcode_values],
vm/nvm_types, errors, vm/interpreter/[gas_meter, opcode_values],
vm/interpreter/utils/utils_numeric
when defined(evmc_enabled):

View File

@ -9,7 +9,7 @@ import
tables, macros,
chronicles,
vm/interpreter/[opcode_values, opcodes_impl, vm_forks, gas_costs, gas_meter, utils/macros_gen_opcodes],
vm/code_stream, vm_types, errors, precompiles, vm/stack,
vm/code_stream, vm/nvm_types, errors, precompiles, vm/stack,
terminal # Those are only needed for logging
logScope:

View File

@ -5,7 +5,7 @@
# * 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.
import vm_types
import vm/nvm_types
proc isCreate*(message: Message): bool =
message.kind in {evmcCreate, evmcCreate2}

117
nimbus/vm/nvm_types.nim Normal file
View File

@ -0,0 +1,117 @@
# 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.
import
tables, eth/common,
options, json, sets,
vm/[memory, stack, code_stream],
vm/interpreter/[gas_costs, opcode_values, vm_forks],
# TODO - will be hidden at a lower layer
db/[db_chain, accounts_cache]
when defined(evmc_enabled):
import
./vm/evmc_api
type
VMFlag* = enum
ExecutionOK
GenerateWitness
ClearCache
BaseVMState* = ref object of RootObj
prevHeaders* : seq[BlockHeader]
chaindb* : BaseChainDB
accessLogs* : AccessLogs
blockHeader* : BlockHeader
name* : string
flags* : set[VMFlag]
tracer* : TransactionTracer
logEntries* : seq[Log]
receipts* : seq[Receipt]
accountDb* : AccountsCache
cumulativeGasUsed*: GasInt
touchedAccounts*: HashSet[EthAddress]
suicides* : HashSet[EthAddress]
txOrigin* : EthAddress
txGasPrice* : GasInt
gasCosts* : GasCosts
fork* : Fork
minerAddress* : EthAddress
AccessLogs* = ref object
reads*: Table[string, string]
writes*: Table[string, string]
TracerFlags* {.pure.} = enum
EnableTracing
DisableStorage
DisableMemory
DisableStack
DisableState
DisableStateDiff
EnableAccount
TransactionTracer* = object
trace*: JsonNode
flags*: set[TracerFlags]
accounts*: HashSet[EthAddress]
storageKeys*: seq[HashSet[Uint256]]
Computation* = ref object
# The execution computation
vmState*: BaseVMState
when defined(evmc_enabled):
host*: HostContext
msg*: Message
memory*: Memory
stack*: Stack
returnStack*: seq[int]
gasMeter*: GasMeter
code*: CodeStream
output*: seq[byte]
returnData*: seq[byte]
error*: Error
touchedAccounts*: HashSet[EthAddress]
suicides*: HashSet[EthAddress]
logEntries*: seq[Log]
savePoint*: SavePoint
instr*: Op
opIndex*: int
Error* = ref object
info*: string
burnsGas*: bool
GasMeter* = object
gasRefunded*: GasInt
gasRemaining*: GasInt
CallKind* = enum
evmcCall = 0, # CALL
evmcDelegateCall = 1, # DELEGATECALL
evmcCallCode = 2, # CALLCODE
evmcCreate = 3, # CREATE
evmcCreate2 = 4 # CREATE2
MsgFlags* = enum
emvcNoFlags = 0
emvcStatic = 1
Message* = ref object
kind*: CallKind
depth*: int
gas*: GasInt
sender*: EthAddress
contractAddress*: EthAddress
codeAddress*: EthAddress
value*: UInt256
data*: seq[byte]
flags*: MsgFlags

View File

@ -1,5 +1,5 @@
import
vm_types,
vm/nvm_types,
vm/interpreter/[gas_meter, gas_costs, utils/utils_numeric, vm_forks],
errors, stint, eth/[keys, common], chronicles, tables, macros,
math, nimcrypto, bncurve/[fields, groups], vm/blake2b_f, vm/blscurve

View File

@ -1,7 +1,7 @@
import
json, strutils, sets, hashes,
chronicles, nimcrypto, eth/common, stint,
vm_types, memory, vm/stack, db/accounts_cache,
vm/nvm_types, memory, vm/stack, db/accounts_cache,
eth/trie/hexary,
vm/interpreter/opcode_values

View File

@ -1,112 +1,54 @@
# 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.
# * 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.
import
tables, eth/common,
options, json, sets,
vm/[memory, stack, code_stream],
vm/interpreter/[gas_costs, opcode_values, vm_forks], # TODO - will be hidden at a lower layer
db/[db_chain, accounts_cache]
./vm/nvm_types as vmt
export
vmt.AccessLogs,
vmt.BaseVMState,
vmt.CallKind,
vmt.Computation,
vmt.Error,
vmt.GasMeter,
vmt.Message,
vmt.MsgFlags,
vmt.TracerFlags,
vmt.TransactionTracer,
vmt.VMFlag
when defined(evmc_enabled):
import ./vm/evmc_api
import
./vm/evmc_api as evmc
export
evmc.HostContext,
evmc.accountExists,
evmc.call,
evmc.copyCode,
evmc.emitLog,
evmc.getBalance,
evmc.getBlockHash,
evmc.getCodeHash,
evmc.getCodeSize,
evmc.getStorage,
evmc.getTxContext,
evmc.init,
evmc.nim_create_nimbus_vm,
evmc.nim_host_create_context,
evmc.nim_host_destroy_context,
evmc.nim_host_get_interface,
evmc.nimbus_host_interface,
evmc.nimbus_message,
evmc.nimbus_result,
evmc.nimbus_tx_context,
evmc.selfDestruct,
evmc.setStorage
type
VMFlag* = enum
ExecutionOK
GenerateWitness
ClearCache
BaseVMState* = ref object of RootObj
prevHeaders* : seq[BlockHeader]
chaindb* : BaseChainDB
accessLogs* : AccessLogs
blockHeader* : BlockHeader
name* : string
flags* : set[VMFlag]
tracer* : TransactionTracer
logEntries* : seq[Log]
receipts* : seq[Receipt]
accountDb* : AccountsCache
cumulativeGasUsed*: GasInt
touchedAccounts*: HashSet[EthAddress]
suicides* : HashSet[EthAddress]
txOrigin* : EthAddress
txGasPrice* : GasInt
gasCosts* : GasCosts
fork* : Fork
minerAddress* : EthAddress
AccessLogs* = ref object
reads*: Table[string, string]
writes*: Table[string, string]
TracerFlags* {.pure.} = enum
EnableTracing
DisableStorage
DisableMemory
DisableStack
DisableState
DisableStateDiff
EnableAccount
TransactionTracer* = object
trace*: JsonNode
flags*: set[TracerFlags]
accounts*: HashSet[EthAddress]
storageKeys*: seq[HashSet[Uint256]]
Computation* = ref object
# The execution computation
vmState*: BaseVMState
when defined(evmc_enabled):
host*: HostContext
msg*: Message
memory*: Memory
stack*: Stack
returnStack*: seq[int]
gasMeter*: GasMeter
code*: CodeStream
output*: seq[byte]
returnData*: seq[byte]
error*: Error
touchedAccounts*: HashSet[EthAddress]
suicides*: HashSet[EthAddress]
logEntries*: seq[Log]
savePoint*: SavePoint
instr*: Op
opIndex*: int
Error* = ref object
info*: string
burnsGas*: bool
GasMeter* = object
gasRefunded*: GasInt
gasRemaining*: GasInt
CallKind* = enum
evmcCall = 0, # CALL
evmcDelegateCall = 1, # DELEGATECALL
evmcCallCode = 2, # CALLCODE
evmcCreate = 3, # CREATE
evmcCreate2 = 4 # CREATE2
MsgFlags* = enum
emvcNoFlags = 0
emvcStatic = 1
Message* = ref object
kind*: CallKind
depth*: int
gas*: GasInt
sender*: EthAddress
contractAddress*: EthAddress
codeAddress*: EthAddress
value*: UInt256
data*: seq[byte]
flags*: MsgFlags
# End