Skip to content

Commit 400c447

Browse files
committed
wip fixing execute with actual blobs
1 parent b0fb3de commit 400c447

File tree

5 files changed

+64
-41
lines changed

5 files changed

+64
-41
lines changed

src/ethereum_test_base_types/conversions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
FixedSizeBytesConvertible: TypeAlias = str | bytes | SupportsBytes | List[int] | int
88
NumberConvertible: TypeAlias = str | bytes | SupportsBytes | int
99

10+
from pytest_plugins.logging import get_logger
11+
12+
logger = get_logger(__name__)
13+
1014

1115
def int_or_none(input_value: Any, default: Optional[int] = None) -> int | None:
1216
"""Convert a value to int or returns a default (None)."""
@@ -47,6 +51,16 @@ def to_bytes(input_bytes: BytesConvertible) -> bytes:
4751
input_bytes = "0" + input_bytes
4852
return bytes.fromhex(input_bytes)
4953

54+
# handle wrapper_version field for >= osaka
55+
if isinstance(input_bytes, int):
56+
assert input_bytes < 256, f"Expected int that fits into one byte, but got {input_bytes}"
57+
return input_bytes.to_bytes(1, "big")
58+
59+
logger.error(
60+
f"This type of input_bytes is not yet supported: {type(input_bytes)}\n\n"
61+
f"input_bytes: {input_bytes}"
62+
)
63+
5064
raise Exception("invalid type for `bytes`")
5165

5266

src/ethereum_test_execution/blob_transaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def versioned_hashes_with_blobs_and_proofs(
1919
proofs.
2020
"""
2121
versioned_hashes: Dict[Hash, BlobAndProofV1 | BlobAndProofV2] = {}
22-
for blob in tx.blobs:
22+
for blob in tx.blob_objects:
2323
if isinstance(blob.proof, Bytes):
2424
versioned_hashes[blob.versioned_hash] = BlobAndProofV1(
2525
blob=blob.data, proof=blob.proof

src/ethereum_test_types/transaction_types.py

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -652,58 +652,54 @@ class NetworkWrappedTransaction(CamelModel, RLPSerializable):
652652
"""
653653
Network wrapped transaction as defined in
654654
[EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#networking).
655-
"""
656-
657-
tx: Transaction
658-
wrapper_version: Union[Bytes | None] = None
659-
blobs: Sequence[Blob]
660655
661-
@computed_field # type: ignore[prop-decorator]
662-
@property
663-
def blob_wrapper_version(self) -> bytes | None:
664-
"""Return the wrapper version (byte 1 for Osaka, None pre-Osaka)."""
665-
# TODO: it could be a mix of blobs from different forks, then what would be the wrapper version?
666-
if len(self.blobs) == 0:
667-
return None
656+
< Osaka:
657+
rlp([tx_payload_body, blobs, commitments, proofs])
668658
669-
fork = self.blobs[0].fork
670-
amount_cell_proofs = fork.get_blob_constant("AMOUNT_CELL_PROOFS")
671-
assert isinstance(amount_cell_proofs, int), (
672-
f"Expected AMOUNT_CELL_PROOFS of fork {fork} to be an int but this is not the case!"
673-
)
674-
if amount_cell_proofs > 0:
675-
return bytes([1])
659+
>= Osaka:
660+
rlp([tx_payload_body, wrapper_version, blobs, commitments, cell_proofs])
661+
"""
676662

677-
return None
663+
tx: Transaction
664+
blob_objects: Sequence[Blob]
665+
wrapper_version: Union[Bytes | None] = None # only exists in >= osaka
678666

679667
@computed_field # type: ignore[prop-decorator]
680668
@property
681-
def blob_data(self) -> Sequence[Bytes]:
682-
"""Return a list of blobs as bytes."""
683-
return [blob.data for blob in self.blobs]
669+
def blobs(self) -> Sequence[Bytes]:
670+
"""Return a list of blob data as bytes."""
671+
return [blob.data for blob in self.blob_objects]
684672

685673
@computed_field # type: ignore[prop-decorator]
686674
@property
687-
def blob_kzg_commitments(self) -> Sequence[Bytes]:
675+
def commitments(self) -> Sequence[Bytes]:
688676
"""Return a list of kzg commitments."""
689-
return [blob.commitment for blob in self.blobs]
677+
return [blob.commitment for blob in self.blob_objects]
690678

691679
@computed_field # type: ignore[prop-decorator]
692680
@property
693-
def blob_kzg_proofs(self) -> Sequence[Bytes | Sequence[Bytes]]:
694-
"""Return a list of kzg proofs."""
695-
proofs: list[Bytes | list[Bytes]] = []
696-
for blob in self.blobs:
681+
def proofs(self) -> Sequence[Bytes] | None:
682+
"""Return a list of kzg proofs (returns None >= Osaka)."""
683+
if self.wrapper_version is not None:
684+
return None
685+
686+
proofs: list[Bytes] = []
687+
for blob in self.blob_objects:
688+
assert isinstance(blob.proof, Bytes)
697689
proofs.append(blob.proof)
698690

699691
return proofs
700692

701693
@computed_field # type: ignore[prop-decorator]
702694
@property
703-
def blob_cells(self) -> Sequence[Sequence[Bytes] | None]:
704-
"""Return a list of cells."""
705-
cells: list[list[Bytes] | None] = []
706-
for blob in self.blobs:
695+
def cell_proofs(self) -> Sequence[Sequence[Bytes]] | None:
696+
"""Return a list of cells (returns None < Osaka)."""
697+
if self.wrapper_version is None:
698+
return None
699+
700+
cells: list[list[Bytes]] = []
701+
for blob in self.blob_objects:
702+
assert isinstance(blob.cells, list)
707703
cells.append(blob.cells)
708704

709705
return cells
@@ -718,13 +714,26 @@ def get_rlp_fields(self) -> List[str]:
718714
719715
The list can be nested list up to one extra level to represent nested fields.
720716
"""
717+
# only put a wrapper_version field for >=osaka (value 1), otherwise omit field
718+
wrapper = []
719+
if self.wrapper_version is not None:
720+
wrapper = ["wrapper_version"]
721+
722+
proofs: list[str] = []
723+
if len(proofs) > 0:
724+
proofs = ["proofs"]
725+
726+
cell_proofs: list[str] = []
727+
if len(cell_proofs) > 0:
728+
cell_proofs = ["cell_proofs"]
729+
721730
return [ # structure explained in https://eips.ethereum.org/EIPS/eip-7594#Networking
722731
"tx", # tx_payload_body
723-
"blob_wrapper_version", # wrapper_version, which is always 1 for osaka (was it non-existing before?)
724-
"blob_data", # blobs
725-
"blob_kzg_commitments", # commitments
726-
"blob_kzg_proofs", # cell_proofs
727-
"blob_cells",
732+
*wrapper, # wrapper_version, which is always 1 for osaka (was non-existing before)
733+
"blobs", # Blob.data
734+
"commitments",
735+
*proofs, # only included < osaka
736+
*cell_proofs, # only included >= osaka
728737
]
729738

730739
def get_rlp_prefix(self) -> bytes:

tests/cancun/eip4844_blobs/test_blob_txs_full.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def txs( # noqa: D103
182182
wrapped_blob_transaction=tx_wrapped_blobs,
183183
)
184184
if tx_wrapped_blobs:
185-
network_wrapped_tx = NetworkWrappedTransaction(tx=tx, blobs=tx_blobs)
185+
network_wrapped_tx = NetworkWrappedTransaction(tx=tx, blob_objects=tx_blobs)
186186
tx.rlp_override = network_wrapped_tx.rlp()
187187
txs.append(tx)
188188
return txs

tests/osaka/eip7594_peerdas/test_get_blobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ def txs( # noqa: D103
182182
)
183183
network_wrapped_tx = NetworkWrappedTransaction(
184184
tx=tx,
185-
blobs=tx_blobs,
186185
wrapper_version=tx_wrapper_version,
186+
blob_objects=tx_blobs,
187187
)
188188
txs.append(network_wrapped_tx)
189189
return txs

0 commit comments

Comments
 (0)