Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,13 @@ transitions are in `ethlambda-types`, per the section above. Nothing above
validation, deneb's and fulu's data availability, and gloas's payload-aware
suites.
- **EIP-8483 and PQ** (consensus-specs' `pq` branch feature forks, pinned at
`4c296784`, pq-devnet-1's spec: staggered aggregators of `4595f0fc`, VRF
`66f143ec`, pq-devnet-2's spec: staggered aggregators of `4595f0fc`, VRF
secrets of `b5d422b2`, `X_MAX_COMMITTEE_COUNT_PER_SLOT` of `af898d07` (one
per process, selected with the preset: absent it is the preset's
`MAX_COMMITTEES_PER_SLOT_PQ`, above that it is refused at startup),
keccak256 legacy keys of `4c296784`) are `ForkName::Eip8483` and `ForkName::Pq` after gloas, selectors
keccak256 legacy keys of `4c296784`, preregistrations that expire by epoch
and are never replaced in place of `c8608e56`, EIP-8483 registrations
removed on exit of `a0d94fdc`, `X_COMMITTEE_COUNTS` of `66f143ec`) are `ForkName::Eip8483` and `ForkName::Pq` after gloas, selectors
8 and 9, implemented in the state transition and fork choice
(`stf/{eip8483,pq}.rs`, `stf/epoch/pq.rs`, `helpers/pq.rs`, `upgrade_to_*`)
and PQ's gossip rules (`gossip/pq.rs`, `p2p/src/beacon/pq.rs`: a PQ digest's
Expand Down
27 changes: 27 additions & 0 deletions crates/blockchain/state_transition/src/beacon/gossip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,33 @@ mod tests {
));
}

/// A slot whose start time does not fit in a `u64` of milliseconds is in
/// the future and nothing else (consensus-specs #5895): the saturating
/// slot start reads as later than any clock, so no rule takes such a
/// message for a current or past one.
#[test]
fn a_far_future_slot_is_future_and_neither_current_nor_past() {
use super::execution_payload_bid::is_current_or_next_slot;
use super::proposer_preferences::is_past_slot;
let config = Config {
genesis_time: 100,
..Config::mainnet()
};
for now_ms in [0, 100_000, 100_000 + 7 * config.slot_duration_ms] {
for slot in [
u64::MAX,
u64::MAX - 1,
u64::MAX / config.slot_duration_ms + 1,
] {
assert!(is_future_slot(&config, slot, now_ms));
assert!(!is_past_slot(&config, slot, now_ms));
assert!(!is_current_slot(&config, slot, now_ms));
assert!(!is_current_or_next_slot(&config, slot, now_ms));
}
assert!(is_future_epoch(&config, u64::MAX, now_ms));
}
}

#[test]
fn the_current_slot_holds_within_the_clock_disparity_at_either_edge() {
let config = Config {
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain/state_transition/src/beacon/gossip/pq.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Gossip validation for the PQ fork's topics
//! (`specs/_features/pq/p2p-interface.md`, consensus-specs' `pq` branch at
//! `4c296784bb6ff54cbdcf72ebdda2a1057cce8893`).
//! `66f143ec87da07452e3059b0954584014043125e`).
//!
//! Every topic whose message carries a validator's or builder's signature
//! carries an XMSS one instead, at the leaf the fork assigns that message, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,9 @@ pub fn get_next_sync_committee_indices(state: &BeaconState) -> Result<Vec<Valida
/// `active_balances` is block processing's cache, or `None` for the uncached
/// total (epoch processing, spec-shaped callers); see
/// [`compute_exit_epoch_and_update_churn`].
///
/// EIP-8483 modifies it to remove the validator's PQ registration, and PQ to
/// not do so again.
pub fn initiate_validator_exit(
state: &mut BeaconState,
index: ValidatorIndex,
Expand Down Expand Up @@ -794,6 +797,10 @@ pub fn initiate_validator_exit(
let validator = state.validator_mut(index)?;
validator.exit_epoch = exit_queue_epoch;
validator.withdrawable_epoch = withdrawable;

// [New in EIP8483] An exiting validator's PQ registration is removed. A
// no-op on every other fork, PQ included, whose state has no such list.
super::mutators::remove_validator_pq_registration(state, index);
Ok(())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::beacon::containers::BeaconState;
use crate::beacon::error::{Error, Result};
use crate::beacon::lean_state_unreachable;
use crate::beacon::preset;
use crate::beacon::primitives::{Epoch, Gwei, ValidatorIndex};
use crate::beacon::primitives::{BlsPubkey, Epoch, Gwei, ValidatorIndex};

use super::accessors::{
ActiveBalanceCache, get_beacon_proposer_index, get_current_epoch, get_validator_churn_limit,
Expand Down Expand Up @@ -265,6 +265,54 @@ pub fn slash_validator(
Ok(())
}

/// `remove_validator_pq_registration` (EIP-8483): drops the PQ material a
/// validator registered, when it initiates its exit. After that it cannot
/// register again.
///
/// Only an EIP-8483 state holds registrations: gloas has none yet, and PQ has
/// adopted them and removed the lists, so on any other fork this does nothing.
/// Removal keeps the remaining records' order, which the state root commits to.
pub fn remove_validator_pq_registration(state: &mut BeaconState, validator_index: ValidatorIndex) {
let BeaconState::Eip8483(inner) = state else {
return;
};
let registrations = &inner.validator_pq_registrations;
if !registrations
.iter()
.any(|registration| registration.validator_index == validator_index)
{
return;
}
let kept: Vec<_> = registrations
.iter()
.filter(|registration| registration.validator_index != validator_index)
.cloned()
.collect();
inner.validator_pq_registrations = kept.into();
}

/// `remove_builder_pq_registration` (EIP-8483): the builder counterpart of
/// [`remove_validator_pq_registration`], by public key, since a builder index
/// is reused once its builder has withdrawn.
pub fn remove_builder_pq_registration(state: &mut BeaconState, builder_pubkey: &BlsPubkey) {
let BeaconState::Eip8483(inner) = state else {
return;
};
let registrations = &inner.builder_pq_registrations;
if !registrations
.iter()
.any(|registration| registration.builder_pubkey == *builder_pubkey)
{
return;
}
let kept: Vec<_> = registrations
.iter()
.filter(|registration| registration.builder_pubkey != *builder_pubkey)
.cloned()
.collect();
inner.builder_pq_registrations = kept.into();
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
46 changes: 11 additions & 35 deletions crates/blockchain/state_transition/src/beacon/helpers/pq.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Helpers the PQ fork adds or modifies (consensus-specs
//! `specs/_features/pq/beacon-chain.md`, on the `pq` branch at
//! `4c296784bb6ff54cbdcf72ebdda2a1057cce8893`).
//! `66f143ec87da07452e3059b0954584014043125e`).
//!
//! # Keys
//!
Expand Down Expand Up @@ -508,52 +508,28 @@ pub fn is_valid_indexed_attestation(
// Preregistrations
// ---------------------------------------------------------------------------

/// The slot of the outstanding parent payload, whose execution requests are
/// the ones being applied: what a preregistration's expiry is compared with.
fn parent_payload_slot(state: &pq::BeaconState) -> Slot {
state.latest_execution_payload_bid.slot
}

/// `is_active_validator_preregistration`.
pub fn is_active_validator_preregistration(
state: &pq::BeaconState,
preregistration: &pq::ValidatorPreregistration,
) -> bool {
parent_payload_slot(state) < preregistration.expiry_slot
}

/// `is_active_builder_preregistration`.
pub fn is_active_builder_preregistration(
state: &pq::BeaconState,
preregistration: &pq::BuilderPreregistration,
) -> bool {
parent_payload_slot(state) < preregistration.expiry_slot
}

/// `get_active_validator_preregistration`.
pub fn get_active_validator_preregistration(
state: &pq::BeaconState,
/// `get_validator_preregistration`: the stored preregistration of `pubkey`.
/// A record binds its key for as long as it is in the state; the epoch
/// transition's sweep is what ends it.
pub fn get_validator_preregistration<'a>(
state: &'a pq::BeaconState,
pubkey: &XmssPubkey,
) -> Option<pq::ValidatorPreregistration> {
) -> Option<&'a pq::ValidatorPreregistration> {
state
.validator_preregistrations
.iter()
.find(|preregistration| preregistration.pubkey == *pubkey)
.filter(|preregistration| is_active_validator_preregistration(state, preregistration))
.cloned()
}

/// `get_active_builder_preregistration`.
pub fn get_active_builder_preregistration(
state: &pq::BeaconState,
/// `get_builder_preregistration`.
pub fn get_builder_preregistration<'a>(
state: &'a pq::BeaconState,
pubkey: &XmssPubkey,
) -> Option<pq::BuilderPreregistration> {
) -> Option<&'a pq::BuilderPreregistration> {
state
.builder_preregistrations
.iter()
.find(|preregistration| preregistration.pubkey == *pubkey)
.filter(|preregistration| is_active_builder_preregistration(state, preregistration))
.cloned()
}

/// The PQ state, mutably, or an error naming the function that needs one.
Expand Down
Loading
Loading