Skip to content
Merged
3 changes: 3 additions & 0 deletions pysetup/spec_builders/capella.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ def deprecate_functions(cls) -> set[str]:
"process_historical_roots_update",
"upgrade_to_bellatrix",
"validate_merge_block",
# Temporarily deprecate gossip validation function until we add the capella version
# which does not use the deprecated is_execution_enabled function.
"validate_beacon_block_gossip",
Comment thread
jtraglia marked this conversation as resolved.
Resolved
]
)
159 changes: 122 additions & 37 deletions specs/bellatrix/p2p-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- [Introduction](#introduction)
- [Modifications in Bellatrix](#modifications-in-bellatrix)
- [Types](#types)
- [Constants](#constants)
- [Helpers](#helpers)
- [Modified `compute_fork_version`](#modified-compute_fork_version)
- [The gossip domain: gossipsub](#the-gossip-domain-gossipsub)
Expand Down Expand Up @@ -39,6 +41,20 @@ understand the changes outlined in this document.

## Modifications in Bellatrix

### Types

| Name | SSZ equivalent | Description |
| ------------------------- | -------------- | ----------------------------------------------- |
| `PayloadValidationStatus` | `uint8` | Execution payload validation status for a block |

### Constants

| Name | Value |
| ------------------------------ | ---------------------------- |
| `PAYLOAD_STATUS_VALID` | `PayloadValidationStatus(0)` |
| `PAYLOAD_STATUS_INVALIDATED` | `PayloadValidationStatus(1)` |
| `PAYLOAD_STATUS_NOT_VALIDATED` | `PayloadValidationStatus(2)` |

### Helpers

#### Modified `compute_fork_version`
Expand Down Expand Up @@ -86,43 +102,112 @@ Bellatrix changes the type of the global beacon block topic.

###### `beacon_block`

The *type* of the payload of this topic changes to the (modified)
`SignedBeaconBlock` found in Bellatrix. Specifically, this type changes with the
addition of `execution_payload` to the inner `BeaconBlockBody`. See Bellatrix
[state transition document](./beacon-chain.md#beaconblockbody) for further
details.

Blocks with execution enabled will be permitted to propagate regardless of the
validity of the execution payload. This prevents network segregation between
[optimistic](../../sync/optimistic.md) and non-optimistic nodes.

In addition to the gossip validations for this topic from prior specifications,
the following validations MUST pass before forwarding the `signed_beacon_block`
on the network. Alias `block = signed_beacon_block.message`,
`execution_payload = block.body.execution_payload`.

If the execution is enabled for the block -- i.e.
`is_execution_enabled(state, block.body)` then validate the following:

- _[REJECT]_ The block's execution payload timestamp is correct with respect to
the slot -- i.e.
`execution_payload.timestamp == compute_time_at_slot(state, block.slot)`.
- If `execution_payload` verification of block's parent by an execution node is
*not* complete:
- _[REJECT]_ The block's parent (defined by `block.parent_root`) passes all
validation (excluding execution node verification of the
`block.body.execution_payload`).
- Otherwise:
- _[IGNORE]_ The block's parent (defined by `block.parent_root`) passes all
validation (including execution node verification of the
`block.body.execution_payload`).

The following gossip validation from prior specifications MUST NOT be applied if
the execution is enabled for the block -- i.e.
`is_execution_enabled(state, block.body)`:

- _[REJECT]_ The block's parent (defined by `block.parent_root`) passes
validation.
The `beacon_block` topic is used solely for propagating new signed beacon blocks
to all nodes on the networks. Signed blocks are sent in their entirety. The
`state` parameter is the head state.

*Note*: Blocks with execution enabled will be permitted to propagate regardless
of the validity of the execution payload. This prevents network segregation
between [optimistic](../../sync/optimistic.md) and non-optimistic nodes.

```python
def validate_beacon_block_gossip(
seen: Seen,
store: Store,
state: BeaconState,
signed_beacon_block: SignedBeaconBlock,
current_time_ms: uint64,
# [New in Bellatrix]
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")

# [New in Bellatrix]
if is_execution_enabled(state, block.body):
# [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")
else:
# [REJECT] The block's parent passes validation
if block.parent_root not in store.block_states:
# [Modified in Bellatrix]
raise GossipReject("block's parent is invalid and execution is not enabled")

# [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")

# [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 for this proposer/slot combination
seen.proposer_slots.add((block.proposer_index, block.slot))
```

#### Transitioning the gossip

Expand Down
2 changes: 1 addition & 1 deletion specs/phase0/p2p-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def validate_beacon_block_gossip(

# [REJECT] The block's parent passes validation
if block.parent_root not in store.block_states:
raise GossipReject("block's parent failed validation")
raise GossipReject("block's parent is invalid")
Comment thread
jtraglia marked this conversation as resolved.
Resolved

# [REJECT] The block is from a higher slot than its parent
if block.slot <= store.blocks[block.parent_root].slot:
Expand Down
Loading