implement EIP 1344 stub

This commit is contained in:
andri lim 2019-11-11 11:58:58 +07:00 committed by zah
parent cda3e2811f
commit 0bb6c73bdb
4 changed files with 24 additions and 2 deletions

View File

@ -436,6 +436,7 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
Number: fixed GasBase, Number: fixed GasBase,
Difficulty: fixed GasBase, Difficulty: fixed GasBase,
GasLimit: fixed GasBase, GasLimit: fixed GasBase,
ChainID: fixed GasBase,
# 50s: Stack, Memory, Storage and Flow Operations # 50s: Stack, Memory, Storage and Flow Operations
Pop: fixed GasBase, Pop: fixed GasBase,

View File

@ -79,6 +79,8 @@ fill_enum_holes:
Difficulty = 0x44, # Get the block's difficulty. Difficulty = 0x44, # Get the block's difficulty.
GasLimit = 0x45, # Get the block's gas limit. GasLimit = 0x45, # Get the block's gas limit.
ChainID = 0x46, # Get current chains EIP-155 unique identifier.
# 50s: Stack, Memory, Storage and Flow Operations # 50s: Stack, Memory, Storage and Flow Operations
Pop = 0x50, # Remove item from stack. Pop = 0x50, # Remove item from stack.
Mload = 0x51, # Load word from memory. Mload = 0x51, # Load word from memory.

View File

@ -372,6 +372,11 @@ op gasLimit, inline = true:
## 0x45, Get the block's gas limit ## 0x45, Get the block's gas limit
push: computation.vmState.gasLimit push: computation.vmState.gasLimit
op chainID, inline = true:
## 0x46, Get current chains EIP-155 unique identifier.
# TODO: this is a stub
push: 0
# ########################################## # ##########################################
# 50s: Stack, Memory, Storage and Flow Operations # 50s: Stack, Memory, Storage and Flow Operations

View File

@ -215,6 +215,12 @@ proc genConstantinopleJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.c
let ConstantinopleOpDispatch {.compileTime.}: array[Op, NimNode] = genConstantinopleJumpTable(ByzantiumOpDispatch) let ConstantinopleOpDispatch {.compileTime.}: array[Op, NimNode] = genConstantinopleJumpTable(ByzantiumOpDispatch)
proc genIstanbulJumpTable(ops: array[Op, NimNode]): array[Op, NimNode] {.compileTime.} =
result = ops
result[ChainID] = newIdentNode "chainID"
let IstanbulOpDispatch {.compileTime.}: array[Op, NimNode] = genIstanbulJumpTable(ConstantinopleOpDispatch)
proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNode = proc opTableToCaseStmt(opTable: array[Op, NimNode], computation: NimNode): NimNode =
let instr = quote do: `computation`.instr let instr = quote do: `computation`.instr
@ -288,6 +294,9 @@ macro genByzantiumDispatch(computation: BaseComputation): untyped =
macro genConstantinopleDispatch(computation: BaseComputation): untyped = macro genConstantinopleDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(ConstantinopleOpDispatch, computation) result = opTableToCaseStmt(ConstantinopleOpDispatch, computation)
macro genIstanbulDispatch(computation: BaseComputation): untyped =
result = opTableToCaseStmt(IstanbulOpDispatch, computation)
proc frontierVM(computation: BaseComputation) = proc frontierVM(computation: BaseComputation) =
genFrontierDispatch(computation) genFrontierDispatch(computation)
@ -306,6 +315,9 @@ proc byzantiumVM(computation: BaseComputation) {.gcsafe.} =
proc constantinopleVM(computation: BaseComputation) {.gcsafe.} = proc constantinopleVM(computation: BaseComputation) {.gcsafe.} =
genConstantinopleDispatch(computation) genConstantinopleDispatch(computation)
proc istanbulVM(computation: BaseComputation) {.gcsafe.} =
genIstanbulDispatch(computation)
proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} = proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} =
# TODO: Optimise getting fork and updating opCodeExec only when necessary # TODO: Optimise getting fork and updating opCodeExec only when necessary
case fork case fork
@ -317,10 +329,12 @@ proc selectVM(computation: BaseComputation, fork: Fork) {.gcsafe.} =
computation.tangerineVM() computation.tangerineVM()
of FkSpurious: of FkSpurious:
computation.spuriousVM() computation.spuriousVM()
of FKByzantium: of FkByzantium:
computation.byzantiumVM() computation.byzantiumVM()
else: of FkConstantinople:
computation.constantinopleVM() computation.constantinopleVM()
else:
computation.istanbulVM()
proc executeOpcodes(computation: BaseComputation) = proc executeOpcodes(computation: BaseComputation) =
let fork = computation.getFork let fork = computation.getFork