Fix blobGas fields handling in evmstate

This commit is contained in:
jangko 2023-09-21 22:21:21 +07:00
parent 7ee862ab3f
commit 2d2def9a8d
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
5 changed files with 33 additions and 12 deletions

View File

@ -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)

View File

@ -35,6 +35,7 @@ type
Shanghai
MergeToShanghaiAtTime15k
Cancun
ShanghaiToCancunAtTime15k
LogLevel* = enum
Silent

View File

@ -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:

View File

@ -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()

View File

@ -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 =