diff --git a/configs/mainnet.yaml b/configs/mainnet.yaml index bbe9195135..cda09fca72 100644 --- a/configs/mainnet.yaml +++ b/configs/mainnet.yaml @@ -52,14 +52,13 @@ DENEB_FORK_VERSION: 0x04000000 DENEB_FORK_EPOCH: 269568 # March 13, 2024, 01:55:35pm UTC # Electra ELECTRA_FORK_VERSION: 0x05000000 -ELECTRA_FORK_EPOCH: 18446744073709551615 +ELECTRA_FORK_EPOCH: 18446744073709551615 # temporary stub +# EIP7594 +EIP7594_FORK_VERSION: 0x06000000 # temporary stub +EIP7594_FORK_EPOCH: 18446744073709551615 # WHISK WHISK_FORK_VERSION: 0x08000000 # temporary stub WHISK_FORK_EPOCH: 18446744073709551615 -# EIP7594 -EIP7594_FORK_VERSION: 0x06000001 -EIP7594_FORK_EPOCH: 18446744073709551615 - # Time parameters # --------------------------------------------------------------- diff --git a/configs/minimal.yaml b/configs/minimal.yaml index 99e84e5fbe..e7a92a811e 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -52,12 +52,12 @@ DENEB_FORK_EPOCH: 18446744073709551615 # Electra ELECTRA_FORK_VERSION: 0x05000001 ELECTRA_FORK_EPOCH: 18446744073709551615 -# WHISK -WHISK_FORK_VERSION: 0x08000001 -WHISK_FORK_EPOCH: 18446744073709551615 # EIP7594 EIP7594_FORK_VERSION: 0x06000001 EIP7594_FORK_EPOCH: 18446744073709551615 +# WHISK +WHISK_FORK_VERSION: 0x08000001 +WHISK_FORK_EPOCH: 18446744073709551615 # Time parameters # --------------------------------------------------------------- diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 56cd45f179..40c66cf290 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -175,7 +175,7 @@ def get_data_column_sidecars(signed_block: SignedBeaconBlock, block.body, get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments'), ) - cells_and_proofs = [compute_cells_and_proofs(blob) for blob in blobs] + cells_and_proofs = [compute_cells_and_kzg_proofs(blob) for blob in blobs] blob_count = len(blobs) cells = [cells_and_proofs[i][0] for i in range(blob_count)] proofs = [cells_and_proofs[i][1] for i in range(blob_count)] diff --git a/specs/_features/eip7594/fork.md b/specs/_features/eip7594/fork.md index d8e8f208cc..790ab0287d 100644 --- a/specs/_features/eip7594/fork.md +++ b/specs/_features/eip7594/fork.md @@ -28,7 +28,7 @@ Warning: this configuration is not definitive. | Name | Value | | - | - | -| `EIP7594_FORK_VERSION` | `Version('0x05000000')` | +| `EIP7594_FORK_VERSION` | `Version('0x06000000')` | | `EIP7594_FORK_EPOCH` | `Epoch(18446744073709551615)` **TBD** | ## Helper functions diff --git a/specs/_features/eip7594/p2p-interface.md b/specs/_features/eip7594/p2p-interface.md index 9bb6d4f726..ab534cc483 100644 --- a/specs/_features/eip7594/p2p-interface.md +++ b/specs/_features/eip7594/p2p-interface.md @@ -74,8 +74,8 @@ def verify_data_column_sidecar_kzg_proofs(sidecar: DataColumnSidecar) -> bool: row_ids = [RowIndex(i) for i in range(len(sidecar.column))] # KZG batch verifies that the cells match the corresponding commitments and proofs - return verify_cell_proof_batch( - row_commitments_bytes=sidecar.kzg_commitments, + return verify_cell_kzg_proof_batch( + row_commitments=sidecar.kzg_commitments, row_indices=row_ids, # all rows column_indices=[sidecar.index], cells=sidecar.column, diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 4d3d6fc125..0b1b37b8f0 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -37,11 +37,11 @@ - [`coset_for_cell`](#coset_for_cell) - [Cells](#cells-1) - [Cell computation](#cell-computation) - - [`compute_cells_and_proofs`](#compute_cells_and_proofs) + - [`compute_cells_and_kzg_proofs`](#compute_cells_and_kzg_proofs) - [`compute_cells`](#compute_cells) - [Cell verification](#cell-verification) - - [`verify_cell_proof`](#verify_cell_proof) - - [`verify_cell_proof_batch`](#verify_cell_proof_batch) + - [`verify_cell_kzg_proof`](#verify_cell_kzg_proof) + - [`verify_cell_kzg_proof_batch`](#verify_cell_kzg_proof_batch) - [Reconstruction](#reconstruction) - [`construct_vanishing_polynomial`](#construct_vanishing_polynomial) - [`recover_shifted_data`](#recover_shifted_data) @@ -423,10 +423,10 @@ def coset_for_cell(cell_id: CellID) -> Coset: ### Cell computation -#### `compute_cells_and_proofs` +#### `compute_cells_and_kzg_proofs` ```python -def compute_cells_and_proofs(blob: Blob) -> Tuple[ +def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[ Vector[Cell, CELLS_PER_EXT_BLOB], Vector[KZGProof, CELLS_PER_EXT_BLOB]]: """ @@ -481,13 +481,13 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_EXT_BLOB]: ### Cell verification -#### `verify_cell_proof` +#### `verify_cell_kzg_proof` ```python -def verify_cell_proof(commitment_bytes: Bytes48, - cell_id: CellID, - cell: Cell, - proof_bytes: Bytes48) -> bool: +def verify_cell_kzg_proof(commitment_bytes: Bytes48, + cell_id: CellID, + cell: Cell, + proof_bytes: Bytes48) -> bool: """ Check a cell proof @@ -507,14 +507,14 @@ def verify_cell_proof(commitment_bytes: Bytes48, bytes_to_kzg_proof(proof_bytes)) ``` -#### `verify_cell_proof_batch` +#### `verify_cell_kzg_proof_batch` ```python -def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], - row_indices: Sequence[RowIndex], - column_indices: Sequence[ColumnIndex], - cells: Sequence[Cell], - proofs_bytes: Sequence[Bytes48]) -> bool: +def verify_cell_kzg_proof_batch(row_commitments_bytes: Sequence[Bytes48], + row_indices: Sequence[RowIndex], + column_indices: Sequence[ColumnIndex], + cells: Sequence[Cell], + proofs_bytes: Sequence[Bytes48]) -> bool: """ Verify a set of cells, given their corresponding proofs and their coordinates (row_id, column_id) in the blob matrix. The list of all commitments is also provided in row_commitments_bytes. diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index ca04ae6a8c..262401f0e6 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -229,7 +229,7 @@ class PendingPartialWithdrawal(Container): ``` #### `ExecutionLayerWithdrawalRequest` -*Note*: The container is new in EIP7251. +*Note*: The container is new in EIP7251:EIP7002. ```python class ExecutionLayerWithdrawalRequest(Container): diff --git a/tests/core/pyspec/eth2spec/VERSION.txt b/tests/core/pyspec/eth2spec/VERSION.txt index b3375e1fe3..dc1605fa64 100644 --- a/tests/core/pyspec/eth2spec/VERSION.txt +++ b/tests/core/pyspec/eth2spec/VERSION.txt @@ -1 +1 @@ -1.5.0-alpha.0 +1.5.0-alpha.1 diff --git a/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py b/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py index 17ffe0b468..153d6eee49 100644 --- a/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py +++ b/tests/core/pyspec/eth2spec/gen_helpers/gen_from_tests/gen.py @@ -77,7 +77,7 @@ def get_provider(create_provider_fn: Callable[[SpecForkName, PresetBaseName, str def get_create_provider_fn(runner_name: str) -> Callable[[SpecForkName, str, str, PresetBaseName], TestProvider]: def prepare_fn() -> None: - bls.use_milagro() + bls.use_fastest() return def create_provider(fork_name: SpecForkName, preset_name: PresetBaseName, diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_execution_payload.py b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_execution_payload.py index 0f3a0b0b8f..8eb6b4eab3 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_execution_payload.py @@ -338,26 +338,30 @@ def run_randomized_non_validated_execution_fields_test(spec, state, execution_va @with_bellatrix_and_later @spec_state_test def test_randomized_non_validated_execution_fields_first_payload__execution_valid(spec, state): + rng = Random(1111) state = build_state_with_incomplete_transition(spec, state) - yield from run_randomized_non_validated_execution_fields_test(spec, state) + yield from run_randomized_non_validated_execution_fields_test(spec, state, rng=rng) @with_bellatrix_and_later @spec_state_test def test_randomized_non_validated_execution_fields_regular_payload__execution_valid(spec, state): + rng = Random(2222) state = build_state_with_complete_transition(spec, state) - yield from run_randomized_non_validated_execution_fields_test(spec, state) + yield from run_randomized_non_validated_execution_fields_test(spec, state, rng=rng) @with_bellatrix_and_later @spec_state_test def test_invalid_randomized_non_validated_execution_fields_first_payload__execution_invalid(spec, state): + rng = Random(3333) state = build_state_with_incomplete_transition(spec, state) - yield from run_randomized_non_validated_execution_fields_test(spec, state, execution_valid=False) + yield from run_randomized_non_validated_execution_fields_test(spec, state, execution_valid=False, rng=rng) @with_bellatrix_and_later @spec_state_test def test_invalid_randomized_non_validated_execution_fields_regular_payload__execution_invalid(spec, state): + rng = Random(4444) state = build_state_with_complete_transition(spec, state) - yield from run_randomized_non_validated_execution_fields_test(spec, state, execution_valid=False) + yield from run_randomized_non_validated_execution_fields_test(spec, state, execution_valid=False, rng=rng) diff --git a/tests/core/pyspec/eth2spec/test/eip7594/merkle_proof/test_single_merkle_proof.py b/tests/core/pyspec/eth2spec/test/eip7594/merkle_proof/test_single_merkle_proof.py index 222f59b775..e2970a25e4 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/merkle_proof/test_single_merkle_proof.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/merkle_proof/test_single_merkle_proof.py @@ -22,7 +22,7 @@ def _run_blob_kzg_commitments_merkle_proof_test(spec, state, rng=None): - opaque_tx, blobs, blob_kzg_commitments, proofs = get_sample_opaque_tx(spec, blob_count=1) + opaque_tx, blobs, blob_kzg_commitments, _ = get_sample_opaque_tx(spec, blob_count=1) if rng is None: block = build_empty_block_for_next_slot(spec, state) else: diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index deb83c223e..c247e0532f 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -31,28 +31,28 @@ def test_fft(spec): @with_eip7594_and_later @spec_test @single_phase -def test_verify_cell_proof(spec): +def test_verify_cell_kzg_proof(spec): blob = get_sample_blob(spec) commitment = spec.blob_to_kzg_commitment(blob) - cells, proofs = spec.compute_cells_and_proofs(blob) + cells, proofs = spec.compute_cells_and_kzg_proofs(blob) cell_id = 0 - assert spec.verify_cell_proof(commitment, cell_id, cells[cell_id], proofs[cell_id]) + assert spec.verify_cell_kzg_proof(commitment, cell_id, cells[cell_id], proofs[cell_id]) cell_id = 1 - assert spec.verify_cell_proof(commitment, cell_id, cells[cell_id], proofs[cell_id]) + assert spec.verify_cell_kzg_proof(commitment, cell_id, cells[cell_id], proofs[cell_id]) @with_eip7594_and_later @spec_test @single_phase -def test_verify_cell_proof_batch(spec): +def test_verify_cell_kzg_proof_batch(spec): blob = get_sample_blob(spec) commitment = spec.blob_to_kzg_commitment(blob) - cells, proofs = spec.compute_cells_and_proofs(blob) + cells, proofs = spec.compute_cells_and_kzg_proofs(blob) assert len(cells) == len(proofs) - assert spec.verify_cell_proof_batch( + assert spec.verify_cell_kzg_proof_batch( row_commitments_bytes=[commitment], row_indices=[0, 0], column_indices=[0, 4], diff --git a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_consolidation.py b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_consolidation.py index 9af262f60e..95bd812e38 100644 --- a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_consolidation.py +++ b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_consolidation.py @@ -404,251 +404,6 @@ def test_consolidation_balance_through_two_churn_epochs(spec, state): assert state.consolidation_balance_to_consume == expected_balance -@with_electra_and_later -@with_presets([MINIMAL], "need sufficient consolidation churn limit") -@with_custom_state( - balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, - threshold_fn=default_activation_threshold, -) -@spec_test -@single_phase -def test_multiple_consolidations_below_churn(spec, state): - # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn - consolidation_churn_limit = spec.get_consolidation_churn_limit(state) - # Set the consolidation balance to consume equal to churn limit - state.consolidation_balance_to_consume = consolidation_churn_limit - current_epoch = spec.get_current_epoch(state) - - yield "pre", state - # Prepare a bunch of consolidations, based on the current state - consolidations = [] - for i in range(3): - source_index = 2 * i - target_index = 2 * i + 1 - source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] - target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] - # Set source and target withdrawal credentials to the same eth1 credential - set_eth1_withdrawal_credential_with_balance(spec, state, source_index) - set_eth1_withdrawal_credential_with_balance(spec, state, target_index) - signed_consolidation = sign_consolidation( - spec, - state, - spec.Consolidation( - epoch=current_epoch, - source_index=source_index, - target_index=target_index, - ), - source_privkey, - target_privkey, - ) - consolidations.append(signed_consolidation) - - # Now run all the consolidations - for consolidation in consolidations: - # the function yields data, but we are just interested in running it here, ignore yields. - for _ in run_consolidation_processing(spec, state, consolidation): - continue - - yield "post", state - - expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) - assert state.earliest_consolidation_epoch == expected_exit_epoch - assert ( - state.consolidation_balance_to_consume - == consolidation_churn_limit - 3 * spec.MIN_ACTIVATION_BALANCE - ) - for i in range(3): - assert state.validators[2 * i].exit_epoch == expected_exit_epoch - - -@with_electra_and_later -@with_presets([MINIMAL], "need sufficient consolidation churn limit") -@with_custom_state( - balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, - threshold_fn=default_activation_threshold, -) -@spec_test -@single_phase -def test_multiple_consolidations_equal_churn(spec, state): - # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn - consolidation_churn_limit = spec.get_consolidation_churn_limit(state) - # Set the consolidation balance to consume equal to churn limit - state.consolidation_balance_to_consume = consolidation_churn_limit - current_epoch = spec.get_current_epoch(state) - - yield "pre", state - # Prepare a bunch of consolidations, based on the current state - consolidations = [] - for i in range(4): - source_index = 2 * i - target_index = 2 * i + 1 - source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] - target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] - # Set source and target withdrawal credentials to the same eth1 credential - set_eth1_withdrawal_credential_with_balance(spec, state, source_index) - set_eth1_withdrawal_credential_with_balance(spec, state, target_index) - signed_consolidation = sign_consolidation( - spec, - state, - spec.Consolidation( - epoch=current_epoch, - source_index=source_index, - target_index=target_index, - ), - source_privkey, - target_privkey, - ) - consolidations.append(signed_consolidation) - - # Now run all the consolidations - for consolidation in consolidations: - # the function yields data, but we are just interested in running it here, ignore yields. - for _ in run_consolidation_processing(spec, state, consolidation): - continue - - yield "post", state - - expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) - assert state.earliest_consolidation_epoch == expected_exit_epoch - assert state.consolidation_balance_to_consume == 0 - for i in range(4): - assert state.validators[2 * i].exit_epoch == expected_exit_epoch - - -@with_electra_and_later -@with_presets([MINIMAL], "need sufficient consolidation churn limit") -@with_custom_state( - balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, - threshold_fn=default_activation_threshold, -) -@spec_test -@single_phase -def test_multiple_consolidations_above_churn(spec, state): - # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn - consolidation_churn_limit = spec.get_consolidation_churn_limit(state) - # Set the consolidation balance to consume equal to churn limit - state.consolidation_balance_to_consume = consolidation_churn_limit - current_epoch = spec.get_current_epoch(state) - - # Prepare a bunch of consolidations, based on the current state - consolidations = [] - for i in range(4): - source_index = 2 * i - target_index = 2 * i + 1 - source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] - target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] - # Set source and target withdrawal credentials to the same eth1 credential - set_eth1_withdrawal_credential_with_balance(spec, state, source_index) - set_eth1_withdrawal_credential_with_balance(spec, state, target_index) - signed_consolidation = sign_consolidation( - spec, - state, - spec.Consolidation( - epoch=current_epoch, - source_index=source_index, - target_index=target_index, - ), - source_privkey, - target_privkey, - ) - consolidations.append(signed_consolidation) - - # Now run all the consolidations - for consolidation in consolidations: - # the function yields data, but we are just interested in running it here, ignore yields. - for _ in run_consolidation_processing(spec, state, consolidation): - continue - - # consolidate an additional validator - source_index = spec.get_active_validator_indices(state, current_epoch)[-2] - target_index = spec.get_active_validator_indices(state, current_epoch)[-1] - source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] - target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] - - # Set source and target withdrawal credentials to the same eth1 credential - set_eth1_withdrawal_credential_with_balance(spec, state, source_index) - set_eth1_withdrawal_credential_with_balance(spec, state, target_index) - - signed_consolidation = sign_consolidation( - spec, - state, - spec.Consolidation( - epoch=current_epoch, source_index=source_index, target_index=target_index - ), - source_privkey, - target_privkey, - ) - # This is the interesting part of the test: on a pre-state with full consolidation queue, - # when processing an additional consolidation, it results in an exit in a later epoch - yield from run_consolidation_processing(spec, state, signed_consolidation) - - expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) - assert state.earliest_consolidation_epoch == expected_exit_epoch + 1 - assert ( - state.consolidation_balance_to_consume - == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE - ) - assert state.validators[source_index].exit_epoch == expected_exit_epoch + 1 - for i in range(4): - assert state.validators[2 * i].exit_epoch == expected_exit_epoch - - -@with_electra_and_later -@with_presets([MINIMAL], "need sufficient consolidation churn limit") -@with_custom_state( - balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, - threshold_fn=default_activation_threshold, -) -@spec_test -@single_phase -def test_multiple_consolidations_equal_twice_churn(spec, state): - # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn - consolidation_churn_limit = spec.get_consolidation_churn_limit(state) - # Set the consolidation balance to consume equal to churn limit - state.consolidation_balance_to_consume = consolidation_churn_limit - current_epoch = spec.get_current_epoch(state) - - yield "pre", state - # Prepare a bunch of consolidations, based on the current state - consolidations = [] - for i in range(8): - source_index = 2 * i - target_index = 2 * i + 1 - source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] - target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] - # Set source and target withdrawal credentials to the same eth1 credential - set_eth1_withdrawal_credential_with_balance(spec, state, source_index) - set_eth1_withdrawal_credential_with_balance(spec, state, target_index) - signed_consolidation = sign_consolidation( - spec, - state, - spec.Consolidation( - epoch=current_epoch, - source_index=source_index, - target_index=target_index, - ), - source_privkey, - target_privkey, - ) - consolidations.append(signed_consolidation) - - # Now run all the consolidations - for consolidation in consolidations: - # the function yields data, but we are just interested in running it here, ignore yields. - for _ in run_consolidation_processing(spec, state, consolidation): - continue - - yield "post", state - - first_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) - assert state.consolidation_balance_to_consume == 0 - assert state.earliest_consolidation_epoch == first_exit_epoch + 1 - for i in range(4): - assert state.validators[2 * i].exit_epoch == first_exit_epoch - for i in range(4, 8): - assert state.validators[2 * i].exit_epoch == first_exit_epoch + 1 - - # Failing tests @with_electra_and_later @@ -856,9 +611,43 @@ def test_invalid_different_credentials(spec, state): @with_electra_and_later -@spec_state_test +@with_presets([MINIMAL], "need sufficient consolidation churn limit") +@with_custom_state( + balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, + threshold_fn=default_activation_threshold, +) +@spec_test +@single_phase @always_bls def test_invalid_source_signature(spec, state): + # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn + current_epoch = spec.get_current_epoch(state) + source_index = spec.get_active_validator_indices(state, current_epoch)[0] + target_index = spec.get_active_validator_indices(state, current_epoch)[1] + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, source_index=source_index, target_index=target_index + ), + source_privkey, + target_privkey, + ) + + # Set earliest consolidation epoch to the expected exit epoch + expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + state.earliest_consolidation_epoch = expected_exit_epoch + consolidation_churn_limit = spec.get_consolidation_churn_limit(state) + # Set the consolidation balance to consume equal to churn limit + state.consolidation_balance_to_consume = consolidation_churn_limit + current_epoch = spec.get_current_epoch(state) source_privkey = pubkey_to_privkey[state.validators[0].pubkey] target_privkey = pubkey_to_privkey[state.validators[1].pubkey] @@ -872,17 +661,53 @@ def test_invalid_source_signature(spec, state): source_privkey, target_privkey, ) + # Change the pubkey of the source validator, invalidating its signature state.validators[0].pubkey = state.validators[1].pubkey + yield from run_consolidation_processing( spec, state, signed_consolidation, valid=False ) @with_electra_and_later -@spec_state_test +@with_presets([MINIMAL], "need sufficient consolidation churn limit") +@with_custom_state( + balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, + threshold_fn=default_activation_threshold, +) +@spec_test +@single_phase @always_bls def test_invalid_target_signature(spec, state): + # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn + current_epoch = spec.get_current_epoch(state) + source_index = spec.get_active_validator_indices(state, current_epoch)[0] + target_index = spec.get_active_validator_indices(state, current_epoch)[1] + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, source_index=source_index, target_index=target_index + ), + source_privkey, + target_privkey, + ) + + # Set earliest consolidation epoch to the expected exit epoch + expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + state.earliest_consolidation_epoch = expected_exit_epoch + consolidation_churn_limit = spec.get_consolidation_churn_limit(state) + # Set the consolidation balance to consume equal to churn limit + state.consolidation_balance_to_consume = consolidation_churn_limit + current_epoch = spec.get_current_epoch(state) source_privkey = pubkey_to_privkey[state.validators[0].pubkey] target_privkey = pubkey_to_privkey[state.validators[1].pubkey] @@ -896,8 +721,10 @@ def test_invalid_target_signature(spec, state): source_privkey, target_privkey, ) + # Change the pubkey of the target validator, invalidating its signature state.validators[1].pubkey = state.validators[2].pubkey + yield from run_consolidation_processing( spec, state, signed_consolidation, valid=False ) diff --git a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_effective_balance_updates.py b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_effective_balance_updates.py index ddff613407..34e31b2748 100644 --- a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_effective_balance_updates.py +++ b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_effective_balance_updates.py @@ -7,6 +7,6 @@ @with_electra_and_later @spec_state_test def test_effective_balance_hysteresis_with_compounding_credentials(spec, state): - run_test_effective_balance_hysteresis( + yield from run_test_effective_balance_hysteresis( spec, state, with_compounding_credentials=True ) diff --git a/tests/core/pyspec/eth2spec/test/electra/fork/__init__.py b/tests/core/pyspec/eth2spec/test/electra/fork/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py new file mode 100644 index 0000000000..3bd6350b34 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py @@ -0,0 +1,82 @@ +from eth2spec.test.context import ( + with_phases, + with_custom_state, + with_presets, + spec_test, with_state, + low_balances, misc_balances, large_validator_set, +) +from eth2spec.test.utils import with_meta_tags +from eth2spec.test.helpers.constants import ( + DENEB, ELECTRA, + MINIMAL, +) +from eth2spec.test.helpers.state import ( + next_epoch, + next_epoch_via_block, +) +from eth2spec.test.helpers.electra.fork import ( + ELECTRA_FORK_TEST_META_TAGS, + run_fork_test, +) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_base_state(spec, phases, state): + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_next_epoch(spec, phases, state): + next_epoch(spec, state) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_next_epoch_with_block(spec, phases, state): + next_epoch_via_block(spec, state) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_many_next_epoch(spec, phases, state): + for _ in range(3): + next_epoch(spec, state) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@with_custom_state(balances_fn=low_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@spec_test +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_random_low_balances(spec, phases, state): + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@with_custom_state(balances_fn=misc_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@spec_test +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_random_misc_balances(spec, phases, state): + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") +@with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@spec_test +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_random_large_validator_set(spec, phases, state): + yield from run_fork_test(phases[ELECTRA], state) diff --git a/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_random.py b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_random.py new file mode 100644 index 0000000000..07495ed453 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_random.py @@ -0,0 +1,84 @@ +from random import Random + +from eth2spec.test.context import ( + with_phases, + with_custom_state, + with_presets, + spec_test, with_state, + low_balances, misc_balances, large_validator_set, +) +from eth2spec.test.utils import with_meta_tags +from eth2spec.test.helpers.constants import ( + DENEB, ELECTRA, + MINIMAL, +) +from eth2spec.test.helpers.electra.fork import ( + ELECTRA_FORK_TEST_META_TAGS, + run_fork_test, +) +from eth2spec.test.helpers.random import randomize_state + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_0(spec, phases, state): + randomize_state(spec, state, rng=Random(1010)) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_1(spec, phases, state): + randomize_state(spec, state, rng=Random(2020)) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_2(spec, phases, state): + randomize_state(spec, state, rng=Random(3030)) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_3(spec, phases, state): + randomize_state(spec, state, rng=Random(4040)) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_custom_state(balances_fn=low_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_low_balances(spec, phases, state): + randomize_state(spec, state, rng=Random(5050)) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_custom_state(balances_fn=misc_balances, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_misc_balances(spec, phases, state): + randomize_state(spec, state, rng=Random(6060)) + yield from run_fork_test(phases[ELECTRA], state) + + +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@with_presets([MINIMAL], + reason="mainnet config leads to larger validator set than limit of public/private keys pre-generated") +@spec_test +@with_custom_state(balances_fn=large_validator_set, threshold_fn=lambda spec: spec.config.EJECTION_BALANCE) +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_electra_fork_random_large_validator_set(spec, phases, state): + randomize_state(spec, state, rng=Random(7070)) + yield from run_fork_test(phases[ELECTRA], state) diff --git a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/__init__.py b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/__init__.py index 3c0e060f3d..46e3659cd3 100644 --- a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/__init__.py +++ b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/__init__.py @@ -1 +1,2 @@ +from .test_consolidation import * # noqa: F401 F403 from .test_deposit_transition import * # noqa: F401 F403 diff --git a/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_consolidation.py b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_consolidation.py new file mode 100644 index 0000000000..2d8613b528 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/electra/sanity/blocks/test_consolidation.py @@ -0,0 +1,271 @@ + +from eth2spec.test.context import ( + with_electra_and_later, + with_presets, + spec_test, + single_phase, + with_custom_state, + scaled_churn_balances_exceed_activation_exit_churn_limit, + default_activation_threshold, +) +from eth2spec.test.helpers.block import ( + build_empty_block_for_next_slot +) +from eth2spec.test.helpers.consolidations import ( + sign_consolidation, +) +from eth2spec.test.helpers.constants import MINIMAL +from eth2spec.test.helpers.keys import pubkey_to_privkey +from eth2spec.test.helpers.state import ( + state_transition_and_sign_block, +) +from eth2spec.test.helpers.withdrawals import ( + set_eth1_withdrawal_credential_with_balance, +) + + +@with_electra_and_later +@with_presets([MINIMAL], "need sufficient consolidation churn limit") +@with_custom_state( + balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, + threshold_fn=default_activation_threshold, +) +@spec_test +@single_phase +def test_multiple_consolidations_below_churn(spec, state): + # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn + consolidation_churn_limit = spec.get_consolidation_churn_limit(state) + # Set the consolidation balance to consume equal to churn limit + state.consolidation_balance_to_consume = consolidation_churn_limit + current_epoch = spec.get_current_epoch(state) + + yield "pre", state + + # Prepare a bunch of consolidations, each of them in a block, based on the current state + blocks = [] + consolidation_count = 3 + for i in range(consolidation_count): + source_index = 2 * i + target_index = 2 * i + 1 + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, + source_index=source_index, + target_index=target_index, + ), + source_privkey, + target_privkey, + ) + block = build_empty_block_for_next_slot(spec, state) + block.body.consolidations = [signed_consolidation] + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + yield "blocks", blocks + yield "post", state + + expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + assert state.earliest_consolidation_epoch == expected_exit_epoch + assert ( + state.consolidation_balance_to_consume + == consolidation_churn_limit - 3 * spec.MIN_ACTIVATION_BALANCE + ) + for i in range(consolidation_count): + assert state.validators[2 * i].exit_epoch == expected_exit_epoch + + +@with_electra_and_later +@with_presets([MINIMAL], "need sufficient consolidation churn limit") +@with_custom_state( + balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, + threshold_fn=default_activation_threshold, +) +@spec_test +@single_phase +def test_multiple_consolidations_equal_churn(spec, state): + # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn + consolidation_churn_limit = spec.get_consolidation_churn_limit(state) + # Set the consolidation balance to consume equal to churn limit + state.consolidation_balance_to_consume = consolidation_churn_limit + current_epoch = spec.get_current_epoch(state) + + yield "pre", state + # Prepare a bunch of consolidations, each of them in a block, based on the current state + blocks = [] + consolidation_count = 4 + for i in range(consolidation_count): + source_index = 2 * i + target_index = 2 * i + 1 + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, + source_index=source_index, + target_index=target_index, + ), + source_privkey, + target_privkey, + ) + block = build_empty_block_for_next_slot(spec, state) + block.body.consolidations = [signed_consolidation] + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + yield "blocks", blocks + yield "post", state + + expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + assert state.earliest_consolidation_epoch == expected_exit_epoch + assert state.consolidation_balance_to_consume == 0 + for i in range(consolidation_count): + assert state.validators[2 * i].exit_epoch == expected_exit_epoch + + +@with_electra_and_later +@with_presets([MINIMAL], "need sufficient consolidation churn limit") +@with_custom_state( + balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, + threshold_fn=default_activation_threshold, +) +@spec_test +@single_phase +def test_multiple_consolidations_above_churn(spec, state): + # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn + consolidation_churn_limit = spec.get_consolidation_churn_limit(state) + # Set the consolidation balance to consume equal to churn limit + state.consolidation_balance_to_consume = consolidation_churn_limit + current_epoch = spec.get_current_epoch(state) + + # Prepare a bunch of consolidations, each of them in a block, based on the current state + blocks = [] + consolidation_count = 4 + for i in range(consolidation_count): + source_index = 2 * i + target_index = 2 * i + 1 + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, + source_index=source_index, + target_index=target_index, + ), + source_privkey, + target_privkey, + ) + block = build_empty_block_for_next_slot(spec, state) + block.body.consolidations = [signed_consolidation] + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + # consolidate an additional validator + source_index = spec.get_active_validator_indices(state, current_epoch)[-2] + target_index = spec.get_active_validator_indices(state, current_epoch)[-1] + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + + # This is the interesting part of the test: on a pre-state with full consolidation queue, + # when processing an additional consolidation, it results in an exit in a later epoch + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, source_index=source_index, target_index=target_index + ), + source_privkey, + target_privkey, + ) + block = build_empty_block_for_next_slot(spec, state) + block.body.consolidations = [signed_consolidation] + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + yield "blocks", blocks + yield "post", state + + expected_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + assert state.earliest_consolidation_epoch == expected_exit_epoch + 1 + assert ( + state.consolidation_balance_to_consume + == consolidation_churn_limit - spec.MIN_ACTIVATION_BALANCE + ) + assert state.validators[source_index].exit_epoch == expected_exit_epoch + 1 + for i in range(consolidation_count): + assert state.validators[2 * i].exit_epoch == expected_exit_epoch + + +@with_electra_and_later +@with_presets([MINIMAL], "need sufficient consolidation churn limit") +@with_custom_state( + balances_fn=scaled_churn_balances_exceed_activation_exit_churn_limit, + threshold_fn=default_activation_threshold, +) +@spec_test +@single_phase +def test_multiple_consolidations_equal_twice_churn(spec, state): + # This state has 256 validators each with 32 ETH in MINIMAL preset, 128 ETH consolidation churn + consolidation_churn_limit = spec.get_consolidation_churn_limit(state) + # Set the consolidation balance to consume equal to churn limit + state.consolidation_balance_to_consume = consolidation_churn_limit + current_epoch = spec.get_current_epoch(state) + + yield "pre", state + # Prepare a bunch of consolidations, each of them in a block, based on the current state + blocks = [] + consolidation_count = 8 + for i in range(consolidation_count): + source_index = 2 * i + target_index = 2 * i + 1 + source_privkey = pubkey_to_privkey[state.validators[source_index].pubkey] + target_privkey = pubkey_to_privkey[state.validators[target_index].pubkey] + # Set source and target withdrawal credentials to the same eth1 credential + set_eth1_withdrawal_credential_with_balance(spec, state, source_index) + set_eth1_withdrawal_credential_with_balance(spec, state, target_index) + signed_consolidation = sign_consolidation( + spec, + state, + spec.Consolidation( + epoch=current_epoch, + source_index=source_index, + target_index=target_index, + ), + source_privkey, + target_privkey, + ) + block = build_empty_block_for_next_slot(spec, state) + block.body.consolidations = [signed_consolidation] + signed_block = state_transition_and_sign_block(spec, state, block) + blocks.append(signed_block) + + yield "blocks", blocks + yield "post", state + + first_exit_epoch = spec.compute_activation_exit_epoch(current_epoch) + assert state.consolidation_balance_to_consume == 0 + assert state.earliest_consolidation_epoch == first_exit_epoch + 1 + for i in range(consolidation_count // 2): + assert state.validators[2 * i].exit_epoch == first_exit_epoch + for i in range(consolidation_count // 2, consolidation_count): + assert state.validators[2 * i].exit_epoch == first_exit_epoch + 1 diff --git a/tests/core/pyspec/eth2spec/test/helpers/deneb/fork.py b/tests/core/pyspec/eth2spec/test/helpers/deneb/fork.py index 7fe0535c10..fd2428a046 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/deneb/fork.py +++ b/tests/core/pyspec/eth2spec/test/helpers/deneb/fork.py @@ -36,6 +36,8 @@ def run_fork_test(post_spec, pre_state): 'current_sync_committee', 'next_sync_committee', # Withdrawals 'next_withdrawal_index', 'next_withdrawal_validator_index', + # Deep history valid from Capella onwards + 'historical_summaries', ] for field in stable_fields: assert getattr(pre_state, field) == getattr(post_state, field) diff --git a/tests/core/pyspec/eth2spec/test/helpers/electra/__init__.py b/tests/core/pyspec/eth2spec/test/helpers/electra/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/core/pyspec/eth2spec/test/helpers/electra/fork.py b/tests/core/pyspec/eth2spec/test/helpers/electra/fork.py new file mode 100644 index 0000000000..39a43a5233 --- /dev/null +++ b/tests/core/pyspec/eth2spec/test/helpers/electra/fork.py @@ -0,0 +1,65 @@ +from eth2spec.test.helpers.constants import ( + ELECTRA, +) + + +ELECTRA_FORK_TEST_META_TAGS = { + 'fork': ELECTRA, +} + + +def run_fork_test(post_spec, pre_state): + yield 'pre', pre_state + + post_state = post_spec.upgrade_to_electra(pre_state) + + # Stable fields + stable_fields = [ + 'genesis_time', 'genesis_validators_root', 'slot', + # History + 'latest_block_header', 'block_roots', 'state_roots', 'historical_roots', + # Eth1 + 'eth1_data', 'eth1_data_votes', 'eth1_deposit_index', + # Registry + # NOTE: 'validators', 'balances' could be changed. + # Randomness + 'randao_mixes', + # Slashings + 'slashings', + # Participation + 'previous_epoch_participation', 'current_epoch_participation', + # Finality + 'justification_bits', 'previous_justified_checkpoint', 'current_justified_checkpoint', 'finalized_checkpoint', + # Inactivity + 'inactivity_scores', + # Sync + 'current_sync_committee', 'next_sync_committee', + # Withdrawals + 'next_withdrawal_index', 'next_withdrawal_validator_index', + # Deep history valid from Capella onwards + 'historical_summaries', + + ] + for field in stable_fields: + assert getattr(pre_state, field) == getattr(post_state, field) + + # Modified fields + modified_fields = ['fork', 'latest_execution_payload_header'] + for field in modified_fields: + assert getattr(pre_state, field) != getattr(post_state, field) + + assert len(pre_state.validators) == len(post_state.validators) + for pre_validator, post_validator in zip(pre_state.validators, post_state.validators): + stable_validator_fields = [ + 'pubkey', 'withdrawal_credentials', + 'slashed', + 'exit_epoch', 'withdrawable_epoch', + ] + for field in stable_validator_fields: + assert getattr(pre_validator, field) == getattr(post_validator, field) + + assert pre_state.fork.current_version == post_state.fork.previous_version + assert post_state.fork.current_version == post_spec.config.ELECTRA_FORK_VERSION + assert post_state.fork.epoch == post_spec.get_current_epoch(post_state) + + yield 'post', post_state diff --git a/tests/core/pyspec/eth2spec/test/utils/kzg_tests.py b/tests/core/pyspec/eth2spec/test/utils/kzg_tests.py index c6bbfef56a..5f1e11b49a 100644 --- a/tests/core/pyspec/eth2spec/test/utils/kzg_tests.py +++ b/tests/core/pyspec/eth2spec/test/utils/kzg_tests.py @@ -152,4 +152,4 @@ def evaluate_blob_at(blob, z): # Cells & Proofs -VALID_CELLS_AND_PROOFS = [] # Saved in case02_compute_cells_and_proofs +VALID_CELLS_AND_PROOFS = [] # Saved in case02_compute_cells_and_kzg_proofs diff --git a/tests/core/pyspec/eth2spec/utils/bls.py b/tests/core/pyspec/eth2spec/utils/bls.py index 299495322f..666de68094 100644 --- a/tests/core/pyspec/eth2spec/utils/bls.py +++ b/tests/core/pyspec/eth2spec/utils/bls.py @@ -11,6 +11,8 @@ pairing as py_ecc_pairing, final_exponentiate as py_ecc_final_exponentiate, FQ12 as py_ecc_GT, + FQ, + FQ2, ) from py_ecc.bls.g2_primitives import ( # noqa: F401 curve_order as BLS_MODULUS, @@ -252,14 +254,14 @@ def multi_exp(points, integers): raise Exception("Invalid point type") result = None - if isinstance(points[0], py_ecc_G1): + if isinstance(points[0][0], FQ): result = Z1() - elif isinstance(points[0], py_ecc_G2): + elif isinstance(points[0][0], FQ2): result = Z2() else: raise Exception("Invalid point type") - for point, scalar in points.zip(integers): + for point, scalar in zip(points, integers): result = add(result, multiply(point, scalar)) return result diff --git a/tests/formats/kzg_7594/README.md b/tests/formats/kzg_7594/README.md index d7d6eeae2c..dbd95dd3dc 100644 --- a/tests/formats/kzg_7594/README.md +++ b/tests/formats/kzg_7594/README.md @@ -7,7 +7,7 @@ We do not recommend rolling your own crypto or using an untested KZG library. The KZG test suite runner has the following handlers: - [`compute_cells`](./compute_cells.md) -- [`compute_cells_and_proofs`](./compute_cells_and_proofs.md) -- [`verify_cell_proof`](./verify_cell_proof.md) -- [`verify_cell_proof_batch`](./verify_cell_proof_batch.md) +- [`compute_cells_and_kzg_proofs`](./compute_cells_and_kzg_proofs.md) +- [`verify_cell_kzg_proof`](./verify_cell_kzg_proof.md) +- [`verify_cell_kzg_proof_batch`](./verify_cell_kzg_proof_batch.md) - [`recover_all_cells`](./recover_all_cells.md) diff --git a/tests/formats/kzg_7594/compute_cells_and_proofs.md b/tests/formats/kzg_7594/compute_cells_and_kzg_proofs.md similarity index 58% rename from tests/formats/kzg_7594/compute_cells_and_proofs.md rename to tests/formats/kzg_7594/compute_cells_and_kzg_proofs.md index 0262d8a673..1ee1be649a 100644 --- a/tests/formats/kzg_7594/compute_cells_and_proofs.md +++ b/tests/formats/kzg_7594/compute_cells_and_kzg_proofs.md @@ -1,4 +1,4 @@ -# Test format: Compute cells and proofs +# Test format: Compute cells and KZG proofs Compute the cells and cell KZG proofs for a given `blob`. @@ -20,4 +20,4 @@ All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with ` ## Condition -The `compute_cells_and_proofs` handler should compute the cells (chunks of an extended blob) and cell KZG proofs for `blob`, and the result should match the expected `output`. If the blob is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element) it should error, i.e. the output should be `null`. +The `compute_cells_and_kzg_proofs` handler should compute the cells (chunks of an extended blob) and cell KZG proofs for `blob`, and the result should match the expected `output`. If the blob is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element) it should error, i.e. the output should be `null`. diff --git a/tests/formats/kzg_7594/verify_cell_proof.md b/tests/formats/kzg_7594/verify_cell_kzg_proof.md similarity index 53% rename from tests/formats/kzg_7594/verify_cell_proof.md rename to tests/formats/kzg_7594/verify_cell_kzg_proof.md index dc9cb93e44..5ab3ad0739 100644 --- a/tests/formats/kzg_7594/verify_cell_proof.md +++ b/tests/formats/kzg_7594/verify_cell_kzg_proof.md @@ -1,4 +1,4 @@ -# Test format: Verify cell proof +# Test format: Verify cell KZG proof Use the cell KZG `proof` to verify that the KZG `commitment` for a given `cell` is correct. @@ -23,4 +23,4 @@ All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with ` ## Condition -The `verify_cell_proof` handler should verify that `commitment` is a correct KZG commitment to `cell` by using the cell KZG proof `proof`, and the result should match the expected `output`. If the commitment or proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), `cell` is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`. +The `verify_cell_kzg_proof` handler should verify that `commitment` is a correct KZG commitment to `cell` by using the cell KZG proof `proof`, and the result should match the expected `output`. If the commitment or proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), `cell` is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`. diff --git a/tests/formats/kzg_7594/verify_cell_proof_batch.md b/tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md similarity index 58% rename from tests/formats/kzg_7594/verify_cell_proof_batch.md rename to tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md index e4a72d2507..9761b55032 100644 --- a/tests/formats/kzg_7594/verify_cell_proof_batch.md +++ b/tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md @@ -1,4 +1,4 @@ -# Test format: Verify cell proof batch +# Test format: Verify cell KZG proof batch Use the cell KZG `proofs` to verify that the KZG `row_commitments` for the given `cells` are correct. @@ -25,4 +25,4 @@ All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with ` ## Condition -The `verify_cell_proof_batch` handler should verify that `row_commitments` are correct KZG commitments to `cells` by using the cell KZG proofs `proofs`, and the result should match the expected `output`. If any of the commitments or proofs are invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), any cell is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or any `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`. +The `verify_cell_kzg_proof_batch` handler should verify that `row_commitments` are correct KZG commitments to `cells` by using the cell KZG proofs `proofs`, and the result should match the expected `output`. If any of the commitments or proofs are invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), any cell is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or any `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`. diff --git a/tests/generators/forks/main.py b/tests/generators/forks/main.py index 7d68a31e7a..91078c8dae 100644 --- a/tests/generators/forks/main.py +++ b/tests/generators/forks/main.py @@ -1,7 +1,7 @@ from typing import Iterable from eth2spec.test.helpers.constants import ( - PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, + PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, MINIMAL, MAINNET, ) from eth2spec.test.helpers.typing import SpecForkName, PresetBaseName @@ -9,6 +9,7 @@ from eth2spec.test.bellatrix.fork import test_bellatrix_fork_basic, test_bellatrix_fork_random from eth2spec.test.capella.fork import test_capella_fork_basic, test_capella_fork_random from eth2spec.test.deneb.fork import test_deneb_fork_basic, test_deneb_fork_random +from eth2spec.test.electra.fork import test_electra_fork_basic, test_electra_fork_random from eth2spec.gen_helpers.gen_base import gen_runner, gen_typing from eth2spec.gen_helpers.gen_from_tests.gen import generate_from_tests @@ -42,6 +43,8 @@ def _get_fork_tests_providers(): yield create_provider(test_capella_fork_random, preset, BELLATRIX, CAPELLA) yield create_provider(test_deneb_fork_basic, preset, CAPELLA, DENEB) yield create_provider(test_deneb_fork_random, preset, CAPELLA, DENEB) + yield create_provider(test_electra_fork_basic, preset, DENEB, ELECTRA) + yield create_provider(test_electra_fork_random, preset, DENEB, ELECTRA) if __name__ == "__main__": diff --git a/tests/generators/kzg_7594/main.py b/tests/generators/kzg_7594/main.py index 670ed29ee3..9afea6efe1 100644 --- a/tests/generators/kzg_7594/main.py +++ b/tests/generators/kzg_7594/main.py @@ -60,17 +60,17 @@ def case01_compute_cells(): ############################################################################### -# Test cases for compute_cells_and_proofs +# Test cases for compute_cells_and_kzg_proofs ############################################################################### -def case02_compute_cells_and_proofs(): +def case02_compute_cells_and_kzg_proofs(): # Valid cases for blob in VALID_BLOBS: - cells, proofs = spec.compute_cells_and_proofs(blob) + cells, proofs = spec.compute_cells_and_kzg_proofs(blob) # Save cells & proofs here to save on time. VALID_CELLS_AND_PROOFS.append((cells, proofs)) identifier = make_id(blob) - yield f'compute_cells_and_proofs_case_valid_{identifier}', { + yield f'compute_cells_and_kzg_proofs_case_valid_{identifier}', { 'input': { 'blob': encode_hex(blob), }, @@ -79,9 +79,9 @@ def case02_compute_cells_and_proofs(): # Edge case: Invalid blobs for blob in INVALID_BLOBS: - expect_exception(spec.compute_cells_and_proofs, blob) + expect_exception(spec.compute_cells_and_kzg_proofs, blob) identifier = make_id(blob) - yield f'compute_cells_and_proofs_case_invalid_blob_{identifier}', { + yield f'compute_cells_and_kzg_proofs_case_invalid_blob_{identifier}', { 'input': { 'blob': encode_hex(blob) }, @@ -90,10 +90,10 @@ def case02_compute_cells_and_proofs(): ############################################################################### -# Test cases for verify_cell_proof +# Test cases for verify_cell_kzg_proof ############################################################################### -def case03_verify_cell_proof(): +def case03_verify_cell_kzg_proof(): # Valid cases for i in range(len(VALID_BLOBS)): cells, proofs = VALID_CELLS_AND_PROOFS[i] @@ -101,9 +101,9 @@ def case03_verify_cell_proof(): cell_id = (2 ** i - 1) % spec.CELLS_PER_EXT_BLOB cell = cells[cell_id] proof = proofs[cell_id] - assert spec.verify_cell_proof(commitment, cell_id, cell, proof) + assert spec.verify_cell_kzg_proof(commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_valid_{identifier}', { + yield f'verify_cell_kzg_proof_case_valid_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -120,9 +120,9 @@ def case03_verify_cell_proof(): cell_id = 99 % spec.CELLS_PER_EXT_BLOB cell = cells[cell_id] proof = proofs[cell_id] - assert not spec.verify_cell_proof(commitment, cell_id, cell, proof) + assert not spec.verify_cell_kzg_proof(commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_incorrect_commitment_{identifier}', { + yield f'verify_cell_kzg_proof_case_incorrect_commitment_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -139,9 +139,9 @@ def case03_verify_cell_proof(): cells, proofs = VALID_CELLS_AND_PROOFS[i] cell = VALID_INDIVIDUAL_RANDOM_CELL_BYTES[i] proof = proofs[cell_id] - assert not spec.verify_cell_proof(commitment, cell_id, cell, proof) + assert not spec.verify_cell_kzg_proof(commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_incorrect_cell_{identifier}', { + yield f'verify_cell_kzg_proof_case_incorrect_cell_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -158,9 +158,9 @@ def case03_verify_cell_proof(): cells, proofs = VALID_CELLS_AND_PROOFS[i] cell = cells[cell_id] proof = bls_add_one(proofs[cell_id]) - assert not spec.verify_cell_proof(commitment, cell_id, cell, proof) + assert not spec.verify_cell_kzg_proof(commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_incorrect_proof_{identifier}', { + yield f'verify_cell_kzg_proof_case_incorrect_proof_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -176,9 +176,9 @@ def case03_verify_cell_proof(): cell_id = 81 % spec.CELLS_PER_EXT_BLOB cell = cells[cell_id] proof = proofs[cell_id] - expect_exception(spec.verify_cell_proof, commitment, cell_id, cell, proof) + expect_exception(spec.verify_cell_kzg_proof, commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_invalid_commitment_{identifier}', { + yield f'verify_cell_kzg_proof_case_invalid_commitment_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -194,9 +194,9 @@ def case03_verify_cell_proof(): commitment = VALID_COMMITMENTS[1] cell = cells[0] proof = proofs[0] - expect_exception(spec.verify_cell_proof, commitment, cell_id, cell, proof) + expect_exception(spec.verify_cell_kzg_proof, commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_invalid_cell_id_{identifier}', { + yield f'verify_cell_kzg_proof_case_invalid_cell_id_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -212,9 +212,9 @@ def case03_verify_cell_proof(): commitment = VALID_COMMITMENTS[2] cells, proofs = VALID_CELLS_AND_PROOFS[2] proof = proofs[cell_id] - expect_exception(spec.verify_cell_proof, commitment, cell_id, cell, proof) + expect_exception(spec.verify_cell_kzg_proof, commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_invalid_cell_{identifier}', { + yield f'verify_cell_kzg_proof_case_invalid_cell_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -230,9 +230,9 @@ def case03_verify_cell_proof(): commitment = VALID_COMMITMENTS[3] cell_id = 36 % spec.CELLS_PER_EXT_BLOB cell = cells[cell_id] - expect_exception(spec.verify_cell_proof, commitment, cell_id, cell, proof) + expect_exception(spec.verify_cell_kzg_proof, commitment, cell_id, cell, proof) identifier = make_id(commitment, cell_id, cell, proof) - yield f'verify_cell_proof_case_invalid_proof_{identifier}', { + yield f'verify_cell_kzg_proof_case_invalid_proof_{identifier}', { 'input': { 'commitment': encode_hex(commitment), 'cell_id': cell_id, @@ -244,19 +244,19 @@ def case03_verify_cell_proof(): ############################################################################### -# Test cases for verify_cell_proof_batch +# Test cases for verify_cell_kzg_proof_batch ############################################################################### -def case04_verify_cell_proof_batch(): +def case04_verify_cell_kzg_proof_batch(): # Valid cases for i in range(len(VALID_BLOBS)): cells, proofs = VALID_CELLS_AND_PROOFS[i] row_commitments = [VALID_COMMITMENTS[i]] row_indices = [0] * spec.CELLS_PER_EXT_BLOB column_indices = list(range(spec.CELLS_PER_EXT_BLOB)) - assert spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_valid_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_valid_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -269,9 +269,9 @@ def case04_verify_cell_proof_batch(): # Valid: zero cells cells, row_commitments, row_indices, column_indices, proofs = [], [], [], [], [] - assert spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_valid_zero_cells_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_valid_zero_cells_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -290,9 +290,9 @@ def case04_verify_cell_proof_batch(): column_indices = [0, 0] cells = [cells0[0], cells1[0]] proofs = [proofs0[0], proofs1[0]] - assert spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_valid_multiple_blobs_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_valid_multiple_blobs_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -310,9 +310,9 @@ def case04_verify_cell_proof_batch(): row_commitments = VALID_COMMITMENTS row_indices = [2] * len(cells) column_indices = list(range(len(cells))) - assert spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_valid_unused_row_commitments_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_valid_unused_row_commitments_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -330,9 +330,9 @@ def case04_verify_cell_proof_batch(): column_indices = [0] * num_duplicates cells = [VALID_CELLS_AND_PROOFS[3][0][0]] * num_duplicates proofs = [VALID_CELLS_AND_PROOFS[3][1][0]] * num_duplicates - assert spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_valid_same_cell_multiple_times_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_valid_same_cell_multiple_times_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -350,9 +350,9 @@ def case04_verify_cell_proof_batch(): row_commitments = [bls_add_one(VALID_COMMITMENTS[5])] row_indices = [0] * len(cells) column_indices = list(range(len(cells))) - assert not spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert not spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_incorrect_row_commitment_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_incorrect_row_commitment_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -371,9 +371,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Change last cell so it's wrong cells[-1] = CELL_RANDOM_VALID2 - assert not spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert not spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_incorrect_cell_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_incorrect_cell_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -392,9 +392,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Change last proof so it's wrong proofs[-1] = bls_add_one(proofs[-1]) - assert not spec.verify_cell_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) + assert not spec.verify_cell_kzg_proof_batch(row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_incorrect_proof_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_incorrect_proof_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -413,9 +413,9 @@ def case04_verify_cell_proof_batch(): row_commitments = [commitment] row_indices = [0] * len(cells) column_indices = list(range(len(cells))) - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_row_commitment_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_row_commitment_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -434,9 +434,9 @@ def case04_verify_cell_proof_batch(): # Set first row index to an invalid value row_indices[0] = 1 column_indices = list(range(len(cells))) - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_row_index_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_row_index_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -455,9 +455,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Set first column index to an invalid value column_indices[0] = spec.CELLS_PER_EXT_BLOB - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_column_index_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_column_index_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -477,9 +477,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Set first cell to the invalid cell cells[0] = cell - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_cell_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_cell_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -499,9 +499,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Set first proof to the invalid proof proofs[0] = proof - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_proof_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_proof_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -519,9 +519,9 @@ def case04_verify_cell_proof_batch(): row_commitments = [] row_indices = [0] * len(cells) column_indices = list(range(len(cells))) - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_missing_row_commitment_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_missing_row_commitment_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -539,9 +539,9 @@ def case04_verify_cell_proof_batch(): # Leave off one of the row indices row_indices = [0] * (len(cells) - 1) column_indices = list(range(len(cells))) - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_missing_row_index_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_missing_row_index_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -559,9 +559,9 @@ def case04_verify_cell_proof_batch(): row_indices = [0] * len(cells) # Leave off one of the column indices column_indices = list(range(len(cells) - 1)) - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_missing_column_index_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_missing_column_index_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -580,9 +580,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Remove the last proof cells = cells[:-1] - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_missing_cell_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_missing_cell_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -601,9 +601,9 @@ def case04_verify_cell_proof_batch(): column_indices = list(range(len(cells))) # Remove the last proof proofs = proofs[:-1] - expect_exception(spec.verify_cell_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, row_commitments, row_indices, column_indices, cells, proofs) identifier = make_id(row_commitments, row_indices, column_indices, cells, proofs) - yield f'verify_cell_proof_batch_case_invalid_missing_proof_{identifier}', { + yield f'verify_cell_kzg_proof_batch_case_invalid_missing_proof_{identifier}', { 'input': { 'row_commitments': encode_hex_list(row_commitments), 'row_indices': row_indices, @@ -830,8 +830,8 @@ def cases_fn() -> Iterable[gen_typing.TestCase]: gen_runner.run_generator("kzg_7594", [ # EIP-7594 create_provider(EIP7594, 'compute_cells', case01_compute_cells), - create_provider(EIP7594, 'compute_cells_and_proofs', case02_compute_cells_and_proofs), - create_provider(EIP7594, 'verify_cell_proof', case03_verify_cell_proof), - create_provider(EIP7594, 'verify_cell_proof_batch', case04_verify_cell_proof_batch), + create_provider(EIP7594, 'compute_cells_and_kzg_proofs', case02_compute_cells_and_kzg_proofs), + create_provider(EIP7594, 'verify_cell_kzg_proof', case03_verify_cell_kzg_proof), + create_provider(EIP7594, 'verify_cell_kzg_proof_batch', case04_verify_cell_kzg_proof_batch), create_provider(EIP7594, 'recover_all_cells', case05_recover_all_cells), ]) diff --git a/tests/generators/merkle_proof/main.py b/tests/generators/merkle_proof/main.py index 59a0e8ce65..b7d30fe9e4 100644 --- a/tests/generators/merkle_proof/main.py +++ b/tests/generators/merkle_proof/main.py @@ -1,14 +1,19 @@ -from eth2spec.test.helpers.constants import DENEB -from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators +from eth2spec.test.helpers.constants import DENEB, EIP7594 +from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators, combine_mods if __name__ == "__main__": deneb_mods = {key: 'eth2spec.test.deneb.merkle_proof.test_' + key for key in [ 'single_merkle_proof', ]} + _new_eip7594_mods = {key: 'eth2spec.test.eip7594.merkle_proof.test_' + key for key in [ + 'single_merkle_proof', + ]} + eip_7594_mods = combine_mods(_new_eip7594_mods, deneb_mods) all_mods = { DENEB: deneb_mods, + EIP7594: eip_7594_mods, } run_state_test_generators(runner_name="merkle_proof", all_mods=all_mods)