Skip to content

Commit af96fb7

Browse files
spencer-tbjsign
authored andcommitted
wip(fw): add the witness to fixture from t8n output result.
1 parent ea76635 commit af96fb7

File tree

6 files changed

+65
-19
lines changed

6 files changed

+65
-19
lines changed

src/ethereum_test_base_types/pydantic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Base pydantic classes used to define the models for Ethereum tests.
33
"""
4+
45
from typing import TypeVar
56

67
from pydantic import BaseModel, ConfigDict

src/ethereum_test_fixtures/blockchain.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
WithdrawalRequest,
4141
WithdrawalRequestGeneric,
4242
)
43+
from ethereum_test_types.verkle import Witness
4344

4445
from .base import BaseFixture
4546
from .formats import FixtureFormats
@@ -412,6 +413,19 @@ def from_consolidation_request(
412413
return cls(**d.model_dump())
413414

414415

416+
class FixtureWitness(Witness):
417+
"""
418+
Structure to represent a single verkle block witness.
419+
"""
420+
421+
@classmethod
422+
def from_witness(cls, w: Witness) -> "FixtureWitness":
423+
"""
424+
Returns a FixtureWitness from a Witness.
425+
"""
426+
return cls(**w.model_dump(exclude_none=False))
427+
428+
415429
class FixtureBlockBase(CamelModel):
416430
"""Representation of an Ethereum block within a test Fixture without RLP bytes."""
417431

@@ -423,6 +437,8 @@ class FixtureBlockBase(CamelModel):
423437
withdrawal_requests: List[FixtureWithdrawalRequest] | None = None
424438
consolidation_requests: List[FixtureConsolidationRequest] | None = None
425439

440+
witness: FixtureWitness | None = None
441+
426442
@computed_field(alias="blocknumber") # type: ignore[misc]
427443
@cached_property
428444
def block_number(self) -> Number:

src/ethereum_test_specs/blockchain.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
FixtureTransaction,
3434
FixtureWithdrawal,
3535
FixtureWithdrawalRequest,
36+
FixtureWitness,
3637
InvalidFixtureBlock,
3738
)
3839
from ethereum_test_forks import EIP6800Transition, Fork, Verkle
@@ -47,7 +48,7 @@
4748
Withdrawal,
4849
WithdrawalRequest,
4950
)
50-
from ethereum_test_types.verkle import VerkleTree
51+
from ethereum_test_types.verkle import VerkleTree, Witness
5152
from evm_transition_tool import TransitionTool
5253

5354
from .base import BaseTest, verify_result, verify_transactions
@@ -411,6 +412,7 @@ def generate_block_data(
411412
Alloc,
412413
Optional[Requests],
413414
Optional[VerkleTree],
415+
Optional[Witness],
414416
]:
415417
"""
416418
Generate common block data for both make_fixture and make_hive_fixture.
@@ -453,13 +455,17 @@ def generate_block_data(
453455
try:
454456
rejected_txs = verify_transactions(txs, transition_tool_output.result)
455457
verify_result(transition_tool_output.result, env)
458+
# TODO: add verify witness (against vkt)
459+
# verify_witness(transition_tool_output.witness, transition_tool_output.vkt)
456460
except Exception as e:
457461
print_traces(t8n.get_traces())
458462
pprint(transition_tool_output.result)
459463
pprint(previous_alloc)
460464
pprint(transition_tool_output.alloc)
461465
if transition_tool_output.vkt is not None:
462466
pprint(transition_tool_output.vkt)
467+
if transition_tool_output.witness is not None:
468+
pprint(transition_tool_output.witness)
463469
raise e
464470

465471
if len(rejected_txs) > 0 and block.exception is None:
@@ -532,6 +538,11 @@ def generate_block_data(
532538
)
533539
)
534540
transition_tool_output.alloc = previous_alloc
541+
# TODO: hack for now
542+
transition_tool_output.witness = Witness(
543+
verkle_proof=transition_tool_output.result.verkle_proof,
544+
state_diff=transition_tool_output.result.state_diff,
545+
)
535546

536547
return (
537548
env,
@@ -540,6 +551,7 @@ def generate_block_data(
540551
transition_tool_output.alloc,
541552
requests,
542553
transition_tool_output.vkt,
554+
transition_tool_output.witness,
543555
)
544556

545557
def network_info(self, fork: Fork, eips: Optional[List[int]] = None):
@@ -616,14 +628,16 @@ def make_fixture(
616628
# This is the most common case, the RLP needs to be constructed
617629
# based on the transactions to be included in the block.
618630
# Set the environment according to the block to execute.
619-
new_env, header, txs, new_alloc, requests, new_vkt = self.generate_block_data(
620-
t8n=t8n,
621-
fork=fork,
622-
block=block,
623-
previous_env=env,
624-
previous_alloc=alloc,
625-
previous_vkt=vkt,
626-
eips=eips,
631+
new_env, header, txs, new_alloc, requests, new_vkt, witness = (
632+
self.generate_block_data(
633+
t8n=t8n,
634+
fork=fork,
635+
block=block,
636+
previous_env=env,
637+
previous_alloc=alloc,
638+
previous_vkt=vkt,
639+
eips=eips,
640+
)
627641
)
628642
fixture_block = FixtureBlockBase(
629643
header=header,
@@ -658,6 +672,7 @@ def make_fixture(
658672
if requests is not None
659673
else None
660674
),
675+
witness=FixtureWitness.from_witness(witness) if witness is not None else None,
661676
).with_rlp(txs=txs, requests=requests)
662677
if block.exception is None:
663678
fixture_blocks.append(fixture_block)
@@ -731,7 +746,8 @@ def make_hive_fixture(
731746
self.blocks.append(Block())
732747

733748
for block in self.blocks:
734-
new_env, header, txs, new_alloc, requests, new_vkt = self.generate_block_data(
749+
# TODO: fix witness for hive fixture? Do we need it?
750+
new_env, header, txs, new_alloc, requests, new_vkt, _ = self.generate_block_data(
735751
t8n=t8n,
736752
fork=fork,
737753
block=block,
@@ -775,7 +791,7 @@ def make_hive_fixture(
775791
# Most clients require the header to start the sync process, so we create an empty
776792
# block on top of the last block of the test to send it as new payload and trigger the
777793
# sync process.
778-
_, sync_header, _, _, requests, _ = self.generate_block_data(
794+
_, sync_header, _, _, requests, _, _ = self.generate_block_data(
779795
t8n=t8n,
780796
fork=fork,
781797
block=Block(),

src/ethereum_test_types/verkle/types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class SuffixStateDiff(CamelModel):
7474
"""
7575

7676
suffix: int
77-
current_value: Hash | None = Field(None)
78-
new_value: Hash | None = Field(None)
77+
current_value: Hash | None = Field(default_factory=None)
78+
new_value: Hash | None = Field(default_factory=None)
7979

8080

8181
class StemStateDiff(CamelModel):
@@ -119,9 +119,9 @@ class Witness(CamelModel):
119119
hash of the state tree before the current block execution.
120120
"""
121121

122-
state_diff: StateDiff = Field(..., alias="Diff")
123-
verkle_proof: VerkleProof | None = Field(None, alias="Proof")
124-
parent_state_root: Hash
122+
state_diff: StateDiff
123+
verkle_proof: VerkleProof
124+
# parent_state_root: Hash
125125

126126

127127
class VerkleTree(RootModel[Dict[Hash, Hash]]):

src/evm_transition_tool/transition_tool.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,16 @@ def _evaluate_filesystem(
311311

312312
# TODO: Verkle specific logic, update when Verkle fork is confirmed.
313313
if t8n_data.fork_name == "Verkle":
314-
output_paths["vkt"] = os.path.join("output", "vkt.json")
315-
args.extend(["--output.vkt", output_paths["vkt"]])
314+
output_paths.update(
315+
{
316+
"vkt": os.path.join("output", "vkt.json"),
317+
"witness": os.path.join("output", "witness.json"),
318+
}
319+
)
320+
args.extend(
321+
["--output.vkt", output_paths["vkt"], "--output.witness", output_paths["witness"]]
322+
)
323+
print(output_paths)
316324
if t8n_data.vkt is not None:
317325
args.extend(["--input.vkt", input_paths["vkt"]])
318326

@@ -371,6 +379,7 @@ def _evaluate_filesystem(
371379
with open(file_path, "r+") as file:
372380
output_contents[key] = json.load(file)
373381
output = TransitionToolOutput(**output_contents)
382+
print(output)
374383
if self.trace:
375384
self.collect_traces(output.result.receipts, temp_dir, debug_output_path)
376385

src/evm_transition_tool/types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Transaction,
1616
WithdrawalRequest,
1717
)
18-
from ethereum_test_types.verkle import VerkleTree
18+
from ethereum_test_types.verkle import StateDiff, VerkleProof, VerkleTree, Witness
1919

2020

2121
class TransactionLog(CamelModel):
@@ -99,6 +99,9 @@ class Result(CamelModel):
9999
alias="currentConversionStorageProcessed",
100100
)
101101

102+
verkle_proof: VerkleProof | None = None
103+
state_diff: StateDiff | None = None
104+
102105

103106
class TransitionToolInput(CamelModel):
104107
"""
@@ -120,3 +123,4 @@ class TransitionToolOutput(CamelModel):
120123
result: Result
121124
body: Bytes | None = None
122125
vkt: VerkleTree | None = None
126+
witness: Witness | None = None

0 commit comments

Comments
 (0)