diff --git a/tools/common/helpers.nim b/tools/common/helpers.nim index 43aee4609..b6f7c3dd2 100644 --- a/tools/common/helpers.nim +++ b/tools/common/helpers.nim @@ -22,7 +22,7 @@ const TimeZero: EthTime = fromUnix(0) proc createForkTransitionTable(transitionFork: HardFork, b: Option[BlockNumber], t: Option[EthTime], ttd: Option[DifficultyInt]): ForkTransitionTable = - + proc blockNumberToUse(f: HardFork): Option[BlockNumber] = if f < transitionFork: some(BlockNumberZero) @@ -30,7 +30,7 @@ proc createForkTransitionTable(transitionFork: HardFork, b: Option[BlockNumber], b else: none(BlockNumber) - + proc timeToUse(f: HardFork): Option[EthTime] = if f < transitionFork: some(TimeZero) @@ -38,13 +38,13 @@ proc createForkTransitionTable(transitionFork: HardFork, b: Option[BlockNumber], t else: none(EthTime) - + for f in low(HardFork) .. lastPurelyBlockNumberBasedFork: result.blockNumberThresholds[f] = blockNumberToUse(f) result.mergeForkTransitionThreshold.blockNumber = blockNumberToUse(HardFork.MergeFork) result.mergeForkTransitionThreshold.ttd = ttd - + for f in firstTimeBasedFork .. high(HardFork): result.timeThresholds[f] = timeToUse(f) @@ -115,6 +115,8 @@ func getChainConfig*(network: string, c: ChainConfig) = c.assignTime(HardFork.Shanghai, fromUnix(15000)) of $TestFork.Cancun: c.assignTime(HardFork.Cancun, TimeZero) + of $TestFork.ShanghaiToCancunAtTime15k: + c.assignTime(HardFork.Cancun, fromUnix(15000)) else: raise newException(ValueError, "unsupported network " & network) diff --git a/tools/common/types.nim b/tools/common/types.nim index f7dc195f2..179ef9786 100644 --- a/tools/common/types.nim +++ b/tools/common/types.nim @@ -35,6 +35,7 @@ type Shanghai MergeToShanghaiAtTime15k Cancun + ShanghaiToCancunAtTime15k LogLevel* = enum Silent diff --git a/tools/evmstate/evmstate.nim b/tools/evmstate/evmstate.nim index d31abf6a2..9adbfa42d 100644 --- a/tools/evmstate/evmstate.nim +++ b/tools/evmstate/evmstate.nim @@ -21,6 +21,7 @@ import ../../nimbus/core/executor, ../../nimbus/common/common, ../../nimbus/evm/tracer/json_tracer, + ../../nimbus/core/eip4844, ../common/helpers as chp, "."/[config, helpers], ../common/state_clearing @@ -28,6 +29,7 @@ import type StateContext = object name: string + parent: BlockHeader header: BlockHeader tx: Transaction expectedHash: Hash256 @@ -37,6 +39,7 @@ type index: int tracerFlags: set[TracerFlags] error: string + trustedSetupLoaded: bool DumpAccount = ref object balance : UInt256 @@ -176,7 +179,6 @@ proc writeRootHashToStderr(vmState: BaseVMState) = proc runExecution(ctx: var StateContext, conf: StateConf, pre: JsonNode): StateResult = let com = CommonRef.new(newCoreDbRef LegacyDbMemory, ctx.chainConfig, pruneTrie = false) - parent = BlockHeader(stateRoot: emptyRlpHash) fork = com.toEVMFork(ctx.header.forkDeterminationInfoForHeader) stream = newFileStream(stderr) tracer = if conf.jsonEnabled: @@ -184,9 +186,17 @@ proc runExecution(ctx: var StateContext, conf: StateConf, pre: JsonNode): StateR else: JsonTracer(nil) + if com.isCancunOrLater(ctx.header.timestamp): + if not ctx.trustedSetupLoaded: + let res = loadKzgTrustedSetup() + if res.isErr: + echo "FATAL: ", res.error + quit(QuitFailure) + ctx.trustedSetupLoaded = true + let vmState = TestVMState() vmState.init( - parent = parent, + parent = ctx.parent, header = ctx.header, com = com, tracer = tracer) @@ -217,7 +227,7 @@ proc runExecution(ctx: var StateContext, conf: StateConf, pre: JsonNode): StateR ctx.tx, sender, ctx.header, fork) if rc.isOk: gasUsed = rc.value - + let miner = ctx.header.coinbase coinbaseStateClearing(vmState, miner, fork) except CatchableError as ex: @@ -248,6 +258,7 @@ proc prepareAndRun(ctx: var StateContext, conf: StateConf): bool = post = n["post"] pre = n["pre"] + ctx.parent = parseParentHeader(n["env"]) ctx.header = parseHeader(n["env"]) if conf.debugEnabled or conf.jsonEnabled: diff --git a/tools/evmstate/evmstate_test.nim b/tools/evmstate/evmstate_test.nim index a6257e3a1..adedce7fe 100644 --- a/tools/evmstate/evmstate_test.nim +++ b/tools/evmstate/evmstate_test.nim @@ -21,8 +21,9 @@ type dispName: string const - inputFolder = "tests" / "fixtures" / "eth_tests" / "GeneralStateTests" - testData = "tools" / "evmstate" / "testdata" + inputFolder = "tests/fixtures/eth_tests/GeneralStateTests" + #inputFolder = "tests/fixtures/eth_tests/EIPTests/StateTests" + testData = "tools/evmstate/testdata" proc runTest(filename: string): bool = let appDir = getAppDir() diff --git a/tools/evmstate/helpers.nim b/tools/evmstate/helpers.nim index ffc9a27e0..e3c36df1a 100644 --- a/tools/evmstate/helpers.nim +++ b/tools/evmstate/helpers.nim @@ -114,9 +114,15 @@ proc parseHeader*(n: JsonNode): BlockHeader = stateRoot : emptyRlpHash, mixDigest : omitZero(Hash256, "currentRandom"), fee : optional(UInt256, "currentBaseFee"), - excessBlobGas: optional(uint64, "excessBlobGas"), - blobGasUsed: optional(uint64, "blobGasUsed"), - parentBeaconBlockRoot: optional(Hash256, "parentBeaconBlockRoot"), + withdrawalsRoot: optional(Hash256, "currentWithdrawalsRoot"), + parentBeaconBlockRoot: optional(Hash256, "currentBeaconRoot"), + ) + +proc parseParentHeader*(n: JsonNode): BlockHeader = + BlockHeader( + stateRoot: emptyRlpHash, + excessBlobGas: optional(uint64, "parentExcessBlobGas"), + blobGasUsed: optional(uint64, "parentBlobGasUsed"), ) proc parseTx*(n: JsonNode, dataIndex, gasIndex, valueIndex: int): Transaction =