Skip to content

Commit 42da122

Browse files
refactor(execute): update eth_config implementation (#2047)
* refactor: update eth_config spec * feat: add more bpo configuration * chore(docs): remove fork hashes and IDs * Apply suggestions from code review --------- Co-authored-by: Mario Vega <[email protected]>
1 parent 8234e90 commit 42da122

File tree

6 files changed

+462
-319
lines changed

6 files changed

+462
-319
lines changed

docs/running_tests/execute/eth_config.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ This command verifies that a client is correctly configured for a specific netwo
1313
- Chain ID.
1414
- Precompile addresses.
1515
- System contract addresses.
16-
- Fork hashes and IDs.
1716

1817
## Usage
1918

Lines changed: 123 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,143 @@
11
"""Test the types in the `ethereum_test_rpc` package."""
22

3+
from typing import Any, Dict
4+
35
import pytest
46

57
from ethereum_test_rpc import EthConfigResponse
68

7-
eth_config_json_data = """
8-
{
9+
eth_config_dict: Dict[str, Any] = {
910
"current": {
10-
"activationTime": 0,
11-
"blobSchedule": {
12-
"baseFeeUpdateFraction": 3338477,
13-
"max": 6,
14-
"target": 3
15-
},
16-
"chainId": "0x88bb0",
17-
"precompiles": {
18-
"0x0000000000000000000000000000000000000001": "ECREC",
19-
"0x0000000000000000000000000000000000000002": "SHA256",
20-
"0x0000000000000000000000000000000000000003": "RIPEMD160",
21-
"0x0000000000000000000000000000000000000004": "ID",
22-
"0x0000000000000000000000000000000000000005": "MODEXP",
23-
"0x0000000000000000000000000000000000000006": "BN254_ADD",
24-
"0x0000000000000000000000000000000000000007": "BN254_MUL",
25-
"0x0000000000000000000000000000000000000008": "BN254_PAIRING",
26-
"0x0000000000000000000000000000000000000009": "BLAKE2F",
27-
"0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION"
28-
},
29-
"systemContracts": {
30-
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"
31-
}
11+
"activationTime": 0,
12+
"blobSchedule": {"baseFeeUpdateFraction": 3338477, "max": 6, "target": 3},
13+
"chainId": "0x88bb0",
14+
"forkId": "0xbef71d30",
15+
"precompiles": {
16+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
17+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
18+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
19+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
20+
"ECREC": "0x0000000000000000000000000000000000000001",
21+
"ID": "0x0000000000000000000000000000000000000004",
22+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
23+
"MODEXP": "0x0000000000000000000000000000000000000005",
24+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
25+
"SHA256": "0x0000000000000000000000000000000000000002",
26+
},
27+
"systemContracts": {"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02"},
3228
},
33-
"currentHash": "0x2eedf329",
34-
"currentForkId": "0xbef71d30",
3529
"next": {
36-
"activationTime": 1742999832,
37-
"blobSchedule": {
38-
"baseFeeUpdateFraction": 5007716,
39-
"max": 9,
40-
"target": 6
41-
},
42-
"chainId": "0x88bb0",
43-
"precompiles": {
44-
"0x0000000000000000000000000000000000000001": "ECREC",
45-
"0x0000000000000000000000000000000000000002": "SHA256",
46-
"0x0000000000000000000000000000000000000003": "RIPEMD160",
47-
"0x0000000000000000000000000000000000000004": "ID",
48-
"0x0000000000000000000000000000000000000005": "MODEXP",
49-
"0x0000000000000000000000000000000000000006": "BN254_ADD",
50-
"0x0000000000000000000000000000000000000007": "BN254_MUL",
51-
"0x0000000000000000000000000000000000000008": "BN254_PAIRING",
52-
"0x0000000000000000000000000000000000000009": "BLAKE2F",
53-
"0x000000000000000000000000000000000000000a": "KZG_POINT_EVALUATION",
54-
"0x000000000000000000000000000000000000000b": "BLS12_G1ADD",
55-
"0x000000000000000000000000000000000000000c": "BLS12_G1MSM",
56-
"0x000000000000000000000000000000000000000d": "BLS12_G2ADD",
57-
"0x000000000000000000000000000000000000000e": "BLS12_G2MSM",
58-
"0x000000000000000000000000000000000000000f": "BLS12_PAIRING_CHECK",
59-
"0x0000000000000000000000000000000000000010": "BLS12_MAP_FP_TO_G1",
60-
"0x0000000000000000000000000000000000000011": "BLS12_MAP_FP2_TO_G2"
61-
},
62-
"systemContracts": {
63-
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
64-
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": "0x0000bbddc7ce488642fb579f8b00f3a590007251",
65-
"DEPOSIT_CONTRACT_ADDRESS": "0x00000000219ab540356cbb839cbe05303d7705fa",
66-
"HISTORY_STORAGE_ADDRESS": "0x0000f90827f1c53a10cb7a02335b175320002935",
67-
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": "0x00000961ef480eb55e80d19ad83579a64c007002"
68-
}
30+
"activationTime": 1742999832,
31+
"blobSchedule": {"baseFeeUpdateFraction": 5007716, "max": 9, "target": 6},
32+
"chainId": "0x88bb0",
33+
"forkId": "0x0929e24e",
34+
"precompiles": {
35+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
36+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
37+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
38+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
39+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
40+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
41+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
42+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
43+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
44+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
45+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
46+
"ECREC": "0x0000000000000000000000000000000000000001",
47+
"ID": "0x0000000000000000000000000000000000000004",
48+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
49+
"MODEXP": "0x0000000000000000000000000000000000000005",
50+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
51+
"SHA256": "0x0000000000000000000000000000000000000002",
52+
},
53+
"systemContracts": {
54+
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
55+
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": (
56+
"0x0000bbddc7ce488642fb579f8b00f3a590007251"
57+
),
58+
"DEPOSIT_CONTRACT_ADDRESS": ("0x00000000219ab540356cbb839cbe05303d7705fa"),
59+
"HISTORY_STORAGE_ADDRESS": ("0x0000f90827f1c53a10cb7a02335b175320002935"),
60+
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": ("0x00000961ef480eb55e80d19ad83579a64c007002"),
61+
},
62+
},
63+
"last": {
64+
"activationTime": 1742999832,
65+
"blobSchedule": {"baseFeeUpdateFraction": 5007716, "max": 9, "target": 6},
66+
"chainId": "0x88bb0",
67+
"forkId": "0x0929e24e",
68+
"precompiles": {
69+
"BLAKE2F": "0x0000000000000000000000000000000000000009",
70+
"BLS12_G1ADD": "0x000000000000000000000000000000000000000b",
71+
"BLS12_G1MSM": "0x000000000000000000000000000000000000000c",
72+
"BLS12_G2ADD": "0x000000000000000000000000000000000000000d",
73+
"BLS12_G2MSM": "0x000000000000000000000000000000000000000e",
74+
"BLS12_MAP_FP2_TO_G2": "0x0000000000000000000000000000000000000011",
75+
"BLS12_MAP_FP_TO_G1": "0x0000000000000000000000000000000000000010",
76+
"BLS12_PAIRING_CHECK": "0x000000000000000000000000000000000000000f",
77+
"BN254_ADD": "0x0000000000000000000000000000000000000006",
78+
"BN254_MUL": "0x0000000000000000000000000000000000000007",
79+
"BN254_PAIRING": "0x0000000000000000000000000000000000000008",
80+
"ECREC": "0x0000000000000000000000000000000000000001",
81+
"ID": "0x0000000000000000000000000000000000000004",
82+
"KZG_POINT_EVALUATION": "0x000000000000000000000000000000000000000a",
83+
"MODEXP": "0x0000000000000000000000000000000000000005",
84+
"RIPEMD160": "0x0000000000000000000000000000000000000003",
85+
"SHA256": "0x0000000000000000000000000000000000000002",
86+
},
87+
"systemContracts": {
88+
"BEACON_ROOTS_ADDRESS": "0x000f3df6d732807ef1319fb7b8bb8522d0beac02",
89+
"CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS": (
90+
"0x0000bbddc7ce488642fb579f8b00f3a590007251"
91+
),
92+
"DEPOSIT_CONTRACT_ADDRESS": ("0x00000000219ab540356cbb839cbe05303d7705fa"),
93+
"HISTORY_STORAGE_ADDRESS": ("0x0000f90827f1c53a10cb7a02335b175320002935"),
94+
"WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS": ("0x00000961ef480eb55e80d19ad83579a64c007002"),
95+
},
6996
},
70-
"nextHash": "0x0d82a81f",
71-
"nextForkId": "0x0929e24e"
7297
}
73-
"""
7498

7599

76100
@pytest.fixture
77101
def eth_config_response() -> EthConfigResponse:
78102
"""Get the `eth_config` response from the client to be verified by all tests."""
79-
return EthConfigResponse.model_validate_json(eth_config_json_data)
103+
return EthConfigResponse.model_validate(eth_config_dict)
80104

81105

82106
def test_fork_config_get_hash(eth_config_response: EthConfigResponse) -> None:
83107
"""Test the `get_hash` method of the `ForkConfig` class."""
84-
assert eth_config_response.current is not None
85-
assert eth_config_response.current_hash is not None
86-
assert eth_config_response.current.get_hash() == eth_config_response.current_hash, (
87-
"Current fork config hash does not match expected value: "
88-
f"{eth_config_response.current.get_hash()} != {eth_config_response.current_hash}"
89-
)
90-
assert eth_config_response.next is not None
91-
assert eth_config_response.next_hash is not None
92-
assert eth_config_response.next.get_hash() == eth_config_response.next_hash, (
93-
"Next fork config hash does not match expected value: "
94-
f"{eth_config_response.next.get_hash()} != {eth_config_response.next_hash}"
95-
)
108+
# Iterate through each fork config and validate
109+
for config_name in ("current", "next", "last"):
110+
config = getattr(eth_config_response, config_name)
111+
expected = eth_config_dict[config_name]
112+
if config is None:
113+
assert expected is None
114+
continue
115+
116+
# Top-level fields
117+
assert config.activation_time == expected["activationTime"]
118+
assert str(config.chain_id) == expected["chainId"]
119+
assert str(config.fork_id) == expected["forkId"]
120+
121+
# Precompiles
122+
assert set(config.precompiles.keys()) == set(expected["precompiles"].keys())
123+
for k, v in expected["precompiles"].items():
124+
assert config.precompiles[k] == v
125+
126+
# System contracts
127+
assert set(config.system_contracts.keys()) == set(expected["systemContracts"].keys())
128+
for k, v in expected["systemContracts"].items():
129+
assert config.system_contracts[k] == v
130+
131+
# Blob schedule
132+
if expected.get("blobSchedule") is not None:
133+
assert config.blob_schedule is not None
134+
assert (
135+
config.blob_schedule.target_blobs_per_block == expected["blobSchedule"]["target"]
136+
)
137+
assert config.blob_schedule.max_blobs_per_block == expected["blobSchedule"]["max"]
138+
assert (
139+
config.blob_schedule.base_fee_update_fraction
140+
== expected["blobSchedule"]["baseFeeUpdateFraction"]
141+
)
142+
else:
143+
assert config.blob_schedule is None

src/ethereum_test_rpc/types.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ class ForkConfig(CamelModel):
214214
activation_time: int
215215
blob_schedule: ForkConfigBlobSchedule | None = None
216216
chain_id: HexNumber
217-
precompiles: Dict[Address, str]
217+
fork_id: ForkHash
218+
precompiles: Dict[str, Address]
218219
system_contracts: Dict[str, Address]
219220

220221
def get_hash(self) -> ForkHash:
@@ -227,11 +228,5 @@ class EthConfigResponse(CamelModel):
227228
"""Response of the `eth_config` RPC endpoint."""
228229

229230
current: ForkConfig
230-
current_hash: ForkHash
231-
current_fork_id: ForkHash
232231
next: ForkConfig | None = None
233-
next_hash: ForkHash | None = None
234-
next_fork_id: ForkHash | None = None
235232
last: ForkConfig | None = None
236-
last_hash: ForkHash | None = None
237-
last_fork_id: ForkHash | None = None

0 commit comments

Comments
 (0)