Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blobGas fields handling in t8n and evmstate #1767

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix blobGas fields handling in evmstate
  • Loading branch information
jangko committed Sep 22, 2023
commit 2d2def9a8d319c0bfda02fe59e4e878ab3f46045
10 changes: 6 additions & 4 deletions tools/common/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ 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)
elif f == transitionFork:
b
else:
none(BlockNumber)

proc timeToUse(f: HardFork): Option[EthTime] =
if f < transitionFork:
some(TimeZero)
elif f == transitionFork:
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)

Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions tools/common/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type
Shanghai
MergeToShanghaiAtTime15k
Cancun
ShanghaiToCancunAtTime15k

LogLevel* = enum
Silent
Expand Down
17 changes: 14 additions & 3 deletions tools/evmstate/evmstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import
../../nimbus/core/executor,
../../nimbus/common/common,
../../nimbus/evm/tracer/json_tracer,
../../nimbus/core/eip4844,
../common/helpers as chp,
"."/[config, helpers],
../common/state_clearing

type
StateContext = object
name: string
parent: BlockHeader
header: BlockHeader
tx: Transaction
expectedHash: Hash256
Expand All @@ -37,6 +39,7 @@ type
index: int
tracerFlags: set[TracerFlags]
error: string
trustedSetupLoaded: bool

DumpAccount = ref object
balance : UInt256
Expand Down Expand Up @@ -176,17 +179,24 @@ 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:
newJSonTracer(stream, ctx.tracerFlags, conf.pretty)
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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tools/evmstate/evmstate_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions tools/evmstate/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading