From 7d9a1482b14107305c6d7fd8d0948995c6b947fd Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 12 May 2026 14:02:13 -0500 Subject: [PATCH 1/4] Add executable gossip validation functions for fulu --- pysetup/spec_builders/fulu.py | 14 + pysetup/spec_builders/gloas.py | 3 + specs/fulu/p2p-interface.md | 267 ++- specs/fulu/partial-columns/p2p-interface.md | 207 ++- specs/gloas/p2p-interface.md | 22 + .../networking/test_gossip_beacon_block.py | 16 +- .../eth_consensus_specs/test/context.py | 9 + .../test_gossip_beacon_aggregate_and_proof.py | 22 +- .../test_gossip_beacon_attestation.py | 22 +- .../networking/test_gossip_beacon_block.py | 6 +- .../networking/test_gossip_voluntary_exit.py | 6 +- .../test_gossip_beacon_aggregate_and_proof.py | 10 +- .../test_gossip_beacon_attestation.py | 6 +- .../networking/test_gossip_beacon_block.py | 75 + .../test_gossip_data_column_sidecar.py | 946 +++++++++++ ...test_gossip_partial_data_column_sidecar.py | 1448 +++++++++++++++++ .../test/helpers/gossip.py | 67 +- .../test_gossip_beacon_aggregate_and_proof.py | 41 +- .../test_gossip_beacon_attestation.py | 23 +- .../networking/test_gossip_beacon_block.py | 23 +- .../networking/test_gossip_voluntary_exit.py | 17 +- .../eth_consensus_specs/utils/ckzg_utils.py | 4 + tests/formats/networking/gossip_validation.md | 52 +- 23 files changed, 3081 insertions(+), 225 deletions(-) create mode 100644 tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py create mode 100644 tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py create mode 100644 tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py diff --git a/pysetup/spec_builders/fulu.py b/pysetup/spec_builders/fulu.py index 20128207993..baa1b99b178 100644 --- a/pysetup/spec_builders/fulu.py +++ b/pysetup/spec_builders/fulu.py @@ -40,11 +40,25 @@ def __init__(self, evals: Optional[Sequence[BLSFieldElement]] = None): super().__init__(evals) """ + @classmethod + def deprecate_containers(cls) -> set[str]: + return set( + [ + "BlobIdentifier", + "BlobSidecar", + ] + ) + @classmethod def deprecate_functions(cls) -> set[str]: return set( [ + "compute_max_request_blob_sidecars", + "compute_subnet_for_blob_sidecar", + "get_blob_sidecars", "upgrade_to_electra", + "validate_blob_sidecar_gossip", + "verify_blob_sidecar_inclusion_proof", ] ) diff --git a/pysetup/spec_builders/gloas.py b/pysetup/spec_builders/gloas.py index 08f7287ea56..8e2c8c75751 100644 --- a/pysetup/spec_builders/gloas.py +++ b/pysetup/spec_builders/gloas.py @@ -49,6 +49,9 @@ def deprecate_functions(cls) -> set[str]: "retrieve_column_sidecars", "upgrade_to_fulu", "verify_partial_data_column_header_inclusion_proof", + # TODO(jtraglia): Temporarily deprecate these until we update them for Gloas. + "validate_data_column_sidecar_gossip", + "validate_partial_data_column_sidecar_gossip", ] ) diff --git a/specs/fulu/p2p-interface.md b/specs/fulu/p2p-interface.md index 5102ab9785b..a37dc5634b9 100644 --- a/specs/fulu/p2p-interface.md +++ b/specs/fulu/p2p-interface.md @@ -9,6 +9,7 @@ - [Containers](#containers) - [`DataColumnsByRootIdentifier`](#datacolumnsbyrootidentifier) - [Helpers](#helpers) + - [Modified `Seen`](#modified-seen) - [Modified `compute_fork_version`](#modified-compute_fork_version) - [New `compute_max_request_data_column_sidecars`](#new-compute_max_request_data_column_sidecars) - [`verify_data_column_sidecar`](#verify_data_column_sidecar) @@ -79,6 +80,30 @@ class DataColumnsByRootIdentifier(Container): ### Helpers +#### Modified `Seen` + +```python +@dataclass +class Seen(object): + proposer_slots: Set[Tuple[ValidatorIndex, Slot]] + aggregator_epochs: Set[Tuple[ValidatorIndex, Epoch]] + aggregate_data_roots: Dict[Tuple[Root, CommitteeIndex], Set[Tuple[boolean, ...]]] + voluntary_exit_indices: Set[ValidatorIndex] + proposer_slashing_indices: Set[ValidatorIndex] + attester_slashing_indices: Set[ValidatorIndex] + attestation_validator_epochs: Set[Tuple[ValidatorIndex, Epoch]] + sync_contribution_aggregator_slots: Set[Tuple[ValidatorIndex, Slot, uint64]] + sync_contribution_data: Dict[Tuple[Slot, Root, uint64], Set[Tuple[boolean, ...]]] + sync_message_validator_slots: Set[Tuple[Slot, ValidatorIndex, uint64]] + bls_to_execution_change_indices: Set[ValidatorIndex] + # [Modified in Fulu:EIP7594] + # Removed `blob_sidecar_tuples` + # [New in Fulu:EIP7594] + data_column_sidecar_tuples: Set[Tuple[Slot, ValidatorIndex, ColumnIndex]] + # [New in Fulu] + partial_data_column_headers: Dict[Root, PartialDataColumnHeader] +``` + #### Modified `compute_fork_version` ```python @@ -213,11 +238,106 @@ Some gossip meshes are upgraded in Fulu to support upgraded types. ###### `beacon_block` -*Updated validation* +*Note*: This function is modified per EIP-7892. The block's KZG commitment count +is bounded by +`get_blob_parameters(get_current_epoch(state)).max_blobs_per_block`. -- _[REJECT]_ The length of KZG commitments is less than or equal to the - limitation defined in the consensus layer -- i.e. validate that - `len(signed_beacon_block.message.body.blob_kzg_commitments) <= get_blob_parameters(get_current_epoch(state)).max_blobs_per_block` +```python +def validate_beacon_block_gossip( + seen: Seen, + store: Store, + state: BeaconState, + signed_beacon_block: SignedBeaconBlock, + current_time_ms: uint64, + block_payload_statuses: Dict[Root, PayloadValidationStatus] = {}, +) -> None: + """ + Validate a SignedBeaconBlock for gossip propagation. + Raises GossipIgnore or GossipReject on validation failure. + """ + block = signed_beacon_block.message + execution_payload = block.body.execution_payload + + # [IGNORE] The block is not from a future slot + # (MAY be queued for processing at the appropriate slot) + if not is_not_from_future_slot(state, block.slot, current_time_ms): + raise GossipIgnore("block is from a future slot") + + # [IGNORE] The block is from a slot greater than the latest finalized slot + # (MAY choose to validate and store such blocks for additional purposes + # -- e.g. slashing detection, archive nodes, etc) + finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + if block.slot <= finalized_slot: + raise GossipIgnore("block is not from a slot greater than the latest finalized slot") + + # [IGNORE] The block is the first block with valid signature received for the proposer for the slot + if (block.proposer_index, block.slot) in seen.proposer_slots: + raise GossipIgnore("block is not the first valid block for this proposer and slot") + + # [REJECT] The proposer index is a valid validator index + if block.proposer_index >= len(state.validators): + raise GossipReject("proposer index out of range") + + # [REJECT] The proposer signature is valid + proposer = state.validators[block.proposer_index] + domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(block.slot)) + signing_root = compute_signing_root(block, domain) + if not bls.Verify(proposer.pubkey, signing_root, signed_beacon_block.signature): + raise GossipReject("invalid proposer signature") + + # [IGNORE] The block's parent has been seen (via gossip or non-gossip sources) + # (MAY be queued until parent is retrieved) + if block.parent_root not in store.blocks: + raise GossipIgnore("block's parent has not been seen") + + # [REJECT] The block's execution payload timestamp is correct with respect to the slot + if execution_payload.timestamp != compute_time_at_slot(state, block.slot): + raise GossipReject("incorrect execution payload timestamp") + + parent_payload_status = PAYLOAD_STATUS_NOT_VALIDATED + if block.parent_root in block_payload_statuses: + parent_payload_status = block_payload_statuses[block.parent_root] + + if block.parent_root not in store.block_states: + if parent_payload_status == PAYLOAD_STATUS_NOT_VALIDATED: + # [REJECT] The block's parent passes validation + raise GossipReject("block's parent is invalid and EL result is unknown") + + # [IGNORE] The block's parent passes validation + raise GossipIgnore("block's parent is invalid and EL result is known") + + # [IGNORE] The block's parent's execution payload passes validation + if parent_payload_status == PAYLOAD_STATUS_INVALIDATED: + raise GossipIgnore("block's parent is valid and EL result is invalid") + + # [REJECT] The block is from a higher slot than its parent + if block.slot <= store.blocks[block.parent_root].slot: + raise GossipReject("block is not from a higher slot than its parent") + + # [REJECT] The current finalized checkpoint is an ancestor of the block + checkpoint_block = get_checkpoint_block( + store, block.parent_root, store.finalized_checkpoint.epoch + ) + if checkpoint_block != store.finalized_checkpoint.root: + raise GossipReject("finalized checkpoint is not an ancestor of block") + + # [Modified in Fulu:EIP7892] + # [REJECT] The length of KZG commitments is less than or equal to the limit + max_blobs = get_blob_parameters(get_current_epoch(state)).max_blobs_per_block + if len(block.body.blob_kzg_commitments) > max_blobs: + raise GossipReject("too many blob kzg commitments") + + # [REJECT] The block is proposed by the expected proposer for the slot + # (if shuffling is not available, IGNORE instead and MAY be queued for later) + parent_state = store.block_states[block.parent_root].copy() + process_slots(parent_state, block.slot) + expected_proposer = get_beacon_proposer_index(parent_state) + if block.proposer_index != expected_proposer: + raise GossipReject("block proposer_index does not match expected proposer") + + # Mark this block as seen + seen.proposer_slots.add((block.proposer_index, block.slot)) +``` ##### Blob subnets @@ -227,52 +347,99 @@ Some gossip meshes are upgraded in Fulu to support upgraded types. ###### `data_column_sidecar_{subnet_id}` -This topic is used to propagate column sidecars, where each column maps to some -`subnet_id`. - -The *type* of the payload of this topic is `DataColumnSidecar`. - -The following validations MUST pass before forwarding the -`sidecar: DataColumnSidecar` on the network, assuming the alias -`block_header = sidecar.signed_block_header.message`: - -- _[REJECT]_ The sidecar is valid as verified by - `verify_data_column_sidecar(sidecar)`. -- _[REJECT]_ The sidecar is for the correct subnet -- i.e. - `compute_subnet_for_data_column_sidecar(sidecar.index) == subnet_id`. -- _[IGNORE]_ The sidecar is not from a future slot (with a - `MAXIMUM_GOSSIP_CLOCK_DISPARITY` allowance) -- i.e. validate that - `block_header.slot <= current_slot` (a client MAY queue future sidecars for - processing at the appropriate slot). -- _[IGNORE]_ The sidecar is from a slot greater than the latest finalized slot - -- i.e. validate that - `block_header.slot > compute_start_slot_at_epoch(state.finalized_checkpoint.epoch)` -- _[REJECT]_ The proposer signature of `sidecar.signed_block_header`, is valid - with respect to the `block_header.proposer_index` pubkey. -- _[IGNORE]_ The sidecar's block's parent (defined by - `block_header.parent_root`) has been seen (via gossip or non-gossip sources) - (a client MAY queue sidecars for processing once the parent block is - retrieved). -- _[REJECT]_ The sidecar's block's parent (defined by - `block_header.parent_root`) passes validation. -- _[REJECT]_ The sidecar is from a higher slot than the sidecar's block's parent - (defined by `block_header.parent_root`). -- _[REJECT]_ The current finalized_checkpoint is an ancestor of the sidecar's - block -- i.e. - `get_checkpoint_block(store, block_header.parent_root, store.finalized_checkpoint.epoch) == store.finalized_checkpoint.root`. -- _[REJECT]_ The sidecar's `kzg_commitments` field inclusion proof is valid as - verified by `verify_data_column_sidecar_inclusion_proof(sidecar)`. -- _[REJECT]_ The sidecar's column data is valid as verified by - `verify_data_column_sidecar_kzg_proofs(sidecar)`. -- _[IGNORE]_ The sidecar is the first sidecar for the tuple - `(block_header.slot, block_header.proposer_index, sidecar.index)` with valid - header signature, sidecar inclusion proof, and kzg proof. -- _[REJECT]_ The sidecar is proposed by the expected `proposer_index` for the - block's slot in the context of the current shuffling (defined by - `block_header.parent_root`/`block_header.slot`). If the `proposer_index` - cannot immediately be verified against the expected shuffling, the sidecar MAY - be queued for later processing while proposers for the block's branch are - calculated -- in such a case _do not_ `REJECT`, instead `IGNORE` this message. +The `data_column_sidecar_{subnet_id}` topics, where each column index maps to +some `subnet_id`, are used to propagate new data column sidecars to nodes on the +network. Sidecars are sent in their entirety. + +```python +def validate_data_column_sidecar_gossip( + seen: Seen, + store: Store, + state: BeaconState, + sidecar: DataColumnSidecar, + subnet_id: SubnetID, + current_time_ms: uint64, +) -> None: + """ + Validate a DataColumnSidecar for gossip propagation on a subnet. + Raises GossipIgnore or GossipReject on validation failure. + """ + block_header = sidecar.signed_block_header.message + + # [REJECT] The sidecar is valid as verified by verify_data_column_sidecar + if not verify_data_column_sidecar(sidecar): + raise GossipReject("invalid sidecar") + + # [REJECT] The sidecar is for the correct subnet + if compute_subnet_for_data_column_sidecar(sidecar.index) != subnet_id: + raise GossipReject("sidecar is for wrong subnet") + + # [IGNORE] The sidecar is not from a future slot + # (MAY be queued for processing at the appropriate slot) + if not is_not_from_future_slot(state, block_header.slot, current_time_ms): + raise GossipIgnore("sidecar is from a future slot") + + # [IGNORE] The sidecar is from a slot greater than the latest finalized slot + finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + if block_header.slot <= finalized_slot: + raise GossipIgnore("sidecar is not from a slot greater than the latest finalized slot") + + # [REJECT] The proposer index is a valid validator index + if block_header.proposer_index >= len(state.validators): + raise GossipReject("proposer index out of range") + + # [REJECT] The proposer signature of sidecar.signed_block_header is valid + proposer = state.validators[block_header.proposer_index] + domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(block_header.slot)) + signing_root = compute_signing_root(block_header, domain) + if not bls.Verify(proposer.pubkey, signing_root, sidecar.signed_block_header.signature): + raise GossipReject("invalid proposer signature on sidecar block header") + + # [IGNORE] The sidecar's block's parent has been seen + # (MAY be queued for processing once the parent block is retrieved) + if block_header.parent_root not in store.blocks: + raise GossipIgnore("sidecar's parent has not been seen") + + # [REJECT] The sidecar's block's parent passes validation + if block_header.parent_root not in store.block_states: + raise GossipReject("sidecar's parent failed validation") + + # [REJECT] The sidecar is from a higher slot than the sidecar's block's parent + if block_header.slot <= store.blocks[block_header.parent_root].slot: + raise GossipReject("sidecar is not from a higher slot than its parent") + + # [REJECT] The current finalized_checkpoint is an ancestor of the sidecar's block + checkpoint_block = get_checkpoint_block( + store, block_header.parent_root, store.finalized_checkpoint.epoch + ) + if checkpoint_block != store.finalized_checkpoint.root: + raise GossipReject("finalized checkpoint is not an ancestor of sidecar's block") + + # [REJECT] The sidecar is valid as verified by verify_data_column_sidecar_inclusion_proof + if not verify_data_column_sidecar_inclusion_proof(sidecar): + raise GossipReject("invalid sidecar inclusion proof") + + # [REJECT] The sidecar is valid as verified by verify_data_column_sidecar_kzg_proofs + if not verify_data_column_sidecar_kzg_proofs(sidecar): + raise GossipReject("invalid sidecar kzg proofs") + + # [IGNORE] The sidecar is the first sidecar for the tuple + # (block_header.slot, block_header.proposer_index, sidecar.index) + sidecar_tuple = (block_header.slot, block_header.proposer_index, sidecar.index) + if sidecar_tuple in seen.data_column_sidecar_tuples: + raise GossipIgnore("already seen sidecar from this proposer for this slot and index") + + # [REJECT] The sidecar is proposed by the expected proposer_index + # (if shuffling is not available, IGNORE instead and MAY be queued for later) + parent_state = store.block_states[block_header.parent_root].copy() + process_slots(parent_state, block_header.slot) + expected_proposer = get_beacon_proposer_index(parent_state) + if block_header.proposer_index != expected_proposer: + raise GossipReject("sidecar proposer_index does not match expected proposer") + + # Mark this data column sidecar as seen + seen.data_column_sidecar_tuples.add(sidecar_tuple) +``` *Note*: In the `verify_data_column_sidecar_inclusion_proof(sidecar)` check, for all the sidecars of the same block, it verifies against the same set of diff --git a/specs/fulu/partial-columns/p2p-interface.md b/specs/fulu/partial-columns/p2p-interface.md index 295009cb02b..7608ef15cce 100644 --- a/specs/fulu/partial-columns/p2p-interface.md +++ b/specs/fulu/partial-columns/p2p-interface.md @@ -149,72 +149,151 @@ def verify_partial_data_column_sidecar_kzg_proofs( ### Partial Messages on `data_column_sidecar_{subnet_id}` -Validating partial messages happens in two parts. First, the +*Note*: Validating partial messages happens in two parts. First, the `PartialDataColumnHeader` needs to be validated, then the cell and proof data. - Once a `PartialDataColumnHeader` is validated for a corresponding block on any -subnet (gossipsub topic), it can be used for all subnets. - -Due to the nature of partial messages, it is possible to get the -`PartialDataColumnHeader` with no cells, and get cells in a future response. - -For all partial messages: - -- _[REJECT]_ A header and/or cells are present in the message (it is not - semantically empty). -- _[REJECT]_ There are the same number of cells and proofs in the message and - this number is equal the number of 1s in the cells_present_bitmap. - -For verifying the `PartialDataColumnHeader` in a partial message: - -- _[REJECT]_ If a valid header was previously received, the received header MUST - equal the previously valid header. -- _[REJECT]_ The hash of the block header in `signed_block_header` MUST be the - same one identified by the partial message's group id. -- _[REJECT]_ The header's `kzg_commitments` list is non-empty. -- _[IGNORE]_ The header is not from a future slot (with a - `MAXIMUM_GOSSIP_CLOCK_DISPARITY` allowance) -- i.e. validate that - `block_header.slot <= current_slot` (a client MAY queue future headers for - processing at the appropriate slot). -- _[IGNORE]_ The header is from a slot greater than the latest finalized slot -- - i.e. validate that - `block_header.slot > compute_start_slot_at_epoch(state.finalized_checkpoint.epoch)`.j -- _[REJECT]_ The proposer signature of `signed_block_header` is valid with - respect to the `block_header.proposer_index` pubkey. -- _[IGNORE]_ The header's block's parent (defined by `block_header.parent_root`) - has been seen (via gossip or non-gossip sources) (a client MAY queue header - for processing once the parent block is retrieved). -- _[REJECT]_ The header's block's parent (defined by `block_header.parent_root`) - passes validation. -- _[REJECT]_ The header is from a higher slot than the header's block's parent - (defined by `block_header.parent_root`). -- _[REJECT]_ The current `finalized_checkpoint` is an ancestor of the header's - block -- i.e. - `get_checkpoint_block(store, block_header.parent_root, store.finalized_checkpoint.epoch) == store.finalized_checkpoint.root`. -- _[REJECT]_ The header's `kzg_commitments` field inclusion proof is valid as - verified by `verify_partial_data_column_header_inclusion_proof`. -- _[REJECT]_ The header is proposed by the expected `proposer_index` for the - block's slot in the context of the current shuffling (defined by - `block_header.parent_root`/`block_header.slot`). If the `proposer_index` - cannot immediately be verified against the expected shuffling, the header MAY - be queued for later processing while proposers for the block's branch are - calculated -- in such a case _do not_ `REJECT`, instead `IGNORE` this message. - -For verifying the cells in a partial message: - -- _[IGNORE]_ If the received partial message contains only cell and proof data, - the node has seen a valid corresponding `PartialDataColumnHeader`. -- _[IGNORE]_ The corresponding header is not from a future slot. See related - header check above for more details. -- _[IGNORE]_ The corresponding header is from a slot greater than the latest - finalized slot. See related header check above for more details. -- _[REJECT]_ The cells present bitmap length is equal to the number of KZG - commitments in the `PartialDataColumnHeader`. -- _[REJECT]_ For cells the receiver already has, The sidecar's cell and proof - data are equal to the local copy. This an optional check for the receiver, but - the sender MUST always send valid cell and proof data. -- _[REJECT]_ The sidecar's cell and proof data is valid as verified by - `verify_partial_data_column_sidecar_kzg_proofs(sidecar, header.kzg_commitments, column_index)`. +subnet (gossipsub topic), it can be used for all subnets. Due to the nature of +partial messages, it is possible to get the `PartialDataColumnHeader` with no +cells, and get cells in a future response. + +```python +def validate_partial_data_column_sidecar_gossip( + seen: Seen, + store: Store, + state: BeaconState, + sidecar: PartialDataColumnSidecar, + block_root: Root, + column_index: ColumnIndex, + current_time_ms: uint64, +) -> None: + """ + Validate a PartialDataColumnSidecar for gossip propagation on a subnet. + Raises GossipIgnore or GossipReject on validation failure. + """ + has_header = len(sidecar.header) == 1 + num_cells_present = sum(1 for b in sidecar.cells_present_bitmap if b) + has_cells = num_cells_present > 0 + + # [REJECT] A header and/or cells are present in the message + if not (has_header or has_cells): + raise GossipReject("partial message is semantically empty") + + # [REJECT] The cell count equals the number of bits set in cells_present_bitmap + if len(sidecar.partial_column) != num_cells_present: + raise GossipReject("number of cells does not match number of set bits") + + # [REJECT] The proof count equals the number of bits set in cells_present_bitmap + if len(sidecar.kzg_proofs) != num_cells_present: + raise GossipReject("number of proofs does not match number of set bits") + + if has_header: + header = sidecar.header[0] + block_header = header.signed_block_header.message + + # [REJECT] The received header MUST equal any previously validated header for this block + prior_header = seen.partial_data_column_headers.get(block_root) + if prior_header is not None and prior_header != header: + raise GossipReject("header differs from previously validated header") + + # [REJECT] The signed_block_header hash matches the partial message's group id + if hash_tree_root(block_header) != block_root: + raise GossipReject("header's block root does not match partial message group id") + + # [REJECT] The header's kzg_commitments list is non-empty + if len(header.kzg_commitments) == 0: + raise GossipReject("header kzg_commitments is empty") + + # [IGNORE] The header is not from a future slot + # (MAY be queued for processing at the appropriate slot) + if not is_not_from_future_slot(state, block_header.slot, current_time_ms): + raise GossipIgnore("header is from a future slot") + + # [IGNORE] The header is from a slot greater than the latest finalized slot + finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + if block_header.slot <= finalized_slot: + raise GossipIgnore("header is not from a slot greater than the latest finalized slot") + + # [REJECT] The proposer index is a valid validator index + if block_header.proposer_index >= len(state.validators): + raise GossipReject("proposer index out of range") + + # [REJECT] The proposer signature of signed_block_header is valid + proposer = state.validators[block_header.proposer_index] + domain = get_domain(state, DOMAIN_BEACON_PROPOSER, compute_epoch_at_slot(block_header.slot)) + signing_root = compute_signing_root(block_header, domain) + if not bls.Verify(proposer.pubkey, signing_root, header.signed_block_header.signature): + raise GossipReject("invalid proposer signature on header") + + # [IGNORE] The header's block's parent has been seen + # (MAY be queued for processing once the parent block is retrieved) + if block_header.parent_root not in store.blocks: + raise GossipIgnore("header's parent has not been seen") + + # [REJECT] The header's block's parent passes validation + if block_header.parent_root not in store.block_states: + raise GossipReject("header's parent failed validation") + + # [REJECT] The header is from a higher slot than the header's block's parent + if block_header.slot <= store.blocks[block_header.parent_root].slot: + raise GossipReject("header is not from a higher slot than its parent") + + # [REJECT] The current finalized_checkpoint is an ancestor of the header's block + checkpoint_block = get_checkpoint_block( + store, block_header.parent_root, store.finalized_checkpoint.epoch + ) + if checkpoint_block != store.finalized_checkpoint.root: + raise GossipReject("finalized checkpoint is not an ancestor of header's block") + + # [REJECT] The header's kzg_commitments inclusion proof is valid + if not verify_partial_data_column_header_inclusion_proof(header): + raise GossipReject("invalid header inclusion proof") + + # [REJECT] The header is proposed by the expected proposer_index + # (if shuffling is not available, IGNORE instead and MAY be queued for later) + parent_state = store.block_states[block_header.parent_root].copy() + process_slots(parent_state, block_header.slot) + expected_proposer = get_beacon_proposer_index(parent_state) + if block_header.proposer_index != expected_proposer: + raise GossipReject("header proposer_index does not match expected proposer") + + # Cache the validated header for future partial messages + seen.partial_data_column_headers[block_root] = header + + if has_cells: + # [IGNORE] A valid corresponding PartialDataColumnHeader has been seen + header = seen.partial_data_column_headers.get(block_root) + if header is None: + raise GossipIgnore("no validated header seen for this block") + + block_header = header.signed_block_header.message + + # [IGNORE] The corresponding header is not from a future slot + # (MAY be queued for processing at the appropriate slot) + if not is_not_from_future_slot(state, block_header.slot, current_time_ms): + raise GossipIgnore("cached header is from a future slot") + + # [IGNORE] The corresponding header is from a slot greater than the latest finalized slot + finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) + if block_header.slot <= finalized_slot: + raise GossipIgnore( + "cached header is not from a slot greater than the latest finalized slot" + ) + + # [REJECT] The cells_present_bitmap length equals the number of header kzg_commitments + if len(sidecar.cells_present_bitmap) != len(header.kzg_commitments): + raise GossipReject("bitmap length does not match number of commitments") + + # [REJECT] The sidecar's cell and proof data is valid + if not verify_partial_data_column_sidecar_kzg_proofs( + sidecar, header.kzg_commitments, column_index + ): + raise GossipReject("invalid sidecar kzg proofs") +``` + +*Note*: The optional check "for cells the receiver already has, the sidecar's +cell and proof data are equal to the local copy" is not encoded above. The +sender MUST always send valid cell and proof data; receivers MAY perform this +equality check against their local copy as an additional safeguard. ### Partial columns for Cell Dissemination diff --git a/specs/gloas/p2p-interface.md b/specs/gloas/p2p-interface.md index b81edab5480..61ba99b5ac5 100644 --- a/specs/gloas/p2p-interface.md +++ b/specs/gloas/p2p-interface.md @@ -12,6 +12,7 @@ - [New `ProposerPreferences`](#new-proposerpreferences) - [New `SignedProposerPreferences`](#new-signedproposerpreferences) - [Helpers](#helpers) + - [Modified `Seen`](#modified-seen) - [Modified `compute_fork_version`](#modified-compute_fork_version) - [Modified `verify_data_column_sidecar_kzg_proofs`](#modified-verify_data_column_sidecar_kzg_proofs) - [Modified `verify_data_column_sidecar`](#modified-verify_data_column_sidecar) @@ -105,6 +106,27 @@ class SignedProposerPreferences(Container): ### Helpers +#### Modified `Seen` + +```python +@dataclass +class Seen(object): + proposer_slots: Set[Tuple[ValidatorIndex, Slot]] + aggregator_epochs: Set[Tuple[ValidatorIndex, Epoch]] + aggregate_data_roots: Dict[Tuple[Root, CommitteeIndex], Set[Tuple[boolean, ...]]] + voluntary_exit_indices: Set[ValidatorIndex] + proposer_slashing_indices: Set[ValidatorIndex] + attester_slashing_indices: Set[ValidatorIndex] + attestation_validator_epochs: Set[Tuple[ValidatorIndex, Epoch]] + sync_contribution_aggregator_slots: Set[Tuple[ValidatorIndex, Slot, uint64]] + sync_contribution_data: Dict[Tuple[Slot, Root, uint64], Set[Tuple[boolean, ...]]] + sync_message_validator_slots: Set[Tuple[Slot, ValidatorIndex, uint64]] + bls_to_execution_change_indices: Set[ValidatorIndex] + data_column_sidecar_tuples: Set[Tuple[Slot, ValidatorIndex, ColumnIndex]] + # [Modified in Gloas:EIP7732] + # Removed `partial_data_column_headers` +``` + #### Modified `compute_fork_version` ```python diff --git a/tests/core/pyspec/eth_consensus_specs/test/bellatrix/networking/test_gossip_beacon_block.py b/tests/core/pyspec/eth_consensus_specs/test/bellatrix/networking/test_gossip_beacon_block.py index 3766c5b6fa6..eeb23e60458 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/bellatrix/networking/test_gossip_beacon_block.py +++ b/tests/core/pyspec/eth_consensus_specs/test/bellatrix/networking/test_gossip_beacon_block.py @@ -6,7 +6,7 @@ build_empty_block_for_next_slot, sign_block, ) -from eth_consensus_specs.test.helpers.constants import BELLATRIX, CAPELLA, DENEB, ELECTRA +from eth_consensus_specs.test.helpers.constants import BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU from eth_consensus_specs.test.helpers.execution_payload import ( build_empty_execution_payload, build_state_with_complete_transition, @@ -29,7 +29,7 @@ ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__valid_execution_enabled(spec, state): """ @@ -110,7 +110,7 @@ def test_gossip_beacon_block__valid_execution_disabled(spec, state): ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_incorrect_execution_payload_timestamp(spec, state): """ @@ -161,7 +161,7 @@ def test_gossip_beacon_block__reject_incorrect_execution_payload_timestamp(spec, ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_parent_consensus_failed_execution_not_verified(spec, state): """ @@ -250,7 +250,7 @@ def test_gossip_beacon_block__reject_parent_consensus_failed_execution_not_verif ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__ignore_parent_consensus_failed_execution_known(spec, state): """ @@ -338,7 +338,7 @@ def test_gossip_beacon_block__ignore_parent_consensus_failed_execution_known(spe ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__ignore_parent_execution_verified_invalid(spec, state): """ @@ -428,7 +428,7 @@ def test_gossip_beacon_block__ignore_parent_execution_verified_invalid(spec, sta ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__valid_parent_execution_verified_valid(spec, state): """ @@ -510,7 +510,7 @@ def test_gossip_beacon_block__valid_parent_execution_verified_valid(spec, state) ) -@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__valid_parent_optimistic(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/context.py b/tests/core/pyspec/eth_consensus_specs/test/context.py index 89f88297667..64d64cdadf5 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/context.py +++ b/tests/core/pyspec/eth_consensus_specs/test/context.py @@ -10,6 +10,7 @@ from lru import LRU from eth_consensus_specs.utils import bls +from eth_consensus_specs.utils.ckzg_utils import apply_ckzg_to_spec from tests.infra.yield_generator import MultiPhaseResult, vector_test from .exceptions import SkippedTest @@ -743,6 +744,14 @@ def get_copy_of_spec(spec): # Preserve existing config overrides module.config = deepcopy(spec.config) + # Re-apply ckzg monkey-patches if the source spec had them. Without this, + # the freshly-loaded module falls back to the pure-Python KZG impl, which + # makes blob-heavy tests (e.g. anything that calls + # `compute_cells_and_kzg_proofs`) prohibitively slow. + ts = getattr(spec, "_ckzg_trusted_setup", None) + if ts is not None: + apply_ckzg_to_spec(module, ts) + return module diff --git a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_aggregate_and_proof.py b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_aggregate_and_proof.py index bffa9d108bf..3430a5ebf07 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_aggregate_and_proof.py +++ b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_aggregate_and_proof.py @@ -5,7 +5,7 @@ from eth_consensus_specs.test.helpers.attestations import ( get_valid_attestation, ) -from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA +from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA, FULU from eth_consensus_specs.test.helpers.fork_choice import ( get_genesis_forkchoice_store_and_block, ) @@ -96,7 +96,7 @@ def build_message(signed_agg, current_time_ms, offset_ms, expected, reason=None) return message -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_one_millisecond_before_slot_start(spec, state): """Test that an aggregate is accepted one millisecond before its slot starts.""" @@ -123,7 +123,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_one_millisecond_before_slot_ yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_at_slot_start(spec, state): """Test that an aggregate is accepted exactly at its slot start.""" @@ -148,7 +148,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_at_slot_start(spec, state): yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignores_first_slot_before_epoch_window_opens( spec, state @@ -181,7 +181,7 @@ def test_gossip_beacon_aggregate_and_proof__ignores_first_slot_before_epoch_wind yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "ignore", reason)] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_first_slot_when_epoch_window_opens(spec, state): """Test that a first-slot aggregate is accepted when the Deneb epoch window opens.""" @@ -209,7 +209,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_first_slot_when_epoch_window yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_first_slot_when_epoch_window_closes( spec, state @@ -239,7 +239,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_first_slot_when_epoch_window yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignores_first_slot_after_epoch_window_closes( spec, state @@ -269,7 +269,7 @@ def test_gossip_beacon_aggregate_and_proof__ignores_first_slot_after_epoch_windo yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "ignore", reason)] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_last_slot_one_millisecond_before_slot_start( spec, state @@ -307,7 +307,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_last_slot_one_millisecond_be yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_last_slot_at_slot_start(spec, state): """Test that a last-slot aggregate is accepted exactly at its slot start.""" @@ -338,7 +338,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_last_slot_at_slot_start(spec yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__accepts_last_slot_when_epoch_window_closes(spec, state): """Test that a last-slot aggregate is accepted at the last valid Deneb epoch time.""" @@ -369,7 +369,7 @@ def test_gossip_beacon_aggregate_and_proof__accepts_last_slot_when_epoch_window_ yield "messages", "meta", [build_message(signed_agg, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignores_last_slot_after_epoch_window_closes( spec, state diff --git a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_attestation.py b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_attestation.py index bb2088b1f4e..cac5b8d226d 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_attestation.py +++ b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_attestation.py @@ -6,7 +6,7 @@ get_valid_attestation, to_single_attestation, ) -from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA +from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA, FULU from eth_consensus_specs.test.helpers.fork_choice import ( get_genesis_forkchoice_store_and_block, ) @@ -93,7 +93,7 @@ def build_message(attestation, subnet_id, current_time_ms, offset_ms, expected, return message -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_one_millisecond_before_slot_start(spec, state): """Test that an attestation is accepted one millisecond before its slot starts.""" @@ -119,7 +119,7 @@ def test_gossip_beacon_attestation__accepts_one_millisecond_before_slot_start(sp yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_at_slot_start(spec, state): """Test that an attestation is accepted exactly at its slot start.""" @@ -145,7 +145,7 @@ def test_gossip_beacon_attestation__accepts_at_slot_start(spec, state): yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__ignores_first_slot_before_epoch_window_opens(spec, state): """ @@ -181,7 +181,7 @@ def test_gossip_beacon_attestation__ignores_first_slot_before_epoch_window_opens ) -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_first_slot_when_epoch_window_opens(spec, state): """Test that a first-slot attestation is accepted when the Deneb epoch window opens.""" @@ -210,7 +210,7 @@ def test_gossip_beacon_attestation__accepts_first_slot_when_epoch_window_opens(s yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_first_slot_when_epoch_window_closes(spec, state): """Test that a first-slot attestation is accepted at the last valid Deneb epoch time.""" @@ -239,7 +239,7 @@ def test_gossip_beacon_attestation__accepts_first_slot_when_epoch_window_closes( yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__ignores_first_slot_after_epoch_window_closes(spec, state): """Test that a first-slot attestation is ignored after the Deneb epoch window closes.""" @@ -272,7 +272,7 @@ def test_gossip_beacon_attestation__ignores_first_slot_after_epoch_window_closes ) -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_last_slot_one_millisecond_before_slot_start( spec, state @@ -307,7 +307,7 @@ def test_gossip_beacon_attestation__accepts_last_slot_one_millisecond_before_slo yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_last_slot_at_slot_start(spec, state): """Test that a last-slot attestation is accepted exactly at its slot start.""" @@ -337,7 +337,7 @@ def test_gossip_beacon_attestation__accepts_last_slot_at_slot_start(spec, state) yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__accepts_last_slot_when_epoch_window_closes(spec, state): """Test that a last-slot attestation is accepted at the last valid Deneb epoch time.""" @@ -367,7 +367,7 @@ def test_gossip_beacon_attestation__accepts_last_slot_when_epoch_window_closes(s yield "messages", "meta", [build_message(attestation, subnet_id, current_time_ms, 0, "valid")] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__ignores_last_slot_after_epoch_window_closes(spec, state): """Test that a last-slot attestation is ignored after the Deneb epoch window closes.""" diff --git a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_block.py b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_block.py index 544d18b9f46..f248050a253 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_block.py +++ b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_beacon_block.py @@ -6,7 +6,7 @@ ) from eth_consensus_specs.test.helpers.blob import get_block_with_blob, get_max_blob_count from eth_consensus_specs.test.helpers.block import sign_block -from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA +from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA, FULU from eth_consensus_specs.test.helpers.execution_payload import ( build_state_with_complete_transition, ) @@ -24,7 +24,7 @@ ) -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__valid_with_blob_kzg_commitments(spec, state): """ @@ -64,7 +64,7 @@ def test_gossip_beacon_block__valid_with_blob_kzg_commitments(spec, state): ) -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_too_many_kzg_commitments(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_voluntary_exit.py b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_voluntary_exit.py index f2e5f3f355c..a79fee726ce 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_voluntary_exit.py +++ b/tests/core/pyspec/eth_consensus_specs/test/deneb/networking/test_gossip_voluntary_exit.py @@ -3,7 +3,7 @@ spec_state_test, with_phases, ) -from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA +from eth_consensus_specs.test.helpers.constants import DENEB, ELECTRA, FULU from eth_consensus_specs.test.helpers.gossip import get_filename, get_seen from eth_consensus_specs.test.helpers.keys import privkeys from eth_consensus_specs.test.helpers.voluntary_exits import ( @@ -30,7 +30,7 @@ def run_validate_voluntary_exit_gossip(spec, seen, state, signed_voluntary_exit) return "reject", str(e) -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__valid_capella_signature(spec, state): """ @@ -53,7 +53,7 @@ def test_gossip_voluntary_exit__valid_capella_signature(spec, state): yield "messages", "meta", [{"message": get_filename(signed_exit), "expected": "valid"}] -@with_phases([DENEB, ELECTRA]) +@with_phases([DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_voluntary_exit__reject_deneb_signature(spec, state): diff --git a/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_aggregate_and_proof.py b/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_aggregate_and_proof.py index 76c398c85b6..ec0c85d7362 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_aggregate_and_proof.py +++ b/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_aggregate_and_proof.py @@ -6,7 +6,7 @@ from eth_consensus_specs.test.helpers.attestations import ( get_valid_attestation, ) -from eth_consensus_specs.test.helpers.constants import ELECTRA, MINIMAL +from eth_consensus_specs.test.helpers.constants import ELECTRA, FULU, MINIMAL from eth_consensus_specs.test.helpers.fork_choice import ( get_genesis_forkchoice_store_and_block, ) @@ -63,7 +63,7 @@ def prepare_signed_aggregate(spec, state): return store, signed_anchor, signed_agg -@with_phases([ELECTRA]) +@with_phases([ELECTRA, FULU]) @spec_state_test @with_presets([MINIMAL], "need multiple committees per slot") def test_gossip_beacon_aggregate_and_proof__accept_same_data_for_disjoint_committees(spec, state): @@ -133,7 +133,7 @@ def test_gossip_beacon_aggregate_and_proof__accept_same_data_for_disjoint_commit yield "messages", "meta", messages -@with_phases([ELECTRA]) +@with_phases([ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_nonzero_data_index(spec, state): """ @@ -176,7 +176,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_nonzero_data_index(spec, stat ) -@with_phases([ELECTRA]) +@with_phases([ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_zero_committees(spec, state): """ @@ -219,7 +219,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_zero_committees(spec, state): ) -@with_phases([ELECTRA]) +@with_phases([ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_multiple_committees(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_attestation.py b/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_attestation.py index c6a445d46f2..2a95c8ad3ac 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_attestation.py +++ b/tests/core/pyspec/eth_consensus_specs/test/electra/networking/test_gossip_beacon_attestation.py @@ -6,7 +6,7 @@ get_valid_attestation, to_single_attestation, ) -from eth_consensus_specs.test.helpers.constants import ELECTRA +from eth_consensus_specs.test.helpers.constants import ELECTRA, FULU from eth_consensus_specs.test.helpers.fork_choice import ( get_genesis_forkchoice_store_and_block, ) @@ -45,7 +45,7 @@ def prepare_single_attestation(spec, state): return store, signed_anchor, single -@with_phases([ELECTRA]) +@with_phases([ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_nonzero_data_index(spec, state): """ @@ -90,7 +90,7 @@ def test_gossip_beacon_attestation__reject_nonzero_data_index(spec, state): ) -@with_phases([ELECTRA]) +@with_phases([ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_attester_not_in_committee(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py new file mode 100644 index 00000000000..f19873b0734 --- /dev/null +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py @@ -0,0 +1,75 @@ +import random + +from frozendict import frozendict + +from eth_consensus_specs.test.context import ( + spec_configured_state_test, + with_phases, +) +from eth_consensus_specs.test.helpers.blob import get_block_with_blob, get_max_blob_count +from eth_consensus_specs.test.helpers.constants import FULU +from eth_consensus_specs.test.helpers.execution_payload import ( + build_state_with_complete_transition, +) +from eth_consensus_specs.test.helpers.fork_choice import ( + get_genesis_forkchoice_store_and_block, +) +from eth_consensus_specs.test.helpers.gossip import ( + get_filename, + get_seen, + run_validate_beacon_block_gossip, + wrap_genesis_block, +) +from eth_consensus_specs.test.helpers.state import ( + state_transition_and_sign_block, +) + + +@with_phases([FULU]) +@spec_configured_state_test( + { + "BLOB_SCHEDULE": (frozendict({"EPOCH": 0, "MAX_BLOBS_PER_BLOCK": 12}),), + } +) +def test_gossip_beacon_block__valid_at_blob_parameters_limit(spec, state): + """ + Test that a block carrying exactly ``get_blob_parameters().max_blobs_per_block`` + blob kzg commitments passes gossip validation under EIP-7892. + """ + yield "topic", "meta", "beacon_block" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + rng = random.Random(1234) + max_blobs = get_max_blob_count(spec, state) + # Sanity check: the BLOB_SCHEDULE override should be exercising the Fulu + # code path (`get_blob_parameters`), not the Electra fallback. A client that + # forgets EIP-7892 and uses MAX_BLOBS_PER_BLOCK_ELECTRA would reject this block. + assert max_blobs > spec.config.MAX_BLOBS_PER_BLOCK_ELECTRA + block, _, _, _ = get_block_with_blob(spec, state, rng=rng, blob_count=max_blobs) + signed_block = state_transition_and_sign_block(spec, state, block) + + yield get_filename(signed_block), signed_block + + block_time_ms = spec.compute_time_at_slot_ms(state, signed_block.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + result, reason = run_validate_beacon_block_gossip( + spec, seen, store, state, signed_block, block_time_ms + 500 + ) + assert result == "valid" + assert reason is None + + yield ( + "messages", + "meta", + [{"offset_ms": 500, "message": get_filename(signed_block), "expected": "valid"}], + ) diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py new file mode 100644 index 00000000000..240a86d24f4 --- /dev/null +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py @@ -0,0 +1,946 @@ +from frozendict import frozendict + +from eth_consensus_specs.test.context import ( + always_bls, + spec_configured_state_test, + spec_state_test, + with_phases, +) +from eth_consensus_specs.test.helpers.blob import ( + get_block_with_blob_and_sidecars, + get_max_blob_count, +) +from eth_consensus_specs.test.helpers.block import build_empty_block_for_next_slot +from eth_consensus_specs.test.helpers.constants import FULU +from eth_consensus_specs.test.helpers.execution_payload import ( + build_state_with_complete_transition, +) +from eth_consensus_specs.test.helpers.fork_choice import ( + get_genesis_forkchoice_store_and_block, +) +from eth_consensus_specs.test.helpers.gossip import ( + get_filename, + get_seen, + run_validate_data_column_sidecar_gossip, + wrap_genesis_block, +) +from eth_consensus_specs.test.helpers.keys import privkeys +from eth_consensus_specs.test.helpers.state import ( + state_transition_and_sign_block, + transition_to, +) + + +def build_signed_block_and_sidecars(spec, state, blob_count=1): + """ + Build a signed block carrying ``blob_count`` blobs (applying the state + transition) and return its (signed_block, data_column_sidecars). + """ + _, _, _, signed_block, sidecars, _ = get_block_with_blob_and_sidecars( + spec, state, blob_count=blob_count + ) + return signed_block, list(sidecars) + + +def setup_store_with_anchor(spec, state): + """Return a store seeded with the genesis anchor block.""" + store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) + return store, anchor_block + + +def correct_subnet(spec, sidecar): + return spec.compute_subnet_for_data_column_sidecar(sidecar.index) + + +def resign_sidecar_header(spec, state, sidecar): + proposer_index = sidecar.signed_block_header.message.proposer_index + domain = spec.get_domain( + state, + spec.DOMAIN_BEACON_PROPOSER, + spec.compute_epoch_at_slot(sidecar.signed_block_header.message.slot), + ) + signing_root = spec.compute_signing_root(sidecar.signed_block_header.message, domain) + sidecar.signed_block_header.signature = spec.bls.Sign(privkeys[proposer_index], signing_root) + + +@with_phases([FULU]) +@spec_configured_state_test( + { + "BLOB_SCHEDULE": (frozendict({"EPOCH": 0, "MAX_BLOBS_PER_BLOCK": 12}),), + } +) +def test_gossip_data_column_sidecar__valid(spec, state): + """Test that a valid data column sidecar passes gossip validation.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + max_blobs = get_max_blob_count(spec, state) + # Sanity check: the BLOB_SCHEDULE override should be exercising the Fulu + # code path (`get_blob_parameters`), not the Electra fallback. A client that + # forgets EIP-7892 and uses MAX_BLOBS_PER_BLOCK_ELECTRA would reject this sidecar. + assert max_blobs > spec.config.MAX_BLOBS_PER_BLOCK_ELECTRA + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=max_blobs) + sidecar = sidecars[0] + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "valid" + assert reason is None + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "valid", + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_index_out_of_range(spec, state): + """Test that a data column sidecar with index >= NUMBER_OF_COLUMNS is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + sidecar.index = spec.ColumnIndex(spec.NUMBER_OF_COLUMNS) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = spec.SubnetID(0) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid sidecar" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_too_many_commitments(spec, state): + """Test that a data column sidecar with too many commitments is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + # Pad commitments past the blob limit. The verify_data_column_sidecar + # check is independent of the inclusion proof, so we don't need a + # consistent block here. + extra = get_max_blob_count(spec, state) + 1 - len(sidecar.kzg_commitments) + sidecar.kzg_commitments = list(sidecar.kzg_commitments) + [spec.KZGCommitment()] * extra + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid sidecar" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_wrong_subnet(spec, state): + """Test that a data column sidecar on the wrong subnet is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + expected_subnet = correct_subnet(spec, sidecar) + wrong_subnet = spec.SubnetID( + (int(expected_subnet) + 1) % spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT + ) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, wrong_subnet, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "sidecar is for wrong subnet" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(wrong_subnet), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__ignore_future_slot(spec, state): + """Test that a data column sidecar from a future slot is ignored.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + yield get_filename(sidecar), sidecar + + slot_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + current_time_ms = slot_time_ms - spec.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY - 1 + yield "current_time_ms", "meta", int(current_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, current_time_ms + ) + assert result == "ignore" + assert reason == "sidecar is from a future slot" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 0, + "message": get_filename(sidecar), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__valid_slot_within_clock_disparity(spec, state): + """Test that a data column sidecar at the future-slot boundary is valid.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + yield get_filename(sidecar), sidecar + + slot_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + current_time_ms = slot_time_ms - spec.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY + yield "current_time_ms", "meta", int(current_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, current_time_ms + ) + assert result == "valid" + assert reason is None + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 0, + "message": get_filename(sidecar), + "expected": "valid", + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__ignore_not_later_than_finalized_slot(spec, state): + """Test that a data column sidecar at the latest finalized slot is ignored.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + transition_to(spec, state, spec.Slot(spec.SLOTS_PER_EPOCH - 1)) + yield "state", state + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + block_header = sidecar.signed_block_header.message + sidecar_epoch = spec.compute_epoch_at_slot(block_header.slot) + store.finalized_checkpoint = spec.Checkpoint( + epoch=sidecar_epoch, + root=store.finalized_checkpoint.root, + ) + yield ( + "finalized_checkpoint", + "meta", + { + "epoch": int(sidecar_epoch), + "block": get_filename(signed_anchor), + }, + ) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, block_header.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "ignore" + assert reason == "sidecar is not from a slot greater than the latest finalized slot" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_proposer_index_out_of_range(spec, state): + """Test that a data column sidecar with proposer_index out of range is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + sidecar.signed_block_header.message.proposer_index = spec.ValidatorIndex(len(state.validators)) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "proposer index out of range" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +@always_bls +def test_gossip_data_column_sidecar__reject_invalid_proposer_signature(spec, state): + """Test that a data column sidecar with an invalid block header signature is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + sidecar.signed_block_header.signature = spec.BLSSignature(b"\x00" * 96) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid proposer signature on sidecar block header" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__ignore_parent_not_seen(spec, state): + """Test that a data column sidecar whose parent is unknown to the store is ignored.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + # Modify parent_root to something unknown to the store + sidecar.signed_block_header.message.parent_root = b"\x12" * 32 + resign_sidecar_header(spec, state, sidecar) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "ignore" + assert reason == "sidecar's parent has not been seen" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_parent_failed_validation(spec, state): + """Test that a data column sidecar whose parent failed validation is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + + # Build the failed parent on a separate state copy so the yielded anchor state stays + # at slot 0 (its `latest_block_header` points at the genesis-equivalent anchor, not at + # `signed_parent`) + parent_state = state.copy() + parent_block = build_empty_block_for_next_slot(spec, parent_state) + signed_parent = state_transition_and_sign_block(spec, parent_state, parent_block) + + yield get_filename(signed_parent), signed_parent + + # Add the parent block to store.blocks but not store.block_states, matching + # the reference-test encoding of a failed block. + store.blocks[signed_parent.message.hash_tree_root()] = signed_parent.message + + yield ( + "blocks", + "meta", + [ + {"block": get_filename(signed_anchor)}, + {"block": get_filename(signed_parent), "failed": True}, + ], + ) + + _, sidecars = build_signed_block_and_sidecars(spec, parent_state.copy(), blob_count=1) + sidecar = sidecars[0] + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "sidecar's parent failed validation" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_slot_not_higher_than_parent(spec, state): + """ + Test that a data column sidecar whose block_header.slot is not strictly greater + than its parent's slot is rejected. + """ + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + + parent_state = state.copy() + parent_block = build_empty_block_for_next_slot(spec, parent_state) + signed_parent = state_transition_and_sign_block(spec, parent_state, parent_block) + + yield get_filename(signed_parent), signed_parent + parent_root = signed_parent.message.hash_tree_root() + store.blocks[parent_root] = signed_parent.message + store.block_states[parent_root] = parent_state.copy() + yield ( + "blocks", + "meta", + [ + {"block": get_filename(signed_anchor)}, + {"block": get_filename(signed_parent)}, + ], + ) + + _, sidecars = build_signed_block_and_sidecars(spec, parent_state.copy(), blob_count=1) + sidecar = sidecars[0] + sidecar.signed_block_header.message.slot = signed_parent.message.slot + resign_sidecar_header(spec, parent_state, sidecar) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "sidecar is not from a higher slot than its parent" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_non_ancestor_finalized_checkpoint(spec, state): + """Test that a data column sidecar is rejected if the finalized checkpoint is not an ancestor.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + fake_finalized_root = spec.Root(b"\xab" * 32) + store.finalized_checkpoint = spec.Checkpoint( + epoch=spec.Epoch(0), + root=fake_finalized_root, + ) + + yield "finalized_checkpoint", "meta", {"epoch": 0, "root": "0x" + "ab" * 32} + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "finalized checkpoint is not an ancestor of sidecar's block" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_invalid_inclusion_proof(spec, state): + """Test that a data column sidecar with a broken inclusion proof is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + # Corrupt the inclusion proof. + sidecar.kzg_commitments_inclusion_proof = spec.compute_merkle_proof(spec.BeaconBlockBody(), 0) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid sidecar inclusion proof" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_invalid_kzg_proofs(spec, state): + """Test that a data column sidecar with invalid KZG cell proofs is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + # Corrupt every KZG proof to the point at infinity, which won't verify + # against the real commitments. + bad_proof = spec.KZGProof(b"\xc0" + b"\x00" * 47) + sidecar.kzg_proofs = [bad_proof for _ in sidecar.kzg_proofs] + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid sidecar kzg proofs" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__ignore_already_seen_tuple(spec, state): + """ + Test that a duplicate data column sidecar for the same + (slot, proposer_index, index) tuple is ignored. + """ + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + messages = [] + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + + # First delivery passes. + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "valid" + messages.append( + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "valid", + } + ) + + # Second delivery of the same sidecar is ignored. + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 600 + ) + assert result == "ignore" + assert reason == "already seen sidecar from this proposer for this slot and index" + messages.append( + { + "subnet_id": int(subnet_id), + "offset_ms": 600, + "message": get_filename(sidecar), + "expected": "ignore", + "reason": reason, + } + ) + + yield "messages", "meta", messages + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_data_column_sidecar__reject_wrong_proposer_index(spec, state): + """Test that a data column sidecar with the wrong proposer_index is rejected.""" + yield "topic", "meta", "data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + + correct_proposer = sidecar.signed_block_header.message.proposer_index + wrong_proposer = spec.ValidatorIndex((int(correct_proposer) + 1) % len(state.validators)) + sidecar.signed_block_header.message.proposer_index = wrong_proposer + resign_sidecar_header(spec, state, sidecar) + + yield get_filename(sidecar), sidecar + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + subnet_id = correct_subnet(spec, sidecar) + result, reason = run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "sidecar proposer_index does not match expected proposer" + + yield ( + "messages", + "meta", + [ + { + "subnet_id": int(subnet_id), + "offset_ms": 500, + "message": get_filename(sidecar), + "expected": "reject", + "reason": reason, + } + ], + ) diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py new file mode 100644 index 00000000000..a0572bcb5f6 --- /dev/null +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py @@ -0,0 +1,1448 @@ +from frozendict import frozendict + +from eth_consensus_specs.test.context import ( + always_bls, + spec_configured_state_test, + spec_state_test, + with_phases, +) +from eth_consensus_specs.test.helpers.blob import ( + get_block_with_blob_and_sidecars, + get_max_blob_count, +) +from eth_consensus_specs.test.helpers.block import build_empty_block_for_next_slot +from eth_consensus_specs.test.helpers.constants import FULU +from eth_consensus_specs.test.helpers.execution_payload import ( + build_state_with_complete_transition, +) +from eth_consensus_specs.test.helpers.fork_choice import ( + get_genesis_forkchoice_store_and_block, +) +from eth_consensus_specs.test.helpers.gossip import ( + get_filename, + get_seen, + run_validate_partial_data_column_sidecar_gossip, + wrap_genesis_block, +) +from eth_consensus_specs.test.helpers.keys import privkeys +from eth_consensus_specs.test.helpers.state import ( + state_transition_and_sign_block, + transition_to, +) + + +def build_signed_block_and_sidecars(spec, state, blob_count=1): + """ + Build a signed block carrying ``blob_count`` blobs (applying the state + transition) and return its (signed_block, data_column_sidecars). + """ + _, _, _, signed_block, sidecars, _ = get_block_with_blob_and_sidecars( + spec, state, blob_count=blob_count + ) + return signed_block, list(sidecars) + + +def setup_store_with_anchor(spec, state): + store, anchor_block = get_genesis_forkchoice_store_and_block(spec, state) + return store, anchor_block + + +def make_partial_header(spec, sidecar): + """Build a PartialDataColumnHeader from a DataColumnSidecar.""" + return spec.PartialDataColumnHeader( + kzg_commitments=sidecar.kzg_commitments, + signed_block_header=sidecar.signed_block_header, + kzg_commitments_inclusion_proof=sidecar.kzg_commitments_inclusion_proof, + ) + + +def make_partial_sidecar(spec, sidecar, blob_indices=None, include_header=True): + """ + Build a PartialDataColumnSidecar from a DataColumnSidecar. + ``blob_indices`` controls which blob indices are present (default: all). + """ + num_blobs = len(sidecar.kzg_commitments) + if blob_indices is None: + blob_indices = list(range(num_blobs)) + + bitmap = [i in blob_indices for i in range(num_blobs)] + cells = [sidecar.column[i] for i in blob_indices] + proofs = [sidecar.kzg_proofs[i] for i in blob_indices] + + header = [make_partial_header(spec, sidecar)] if include_header else [] + + return spec.PartialDataColumnSidecar( + cells_present_bitmap=bitmap, + partial_column=cells, + kzg_proofs=proofs, + header=header, + ) + + +def block_root_of(spec, sidecar): + return spec.hash_tree_root(sidecar.signed_block_header.message) + + +def resign_header(spec, state, header): + proposer_index = header.signed_block_header.message.proposer_index + domain = spec.get_domain( + state, + spec.DOMAIN_BEACON_PROPOSER, + spec.compute_epoch_at_slot(header.signed_block_header.message.slot), + ) + signing_root = spec.compute_signing_root(header.signed_block_header.message, domain) + header.signed_block_header.signature = spec.bls.Sign(privkeys[proposer_index], signing_root) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__valid_header_only(spec, state): + """Test that a header-only partial sidecar passes gossip validation.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "valid" + assert reason is None + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "valid", + } + ], + ) + + +@with_phases([FULU]) +@spec_configured_state_test( + { + "BLOB_SCHEDULE": (frozendict({"EPOCH": 0, "MAX_BLOBS_PER_BLOCK": 12}),), + } +) +def test_gossip_partial_data_column_sidecar__valid_header_and_cells(spec, state): + """Test that a partial sidecar carrying both header and cells passes gossip validation.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + max_blobs = get_max_blob_count(spec, state) + # Sanity check: the BLOB_SCHEDULE override should be exercising the Fulu + # code path (`get_blob_parameters`), not the Electra fallback. A client that + # forgets EIP-7892 and uses MAX_BLOBS_PER_BLOCK_ELECTRA would reject this sidecar. + assert max_blobs > spec.config.MAX_BLOBS_PER_BLOCK_ELECTRA + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=max_blobs) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, include_header=True) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "valid" + assert reason is None + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "valid", + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__valid_cells_only_with_cached_header(spec, state): + """Test that a cells-only partial sidecar passes when a header was cached previously.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=2) + sidecar = sidecars[0] + block_root = block_root_of(spec, sidecar) + + # First message: header only, populates the cache. + header_msg = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + # Second message: cells only. + cells_msg = make_partial_sidecar(spec, sidecar, include_header=False) + + yield get_filename(header_msg), header_msg + yield get_filename(cells_msg), cells_msg + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + + messages = [] + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, header_msg, block_root, column_index, block_time_ms + 500 + ) + assert result == "valid" + messages.append( + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(header_msg), + "expected": "valid", + } + ) + + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, cells_msg, block_root, column_index, block_time_ms + 600 + ) + assert result == "valid" + assert reason is None + messages.append( + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 600, + "message": get_filename(cells_msg), + "expected": "valid", + } + ) + + yield "messages", "meta", messages + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_semantically_empty(spec, state): + """Test that a partial sidecar with no header and no cells is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=False) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "partial message is semantically empty" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_cell_count_mismatch(spec, state): + """Test that a partial sidecar with cell count != set bits is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=2) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, include_header=True) + # Drop a cell so the count no longer matches the bitmap. + partial.partial_column = list(partial.partial_column)[:-1] + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "number of cells does not match number of set bits" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_proof_count_mismatch(spec, state): + """Test that a partial sidecar with proof count != set bits is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=2) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, include_header=True) + # Drop a proof so the count no longer matches the bitmap. + partial.kzg_proofs = list(partial.kzg_proofs)[:-1] + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "number of proofs does not match number of set bits" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_prior_header_differs(spec, state): + """Test that a header differing from a previously cached one is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + block_root = block_root_of(spec, sidecar) + + good = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + + # Build a second partial message whose header has a different inclusion + # proof, with the cache populated by `good` so the equality check fires. + diverging = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + diverging.header[0].kzg_commitments_inclusion_proof = spec.compute_merkle_proof( + spec.BeaconBlockBody(), 0 + ) + + yield get_filename(good), good + yield get_filename(diverging), diverging + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + + messages = [] + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, good, block_root, column_index, block_time_ms + 500 + ) + assert result == "valid" + messages.append( + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(good), + "expected": "valid", + } + ) + + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, diverging, block_root, column_index, block_time_ms + 600 + ) + assert result == "reject" + assert reason == "header differs from previously validated header" + messages.append( + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 600, + "message": get_filename(diverging), + "expected": "reject", + "reason": reason, + } + ) + + yield "messages", "meta", messages + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_block_root_mismatch(spec, state): + """Test that a header whose block root differs from the group id is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + block_root = spec.Root(b"\xab" * 32) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "header's block root does not match partial message group id" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_empty_commitments(spec, state): + """Test that a header with empty kzg_commitments is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + partial.header[0].kzg_commitments = [] + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "header kzg_commitments is empty" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__ignore_future_slot(spec, state): + """Test that a header from a future slot is ignored.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + slot_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + current_time_ms = slot_time_ms - spec.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY - 1 + yield "current_time_ms", "meta", int(current_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, current_time_ms + ) + assert result == "ignore" + assert reason == "header is from a future slot" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 0, + "message": get_filename(partial), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__ignore_not_later_than_finalized_slot(spec, state): + """Test that a header at the latest finalized slot is ignored.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + transition_to(spec, state, spec.Slot(spec.SLOTS_PER_EPOCH - 1)) + yield "state", state + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + block_root = block_root_of(spec, sidecar) + + block_header = sidecar.signed_block_header.message + sidecar_epoch = spec.compute_epoch_at_slot(block_header.slot) + store.finalized_checkpoint = spec.Checkpoint( + epoch=sidecar_epoch, + root=store.finalized_checkpoint.root, + ) + yield ( + "finalized_checkpoint", + "meta", + {"epoch": int(sidecar_epoch), "block": get_filename(signed_anchor)}, + ) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, block_header.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "ignore" + assert reason == "header is not from a slot greater than the latest finalized slot" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_proposer_index_out_of_range(spec, state): + """Test that a header with proposer_index out of range is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + partial.header[0].signed_block_header.message.proposer_index = spec.ValidatorIndex( + len(state.validators) + ) + block_root = spec.hash_tree_root(partial.header[0].signed_block_header.message) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "proposer index out of range" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +@always_bls +def test_gossip_partial_data_column_sidecar__reject_invalid_proposer_signature(spec, state): + """Test that a header with an invalid proposer signature is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + partial.header[0].signed_block_header.signature = spec.BLSSignature(b"\x00" * 96) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid proposer signature on header" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__ignore_parent_not_seen(spec, state): + """Test that a header whose parent is unknown to the store is ignored.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + partial.header[0].signed_block_header.message.parent_root = b"\x12" * 32 + resign_header(spec, state, partial.header[0]) + block_root = spec.hash_tree_root(partial.header[0].signed_block_header.message) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "ignore" + assert reason == "header's parent has not been seen" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_parent_failed_validation(spec, state): + """Test that a header whose parent failed validation is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + + parent_state = state.copy() + parent_block = build_empty_block_for_next_slot(spec, parent_state) + signed_parent = state_transition_and_sign_block(spec, parent_state, parent_block) + + yield get_filename(signed_parent), signed_parent + + store.blocks[signed_parent.message.hash_tree_root()] = signed_parent.message + + yield ( + "blocks", + "meta", + [ + {"block": get_filename(signed_anchor)}, + {"block": get_filename(signed_parent), "failed": True}, + ], + ) + + _, sidecars = build_signed_block_and_sidecars(spec, parent_state.copy(), blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "header's parent failed validation" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_slot_not_higher_than_parent(spec, state): + """Test that a header whose slot is not greater than its parent's is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + + parent_state = state.copy() + parent_block = build_empty_block_for_next_slot(spec, parent_state) + signed_parent = state_transition_and_sign_block(spec, parent_state, parent_block) + + yield get_filename(signed_parent), signed_parent + parent_root = signed_parent.message.hash_tree_root() + store.blocks[parent_root] = signed_parent.message + store.block_states[parent_root] = parent_state.copy() + yield ( + "blocks", + "meta", + [ + {"block": get_filename(signed_anchor)}, + {"block": get_filename(signed_parent)}, + ], + ) + + _, sidecars = build_signed_block_and_sidecars(spec, parent_state.copy(), blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + partial.header[0].signed_block_header.message.slot = signed_parent.message.slot + resign_header(spec, parent_state, partial.header[0]) + block_root = spec.hash_tree_root(partial.header[0].signed_block_header.message) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms( + state, partial.header[0].signed_block_header.message.slot + ) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "header is not from a higher slot than its parent" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_non_ancestor_finalized_checkpoint(spec, state): + """Test that a header is rejected if the finalized checkpoint is not an ancestor.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + block_root = block_root_of(spec, sidecar) + + fake_finalized_root = spec.Root(b"\xab" * 32) + store.finalized_checkpoint = spec.Checkpoint( + epoch=spec.Epoch(0), + root=fake_finalized_root, + ) + + yield "finalized_checkpoint", "meta", {"epoch": 0, "root": "0x" + "ab" * 32} + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "finalized checkpoint is not an ancestor of header's block" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_invalid_inclusion_proof(spec, state): + """Test that a header with a broken inclusion proof is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + partial.header[0].kzg_commitments_inclusion_proof = spec.compute_merkle_proof( + spec.BeaconBlockBody(), 0 + ) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid header inclusion proof" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_wrong_proposer_index(spec, state): + """Test that a header with the wrong proposer_index is rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + + correct_proposer = partial.header[0].signed_block_header.message.proposer_index + wrong_proposer = spec.ValidatorIndex((int(correct_proposer) + 1) % len(state.validators)) + partial.header[0].signed_block_header.message.proposer_index = wrong_proposer + resign_header(spec, state, partial.header[0]) + block_root = spec.hash_tree_root(partial.header[0].signed_block_header.message) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "header proposer_index does not match expected proposer" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__ignore_cells_without_cached_header(spec, state): + """Test that a cells-only partial sidecar is ignored when no header is cached.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, include_header=False) + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "ignore" + assert reason == "no validated header seen for this block" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "ignore", + "reason": reason, + } + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__ignore_cells_with_cached_header_future_slot( + spec, state +): + """Test that a cached-header cells-only sidecar is ignored if it is from a future slot.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + block_root = block_root_of(spec, sidecar) + + header_msg = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + cells_msg = make_partial_sidecar(spec, sidecar, include_header=False) + + yield get_filename(header_msg), header_msg + yield get_filename(cells_msg), cells_msg + + slot_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + current_time_ms = slot_time_ms - spec.config.MAXIMUM_GOSSIP_CLOCK_DISPARITY - 1 + yield "current_time_ms", "meta", int(current_time_ms) + + column_index = sidecar.index + + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, header_msg, block_root, column_index, current_time_ms + 1 + ) + assert result == "valid" + assert reason is None + + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, cells_msg, block_root, column_index, current_time_ms + ) + assert result == "ignore" + assert reason == "cached header is from a future slot" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 1, + "message": get_filename(header_msg), + "expected": "valid", + }, + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 0, + "message": get_filename(cells_msg), + "expected": "ignore", + "reason": reason, + }, + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__ignore_cells_with_cached_header_not_later_than_finalized_slot( # noqa: E501 + spec, state +): + """Test that a cached-header cells-only sidecar is ignored once finalization advances.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + transition_to(spec, state, spec.Slot(spec.SLOTS_PER_EPOCH - 1)) + yield "state", state + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + block_root = block_root_of(spec, sidecar) + + header = make_partial_header(spec, sidecar) + cells_msg = make_partial_sidecar(spec, sidecar, include_header=False) + + yield get_filename(header), header + yield get_filename(cells_msg), cells_msg + + block_header = sidecar.signed_block_header.message + sidecar_epoch = spec.compute_epoch_at_slot(block_header.slot) + block_time_ms = spec.compute_time_at_slot_ms(state, block_header.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + seen.partial_data_column_headers[block_root] = header + + yield ( + "seen_partial_data_column_headers", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "header": get_filename(header), + } + ], + ) + + store.finalized_checkpoint = spec.Checkpoint( + epoch=sidecar_epoch, + root=store.finalized_checkpoint.root, + ) + + yield ( + "finalized_checkpoint", + "meta", + {"epoch": int(sidecar_epoch), "block": get_filename(signed_anchor)}, + ) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, cells_msg, block_root, column_index, block_time_ms + 500 + ) + assert result == "ignore" + assert reason == "cached header is not from a slot greater than the latest finalized slot" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(cells_msg), + "expected": "ignore", + "reason": reason, + }, + ], + ) + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_bitmap_length_mismatch(spec, state): + """ + Test that a cells-bearing partial sidecar whose bitmap length does not match + the cached header's commitment count is rejected. + """ + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=2) + sidecar = sidecars[0] + block_root = block_root_of(spec, sidecar) + + # Seed the cache with a valid header for `block_root`. + header_msg = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) + cells_msg = make_partial_sidecar(spec, sidecar, blob_indices=[0], include_header=False) + # Stretch the bitmap so its length exceeds the cached header's commitments. + Bitlist = type(cells_msg.cells_present_bitmap) + cells_msg.cells_present_bitmap = Bitlist(list(cells_msg.cells_present_bitmap) + [False, False]) + + yield get_filename(header_msg), header_msg + yield get_filename(cells_msg), cells_msg + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + + messages = [] + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, header_msg, block_root, column_index, block_time_ms + 500 + ) + assert result == "valid" + messages.append( + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(header_msg), + "expected": "valid", + } + ) + + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, cells_msg, block_root, column_index, block_time_ms + 600 + ) + assert result == "reject" + assert reason == "bitmap length does not match number of commitments" + messages.append( + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 600, + "message": get_filename(cells_msg), + "expected": "reject", + "reason": reason, + } + ) + + yield "messages", "meta", messages + + +@with_phases([FULU]) +@spec_state_test +def test_gossip_partial_data_column_sidecar__reject_invalid_kzg_proofs(spec, state): + """Test that cells with invalid KZG proofs are rejected.""" + yield "topic", "meta", "partial_data_column_sidecar" + + state = build_state_with_complete_transition(spec, state) + yield "state", state + + seen = get_seen(spec) + store, anchor_block = setup_store_with_anchor(spec, state) + signed_anchor = wrap_genesis_block(spec, anchor_block) + yield get_filename(signed_anchor), signed_anchor + yield "blocks", "meta", [{"block": get_filename(signed_anchor)}] + + _, sidecars = build_signed_block_and_sidecars(spec, state, blob_count=1) + sidecar = sidecars[0] + partial = make_partial_sidecar(spec, sidecar, include_header=True) + # Corrupt every KZG proof to the point at infinity, which won't verify + # against the real commitments. + bad_proof = spec.KZGProof(b"\xc0" + b"\x00" * 47) + partial.kzg_proofs = [bad_proof for _ in partial.kzg_proofs] + block_root = block_root_of(spec, sidecar) + + yield get_filename(partial), partial + + block_time_ms = spec.compute_time_at_slot_ms(state, sidecar.signed_block_header.message.slot) + yield "current_time_ms", "meta", int(block_time_ms) + + column_index = sidecar.index + result, reason = run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 + ) + assert result == "reject" + assert reason == "invalid sidecar kzg proofs" + + yield ( + "messages", + "meta", + [ + { + "block_root": "0x" + block_root.hex(), + "column_index": int(column_index), + "offset_ms": 500, + "message": get_filename(partial), + "expected": "reject", + "reason": reason, + } + ], + ) diff --git a/tests/core/pyspec/eth_consensus_specs/test/helpers/gossip.py b/tests/core/pyspec/eth_consensus_specs/test/helpers/gossip.py index 7a5c69cc05a..2fe98101eb8 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/helpers/gossip.py +++ b/tests/core/pyspec/eth_consensus_specs/test/helpers/gossip.py @@ -1,6 +1,12 @@ from eth_utils import encode_hex -from eth_consensus_specs.test.helpers.forks import is_post_altair, is_post_capella, is_post_deneb +from eth_consensus_specs.test.helpers.forks import ( + is_post_altair, + is_post_capella, + is_post_deneb, + is_post_fulu, + is_post_gloas, +) PAYLOAD_STATUS_VALID = "VALID" PAYLOAD_STATUS_INVALIDATED = "INVALIDATED" @@ -53,6 +59,44 @@ def run_validate_beacon_block_gossip( return "reject", str(e) +def run_validate_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, subnet_id, current_time_ms +): + """ + Run validate_data_column_sidecar_gossip and return the result. + Returns: tuple of (result, reason) where result is "valid", "ignore", or "reject" + and reason is the exception message (or None for valid). + """ + try: + spec.validate_data_column_sidecar_gossip( + seen, store, state, sidecar, subnet_id, current_time_ms + ) + return "valid", None + except spec.GossipIgnore as e: + return "ignore", str(e) + except spec.GossipReject as e: + return "reject", str(e) + + +def run_validate_partial_data_column_sidecar_gossip( + spec, seen, store, state, sidecar, block_root, column_index, current_time_ms +): + """ + Run validate_partial_data_column_sidecar_gossip and return the result. + Returns: tuple of (result, reason) where result is "valid", "ignore", or "reject" + and reason is the exception message (or None for valid). + """ + try: + spec.validate_partial_data_column_sidecar_gossip( + seen, store, state, sidecar, block_root, column_index, current_time_ms + ) + return "valid", None + except spec.GossipIgnore as e: + return "ignore", str(e) + except spec.GossipReject as e: + return "reject", str(e) + + def get_seen(spec): """Create an empty Seen object for gossip validation.""" kwargs = dict( @@ -78,12 +122,24 @@ def get_seen(spec): bls_to_execution_change_indices=set(), ) ) - if is_post_deneb(spec): + if is_post_deneb(spec) and not is_post_fulu(spec): kwargs.update( dict( blob_sidecar_tuples=set(), ) ) + if is_post_fulu(spec): + kwargs.update( + dict( + data_column_sidecar_tuples=set(), + ) + ) + if not is_post_gloas(spec): + kwargs.update( + dict( + partial_data_column_headers={}, + ) + ) return spec.Seen(**kwargs) @@ -117,6 +173,13 @@ def get_filename(obj): # deneb elif class_name == "BlobSidecar": prefix = "blob_sidecar" + # fulu + elif class_name == "DataColumnSidecar": + prefix = "data_column_sidecar" + elif class_name == "PartialDataColumnHeader": + prefix = "partial_data_column_header" + elif class_name == "PartialDataColumnSidecar": + prefix = "partial_data_column_sidecar" else: raise Exception(f"unsupported type: {class_name}") diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py index b6b2ae971d4..ae816dc391b 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_aggregate_and_proof.py @@ -21,6 +21,7 @@ CAPELLA, DENEB, ELECTRA, + FULU, MAINNET, PHASE0, ) @@ -95,7 +96,7 @@ def run_validate_beacon_aggregate_and_proof_gossip( return "reject", str(e) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__valid(spec, state): """ @@ -136,7 +137,7 @@ def test_gossip_beacon_aggregate_and_proof__valid(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_committee_index_out_of_range(spec, state): """ @@ -248,7 +249,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_slot_not_within_range(spec, s ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__valid_within_clock_disparity(spec, state): """ @@ -297,7 +298,7 @@ def test_gossip_beacon_aggregate_and_proof__valid_within_clock_disparity(spec, s ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_epoch_mismatch(spec, state): """ @@ -348,7 +349,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_epoch_mismatch(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregate(spec, state): """ @@ -402,7 +403,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregate(spec, yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignore_same_data_root_without_superset(spec, state): """ @@ -506,7 +507,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_same_data_root_without_supers yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__valid_two_aggregators_same_data(spec, state): """ @@ -590,7 +591,7 @@ def test_gossip_beacon_aggregate_and_proof__valid_two_aggregators_same_data(spec yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignore_block_not_seen(spec, state): """ @@ -644,7 +645,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_block_not_seen(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_aggregation_bits_size_mismatch(spec, state): """ @@ -701,7 +702,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregation_bits_size_mismatc ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_no_participants(spec, state): """ @@ -756,7 +757,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_no_participants(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregator(spec, state): """ @@ -819,7 +820,7 @@ def test_gossip_beacon_aggregate_and_proof__ignore_already_seen_aggregator(spec, yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @with_presets([MAINNET], reason="minimal preset has committees < 16, so everyone is an aggregator") @spec_test @with_custom_state( @@ -908,7 +909,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_not_aggregator(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_aggregator_not_in_committee(spec, state): """ @@ -967,7 +968,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregator_not_in_committee(s ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_aggregator_index_out_of_range(spec, state): """ @@ -1017,7 +1018,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_aggregator_index_out_of_range ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_beacon_aggregate_and_proof__reject_invalid_selection_proof(spec, state): @@ -1069,7 +1070,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_selection_proof(spec, ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregator_signature(spec, state): @@ -1121,7 +1122,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregator_signature( ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregate_signature(spec, state): @@ -1173,7 +1174,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_invalid_aggregate_signature(s ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_block_failed_validation(spec, state): """ @@ -1237,7 +1238,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_block_failed_validation(spec, ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__reject_target_not_ancestor(spec, state): """ @@ -1289,7 +1290,7 @@ def test_gossip_beacon_aggregate_and_proof__reject_target_not_ancestor(spec, sta ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_aggregate_and_proof__ignore_finalized_not_ancestor(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py index 782d6171259..0324d564c2b 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_attestation.py @@ -16,6 +16,7 @@ CAPELLA, DENEB, ELECTRA, + FULU, PHASE0, ) from eth_consensus_specs.test.helpers.fork_choice import ( @@ -60,7 +61,7 @@ def run_validate_beacon_attestation_gossip( return "reject", str(e) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__valid(spec, state): """ @@ -123,7 +124,7 @@ def test_gossip_beacon_attestation__valid(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_committee_index_out_of_range(spec, state): """ @@ -180,7 +181,7 @@ def test_gossip_beacon_attestation__reject_committee_index_out_of_range(spec, st ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_wrong_subnet(spec, state): """ @@ -294,7 +295,7 @@ def test_gossip_beacon_attestation__ignore_slot_not_in_range(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__valid_within_clock_disparity(spec, state): """ @@ -482,7 +483,7 @@ def test_gossip_beacon_attestation__ignore_slot_too_old(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_epoch_mismatch(spec, state): """ @@ -651,7 +652,7 @@ def test_gossip_beacon_attestation__reject_aggregation_bits_size_mismatch(spec, ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__ignore_already_seen(spec, state): """ @@ -727,7 +728,7 @@ def test_gossip_beacon_attestation__ignore_already_seen(spec, state): yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__ignore_block_not_seen(spec, state): """ @@ -792,7 +793,7 @@ def test_gossip_beacon_attestation__ignore_block_not_seen(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_block_failed_validation(spec, state): """ @@ -870,7 +871,7 @@ def test_gossip_beacon_attestation__reject_block_failed_validation(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_beacon_attestation__reject_invalid_signature(spec, state): @@ -932,7 +933,7 @@ def test_gossip_beacon_attestation__reject_invalid_signature(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__reject_target_not_ancestor(spec, state): """ @@ -997,7 +998,7 @@ def test_gossip_beacon_attestation__reject_target_not_ancestor(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_attestation__ignore_finalized_not_ancestor(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py index 6beab43dcaa..4ab9faa6132 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_beacon_block.py @@ -13,6 +13,7 @@ CAPELLA, DENEB, ELECTRA, + FULU, PHASE0, ) from eth_consensus_specs.test.helpers.execution_payload import ( @@ -34,7 +35,7 @@ ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__valid_block(spec, state): """ @@ -72,7 +73,7 @@ def test_gossip_beacon_block__valid_block(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__ignore_future_slot(spec, state): """ @@ -118,7 +119,7 @@ def test_gossip_beacon_block__ignore_future_slot(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__valid_within_clock_disparity(spec, state): """ @@ -157,7 +158,7 @@ def test_gossip_beacon_block__valid_within_clock_disparity(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__ignore_already_seen_proposer_slot(spec, state): """ @@ -209,7 +210,7 @@ def test_gossip_beacon_block__ignore_already_seen_proposer_slot(spec, state): yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__ignore_slot_not_greater_than_finalized(spec, state): """ @@ -281,7 +282,7 @@ def test_gossip_beacon_block__ignore_slot_not_greater_than_finalized(spec, state ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__ignore_parent_not_seen(spec, state): """ @@ -424,7 +425,7 @@ def test_gossip_beacon_block__reject_parent_failed_validation(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_slot_not_higher_than_parent(spec, state): """ @@ -498,7 +499,7 @@ def test_gossip_beacon_block__reject_slot_not_higher_than_parent(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_finalized_checkpoint_not_ancestor(spec, state): """ @@ -583,7 +584,7 @@ def test_gossip_beacon_block__reject_finalized_checkpoint_not_ancestor(spec, sta ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_beacon_block__reject_invalid_proposer_signature(spec, state): @@ -632,7 +633,7 @@ def test_gossip_beacon_block__reject_invalid_proposer_signature(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_invalid_proposer_index(spec, state): """ @@ -680,7 +681,7 @@ def test_gossip_beacon_block__reject_invalid_proposer_index(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_beacon_block__reject_wrong_proposer_index(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py index 2f59f0d10b5..a8de66f9cd5 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py +++ b/tests/core/pyspec/eth_consensus_specs/test/phase0/networking/test_gossip_voluntary_exit.py @@ -9,6 +9,7 @@ CAPELLA, DENEB, ELECTRA, + FULU, PHASE0, ) from eth_consensus_specs.test.helpers.gossip import get_filename, get_seen @@ -50,7 +51,7 @@ def run_validate_voluntary_exit_gossip(spec, seen, state, signed_voluntary_exit) return "reject", str(e) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__valid(spec, state): """ @@ -79,7 +80,7 @@ def test_gossip_voluntary_exit__valid(spec, state): yield "messages", "meta", [{"message": get_filename(signed_exit), "expected": "valid"}] -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__ignore_already_seen(spec, state): """ @@ -117,7 +118,7 @@ def test_gossip_voluntary_exit__ignore_already_seen(spec, state): yield "messages", "meta", messages -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__reject_validator_index_out_of_range(spec, state): """ @@ -153,7 +154,7 @@ def test_gossip_voluntary_exit__reject_validator_index_out_of_range(spec, state) ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__reject_validator_not_active(spec, state): """ @@ -187,7 +188,7 @@ def test_gossip_voluntary_exit__reject_validator_not_active(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__reject_already_initiated_exit(spec, state): """ @@ -221,7 +222,7 @@ def test_gossip_voluntary_exit__reject_already_initiated_exit(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__reject_epoch_in_future(spec, state): """ @@ -255,7 +256,7 @@ def test_gossip_voluntary_exit__reject_epoch_in_future(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test def test_gossip_voluntary_exit__reject_not_active_long_enough(spec, state): """ @@ -290,7 +291,7 @@ def test_gossip_voluntary_exit__reject_not_active_long_enough(spec, state): ) -@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA]) +@with_phases([PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA, FULU]) @spec_state_test @always_bls def test_gossip_voluntary_exit__reject_invalid_signature(spec, state): diff --git a/tests/core/pyspec/eth_consensus_specs/utils/ckzg_utils.py b/tests/core/pyspec/eth_consensus_specs/utils/ckzg_utils.py index 6d54a02fd77..67e3e0c2ddf 100644 --- a/tests/core/pyspec/eth_consensus_specs/utils/ckzg_utils.py +++ b/tests/core/pyspec/eth_consensus_specs/utils/ckzg_utils.py @@ -185,3 +185,7 @@ def recover_cells_and_kzg_proofs(cell_indices, cells): ) spec.recover_cells_and_kzg_proofs = recover_cells_and_kzg_proofs + + # Mark the spec module as ckzg-patched and remember its trusted setup so + # `get_copy_of_spec` can re-apply the same patches to fresh copies. + spec._ckzg_trusted_setup = ts diff --git a/tests/formats/networking/gossip_validation.md b/tests/formats/networking/gossip_validation.md index 4c3d02596d5..fda93f89cc7 100644 --- a/tests/formats/networking/gossip_validation.md +++ b/tests/formats/networking/gossip_validation.md @@ -19,7 +19,8 @@ validation rules for messages received via gossip topics. ### `meta.yaml` ```yaml -topic: string -- The gossip topic name (e.g., "beacon_block", "beacon_attestation"). +topic: string -- The gossip topic name (e.g., "beacon_block", "blob_sidecar", + -- "data_column_sidecar", "partial_data_column_sidecar"). blocks: [{ -- Optional. Blocks to import before validation (oldest to newest). block: string, -- The block file (without extension). failed: bool, -- Optional. If true, block failed validation (for testing descendant rejection). @@ -32,10 +33,20 @@ finalized_checkpoint: -- Optional. Custom finalized checkpoint. epoch: int -- The epoch of the finalized checkpoint. root: string -- Hex-encoded root (use this OR block, not both). block: string -- Block file whose root to use (use this OR root, not both). +seen_partial_data_column_headers: [{ + -- Optional. Preload validated partial + -- data column headers into `seen`. + block_root: string, -- Hex-encoded partial message group root. + header: string, -- `PartialDataColumnHeader` file to cache. +}] current_time_ms: int -- The base time in milliseconds since genesis. messages: [{ -- List of messages to validate in sequence. offset_ms: int, -- Time offset from current_time_ms when message is received. - subnet_id: int, -- Optional. The subnet ID. + subnet_id: int, -- Optional. The subnet ID for subnet-scoped topics. + column_index: int, -- Optional. The column index for + -- `partial_data_column_sidecar` vectors. + block_root: string, -- Optional. Hex-encoded block/group root for + -- `partial_data_column_sidecar` vectors. message: string, -- The name of the message file (without extension). expected: string, -- Expected result: "valid", "ignore", or "reject". reason: string, -- Optional. The expected reason for ignore/reject. @@ -55,17 +66,21 @@ An SSZ-snappy encoded `BeaconState`. This state provides: Message files are named with a prefix indicating their type and the 32-byte hash tree root: -| Topic | File prefix | SSZ type | -| --------------------------------------- | -------------------------- | ---------------------------- | -| `beacon_block` | `block_` | `SignedBeaconBlock` | -| `beacon_attestation` | `attestation_` | `Attestation` | -| `beacon_aggregate_and_proof` | `aggregate_` | `SignedAggregateAndProof` | -| `proposer_slashing` | `proposer_slashing_` | `ProposerSlashing` | -| `attester_slashing` | `attester_slashing_` | `AttesterSlashing` | -| `voluntary_exit` | `voluntary_exit_` | `SignedVoluntaryExit` | -| `sync_committee_contribution_and_proof` | `contribution_` | `SignedContributionAndProof` | -| `sync_committee` | `sync_committee_message_` | `SyncCommitteeMessage` | -| `bls_to_execution_change` | `bls_to_execution_change_` | `SignedBLSToExecutionChange` | +| Topic | File prefix | SSZ type | +| --------------------------------------- | ------------------------------ | ---------------------------- | +| `beacon_block` | `block_` | `SignedBeaconBlock` | +| `beacon_attestation` | `attestation_` | `Attestation` | +| `beacon_aggregate_and_proof` | `aggregate_` | `SignedAggregateAndProof` | +| `proposer_slashing` | `proposer_slashing_` | `ProposerSlashing` | +| `attester_slashing` | `attester_slashing_` | `AttesterSlashing` | +| `voluntary_exit` | `voluntary_exit_` | `SignedVoluntaryExit` | +| `sync_committee_contribution_and_proof` | `contribution_` | `SignedContributionAndProof` | +| `sync_committee` | `sync_committee_message_` | `SyncCommitteeMessage` | +| `bls_to_execution_change` | `bls_to_execution_change_` | `SignedBLSToExecutionChange` | +| `blob_sidecar` | `blob_sidecar_` | `BlobSidecar` | +| `data_column_sidecar` | `data_column_sidecar_` | `DataColumnSidecar` | +| `partial_data_column_header` | `partial_data_column_header_` | `PartialDataColumnHeader` | +| `partial_data_column_sidecar` | `partial_data_column_sidecar_` | `PartialDataColumnSidecar` | Block files (`block_.ssz_snappy`) serve multiple purposes: @@ -91,11 +106,18 @@ Block files (`block_.ssz_snappy`) serve multiple purposes: - For `beacon_block` gossip validation, `NOT_VALIDATED` represents the optimistic case where no valid/invalid payload result is yet available for the parent block. + - If `seen_partial_data_column_headers` is present, preload each referenced + `PartialDataColumnHeader` into `seen.partial_data_column_headers` using its + `block_root`. 3. Iterate sequentially through `messages`: - Set `current_time_ms` to `meta.current_time_ms + message.offset_ms`. + `offset_ms` values are independent and need not be monotonic. - Deserialize the message file based on the topic type. - - Execute the appropriate validation function (e.g., - `validate_beacon_block_gossip` for the `beacon_block` topic). + - Execute the appropriate validation function. + - For subnet-scoped topics such as `beacon_attestation`, `blob_sidecar`, + and `data_column_sidecar`, pass `message.subnet_id`. + - For `partial_data_column_sidecar`, pass `message.block_root` and + `message.column_index`. - Verify the result matches `expected`. - If the result is `valid`, update the store as the validation function would (e.g., add to `seen_proposer_slots`, track seen attestations). From 1a00410087d31b5c975e9faf75579bd4b99d879d Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 15 May 2026 14:06:41 -0500 Subject: [PATCH 2/4] Apply suggestions from Jihoon --- specs/fulu/p2p-interface.md | 12 ++++++------ specs/fulu/partial-columns/p2p-interface.md | 12 ++++++------ .../test_gossip_partial_data_column_sidecar.py | 16 +++++++++------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/specs/fulu/p2p-interface.md b/specs/fulu/p2p-interface.md index a37dc5634b9..712347312c1 100644 --- a/specs/fulu/p2p-interface.md +++ b/specs/fulu/p2p-interface.md @@ -366,6 +366,12 @@ def validate_data_column_sidecar_gossip( """ block_header = sidecar.signed_block_header.message + # [IGNORE] The sidecar is the first sidecar for the tuple + # (block_header.slot, block_header.proposer_index, sidecar.index) + sidecar_tuple = (block_header.slot, block_header.proposer_index, sidecar.index) + if sidecar_tuple in seen.data_column_sidecar_tuples: + raise GossipIgnore("already seen sidecar from this proposer for this slot and index") + # [REJECT] The sidecar is valid as verified by verify_data_column_sidecar if not verify_data_column_sidecar(sidecar): raise GossipReject("invalid sidecar") @@ -423,12 +429,6 @@ def validate_data_column_sidecar_gossip( if not verify_data_column_sidecar_kzg_proofs(sidecar): raise GossipReject("invalid sidecar kzg proofs") - # [IGNORE] The sidecar is the first sidecar for the tuple - # (block_header.slot, block_header.proposer_index, sidecar.index) - sidecar_tuple = (block_header.slot, block_header.proposer_index, sidecar.index) - if sidecar_tuple in seen.data_column_sidecar_tuples: - raise GossipIgnore("already seen sidecar from this proposer for this slot and index") - # [REJECT] The sidecar is proposed by the expected proposer_index # (if shuffling is not available, IGNORE instead and MAY be queued for later) parent_state = store.block_states[block_header.parent_root].copy() diff --git a/specs/fulu/partial-columns/p2p-interface.md b/specs/fulu/partial-columns/p2p-interface.md index 7608ef15cce..71322076601 100644 --- a/specs/fulu/partial-columns/p2p-interface.md +++ b/specs/fulu/partial-columns/p2p-interface.md @@ -201,7 +201,7 @@ def validate_partial_data_column_sidecar_gossip( # [REJECT] The header's kzg_commitments list is non-empty if len(header.kzg_commitments) == 0: - raise GossipReject("header kzg_commitments is empty") + raise GossipReject("header's kzg_commitments is empty") # [IGNORE] The header is not from a future slot # (MAY be queued for processing at the appropriate slot) @@ -256,32 +256,32 @@ def validate_partial_data_column_sidecar_gossip( if block_header.proposer_index != expected_proposer: raise GossipReject("header proposer_index does not match expected proposer") - # Cache the validated header for future partial messages + # Mark this header as seen seen.partial_data_column_headers[block_root] = header if has_cells: # [IGNORE] A valid corresponding PartialDataColumnHeader has been seen header = seen.partial_data_column_headers.get(block_root) if header is None: - raise GossipIgnore("no validated header seen for this block") + raise GossipIgnore("valid corresponding header has not been seen") block_header = header.signed_block_header.message # [IGNORE] The corresponding header is not from a future slot # (MAY be queued for processing at the appropriate slot) if not is_not_from_future_slot(state, block_header.slot, current_time_ms): - raise GossipIgnore("cached header is from a future slot") + raise GossipIgnore("corresponding header is from a future slot") # [IGNORE] The corresponding header is from a slot greater than the latest finalized slot finalized_slot = compute_start_slot_at_epoch(store.finalized_checkpoint.epoch) if block_header.slot <= finalized_slot: raise GossipIgnore( - "cached header is not from a slot greater than the latest finalized slot" + "corresponding header is not from a slot greater than the latest finalized slot" ) # [REJECT] The cells_present_bitmap length equals the number of header kzg_commitments if len(sidecar.cells_present_bitmap) != len(header.kzg_commitments): - raise GossipReject("bitmap length does not match number of commitments") + raise GossipReject("bitmap length does not match commitments length") # [REJECT] The sidecar's cell and proof data is valid if not verify_partial_data_column_sidecar_kzg_proofs( diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py index a0572bcb5f6..e1250f98e6d 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py @@ -559,7 +559,7 @@ def test_gossip_partial_data_column_sidecar__reject_empty_commitments(spec, stat spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 ) assert result == "reject" - assert reason == "header kzg_commitments is empty" + assert reason == "header's kzg_commitments is empty" yield ( "messages", @@ -1159,7 +1159,7 @@ def test_gossip_partial_data_column_sidecar__ignore_cells_without_cached_header( spec, seen, store, state, partial, block_root, column_index, block_time_ms + 500 ) assert result == "ignore" - assert reason == "no validated header seen for this block" + assert reason == "valid corresponding header has not been seen" yield ( "messages", @@ -1220,7 +1220,7 @@ def test_gossip_partial_data_column_sidecar__ignore_cells_with_cached_header_fut spec, seen, store, state, cells_msg, block_root, column_index, current_time_ms ) assert result == "ignore" - assert reason == "cached header is from a future slot" + assert reason == "corresponding header is from a future slot" yield ( "messages", @@ -1307,7 +1307,9 @@ def test_gossip_partial_data_column_sidecar__ignore_cells_with_cached_header_not spec, seen, store, state, cells_msg, block_root, column_index, block_time_ms + 500 ) assert result == "ignore" - assert reason == "cached header is not from a slot greater than the latest finalized slot" + assert ( + reason == "corresponding header is not from a slot greater than the latest finalized slot" + ) yield ( "messages", @@ -1330,7 +1332,7 @@ def test_gossip_partial_data_column_sidecar__ignore_cells_with_cached_header_not def test_gossip_partial_data_column_sidecar__reject_bitmap_length_mismatch(spec, state): """ Test that a cells-bearing partial sidecar whose bitmap length does not match - the cached header's commitment count is rejected. + the corresponding header's commitment count is rejected. """ yield "topic", "meta", "partial_data_column_sidecar" @@ -1350,7 +1352,7 @@ def test_gossip_partial_data_column_sidecar__reject_bitmap_length_mismatch(spec, # Seed the cache with a valid header for `block_root`. header_msg = make_partial_sidecar(spec, sidecar, blob_indices=[], include_header=True) cells_msg = make_partial_sidecar(spec, sidecar, blob_indices=[0], include_header=False) - # Stretch the bitmap so its length exceeds the cached header's commitments. + # Stretch the bitmap so its length exceeds the corresponding header's commitments. Bitlist = type(cells_msg.cells_present_bitmap) cells_msg.cells_present_bitmap = Bitlist(list(cells_msg.cells_present_bitmap) + [False, False]) @@ -1381,7 +1383,7 @@ def test_gossip_partial_data_column_sidecar__reject_bitmap_length_mismatch(spec, spec, seen, store, state, cells_msg, block_root, column_index, block_time_ms + 600 ) assert result == "reject" - assert reason == "bitmap length does not match number of commitments" + assert reason == "bitmap length does not match commitments length" messages.append( { "block_root": "0x" + block_root.hex(), From 3138c457ff69355baf329deac3867458e808e6ca Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 20 May 2026 18:55:36 -0500 Subject: [PATCH 3/4] Run make lint --- specs/fulu/p2p-interface.md | 2 +- specs/gloas/p2p-interface.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/fulu/p2p-interface.md b/specs/fulu/p2p-interface.md index f3d6e1fd5ee..217461654a0 100644 --- a/specs/fulu/p2p-interface.md +++ b/specs/fulu/p2p-interface.md @@ -84,7 +84,7 @@ class DataColumnsByRootIdentifier(Container): ```python @dataclass -class Seen(object): +class Seen: proposer_slots: Set[Tuple[ValidatorIndex, Slot]] aggregator_epochs: Set[Tuple[ValidatorIndex, Epoch]] aggregate_data_roots: Dict[Tuple[Root, CommitteeIndex], Set[Tuple[boolean, ...]]] diff --git a/specs/gloas/p2p-interface.md b/specs/gloas/p2p-interface.md index 80234a2fce7..ff9d8abca4e 100644 --- a/specs/gloas/p2p-interface.md +++ b/specs/gloas/p2p-interface.md @@ -110,7 +110,7 @@ class SignedProposerPreferences(Container): ```python @dataclass -class Seen(object): +class Seen: proposer_slots: Set[Tuple[ValidatorIndex, Slot]] aggregator_epochs: Set[Tuple[ValidatorIndex, Epoch]] aggregate_data_roots: Dict[Tuple[Root, CommitteeIndex], Set[Tuple[boolean, ...]]] From 86bf6ffa426ba718028525752f942008fdf802b8 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 20 May 2026 21:24:11 -0500 Subject: [PATCH 4/4] Add activate_at_genesis option --- .../eth_consensus_specs/test/context.py | 22 ++++++++++++++++--- .../networking/test_gossip_beacon_block.py | 3 ++- .../test_gossip_data_column_sidecar.py | 3 ++- ...test_gossip_partial_data_column_sidecar.py | 3 ++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth_consensus_specs/test/context.py b/tests/core/pyspec/eth_consensus_specs/test/context.py index 64d64cdadf5..88594e5074e 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/context.py +++ b/tests/core/pyspec/eth_consensus_specs/test/context.py @@ -352,11 +352,27 @@ def spec_state_test(fn): return spec_test(with_state(single_phase(fn))) -def spec_configured_state_test(conf): - overrides = _with_config_overrides_emit(conf) +def spec_configured_state_test(conf, *, activate_at_genesis: bool = False): + """ + If ``activate_at_genesis`` is True, set the spec module's own ``*_FORK_EPOCH`` to + 0 so the emitted ``config.cfg`` resolves the test's fork as the latest scheduled + activation. Useful for fixtures consumed by clients that resolve forks via + ``getForkName(slot)``. Entries in ``conf`` win on conflict. + """ + if not activate_at_genesis: + overrides = _with_config_overrides_emit(conf) + + def decorator(fn): + return spec_test(overrides(with_state(single_phase(fn)))) + + return decorator def decorator(fn): - return spec_test(overrides(with_state(single_phase(fn)))) + def wrapper(*args, spec: Spec, **kw): + combined = {f"{spec.fork.upper()}_FORK_EPOCH": 0, **conf} + return _with_config_overrides_emit(combined)(fn)(*args, spec=spec, **kw) + + return spec_test(with_state(single_phase(wrapper))) return decorator diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py index f19873b0734..460b3dfebb7 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_beacon_block.py @@ -29,7 +29,8 @@ @spec_configured_state_test( { "BLOB_SCHEDULE": (frozendict({"EPOCH": 0, "MAX_BLOBS_PER_BLOCK": 12}),), - } + }, + activate_at_genesis=True, ) def test_gossip_beacon_block__valid_at_blob_parameters_limit(spec, state): """ diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py index 240a86d24f4..199f3f13b41 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_data_column_sidecar.py @@ -67,7 +67,8 @@ def resign_sidecar_header(spec, state, sidecar): @spec_configured_state_test( { "BLOB_SCHEDULE": (frozendict({"EPOCH": 0, "MAX_BLOBS_PER_BLOCK": 12}),), - } + }, + activate_at_genesis=True, ) def test_gossip_data_column_sidecar__valid(spec, state): """Test that a valid data column sidecar passes gossip validation.""" diff --git a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py index e1250f98e6d..0c5e24508ef 100644 --- a/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py +++ b/tests/core/pyspec/eth_consensus_specs/test/fulu/networking/test_gossip_partial_data_column_sidecar.py @@ -145,7 +145,8 @@ def test_gossip_partial_data_column_sidecar__valid_header_only(spec, state): @spec_configured_state_test( { "BLOB_SCHEDULE": (frozendict({"EPOCH": 0, "MAX_BLOBS_PER_BLOCK": 12}),), - } + }, + activate_at_genesis=True, ) def test_gossip_partial_data_column_sidecar__valid_header_and_cells(spec, state): """Test that a partial sidecar carrying both header and cells passes gossip validation."""