Allow EVM dispatcher to use different GasCostKind for each fork
Why? Some opcodes such as labeled EIP-2929 changed their behavior from fixed gas cost to dynamic gas cost. This changes together with #1715 and #1717 will make the new EVM tracer to produce trace result identical to geth.
This commit is contained in:
parent
85134eb24b
commit
0b0d478966
|
@ -866,6 +866,31 @@ gasCosts(FkBerlin, berlin, BerlinGasCosts)
|
||||||
gasCosts(FkLondon, london, LondonGasCosts)
|
gasCosts(FkLondon, london, LondonGasCosts)
|
||||||
gasCosts(FkShanghai, shanghai, ShanghaiGasCosts)
|
gasCosts(FkShanghai, shanghai, ShanghaiGasCosts)
|
||||||
|
|
||||||
|
type
|
||||||
|
OpGck* = array[Op, GasCostKind]
|
||||||
|
|
||||||
|
func opGck(gc: GasCosts): OpGck {.compileTime.} =
|
||||||
|
for op, x in gc:
|
||||||
|
result[op] = x.kind
|
||||||
|
|
||||||
|
# Map fork to GasCostKind
|
||||||
|
# used in op_dispatcher.nim
|
||||||
|
const forkToGck*: array[EVMFork, OpGck] = [
|
||||||
|
opGck BaseGasCosts , # FkFrontier
|
||||||
|
opGck HomesteadGasCosts , # FkHomestead
|
||||||
|
opGck TangerineGasCosts , # kTangerine
|
||||||
|
opGck SpuriousGasCosts , # FkSpurious
|
||||||
|
opGck SpuriousGasCosts , # FkByzantium
|
||||||
|
opGck ConstantinopleGasCosts, # FkConstantinople
|
||||||
|
opGck SpuriousGasCosts , # FkPetersburg
|
||||||
|
opGck IstanbulGasCosts , # FkIstanbul
|
||||||
|
opGck BerlinGasCosts , # FkBerlin
|
||||||
|
opGck LondonGasCosts , # FkLondon
|
||||||
|
opGck LondonGasCosts , # FkParis
|
||||||
|
opGck ShanghaiGasCosts , # FkShanghai
|
||||||
|
opGck ShanghaiGasCosts , # FkCancun
|
||||||
|
]
|
||||||
|
|
||||||
proc forkToSchedule*(fork: EVMFork): GasCosts =
|
proc forkToSchedule*(fork: EVMFork): GasCosts =
|
||||||
if fork < FkHomestead:
|
if fork < FkHomestead:
|
||||||
BaseGasCosts
|
BaseGasCosts
|
||||||
|
|
|
@ -83,12 +83,13 @@ proc toCaseStmt(forkArg, opArg, k: NimNode): NimNode =
|
||||||
var forkCaseSubExpr = nnkCaseStmt.newTree(branchOnFork)
|
var forkCaseSubExpr = nnkCaseStmt.newTree(branchOnFork)
|
||||||
for fork in EVMFork:
|
for fork in EVMFork:
|
||||||
let asFork = quote do: EVMFork(`fork`)
|
let asFork = quote do: EVMFork(`fork`)
|
||||||
|
let gcTable = forkToGck[fork]
|
||||||
|
|
||||||
let branchStmt = block:
|
let branchStmt = block:
|
||||||
if op == Stop:
|
if op == Stop:
|
||||||
quote do:
|
quote do:
|
||||||
handleStopDirective(`k`)
|
handleStopDirective(`k`)
|
||||||
elif BaseGasCosts[op].kind == GckFixed:
|
elif gcTable[op] == GckFixed:
|
||||||
quote do:
|
quote do:
|
||||||
handleFixedGasCostsDirective(`asFork`,`asOp`,`k`)
|
handleFixedGasCostsDirective(`asFork`,`asOp`,`k`)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -212,13 +212,20 @@ proc runExecution(ctx: var StateContext, conf: StateConf, pre: JsonNode): StateR
|
||||||
if conf.jsonEnabled:
|
if conf.jsonEnabled:
|
||||||
writeRootHashToStderr(vmState)
|
writeRootHashToStderr(vmState)
|
||||||
|
|
||||||
let rc = vmState.processTransaction(
|
try:
|
||||||
ctx.tx, sender, ctx.header, fork)
|
let rc = vmState.processTransaction(
|
||||||
if rc.isOk:
|
ctx.tx, sender, ctx.header, fork)
|
||||||
gasUsed = rc.value
|
if rc.isOk:
|
||||||
|
gasUsed = rc.value
|
||||||
let miner = ctx.header.coinbase
|
|
||||||
coinbaseStateClearing(vmState, miner, fork)
|
let miner = ctx.header.coinbase
|
||||||
|
coinbaseStateClearing(vmState, miner, fork)
|
||||||
|
except CatchableError as ex:
|
||||||
|
echo "FATAL: ", ex.msg
|
||||||
|
quit(QuitFailure)
|
||||||
|
except AssertionDefect as ex:
|
||||||
|
echo "FATAL: ", ex.msg
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
proc toTracerFlags(conf: Stateconf): set[TracerFlags] =
|
proc toTracerFlags(conf: Stateconf): set[TracerFlags] =
|
||||||
result = {
|
result = {
|
||||||
|
|
Loading…
Reference in New Issue