diff --git a/src/ethereum_test_specs/blockchain.py b/src/ethereum_test_specs/blockchain.py index d785440e8f..3534622413 100644 --- a/src/ethereum_test_specs/blockchain.py +++ b/src/ethereum_test_specs/blockchain.py @@ -3,7 +3,7 @@ """ from pprint import pprint -from typing import Any, Callable, ClassVar, Dict, Generator, List, Optional, Tuple, Type +from typing import Any, Callable, ClassVar, Dict, Generator, List, Mapping, Optional, Tuple, Type import pytest from pydantic import ConfigDict, Field, field_validator @@ -35,12 +35,13 @@ FixtureBlock, FixtureBlockBase, FixtureEngineNewPayload, + FixtureForkBlobSchedule, FixtureHeader, FixtureTransaction, FixtureWithdrawal, InvalidFixtureBlock, ) -from ethereum_test_forks import Fork +from ethereum_test_forks import Fork, TransitionFork from ethereum_test_types import Alloc, Environment, Removable, Requests, Transaction, Withdrawal from .base import BaseTest, verify_result @@ -119,7 +120,6 @@ class Header(CamelModel): excess_blob_gas: Removable | HexNumber | None = None parent_beacon_block_root: Removable | Hash | None = None requests_hash: Removable | Hash | None = None - target_blobs_per_block: Removable | HexNumber | None = None REMOVE_FIELD: ClassVar[Removable] = Removable() """ @@ -270,8 +270,6 @@ def set_environment(self, env: Environment) -> Environment: new_env_values["blob_gas_used"] = self.blob_gas_used if not isinstance(self.parent_beacon_block_root, Removable): new_env_values["parent_beacon_block_root"] = self.parent_beacon_block_root - if not isinstance(self.target_blobs_per_block, Removable): - new_env_values["target_blobs_per_block"] = self.target_blobs_per_block """ These values are required, but they depend on the previous environment, so they can be calculated here. @@ -515,6 +513,36 @@ def network_info(self, fork: Fork, eips: Optional[List[int]] = None): else fork.blockchain_test_network_name() ) + def blob_schedule( + self, fork: Fork | TransitionFork, eips: Optional[List[int]] = None + ) -> Mapping[str, FixtureForkBlobSchedule] | None: + """ + Returns the blob schedule for the given fork and EIPs. + """ + if fork.is_transition_fork(): + fork: Fork = fork.transitions_to() # type: ignore + blob_schedule: Dict[str, FixtureForkBlobSchedule] = {} + last_fork_blob_schedule: FixtureForkBlobSchedule | None = None + for fork in fork.parents() + [fork]: + if fork.target_blobs_per_block(0, 0) is None or fork.max_blobs_per_block(0, 0) is None: + continue + current_fork_blob_schedule = FixtureForkBlobSchedule( + target_blobs_per_block=fork.target_blobs_per_block(0, 0), + max_blobs_per_block=fork.max_blobs_per_block(0, 0), + ) + if ( + last_fork_blob_schedule is None + or current_fork_blob_schedule != last_fork_blob_schedule + ): + blob_schedule[fork.name()] = current_fork_blob_schedule + + last_fork_blob_schedule = current_fork_blob_schedule + + if not blob_schedule: + return None + + return blob_schedule + def verify_post_state(self, t8n, alloc: Alloc): """ Verifies the post alloc after all block/s or payload/s are generated. @@ -607,6 +635,7 @@ def make_fixture( last_block_hash=head, pre=pre, post_state=alloc, + blob_schedule=self.blob_schedule(fork, eips), ) def make_hive_fixture( @@ -697,6 +726,7 @@ def make_hive_fixture( post_state=alloc, sync_payload=sync_payload, last_block_hash=head_hash, + blob_schedule=self.blob_schedule(fork, eips), ) def generate( diff --git a/src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test.json b/src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test.json new file mode 100644 index 0000000000..b5f66f9bd0 --- /dev/null +++ b/src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test.json @@ -0,0 +1,138 @@ +{ + "000/my_chain_id_test/Cancun": { + "_info": { + "hash": "0x969794b41e3ae61c6ed89b7117f28a76f31498638931efd525446fe8939a7b50", + "fixture_format": "blockchain_test" + }, + "network": "Cancun", + "genesisRLP": "0xf9023df90237a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527efa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080808502540be400808000a0000000000000000000000000000000000000000000000000000000000000000088000000000000000007a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000c0c0c0", + "genesisBlockHeader": { + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "coinbase": "0x0000000000000000000000000000000000000000", + "stateRoot": "0x789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527ef", + "transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x00", + "number": "0x00", + "gasLimit": "0x02540be400", + "gasUsed": "0x00", + "timestamp": "0x00", + "extraData": "0x00", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000000", + "baseFeePerGas": "0x07", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "blobGasUsed": "0x00", + "excessBlobGas": "0x00", + "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "hash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b" + }, + "blocks": [ + { + "rlp": "0xf902a5f9023ba028c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942adc25665018aa1fe0e6bc666dac8fc2697ff9baa0db94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbba08151d548273f6683169524b66ca9fe338b9ce42bc3540046c828fd939ae23bcba0c598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0ab901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080018502540be40082a8618203e800a0000000000000000000000000000000000000000000000000000000000000000088000000000000000007a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b4218080a00000000000000000000000000000000000000000000000000000000000000000f863f861800a8405f5e10094100000000000000000000000000000000000000080801ba07e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37a05f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509bc0c0", + "blockHeader": { + "parentHash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b", + "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "coinbase": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "stateRoot": "0xdb94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbb", + "transactionsTrie": "0x8151d548273f6683169524b66ca9fe338b9ce42bc3540046c828fd939ae23bcb", + "receiptTrie": "0xc598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0a", + "bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x00", + "number": "0x01", + "gasLimit": "0x02540be400", + "gasUsed": "0xa861", + "timestamp": "0x03e8", + "extraData": "0x00", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000000", + "baseFeePerGas": "0x07", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "blobGasUsed": "0x00", + "excessBlobGas": "0x00", + "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "hash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b" + }, + "blocknumber": "1", + "transactions": [ + { + "type": "0x00", + "chainId": "0x00", + "nonce": "0x00", + "gasPrice": "0x0a", + "gasLimit": "0x05f5e100", + "to": "0x1000000000000000000000000000000000000000", + "value": "0x00", + "data": "0x", + "v": "0x1b", + "r": "0x7e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37", + "s": "0x5f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509b", + "sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" + } + ], + "uncleHeaders": [], + "withdrawals": [] + } + ], + "lastblockhash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b", + "pre": { + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": { + "balance": "0x00", + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500", + "nonce": "0x01", + "storage": {} + }, + "0x1000000000000000000000000000000000000000": { + "nonce": "0x00", + "balance": "0x00", + "code": "0x4660015500", + "storage": {} + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "nonce": "0x00", + "balance": "0x3635c9adc5dea00000", + "code": "0x", + "storage": {} + } + }, + "postState": { + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": { + "balance": "0x00", + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500", + "nonce": "0x01", + "storage": { + "0x03e8": "0x03e8" + } + }, + "0x1000000000000000000000000000000000000000": { + "nonce": "0x00", + "balance": "0x00", + "code": "0x4660015500", + "storage": { + "0x01": "0x01" + } + }, + "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { + "nonce": "0x00", + "balance": "0x01f923", + "code": "0x", + "storage": {} + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "nonce": "0x01", + "balance": "0x3635c9adc5de996c36", + "code": "0x", + "storage": {} + } + }, + "sealEngine": "NoProof", + "blobSchedule": { + "Cancun": { + "max": "0x6", + "target": "0x3" + } + } + } +} \ No newline at end of file diff --git a/src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test_engine.json b/src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test_engine.json new file mode 100644 index 0000000000..2e57545fc6 --- /dev/null +++ b/src/ethereum_test_specs/tests/fixtures/chainid_cancun_blockchain_test_engine.json @@ -0,0 +1,120 @@ +{ + "000/my_chain_id_test/Cancun": { + "_info": { + "hash": "0xbcdeaa614ee2a96bf828dc699226b90733204283f14510bb739b67285250c126", + "fixture_format": "blockchain_test_engine" + }, + "network": "Cancun", + "genesisBlockHeader": { + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "uncleHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "coinbase": "0x0000000000000000000000000000000000000000", + "stateRoot": "0x789d559bf5d313e15da4139b57627160d23146cf6cdf9995e0394d165b1527ef", + "transactionsTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "receiptTrie": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "difficulty": "0x00", + "number": "0x00", + "gasLimit": "0x02540be400", + "gasUsed": "0x00", + "timestamp": "0x00", + "extraData": "0x00", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "nonce": "0x0000000000000000", + "baseFeePerGas": "0x07", + "withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "blobGasUsed": "0x00", + "excessBlobGas": "0x00", + "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "hash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b" + }, + "engineNewPayloads": [ + { + "params": [ + { + "parentHash": "0x28c341ffc393152bd02e8689d8172dd66939ac3be2b91c5841721d1755d13c2b", + "feeRecipient": "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", + "stateRoot": "0xdb94ed1be4d52fb6360c88b363cb71af08df2493e57a66ec4751f90097f2fcbb", + "receiptsRoot": "0xc598f69a5674cae9337261b669970e24abc0b46e6d284372a239ec8ccbf20b0a", + "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "blockNumber": "0x1", + "gasLimit": "0x2540be400", + "gasUsed": "0xa861", + "timestamp": "0x3e8", + "extraData": "0x00", + "prevRandao": "0x0000000000000000000000000000000000000000000000000000000000000000", + "baseFeePerGas": "0x7", + "blobGasUsed": "0x0", + "excessBlobGas": "0x0", + "blockHash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b", + "transactions": [ + "0xf861800a8405f5e10094100000000000000000000000000000000000000080801ba07e09e26678ed4fac08a249ebe8ed680bf9051a5e14ad223e4b2b9d26e0208f37a05f6e3f188e3e6eab7d7d3b6568f5eac7d687b08d307d3154ccd8c87b4630509b" + ], + "withdrawals": [] + }, + [], + "0x0000000000000000000000000000000000000000000000000000000000000000" + ], + "newPayloadVersion": "3", + "forkchoiceUpdatedVersion": "3" + } + ], + "lastblockhash": "0x3cce15f0f21f4ea23499856be01a090f0ea1be6bea4a11777b4d0cc70d105a4b", + "pre": { + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": { + "balance": "0x00", + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500", + "nonce": "0x01", + "storage": {} + }, + "0x1000000000000000000000000000000000000000": { + "nonce": "0x00", + "balance": "0x00", + "code": "0x4660015500", + "storage": {} + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "nonce": "0x00", + "balance": "0x3635c9adc5dea00000", + "code": "0x", + "storage": {} + } + }, + "postState": { + "0x000f3df6d732807ef1319fb7b8bb8522d0beac02": { + "balance": "0x00", + "code": "0x3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500", + "nonce": "0x01", + "storage": { + "0x03e8": "0x03e8" + } + }, + "0x1000000000000000000000000000000000000000": { + "nonce": "0x00", + "balance": "0x00", + "code": "0x4660015500", + "storage": { + "0x01": "0x01" + } + }, + "0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": { + "nonce": "0x00", + "balance": "0x01f923", + "code": "0x", + "storage": {} + }, + "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "nonce": "0x01", + "balance": "0x3635c9adc5de996c36", + "code": "0x", + "storage": {} + } + }, + "blobSchedule": { + "Cancun": { + "max": "0x6", + "target": "0x3" + } + } + } +} \ No newline at end of file diff --git a/src/ethereum_test_specs/tests/test_fixtures.py b/src/ethereum_test_specs/tests/test_fixtures.py index 9c92e51496..bf6583c78e 100644 --- a/src/ethereum_test_specs/tests/test_fixtures.py +++ b/src/ethereum_test_specs/tests/test_fixtures.py @@ -20,7 +20,7 @@ StateFixture, ) from ethereum_test_fixtures.blockchain import FixtureCommon -from ethereum_test_forks import Berlin, Fork, Istanbul, London, Paris, Shanghai +from ethereum_test_forks import Berlin, Cancun, Fork, Istanbul, London, Paris, Shanghai from ethereum_test_types import Alloc, Environment, Transaction from ethereum_test_vm import Opcodes as Op @@ -30,14 +30,17 @@ @pytest.fixture() -def hash(request: pytest.FixtureRequest): +def hash(fork: Fork) -> bytes: """ Set the hash based on the fork and solc version. """ - if request.node.funcargs["fork"] == Berlin: + if fork == Berlin: return bytes.fromhex("e57ad774ca") - elif request.node.funcargs["fork"] == London: + elif fork == London: return bytes.fromhex("3714102a4c") + elif fork == Cancun: + return bytes.fromhex("2885c707e3") + raise ValueError(f"Unexpected fork: {fork}") def test_check_helper_fixtures(): @@ -61,12 +64,12 @@ def test_check_helper_fixtures(): @pytest.mark.run_in_serial @pytest.mark.parametrize( - "fork,hash", + "fork", [ - (Berlin, "set using indirect & hash fixture"), - (London, "set using indirect & hash fixture"), + Berlin, + London, + Cancun, ], - indirect=["hash"], ) def test_make_genesis(fork: Fork, hash: bytes): # noqa: D103 env = Environment() @@ -108,8 +111,10 @@ def test_make_genesis(fork: Fork, hash: bytes): # noqa: D103 [ (Istanbul, BlockchainFixture), (London, BlockchainFixture), + (Cancun, BlockchainFixture), (Paris, BlockchainEngineFixture), (Shanghai, BlockchainEngineFixture), + (Cancun, BlockchainEngineFixture), (Paris, StateFixture), (Shanghai, StateFixture), ],