clean up cyclic-import-breaker function stubs where possible for op handlers

why:
  using function stubs made it possible to check the syntax of an op
  handler source file by compiling this very file. this was previously
  impossible due cyclic import/include mechanism.

details:
  only oph_call.nim, oph_create.nim and subsequently op_handlers.nim
  still need the -d:kludge:1 flag for syntax check compiling. this flag
  also works with interpreter_dispatch.nim which imports op_handlers.nim.
This commit is contained in:
Jordan Hrycaj 2021-04-21 18:04:54 +01:00 committed by zah
parent 59d7ba1f1e
commit 3ed234e0a1
18 changed files with 375 additions and 808 deletions

View File

@ -16,47 +16,81 @@ const
noisy {.intdefine.}: int = 0
isNoisy {.used.} = noisy > 0
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
strformat,
./forks_list,
./op_codes,
./op_handlers/[oph_defs,
oph_arithmetic, oph_hash, oph_envinfo, oph_blockdata,
oph_memory, oph_push, oph_dup, oph_swap, oph_log,
oph_create, oph_call, oph_sysops]
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
const
useExecCreate = vm2OpExecCreate
useExecCall = vm2OpExecCall
else:
# note: oph_create/call are always imported to check for syntactic corretness,
# at the moment, it would not match the other handler lists due to the
# fake Computation object definition.
const
useExecCreate: seq[Vm2OpExec] = @[]
useExecCall: seq[Vm2OpExec] = @[]
ignoreVm2OpExecCreate {.used.} = vm2OpExecCreate
ignoreVm2OpExecCall {.used.} = vm2OpExecCall
{.warning: "*** Ignoring tables from <oph_create> and <oph_call>".}
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
const
allHandlersList = @[
(vm2OpExecArithmetic, "Arithmetic"),
(vm2OpExecHash, "Hash"),
(vm2OpExecEnvInfo, "EnvInfo"),
(vm2OpExecBlockData, "BlockData"),
(vm2OpExecMemory, "Memory"),
(vm2OpExecPush, "Push"),
(vm2OpExecDup, "Dup"),
(vm2OpExecSwap, "Swap"),
(vm2OpExecLog, "Log"),
(useExecCreate, "Create"),
(useExecCall, "Call"),
(vm2OpExecSysOp, "SysOp")]
# ------------------------------------------------------------------------------
# Helper
# ------------------------------------------------------------------------------
proc importList(rc: var array[Op,Vm2OpExec];
sel: Fork; list: seq[Vm2OpExec]; s: string) {.compileTime.} =
for w in list:
if sel notin w.forks:
continue
var oInf = rc[w.opCode].info
if oInf != "" or 0 < rc[w.opCode].forks.card:
echo &"*** {s}: duplicate <{w.opCode}> entry: \"{oInf}\" vs. \"{w.info}\""
doAssert rc[w.opCode].info == ""
doAssert rc[w.opCode].forks.card == 0
rc[w.opCode] = w
proc mkOpTable(selected: Fork): array[Op,Vm2OpExec] {.compileTime.} =
# Collect selected <fork> entries
for (subList,subName) in allHandlersList:
for w in subList:
if selected notin w.forks:
continue
# definitions must be mutually exclusive
var prvInfo = result[w.opCode].info
if prvInfo != "" or 0 < result[w.opCode].forks.card:
echo &"*** {subName}: duplicate <{w.opCode}> entry: ",
&"\"{prvInfo}\" vs. \"{w.info}\""
doAssert result[w.opCode].info == ""
doAssert result[w.opCode].forks.card == 0
result[w.opCode] = w
proc mkOpTable(select: Fork): array[Op,Vm2OpExec] {.compileTime.} =
result.importList(select, vm2OpExecArithmetic, "Arithmetic")
result.importList(select, vm2OpExecHash, "Hash")
result.importList(select, vm2OpExecEnvInfo, "EnvInfo")
result.importList(select, vm2OpExecBlockData, "BlockData")
result.importList(select, vm2OpExecMemory, "Memory")
result.importList(select, vm2OpExecPush, "Push")
result.importList(select, vm2OpExecDup, "Dup")
result.importList(select, vm2OpExecSwap, "Swap")
result.importList(select, vm2OpExecLog, "Log")
result.importList(select, vm2OpExecCreate, "Create")
result.importList(select, vm2OpExecCall, "Call")
result.importList(select, vm2OpExecSysOp, "SysOp")
# Initialise unused entries
for op in Op:
if select notin result[op].forks:
if selected notin result[op].forks:
result[op] = result[Invalid]
result[op].opCode = op
if op == Stop:

View File

@ -12,65 +12,22 @@
## ===================================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../constants,
../../compu_helper,
../../stack,
../../v2types,
../op_codes,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
./oph_defs,
chronicles,
eth/common,
options,
sets,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../constants,
../../compu_helper,
../../stack,
../../v2types,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
chronicles,
eth/common,
options,
sets
else:
import macros
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc push[T](x: Stack; n: T) = discard
proc popInt(x: var Stack): UInt256 = result
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = result
# function stubs from v2utils_numeric.nim
proc extractSign(v: var UInt256, sign: var bool) = discard
proc setSign(v: var UInt256, sign: bool) = discard
func safeInt(x: Uint256): int = discard
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# stubs from gas_costs.nim
proc d_handler(x: int; value: Uint256): int = result
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Private, op handlers implementation
# ------------------------------------------------------------------------------

View File

@ -12,53 +12,15 @@
## ===============================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../compu_helper,
../../stack,
../../v2state,
../op_codes,
./oph_defs,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../compu_helper,
../../stack,
../../v2state,
eth/common,
times
else:
import macros
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc push[T](x: Stack; n: T) = discard
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc getBalance[T](c: Computation, address: T): Uint256 = 0.u256
proc getBlockHash(c: Computation, blockNumber: Uint256): Uint256 = 0.u256
proc getCoinbase(c: Computation): Uint256 = 0.u256
proc getTimestamp(c: Computation): int64 = 0
proc getBlockNumber(c: Computation): Uint256 = 0.u256
proc getDifficulty(c: Computation): int = 0
proc getGasLimit(c: Computation): int = 0
proc getChainId(c: Computation): uint = 0
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
eth/common,
stint,
times
# ------------------------------------------------------------------------------
# Private, op handlers implementation

View File

@ -18,8 +18,13 @@ const
import
../../../errors,
./oph_defs,
../../stack,
../../v2memory,
../forks_list,
../op_codes,
../utils/v2utils_numeric,
chronicles,
eth/common/eth_types,
stint
# ------------------------------------------------------------------------------
@ -28,90 +33,21 @@ import
when not breakCircularDependency:
import
./oph_defs,
../../../constants,
../../../db/accounts_cache,
../../compu_helper,
../../stack,
../../v2computation,
../../v2memory,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
eth/common
else:
import macros
type
MsgFlags = int
GasResult = tuple[gasCost, gasRefund: GasInt]
const
evmcCall = 42
evmcDelegateCall = 43
evmcCallCode = 44
emvcStatic = 45
MaxCallDepth = 46
ColdAccountAccessCost = 47
WarmStorageReadCost = 48
# function stubs from stack.nim (to satisfy compiler logic)
proc `[]`(x: Stack, i: BackwardsIndex; T: typedesc): T = result
proc top[T](x: Stack, value: T) = discard
proc push[T](x: Stack; n: T) = discard
proc popAddress(x: var Stack): EthAddress = result
proc popInt(x: var Stack): UInt256 = result
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = result
proc getBalance[T](c: Computation, address: T): Uint256 = result
proc accountExists(c: Computation, address: EthAddress): bool = result
# function stubs from v2computation.nim (to satisfy compiler logic)
func shouldBurnGas(c: Computation): bool = result
proc newComputation[A,B](v:A, m:B, salt = 0.u256): Computation = new result
proc isSuccess(c: Computation): bool = result
proc merge(c, child: Computation) = discard
template chainTo(c, d: Computation, e: untyped) =
c.child = d; c.continuation = proc() = e
# function stubs from v2utils_numeric.nim
func calcMemSize*(offset, length: int): int = result
# function stubs from v2memory.nim
proc len(mem: Memory): int = result
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
proc read(mem: var Memory, startPos: Natural, size: Natural): seq[byte] = @[]
proc write(mem: var Memory, startPos: Natural, val: openarray[byte]) = discard
# function stubs from v2state.nim
template mutateStateDB(vmState: BaseVMState, body: untyped) =
block:
var db {.inject.} = vmState.accountDb
body
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
proc returnGas(gasMeter: var GasMeter; amount: GasInt) = discard
# function stubs from v2utils_numeric.nim
func cleanMemRef(x: UInt256): int = result
# stubs from gas_costs.nim
type GasParams = object
case kind*: Op
of Call, CallCode, DelegateCall, StaticCall:
c_isNewAccount: bool
c_contractGas: Uint256
c_gasBalance, c_currentMemSize, c_memOffset, c_memLength: int64
else:
discard
proc c_handler(x: int; y: Uint256, z: GasParams): GasResult = result
# function stubs from accounts_cache.nim:
func inAccessList[A,B](ac: A; address: B): bool = result
proc accessList[A,B](ac: var A; address: B) = discard
import
./oph_defs_kludge,
./oph_helpers_kludge
# ------------------------------------------------------------------------------
# Kludge END

View File

@ -18,11 +18,15 @@ const
import
../../../errors,
./oph_defs,
./oph_helpers,
../../stack,
../../v2memory,
../forks_list,
../op_codes,
../utils/v2utils_numeric,
chronicles,
strformat,
stint
eth/common/eth_types,
stint,
strformat
# ------------------------------------------------------------------------------
# Kludge BEGIN
@ -32,64 +36,19 @@ when not breakCircularDependency:
import
../../../constants,
../../compu_helper,
../../stack,
../../v2computation,
../../v2memory,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
./oph_defs,
./oph_helpers,
eth/common
else:
import macros
type
GasResult = tuple[gasCost, gasRefund: GasInt]
const
evmcCreate = 42
evmcCreate2 = 43
MaxCallDepth = 45
# function stubs from stack.nim (to satisfy compiler logic)
proc top[T](x: Stack, value: T) = discard
proc peekInt(x: Stack): UInt256 = result
proc popInt(x: var Stack): UInt256 = result
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = result
proc getBalance[T](c: Computation, address: T): Uint256 = result
# function stubs from v2computation.nim (to satisfy compiler logic)
proc newComputation[A,B](v:A, m:B, salt = 0.u256): Computation = new result
func shouldBurnGas(c: Computation): bool = result
proc isSuccess(c: Computation): bool = result
proc merge(c, child: Computation) = discard
template chainTo(c, d: Computation, e: untyped) =
c.child = d; c.continuation = proc() = e
# function stubs from v2utils_numeric.nim
func safeInt(x: Uint256): int = 0
# function stubs from v2memory.nim
proc len(mem: Memory): int = 0
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
proc read(mem: var Memory, startPos: Natural, size: Natural): seq[byte] = @[]
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
proc returnGas(gasMeter: var GasMeter; amount: GasInt) = discard
# stubs from gas_costs.nim
type GasParams = object
case kind*: Op
of Create:
cr_currentMemSize, cr_memOffset, cr_memLength: int64
else:
discard
proc c_handler(x: int; y: Uint256, z: GasParams): GasResult = result
proc m_handler(x: int; curMemSize, memOffset, memLen: int64): int = result
import
./oph_defs_kludge,
./oph_helpers_kludge
# ------------------------------------------------------------------------------
# Kludge END

View File

@ -12,78 +12,22 @@
## ========================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
# Including v2types.nim needed unless included (not imported) into
# oph_defs_kludge.nim
#
# Note that the nim compiler will distinguish <Vm2Ctx> tuples defined
# here when imported and from oph_defs_kludge.nim. This is so due to the
# duplicate/different Computation definitions.
#
when not declared(Computation):
import
../../v2types
import
../forks_list,
../op_codes,
../../memory_defs,
../../stack_defs,
eth/common/eth_types
# ------------------------------------------------------------------------------
# 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
GasInt* = int
ReadOnlyStateDB* =
seq[byte]
GasMeter* = object
gasRemaining*: int
CodeStream* = ref object
bytes*: seq[byte]
pc*: int
BaseVMState* = ref object
accountDb*: ReadOnlyStateDB
Message* = ref object
kind*: int
depth*: int
gas*: GasInt
contractAddress*: EthAddress
codeAddress*: EthAddress
sender*: EthAddress
value*: UInt256
data*: seq[byte]
flags*: int
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.}
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
export
Op, Fork, Computation, Memory, Stack, UInt256, Message, EthAddress
type
Vm2Ctx* = tuple
cpt: Computation ## computation text

View File

@ -0,0 +1,88 @@
# 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_defs,
../../stack_defs,
eth/common/eth_types
# ------------------------------------------------------------------------------
# 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
BaseVMState* = ref object of RootObj
accountDb*: ReadOnlyStateDB
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.}
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
include
./oph_defs
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------

View File

@ -12,33 +12,14 @@
## ===========================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../stack,
../op_codes,
./oph_defs,
./oph_helpers,
sequtils,
strformat,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../stack
else:
# function stubs from stack.nim (to satisfy compiler logic)
proc dup(stack: var Stack, position: int | UInt256) = discard
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
stint,
strformat
# ------------------------------------------------------------------------------
# Private helpers

View File

@ -12,85 +12,23 @@
## ==============================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../errors,
../../code_stream,
../../compu_helper,
../../stack,
../../v2memory,
../../v2state,
../gas_costs,
../gas_meter,
../op_codes,
../utils/v2utils_numeric,
./oph_defs,
./oph_helpers,
eth/common,
sequtils,
strformat,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../code_stream,
../../compu_helper,
../../stack,
../../v2memory,
../../v2state,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
eth/common
else:
import macros
const
GasBalance = 0
GasExtCode = 42
GasExtCodeHash = 7
var
gasFees: array[Fork,array[0..123,int]]
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc push[T](x: Stack; n: T) = discard
proc popAddress(x: var Stack): EthAddress = result
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = result
proc getBalance[T](c: Computation, address: T): Uint256 = result
proc getCodeSize[T](c: Computation, address: T): uint = result
proc getCode[T](c: Computation, address: T): seq[byte] = @[]
proc getGasPrice(c: Computation): Uint256 = result
proc getOrigin(c: Computation): Uint256 = result
proc getCodeHash[T](c: Computation, address: T): Uint256 = result
# function stubs from v2utils_numeric.nim
func cleanMemRef(x: UInt256): int = 0
# function stubs from v2memory.nim
proc len(mem: Memory): int = 0
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
proc write(mem: var Memory, startPos: Natural, val: openarray[byte]) = discard
# function stubs from code_stream.nim
proc len(c: CodeStream): int = len(c.bytes)
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# stubs from gas_costs.nim
proc m_handler(x: int; curMemSize, memOffset, memLen: int64): int = 0
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
stint,
strformat
# ------------------------------------------------------------------------------
# Private helpers

View File

@ -12,72 +12,21 @@
## ===========================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../constants,
../../../errors,
../../compu_helper,
../../stack,
../../v2memory,
../gas_costs,
../gas_meter,
../op_codes,
../utils/v2utils_numeric,
./oph_defs,
eth/common,
nimcrypto,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../constants,
../../compu_helper,
../../stack,
../../v2memory,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
eth/common,
nimcrypto
else:
import macros
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc push[T](x: Stack; n: T) = discard
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from v2utils_numeric.nim
func safeInt(x: Uint256): int = discard
# function stubs from v2memory.nim
proc len(mem: Memory): int = 0
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = result
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# dummy stubs from constants
const EMPTY_SHA3 = 0xdeadbeef.u256
# function stubs from nimcrypto/hash.nim and nimcrypto/keccak.nim
const keccak256 = 0xfeedbeef
proc digest(dummy: int64, data: openarray[byte]): UInt256 = EMPTY_SHA3
# stubs from gas_costs.nim
proc m_handler(x: int; curMemSize, memOffset, memLen: int64): int = 0
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Private, op handlers implementation
# ------------------------------------------------------------------------------

View File

@ -12,13 +12,22 @@
## ==============================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
# Including v2types.nim and others unless included (not imported) into
# oph_helpes_kludge.nim
#
when not declared(consumeGas):
import
../../../db/accounts_cache,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
./oph_defs,
eth/common
import
../../../errors,
./oph_defs,
eth/common/eth_types,
macros,
stint,
strutils
@ -30,42 +39,6 @@ type
const
recForkSet = "Vm2OpAllForks"
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../db/accounts_cache,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
eth/common
else:
const
emvcStatic = 1
ColdAccountAccessCost = 2
WarmStorageReadCost = 3
# function stubs from v2state.nim
template mutateStateDB(vmState: BaseVMState, body: untyped) =
block:
var db {.inject.} = vmState.accountDb
body
# function stubs from accounts_cache.nim:
func inAccessList[A,B](ac: A; address: B): bool = false
proc accessList[A,B](ac: var A, address: B) = discard
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Private helpers
# ------------------------------------------------------------------------------

View File

@ -0,0 +1,88 @@
# 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 Opcode Handlers: Helper Functions -- Kludge Version
## =======================================================
##
import
../../../errors,
../op_codes,
./oph_defs_kludge,
eth/common/eth_types,
macros,
stint,
strutils
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
const
ColdAccountAccessCost* = 2
WarmStorageReadCost* = 3
MaxCallDepth* = 42
# function stubs from v2state.nim
template mutateStateDB*(vmState: BaseVMState, body: untyped) =
block:
var db {.inject.} = vmState.accountDb
body
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts*(c: Computation): array[Op,int] = result
proc getBalance*[T](c: Computation, address: T): Uint256 = result
proc accountExists*(c: Computation, address: EthAddress): bool = result
# function stubs from v2computation.nim (to satisfy compiler logic)
func shouldBurnGas*(c: Computation): bool = result
proc newComputation*[A,B](v:A, m:B, salt = 0.u256): Computation = new result
proc isSuccess*(c: Computation): bool = result
proc merge*(c, child: Computation) = discard
template chainTo*(c, d: Computation, e: untyped) =
c.child = d; c.continuation = proc() = e
# function stubs from accounts_cache.nim:
func inAccessList*[A,B](ac: A; address: B): bool = false
proc accessList*[A,B](ac: var A, address: B) = discard
# function stubs from gas_meter.nim
proc consumeGas*(gasMeter: var GasMeter;amount: GasInt;reason: string) = discard
proc returnGas*(gasMeter: var GasMeter; amount: GasInt) = discard
# stubs from gas_costs.nim
type
GasResult* =
tuple[gasCost, gasRefund: GasInt]
GasParams* = object
case kind*: Op
of Create:
cr_currentMemSize*, cr_memOffset*, cr_memLength*: int64
of Call, CallCode, DelegateCall, StaticCall:
c_isNewAccount*: bool
c_contractGas*: Uint256
c_gasBalance*, c_currentMemSize*, c_memOffset*, c_memLength*: int64
else:
discard
proc c_handler*(x: int; y: Uint256, z: GasParams): GasResult = result
proc m_handler*(x: int; curMemSize, memOffset, memLen: int64): int = result
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
include
./oph_helpers
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------

View File

@ -12,75 +12,24 @@
## =======================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../constants,
../../../errors,
../../compu_helper,
../../stack,
../../v2memory,
../../v2types,
../gas_costs,
../gas_meter,
../op_codes,
../utils/v2utils_numeric,
./oph_defs,
./oph_helpers,
sequtils,
eth/common,
strformat,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../constants,
../../compu_helper,
../../stack,
../../v2memory,
../../v2types,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
eth/common
else:
import
macros
var blindGasCosts: array[Op,int]
var blindTopic: Topic
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc popTopic(x: var Stack): Topic = blindTopic
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = blindGasCosts
proc addLogEntry(c: Computation, log: Log) = discard
# function stubs from v2utils_numeric.nim
func cleanMemRef(x: UInt256): int = 0
# function stubs from v2memory.nim
proc len(mem: Memory): int = 0
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
proc read(mem: var Memory, startPos: Natural, size: Natural): seq[byte] = @[]
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# stubs from gas_costs.nim
proc m_handler(x: int; curMemSize, memOffset, memLen: int64): int = 0
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
eth/common,
sequtils,
stint,
strformat
# ------------------------------------------------------------------------------
# Private, names & settings

View File

@ -12,105 +12,24 @@
## ===============================================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../db/accounts_cache,
../../../errors,
../../code_stream,
../../compu_helper,
../../stack,
../../v2memory,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
../op_codes,
../utils/v2utils_numeric,
./oph_defs,
./oph_helpers,
strformat,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../db/accounts_cache,
../../code_stream,
../../compu_helper,
../../stack,
../../v2memory,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
eth/common
else:
import macros
const
ColdSloadCost = 42
WarmStorageReadCost = 43
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc push[T](x: Stack; n: T) = discard
proc popInt(x: var Stack): UInt256 = discard
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc getStorage(c: Computation, slot: Uint256): Uint256 = result
proc gasCosts(c: Computation): array[Op,int] = result
# function stubs from v2utils_numeric.nim
func cleanMemRef(x: UInt256): int = 0
# function stubs from v2memory.nim
proc len(mem: Memory): int = 0
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
proc write(mem: var Memory, startPos: Natural, val: openarray[byte]) = discard
proc read(mem: var Memory, startPos: Natural, size: Natural): seq[byte] = @[]
# function stubs from code_stream.nim
proc len(c: CodeStream): int = len(c.bytes)
proc peek(c: var CodeStream): Op = Stop
proc isValidOpcode(c: CodeStream, position: int): bool = false
# function stubs from v2state.nim
proc readOnlyStateDB(x: BaseVMState): ReadOnlyStateDB = result
template mutateStateDB(vmState: BaseVMState, body: untyped) =
block:
var db {.inject.} = vmState.accountDb
body
# function stubs from gas_meter.nim
proc refundGas(gasMeter: var GasMeter; amount: int) = discard
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# stubs from gas_costs.nim
type GasParams = object
case kind*: Op
of Sstore:
s_currentValue: Uint256
s_originalValue: Uint256
else:
discard
proc c_handler(x: int; y: Uint256, z: GasParams): (int,int) = result
proc m_handler(x: int; curMemSize, memOffset, memLen: int64): int = 0
# function stubs from state_db.nim
proc getCommittedStorage[A,B](x: A; y: B; z: Uint256): Uint256 = result
# function stubs from accounts_cache.nim:
func inAccessList[A,B](ac: A; address: B; slot: UInt256): bool = result
proc accessList[A,B](ac: var A; address: B; slot: UInt256) = discard
proc setStorage[A,B](ac: var A; address: B, slot, value: UInt256) = discard
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
eth/common,
stint,
strformat
# ------------------------------------------------------------------------------
# Private helpers

View File

@ -12,37 +12,15 @@
## ====================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../code_stream,
../../stack,
../op_codes,
./oph_defs,
./oph_helpers,
sequtils,
strformat,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../code_stream,
../../stack
else:
# function stubs from stack.nim (to satisfy compiler logic)
proc push[T](x: Stack; n: T) = discard
# function stubs from code_stream.nim
proc readVmWord(c: var CodeStream, n: int): UInt256 = 0.u256
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
stint,
strformat
# ------------------------------------------------------------------------------
# Private helpers

View File

@ -12,33 +12,14 @@
## ====================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../stack,
../op_codes,
./oph_defs,
./oph_helpers,
sequtils,
strformat
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../stack
else:
# function stubs from stack.nim (to satisfy compiler logic)
proc swap(stack: var Stack, position: int) = discard
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Private, names & settings
# ------------------------------------------------------------------------------

View File

@ -12,94 +12,24 @@
## ======================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../db/accounts_cache,
../../../errors,
../../compu_helper,
../../stack,
../../v2memory,
../../v2state,
../../v2types,
../forks_list,
../gas_costs,
../gas_meter,
../op_codes,
../utils/v2utils_numeric,
./oph_defs,
./oph_helpers,
eth/common,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../db/accounts_cache,
../../compu_helper,
../../stack,
../../v2memory,
../../v2state,
../../v2types,
../gas_costs,
../gas_meter,
../utils/v2utils_numeric,
eth/common
else:
import macros
type
GasResult = tuple[gasCost, gasRefund: GasInt]
const
ColdAccountAccessCost = 42
# copied from stack.nim
macro genTupleType(len: static[int], elemType: untyped): untyped =
result = nnkTupleConstr.newNimNode()
for i in 0 ..< len: result.add(elemType)
# function stubs from stack.nim (to satisfy compiler logic)
proc popAddress(x: var Stack): EthAddress = result
proc popInt(x: var Stack, n: static[int]): auto =
var rc: genTupleType(n, UInt256)
return rc
# function stubs from compu_helper.nim (to satisfy compiler logic)
proc gasCosts(c: Computation): array[Op,int] = result
proc setError(c: Computation, msg: string, burnsGas = false) = discard
proc selfDestruct(c: Computation, address: EthAddress) = discard
proc accountExists(c: Computation, address: EthAddress): bool = result
proc getBalance[T](c: Computation, address: T): Uint256 = result
# function stubs from v2utils_numeric.nim
func cleanMemRef(x: UInt256): int = result
# function stubs from v2memory.nim
proc len(mem: Memory): int = result
proc extend(mem: var Memory; startPos: Natural; size: Natural) = discard
proc read(mem: var Memory, startPos: Natural, size: Natural): seq[byte] = @[]
# function stubs from v2state.nim
template mutateStateDB(vmState: BaseVMState, body: untyped) =
block:
var db {.inject.} = vmState.accountDb
body
# function stubs from gas_meter.nim
proc consumeGas(gasMeter: var GasMeter; amount: int; reason: string) = discard
# stubs from gas_costs.nim
type GasParams = object
case kind*: Op
of SelfDestruct:
sd_condition: bool
else:
discard
proc c_handler(x: int; y: Uint256, z: GasParams): GasResult = result
proc m_handler(x: int; curMemSize, memOffset, memLen: int64): int = result
# function stubs from accounts_cache.nim:
func inAccessList[A,B](ac: A; address: B): bool = result
proc accessList[A,B](ac: var A; address: B) = discard
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Private
# ------------------------------------------------------------------------------

View File

@ -10,7 +10,8 @@
import
./compu_helper,
./interpreter/[gas_meter, op_handlers, op_handlers/oph_defs, gas_costs],
./interpreter/[forks_list, gas_costs, gas_meter,
op_codes, op_handlers, op_handlers/oph_defs],
./code_stream,
./v2types,
chronicles