removed kludge and simplified sources oph_call.nim and oph_create.nim

why:
  kludge not needed anymore for oph_handlers.nim sub-sources and sources
  that rely on oph_handlers.nim (but not state_transactions.nim which
  relies on computation.nim.)
This commit is contained in:
Jordan Hrycaj 2021-04-23 18:43:44 +01:00 committed by zah
parent 77518446d9
commit caabc9c292
5 changed files with 137 additions and 249 deletions

View File

@ -14,10 +14,8 @@
const
noisy {.intdefine.}: int = 0
isNoisy {.used.} = noisy > 0
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
# isNoisy {.used.} = noisy > 0
isChatty {.used.} = noisy > 1
import
strformat,
@ -28,31 +26,6 @@ import
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"),
@ -64,8 +37,8 @@ const
(vm2OpExecDup, "Dup"),
(vm2OpExecSwap, "Swap"),
(vm2OpExecLog, "Log"),
(useExecCreate, "Create"),
(useExecCall, "Call"),
(vm2OpExecCreate, "Create"),
(vm2OpExecCall, "Call"),
(vm2OpExecSysOp, "SysOp")]
# ------------------------------------------------------------------------------
@ -146,7 +119,7 @@ const
# Debugging ...
# ------------------------------------------------------------------------------
when isMainModule and isNoisy:
when isMainModule and isChatty:
proc opHandlersRun(fork: Fork; op: Op; d: var Vm2Ctx) {.used.} =
## Given a particular `fork` and an `op`-code, run the associated handler

View File

@ -12,46 +12,26 @@
## ====================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../constants,
../../../db/accounts_cache,
../../../errors,
../../stack,
../../compu_helper,
../../memory,
../../stack,
../../state,
../../types,
../forks_list,
../gas_costs,
../gas_meter,
../op_codes,
../utils/utils_numeric,
./oph_defs,
chronicles,
eth/common,
eth/common/eth_types,
stint
# ------------------------------------------------------------------------------
# Kludge BEGIN
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
./oph_defs,
../../../constants,
../../../db/accounts_cache,
../../compu_helper,
../../computation,
../../state,
../../types,
../gas_costs,
../gas_meter,
eth/common
else:
import
./oph_kludge
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# Private
# ------------------------------------------------------------------------------
@ -158,6 +138,29 @@ proc staticCallParams(c: Computation): LocalParams =
result.updateStackAndParams(c)
proc execSubCall(k: var Vm2Ctx; childMsg: Message; memPos, memLen: int) =
## Call new VM -- helper for `Call`-like operations
# need to provide explicit <c> and <child> for capturing in chainTo proc()
# <memPos> and <memLen> are provided by value and need not be captured
var
c = k.cpt
child = newComputation(k.cpt.vmState, childMsg)
k.cpt.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top(1)
c.returnData = child.output
let actualOutputSize = min(memLen, child.output.len)
if actualOutputSize > 0:
c.memory.write(memPos, child.output.toOpenArray(0, actualOutputSize - 1))
# ------------------------------------------------------------------------------
# Private, op handlers implementation
# ------------------------------------------------------------------------------
@ -215,34 +218,19 @@ const
k.cpt.gasMeter.returnGas(childGasLimit)
return
let msg = Message(
kind: evmcCall,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags)
# call -- need to un-capture k
var
c = k.cpt
child = newComputation(c.vmState, msg)
c.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top(1)
c.returnData = child.output
let actualOutputSize = min(p.memOutLen, child.output.len)
if actualOutputSize > 0:
c.memory.write(p.memOutPos,
child.output.toOpenArray(0, actualOutputSize - 1))
k.execSubCall(
memPos = p.memOutPos,
memLen = p.memOutLen,
childMsg = Message(
kind: evmcCall,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags))
# ---------------------
@ -296,34 +284,19 @@ const
k.cpt.gasMeter.returnGas(childGasLimit)
return
let msg = Message(
kind: evmcCallCode,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags)
# call -- need to un-capture k
var
c = k.cpt
child = newComputation(c.vmState, msg)
c.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top(1)
c.returnData = child.output
let actualOutputSize = min(p.memOutLen, child.output.len)
if actualOutputSize > 0:
c.memory.write(p.memOutPos,
child.output.toOpenArray(0, actualOutputSize - 1))
k.execSubCall(
memPos = p.memOutPos,
memLen = p.memOutLen,
childMsg = Message(
kind: evmcCallCode,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags))
# ---------------------
@ -366,34 +339,19 @@ const
k.cpt.memory.extend(p.memInPos, p.memInLen)
k.cpt.memory.extend(p.memOutPos, p.memOutLen)
let msg = Message(
kind: evmcDelegateCall,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags)
# call -- need to un-capture k
var
c = k.cpt
child = newComputation(c.vmState, msg)
c.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top(1)
c.returnData = child.output
let actualOutputSize = min(p.memOutLen, child.output.len)
if actualOutputSize > 0:
c.memory.write(p.memOutPos,
child.output.toOpenArray(0, actualOutputSize - 1))
k.execSubCall(
memPos = p.memOutPos,
memLen = p.memOutLen,
childMsg = Message(
kind: evmcDelegateCall,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags))
# ---------------------
@ -441,34 +399,19 @@ const
k.cpt.memory.extend(p.memInPos, p.memInLen)
k.cpt.memory.extend(p.memOutPos, p.memOutLen)
let msg = Message(
kind: evmcCall,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags)
# call -- need to un-capture k
var
c = k.cpt
child = newComputation(c.vmState, msg)
c.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top(1)
c.returnData = child.output
let actualOutputSize = min(p.memOutLen, child.output.len)
if actualOutputSize > 0:
c.memory.write(p.memOutPos,
child.output.toOpenArray(0, actualOutputSize - 1))
k.execSubCall(
memPos = p.memOutPos,
memLen = p.memOutLen,
childMsg = Message(
kind: evmcCall,
depth: k.cpt.msg.depth + 1,
gas: childGasLimit,
sender: p.sender,
contractAddress: p.contractAddress,
codeAddress: p.destination,
value: p.value,
data: k.cpt.memory.read(p.memInPos, p.memInLen),
flags: p.flags))
# ------------------------------------------------------------------------------
# Public, op exec table entries

View File

@ -12,46 +12,48 @@
## ======================================
##
const
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
import
../../../constants,
../../../errors,
../../stack,
../../compu_helper,
../../memory,
../../stack,
../../state,
../../types,
../forks_list,
../gas_costs,
../gas_meter,
../op_codes,
../utils/utils_numeric,
./oph_defs,
./oph_helpers,
chronicles,
eth/common,
eth/common/eth_types,
stint,
strformat
# ------------------------------------------------------------------------------
# Kludge BEGIN
# Private helpers
# ------------------------------------------------------------------------------
when not breakCircularDependency:
import
../../../constants,
../../compu_helper,
../../computation,
../../state,
../../types,
../gas_costs,
../gas_meter,
./oph_defs,
./oph_helpers,
eth/common
proc execSubCreate(k: var Vm2Ctx; childMsg: Message; salt = 0.u256) =
## Create new VM -- helper for `Create`-like operations
else:
import
./oph_kludge
# need to provide explicit <c> and <child> for capturing in chainTo proc()
var
c = k.cpt
child = newComputation(k.cpt.vmState, childMsg, salt)
# ------------------------------------------------------------------------------
# Kludge END
# ------------------------------------------------------------------------------
k.cpt.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top child.msg.contractAddress
else:
c.returnData = child.output
# ------------------------------------------------------------------------------
# Private, op handlers implementation
@ -66,7 +68,6 @@ const
endowment = k.cpt.stack.popInt()
memPos = k.cpt.stack.popInt().safeInt
memLen = k.cpt.stack.peekInt().safeInt
salt = 0.u256
k.cpt.stack.top(0)
@ -103,27 +104,14 @@ const
createMsgGas -= createMsgGas div 64
k.cpt.gasMeter.consumeGas(createMsgGas, reason = "CREATE")
let childMsg = Message(
kind: evmcCreate,
depth: k.cpt.msg.depth + 1,
gas: createMsgGas,
sender: k.cpt.msg.contractAddress,
value: endowment,
data: k.cpt.memory.read(memPos, memLen))
# call -- need to un-capture k
var
c = k.cpt
child = newComputation(c.vmState, childMsg, salt)
c.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top child.msg.contractAddress
else:
c.returnData = child.output
k.execSubCreate(
childMsg = Message(
kind: evmcCreate,
depth: k.cpt.msg.depth + 1,
gas: createMsgGas,
sender: k.cpt.msg.contractAddress,
value: endowment,
data: k.cpt.memory.read(memPos, memLen)))
# ---------------------
@ -174,27 +162,15 @@ const
createMsgGas -= createMsgGas div 64
k.cpt.gasMeter.consumeGas(createMsgGas, reason = "CREATE")
let childMsg = Message(
kind: evmcCreate2,
depth: k.cpt.msg.depth + 1,
gas: createMsgGas,
sender: k.cpt.msg.contractAddress,
value: endowment,
data: k.cpt.memory.read(memPos, memLen))
# call -- need to un-capture k
var
c = k.cpt
child = newComputation(c.vmState, childMsg, salt)
c.chainTo(child):
if not child.shouldBurnGas:
c.gasMeter.returnGas(child.gasMeter.gasRemaining)
if child.isSuccess:
c.merge(child)
c.stack.top child.msg.contractAddress
else:
c.returnData = child.output
k.execSubCreate(
salt = salt,
childMsg = Message(
kind: evmcCreate2,
depth: k.cpt.msg.depth + 1,
gas: createMsgGas,
sender: k.cpt.msg.contractAddress,
value: endowment,
data: k.cpt.memory.read(memPos, memLen)))
# ------------------------------------------------------------------------------
# Public, op exec table entries

View File

@ -20,7 +20,6 @@ import
../../stack,
../../state,
../../types,
../forks_list,
../gas_costs,
../gas_meter,
../op_codes,

View File

@ -13,13 +13,10 @@ const
lowmem {.intdefine.}: int = 0
lowMemoryCompileTime {.used.} = lowmem > 0
# debugging flag
# debugging flag, dump macro info when asked for
noisy {.intdefine.}: int = 0
isNoisy {.used.} = noisy > 0
# needed for compiling locally
kludge {.intdefine.}: int = 0
breakCircularDependency {.used.} = kludge > 0
# isNoisy {.used.} = noisy > 0
isChatty {.used.} = noisy > 1
import
./compu_helper,
@ -121,7 +118,7 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
newIdentNode(op.toSymbolName),
branchStmt)
when breakCircularDependency and isNoisy:
when isChatty:
echo ">>> ", result.repr