# 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 chronos, json_rpc/rpcclient, "."/[stack, memory, code_stream], ./interpreter/[gas_costs, op_codes], ./async/data_sources, ../db/accounts_cache, ../common/[common, evmforks] {.push raises: [].} when defined(evmc_enabled): import ./evmc_api # Select between small-stack recursion and no recursion. Both are good, fast, # low resource using methods. Keep both here because true EVMC API requires # the small-stack method, but Chronos `async` is better without recursion. const vm_use_recursion* = defined(evmc_enabled) type VMFlag* = enum ExecutionOK GenerateWitness ClearCache BaseVMState* = ref object of RootObj prevHeaders* : seq[BlockHeader] com* : CommonRef gasPool* : GasInt parent* : BlockHeader timestamp* : EthTime gasLimit* : GasInt fee* : Option[UInt256] prevRandao* : Hash256 blockDifficulty*: UInt256 flags* : set[VMFlag] tracer* : TracerRef receipts* : seq[Receipt] stateDB* : AccountsCache cumulativeGasUsed*: GasInt txOrigin* : EthAddress txGasPrice* : GasInt txVersionedHashes*: VersionedHashes gasCosts* : GasCosts fork* : EVMFork minerAddress* : EthAddress asyncFactory* : AsyncOperationFactory Computation* = ref object # The execution computation vmState*: BaseVMState msg*: Message memory*: Memory stack*: Stack returnStack*: seq[int] gasMeter*: GasMeter code*: CodeStream output*: seq[byte] returnData*: seq[byte] error*: Error savePoint*: SavePoint instr*: Op opIndex*: int when defined(evmc_enabled): host*: HostContext child*: ref nimbus_message res*: nimbus_result else: parent*, child*: Computation pendingAsyncOperation*: Future[void] continuation*: proc() {.gcsafe, raises: [CatchableError].} 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 TracerFlags* {.pure.} = enum DisableStorage DisableMemory DisableStack DisableState DisableStateDiff EnableAccount DisableReturnData StructLog* = object pc* : int op* : Op gas* : GasInt gasCost* : GasInt memory* : seq[byte] memSize* : int stack* : seq[UInt256] returnData* : seq[byte] storage* : Table[UInt256, UInt256] depth* : int refund* : GasInt opName* : string error* : string TracerRef* = ref object of RootObj flags*: set[TracerFlags] # Transaction level method captureTxStart*(ctx: TracerRef, gasLimit: GasInt) {.base, gcsafe.} = discard method captureTxEnd*(ctx: TracerRef, restGas: GasInt) {.base, gcsafe.} = discard # Top call frame method captureStart*(ctx: TracerRef, c: Computation, sender: EthAddress, to: EthAddress, create: bool, input: openArray[byte], gas: GasInt, value: UInt256) {.base, gcsafe.} = discard method captureEnd*(ctx: TracerRef, output: openArray[byte], gasUsed: GasInt, error: Option[string]) {.base, gcsafe.} = discard # Rest of call frames method captureEnter*(ctx: TracerRef, op: Op, sender: EthAddress, to: EthAddress, input: openArray[byte], gas: GasInt, value: UInt256) {.base, gcsafe.} = discard method captureExit*(ctx: TracerRef, output: openArray[byte], gasUsed: GasInt, error: Option[string]) {.base, gcsafe.} = discard # Opcode level method captureOpStart*(ctx: TracerRef, pc: int, op: Op, gas: GasInt, depth: int): int {.base, gcsafe.} = discard method captureOpEnd*(ctx: TracerRef, pc: int, op: Op, gas: GasInt, refund: GasInt, rData: openArray[byte], depth: int, opIndex: int) {.base, gcsafe.} = discard method captureFault*(ctx: TracerRef, pc: int, op: Op, gas: GasInt, refund: GasInt, rData: openArray[byte], depth: int, error: Option[string]) {.base, gcsafe.} = discard method capturePrepare*(ctx: TracerRef, depth: int) {.base, gcsafe.} = discard