Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pysetup/spec_builders/fulu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)

Expand Down
3 changes: 3 additions & 0 deletions pysetup/spec_builders/gloas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
)

Expand Down
267 changes: 217 additions & 50 deletions specs/fulu/p2p-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Comment thread
jtraglia marked this conversation as resolved.
Resolved
```

#### Modified `compute_fork_version`

```python
Expand Down Expand Up @@ -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

Expand All @@ -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
Comment thread
jtraglia marked this conversation as resolved.
Resolved
# (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
Expand Down
Loading