Skip to content

Commit f07306e

Browse files
committed
added kzg functions for peerdas tests
1 parent ee9b84d commit f07306e

File tree

15 files changed

+9009
-73
lines changed

15 files changed

+9009
-73
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ dependencies = [
5050
"pytest-regex>=0.2.0,<0.3",
5151
"eth-abi>=5.2.0",
5252
"joblib>=1.4.2",
53+
"ckzg>=2.1.1",
5354
]
5455

5556
[project.urls]

src/ethereum_test_execution/blob_transaction.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import ClassVar, Dict, List
44

55
from ethereum_test_base_types import Hash
6+
from ethereum_test_base_types.base_types import Bytes
67
from ethereum_test_forks import Fork
78
from ethereum_test_rpc import BlobAndProofV1, BlobAndProofV2, EngineRPC, EthRPC
89
from ethereum_test_types import NetworkWrappedTransaction, Transaction
@@ -19,16 +20,17 @@ def versioned_hashes_with_blobs_and_proofs(
1920
"""
2021
versioned_hashes: Dict[Hash, BlobAndProofV1 | BlobAndProofV2] = {}
2122
for blob in tx.blobs:
22-
versioned_hash = blob.versioned_hash()
23-
if blob.kzg_proof is not None:
24-
versioned_hashes[versioned_hash] = BlobAndProofV1(blob=blob.data, proof=blob.kzg_proof)
25-
elif blob.kzg_cell_proofs is not None:
26-
versioned_hashes[versioned_hash] = BlobAndProofV2(
27-
blob=blob.data, proofs=blob.kzg_cell_proofs
23+
if isinstance(blob.proof, Bytes):
24+
versioned_hashes[blob.versioned_hash] = BlobAndProofV1(
25+
blob=blob.data, proof=blob.proof
26+
)
27+
elif isinstance(blob.proof, list):
28+
versioned_hashes[blob.versioned_hash] = BlobAndProofV2(
29+
blob=blob.data, proofs=blob.proof
2830
)
2931
else:
3032
raise ValueError(
31-
f"Blob with versioned hash {versioned_hash.hex()} requires either kzg_proof "
33+
f"Blob with versioned hash {blob.versioned_hash.hex()} requires either kzg_proof "
3234
"or kzg_cell_proofs, but both are None"
3335
)
3436

src/ethereum_test_forks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
BerlinToLondonAt5,
2525
CancunToPragueAtTime15k,
2626
ParisToShanghaiAtTime15k,
27+
PragueToOsakaAtTime15k,
2728
ShanghaiToCancunAtTime15k,
2829
)
2930
from .gas_costs import GasCosts
@@ -76,6 +77,7 @@
7677
"Cancun",
7778
"CancunToPragueAtTime15k",
7879
"Prague",
80+
"PragueToOsakaAtTime15k",
7981
"Osaka",
8082
"get_transition_forks",
8183
"forks_from",

src/ethereum_test_forks/base_fork.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
"""Abstract base class for Ethereum forks."""
22

33
from abc import ABC, ABCMeta, abstractmethod
4-
from typing import Any, ClassVar, List, Mapping, Optional, Protocol, Sized, Tuple, Type
4+
from typing import (
5+
Any,
6+
ClassVar,
7+
Dict,
8+
List,
9+
Literal,
10+
Mapping,
11+
Optional,
12+
Protocol,
13+
Sized,
14+
Tuple,
15+
Type,
16+
Union,
17+
)
518

619
from semver import Version
720

@@ -155,6 +168,14 @@ class BaseFork(ABC, metaclass=BaseForkMeta):
155168
_solc_name: ClassVar[Optional[str]] = None
156169
_ignore: ClassVar[bool] = False
157170

171+
# make mypy happy
172+
BLOB_CONSTANTS: ClassVar[Dict[str, Union[int, Literal["big"]]]] = {}
173+
174+
@classmethod
175+
def get_blob_constant(cls, name: str) -> int | Literal["big"]:
176+
"""Return value of requested blob constant."""
177+
raise NotImplementedError
178+
158179
def __init_subclass__(
159180
cls,
160181
*,

src/ethereum_test_forks/forks/forks.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from hashlib import sha256
55
from os.path import realpath
66
from pathlib import Path
7-
from typing import List, Mapping, Optional, Sized, Tuple
7+
from typing import List, Literal, Mapping, Optional, Sized, Tuple
88

99
from semver import Version
1010

@@ -894,6 +894,27 @@ def valid_opcodes(
894894
class Cancun(Shanghai):
895895
"""Cancun fork."""
896896

897+
BLOB_CONSTANTS = { # every value is an int or a Literal
898+
"FIELD_ELEMENTS_PER_BLOB": 4096,
899+
"BYTES_PER_FIELD_ELEMENT": 32,
900+
"CELL_LENGTH": 2048,
901+
"BLS_MODULUS": 0x73EDA753299D7D483339D80809A1D80553BDA402FFFE5BFEFFFFFFFF00000001, # EIP-2537: Main subgroup order = q, due to this BLS_MODULUS every blob byte (uint256) must be smaller than 116 # noqa: E501
902+
# https://github.com/ethereum/consensus-specs/blob/cc6996c22692d70e41b7a453d925172ee4b719ad/specs/deneb/polynomial-commitments.md?plain=1#L78
903+
"BYTES_PER_PROOF": 48,
904+
"BYTES_PER_COMMITMENT": 48,
905+
"KZG_ENDIANNESS": "big",
906+
"AMOUNT_CELL_PROOFS": 0,
907+
}
908+
909+
@classmethod
910+
def get_blob_constant(cls, name: str) -> int | Literal["big"]:
911+
"""Return blob constant if it exists."""
912+
retrieved_constant = cls.BLOB_CONSTANTS.get(name)
913+
assert retrieved_constant is not None, (
914+
f"You tried to retrieve the blob constant {name} but it does not exist!"
915+
)
916+
return retrieved_constant
917+
897918
@classmethod
898919
def solc_min_version(cls) -> Version:
899920
"""Return minimum version of solc that supports this fork."""
@@ -1077,6 +1098,16 @@ def valid_opcodes(
10771098
class Prague(Cancun):
10781099
"""Prague fork."""
10791100

1101+
# update some blob constants
1102+
BLOB_CONSTANTS = {
1103+
**Cancun.BLOB_CONSTANTS, # same base constants as cancun
1104+
"MAX_BLOBS_PER_BLOCK": 9, # but overwrite or add these
1105+
"TARGET_BLOBS_PER_BLOCK": 6,
1106+
"MAX_BLOB_GAS_PER_BLOCK": 1179648,
1107+
"TARGET_BLOB_GAS_PER_BLOCK": 786432,
1108+
"BLOB_BASE_FEE_UPDATE_FRACTION": 5007716,
1109+
}
1110+
10801111
@classmethod
10811112
def is_deployed(cls) -> bool:
10821113
"""
@@ -1328,6 +1359,12 @@ def engine_forkchoice_updated_version(
13281359
class Osaka(Prague, solc_name="cancun"):
13291360
"""Osaka fork."""
13301361

1362+
# update some blob constants
1363+
BLOB_CONSTANTS = {
1364+
**Prague.BLOB_CONSTANTS, # same base constants as prague
1365+
"AMOUNT_CELL_PROOFS": 128,
1366+
}
1367+
13311368
@classmethod
13321369
def engine_get_payload_version(
13331370
cls, block_number: int = 0, timestamp: int = 0

src/ethereum_test_forks/forks/transition.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""List of all transition fork definitions."""
22

33
from ..transition_base_fork import transition_fork
4-
from .forks import Berlin, Cancun, London, Paris, Prague, Shanghai
4+
from .forks import Berlin, Cancun, London, Osaka, Paris, Prague, Shanghai
55

66

77
# Transition Forks
@@ -31,3 +31,10 @@ class CancunToPragueAtTime15k(Cancun):
3131
"""Cancun to Prague transition at Timestamp 15k."""
3232

3333
pass
34+
35+
36+
@transition_fork(to_fork=Osaka, at_timestamp=15_000)
37+
class PragueToOsakaAtTime15k(Prague):
38+
"""Prague to Cancun transition at Timestamp 15k."""
39+
40+
pass

src/ethereum_test_types/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Common definitions and types."""
22

33
from .account_types import EOA, Alloc
4+
from .blob_types import Blob
45
from .block_types import (
56
Environment,
67
EnvironmentDefaults,
@@ -23,7 +24,6 @@
2324
)
2425
from .transaction_types import (
2526
AuthorizationTuple,
26-
Blob,
2727
NetworkWrappedTransaction,
2828
Transaction,
2929
TransactionDefaults,

0 commit comments

Comments
 (0)