2021-04-12 17:13:30 +00:00
|
|
|
# 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.
|
|
|
|
|
2021-04-13 17:12:47 +00:00
|
|
|
## EVM Opcodes, Definitions
|
|
|
|
## ========================
|
2021-04-12 17:13:30 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
const
|
|
|
|
kludge {.intdefine.}: int = 0
|
|
|
|
breakCircularDependency {.used.} = kludge > 0
|
|
|
|
|
|
|
|
import
|
|
|
|
../forks_list,
|
|
|
|
../op_codes,
|
|
|
|
../../memory_defs,
|
2021-04-15 13:40:31 +00:00
|
|
|
../../stack_defs,
|
|
|
|
eth/common/eth_types
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Kludge BEGIN
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
when not breakCircularDependency:
|
|
|
|
import
|
|
|
|
../../v2types
|
|
|
|
else:
|
|
|
|
{.warning: "Circular dependency breaker kludge -- "&
|
|
|
|
"no production code".}
|
|
|
|
when defined(vm2_enabled):
|
|
|
|
{.fatal: "Flag \"vm2_enabled\" must be unset "&
|
|
|
|
"while circular dependency breaker kludge is activated".}
|
|
|
|
type
|
2021-04-16 10:53:05 +00:00
|
|
|
GasInt* = int
|
|
|
|
|
2021-04-14 16:34:24 +00:00
|
|
|
ReadOnlyStateDB* =
|
|
|
|
seq[byte]
|
|
|
|
|
2021-04-13 17:12:47 +00:00
|
|
|
GasMeter* = object
|
2021-04-14 16:34:24 +00:00
|
|
|
gasRemaining*: int
|
2021-04-13 17:12:47 +00:00
|
|
|
|
|
|
|
CodeStream* = ref object
|
|
|
|
bytes*: seq[byte]
|
2021-04-14 16:34:24 +00:00
|
|
|
pc*: int
|
|
|
|
|
|
|
|
BaseVMState* = ref object
|
|
|
|
accountDb*: ReadOnlyStateDB
|
2021-04-13 17:12:47 +00:00
|
|
|
|
|
|
|
Message* = ref object
|
2021-04-16 10:53:05 +00:00
|
|
|
kind*: int
|
|
|
|
depth*: int
|
|
|
|
gas*: GasInt
|
2021-04-15 13:40:31 +00:00
|
|
|
contractAddress*: EthAddress
|
2021-04-16 15:06:02 +00:00
|
|
|
codeAddress*: EthAddress
|
2021-04-16 10:53:05 +00:00
|
|
|
sender*: EthAddress
|
2021-04-13 17:12:47 +00:00
|
|
|
value*: UInt256
|
|
|
|
data*: seq[byte]
|
2021-04-14 16:34:24 +00:00
|
|
|
flags*: int
|
2021-04-13 17:12:47 +00:00
|
|
|
|
2021-04-12 17:13:30 +00:00
|
|
|
Computation* = ref object
|
2021-04-14 16:34:24 +00:00
|
|
|
returnStack*: seq[int]
|
2021-04-15 17:42:43 +00:00
|
|
|
output*: seq[byte]
|
2021-04-14 16:34:24 +00:00
|
|
|
vmState*: BaseVMState
|
2021-04-13 17:12:47 +00:00
|
|
|
gasMeter*: GasMeter
|
2021-04-12 17:13:30 +00:00
|
|
|
stack*: Stack
|
|
|
|
memory*: Memory
|
2021-04-13 17:12:47 +00:00
|
|
|
msg*: Message
|
|
|
|
code*: CodeStream
|
|
|
|
returnData*: seq[byte]
|
2021-04-15 16:42:19 +00:00
|
|
|
fork*: Fork
|
2021-04-16 10:53:05 +00:00
|
|
|
parent*, child*: Computation
|
|
|
|
continuation*: proc() {.gcsafe.}
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Kludge END
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export
|
2021-04-15 13:40:31 +00:00
|
|
|
Op, Fork, Computation, Memory, Stack, UInt256, Message, EthAddress
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
type
|
2021-04-20 12:07:01 +00:00
|
|
|
Vm2Ctx* = tuple
|
|
|
|
cpt: Computation ## computation text
|
|
|
|
rc: int ## return code from op handler
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
Vm2OpFn* = ## general op handler, return codes are passed
|
|
|
|
## back via argument descriptor ``k``
|
2021-04-20 12:07:01 +00:00
|
|
|
proc(k: var Vm2Ctx) {.gcsafe.}
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
Vm2OpHanders* = tuple ## three step op code execution, typically
|
|
|
|
## only the ``run`` entry is activated
|
|
|
|
prep: Vm2OpFn
|
|
|
|
run: Vm2OpFn
|
|
|
|
post: Vm2OpFn
|
|
|
|
|
|
|
|
|
|
|
|
Vm2OpExec* = tuple ## op code handler entry
|
|
|
|
opCode: Op ## index back-reference
|
|
|
|
forks: set[Fork] ## forks applicable for this operation
|
2021-04-19 09:15:35 +00:00
|
|
|
name: string ## handler name
|
|
|
|
info: string ## handter info, explainer
|
2021-04-12 17:13:30 +00:00
|
|
|
exec: Vm2OpHanders
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Public
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const
|
|
|
|
vm2OpIgnore*: Vm2OpFn = ## No operation, placeholder function
|
2021-04-20 12:07:01 +00:00
|
|
|
proc(k: var Vm2Ctx) = discard
|
2021-04-12 17:13:30 +00:00
|
|
|
|
|
|
|
# similar to: toSeq(Fork).mapIt({it}).foldl(a+b)
|
|
|
|
Vm2OpAllForks* =
|
|
|
|
{Fork.low .. Fork.high}
|
|
|
|
|
|
|
|
Vm2OpHomesteadAndLater* = ## Set of all fork symbols
|
|
|
|
Vm2OpAllForks - {FkFrontier}
|
|
|
|
|
|
|
|
Vm2OpTangerineAndLater* = ## Set of fork symbols starting from Homestead
|
|
|
|
Vm2OpHomesteadAndLater - {FkHomestead}
|
|
|
|
|
|
|
|
Vm2OpSpuriousAndLater* = ## ditto ...
|
|
|
|
Vm2OpTangerineAndLater - {FkTangerine}
|
|
|
|
|
|
|
|
Vm2OpByzantiumAndLater* =
|
|
|
|
Vm2OpSpuriousAndLater - {FkSpurious}
|
|
|
|
|
|
|
|
Vm2OpConstantinopleAndLater* =
|
|
|
|
Vm2OpByzantiumAndLater - {FkByzantium}
|
|
|
|
|
|
|
|
Vm2OpPetersburgAndLater* =
|
|
|
|
Vm2OpConstantinopleAndLater - {FkConstantinople}
|
|
|
|
|
|
|
|
Vm2OpIstanbulAndLater* =
|
|
|
|
Vm2OpPetersburgAndLater - {FkPetersburg}
|
|
|
|
|
|
|
|
Vm2OpBerlinAndLater* =
|
|
|
|
Vm2OpIstanbulAndLater - {FkIstanbul}
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# End
|
|
|
|
# ------------------------------------------------------------------------------
|