From 65bb931cd6f52f646a66a1235c7573735eafe1fd Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Thu, 18 Jul 2024 17:08:02 +1000 Subject: [PATCH 1/2] Add PeerDAS presets and configs. --- .../chiado/config.yaml | 4 + .../gnosis/config.yaml | 5 + .../holesky/config.yaml | 5 + .../mainnet/config.yaml | 7 ++ .../sepolia/config.yaml | 5 + consensus/types/presets/gnosis/eip7594.yaml | 10 ++ consensus/types/presets/mainnet/eip7594.yaml | 10 ++ consensus/types/presets/minimal/eip7594.yaml | 10 ++ consensus/types/src/chain_spec.rs | 103 +++++++++++++++++- consensus/types/src/preset.rs | 25 +++++ .../environment/tests/testnet_dir/config.yaml | 5 + 11 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 consensus/types/presets/gnosis/eip7594.yaml create mode 100644 consensus/types/presets/mainnet/eip7594.yaml create mode 100644 consensus/types/presets/minimal/eip7594.yaml diff --git a/common/eth2_network_config/built_in_network_configs/chiado/config.yaml b/common/eth2_network_config/built_in_network_configs/chiado/config.yaml index 07d100b011c..066b27795cd 100644 --- a/common/eth2_network_config/built_in_network_configs/chiado/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/chiado/config.yaml @@ -137,3 +137,7 @@ MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 16384 # `6` BLOB_SIDECAR_SUBNET_COUNT: 6 +# DAS +CUSTODY_REQUIREMENT: 1 +DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 +NUMBER_OF_COLUMNS: 128 \ No newline at end of file diff --git a/common/eth2_network_config/built_in_network_configs/gnosis/config.yaml b/common/eth2_network_config/built_in_network_configs/gnosis/config.yaml index 50a5fcc3a50..23cf040b276 100644 --- a/common/eth2_network_config/built_in_network_configs/gnosis/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/gnosis/config.yaml @@ -119,3 +119,8 @@ MAX_REQUEST_BLOB_SIDECARS: 768 MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 16384 # `6` BLOB_SIDECAR_SUBNET_COUNT: 6 + +# DAS +CUSTODY_REQUIREMENT: 1 +DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 +NUMBER_OF_COLUMNS: 128 \ No newline at end of file diff --git a/common/eth2_network_config/built_in_network_configs/holesky/config.yaml b/common/eth2_network_config/built_in_network_configs/holesky/config.yaml index 6a399b957d2..cec2b61f213 100644 --- a/common/eth2_network_config/built_in_network_configs/holesky/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/holesky/config.yaml @@ -123,3 +123,8 @@ MAX_REQUEST_BLOB_SIDECARS: 768 MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096 # `6` BLOB_SIDECAR_SUBNET_COUNT: 6 + +# DAS +CUSTODY_REQUIREMENT: 1 +DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 +NUMBER_OF_COLUMNS: 128 \ No newline at end of file diff --git a/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml index fc9c002daba..500b9e60a5c 100644 --- a/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/mainnet/config.yaml @@ -53,6 +53,8 @@ DENEB_FORK_EPOCH: 269568 # March 13, 2024, 01:55:35pm UTC # Electra ELECTRA_FORK_VERSION: 0x05000000 ELECTRA_FORK_EPOCH: 18446744073709551615 +# PeerDAS +EIP7594_FORK_EPOCH: 18446744073709551615 # Time parameters @@ -143,3 +145,8 @@ MAX_REQUEST_BLOB_SIDECARS: 768 MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096 # `6` BLOB_SIDECAR_SUBNET_COUNT: 6 + +# DAS +CUSTODY_REQUIREMENT: 1 +DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 +NUMBER_OF_COLUMNS: 128 \ No newline at end of file diff --git a/common/eth2_network_config/built_in_network_configs/sepolia/config.yaml b/common/eth2_network_config/built_in_network_configs/sepolia/config.yaml index 72a48679118..2a1809d6ce9 100644 --- a/common/eth2_network_config/built_in_network_configs/sepolia/config.yaml +++ b/common/eth2_network_config/built_in_network_configs/sepolia/config.yaml @@ -119,3 +119,8 @@ MAX_REQUEST_BLOB_SIDECARS: 768 MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS: 4096 # `6` BLOB_SIDECAR_SUBNET_COUNT: 6 + +# DAS +CUSTODY_REQUIREMENT: 1 +DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 +NUMBER_OF_COLUMNS: 128 \ No newline at end of file diff --git a/consensus/types/presets/gnosis/eip7594.yaml b/consensus/types/presets/gnosis/eip7594.yaml new file mode 100644 index 00000000000..813febf26d5 --- /dev/null +++ b/consensus/types/presets/gnosis/eip7594.yaml @@ -0,0 +1,10 @@ +# Mainnet preset - EIP7594 + +# Misc +# --------------------------------------------------------------- +# `uint64(2**6)` (= 64) +FIELD_ELEMENTS_PER_CELL: 64 +# `uint64(2 * 4096)` (= 8192) +FIELD_ELEMENTS_PER_EXT_BLOB: 8192 +# uint64(floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) +KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH: 4 diff --git a/consensus/types/presets/mainnet/eip7594.yaml b/consensus/types/presets/mainnet/eip7594.yaml new file mode 100644 index 00000000000..813febf26d5 --- /dev/null +++ b/consensus/types/presets/mainnet/eip7594.yaml @@ -0,0 +1,10 @@ +# Mainnet preset - EIP7594 + +# Misc +# --------------------------------------------------------------- +# `uint64(2**6)` (= 64) +FIELD_ELEMENTS_PER_CELL: 64 +# `uint64(2 * 4096)` (= 8192) +FIELD_ELEMENTS_PER_EXT_BLOB: 8192 +# uint64(floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) +KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH: 4 diff --git a/consensus/types/presets/minimal/eip7594.yaml b/consensus/types/presets/minimal/eip7594.yaml new file mode 100644 index 00000000000..847719a4210 --- /dev/null +++ b/consensus/types/presets/minimal/eip7594.yaml @@ -0,0 +1,10 @@ +# Minimal preset - EIP7594 + +# Misc +# --------------------------------------------------------------- +# `uint64(2**6)` (= 64) +FIELD_ELEMENTS_PER_CELL: 64 +# `uint64(2 * 4096)` (= 8192) +FIELD_ELEMENTS_PER_EXT_BLOB: 8192 +# uint64(floorlog2(get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')) +KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH: 4 diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 9cc864f9641..11c7e5ae178 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -1,5 +1,6 @@ use crate::application_domain::{ApplicationDomain, APPLICATION_DOMAIN_BUILDER}; use crate::blob_sidecar::BlobIdentifier; +use crate::data_column_sidecar::DataColumnIdentifier; use crate::*; use int_to_bytes::int_to_bytes4; use safe_arith::{ArithError, SafeArith}; @@ -193,6 +194,9 @@ pub struct ChainSpec { /* * DAS params */ + pub eip7594_fork_epoch: Option, + pub custody_requirement: u64, + pub data_column_sidecar_subnet_count: u64, pub number_of_columns: usize, /* @@ -223,6 +227,7 @@ pub struct ChainSpec { */ pub max_request_blocks_deneb: u64, pub max_request_blob_sidecars: u64, + pub max_request_data_column_sidecars: u64, pub min_epochs_for_blob_sidecars_requests: u64, pub blob_sidecar_subnet_count: u64, @@ -234,6 +239,7 @@ pub struct ChainSpec { pub max_blocks_by_root_request: usize, pub max_blocks_by_root_request_deneb: usize, pub max_blobs_by_root_request: usize, + pub max_data_columns_by_root_request: usize, /* * Application params @@ -413,6 +419,13 @@ impl ChainSpec { } } + /// Returns true if the given epoch is greater than or equal to the `EIP7594_FORK_EPOCH`. + pub fn is_peer_das_enabled_for_epoch(&self, block_epoch: Epoch) -> bool { + self.eip7594_fork_epoch.map_or(false, |eip7594_fork_epoch| { + block_epoch >= eip7594_fork_epoch + }) + } + /// Returns a full `Fork` struct for a given epoch. pub fn fork_at_epoch(&self, epoch: Epoch) -> Fork { let current_fork_name = self.fork_name_at_epoch(epoch); @@ -587,6 +600,12 @@ impl ChainSpec { } } + pub fn data_columns_per_subnet(&self) -> usize { + self.number_of_columns + .safe_div(self.data_column_sidecar_subnet_count as usize) + .expect("Subnet count must be greater than 0") + } + /// Returns a `ChainSpec` compatible with the Ethereum Foundation specification. pub fn mainnet() -> Self { Self { @@ -777,6 +796,12 @@ impl ChainSpec { }) .expect("calculation does not overflow"), + /* + * DAS params + */ + eip7594_fork_epoch: None, + custody_requirement: 1, + data_column_sidecar_subnet_count: 32, number_of_columns: 128, /* @@ -808,6 +833,7 @@ impl ChainSpec { */ max_request_blocks_deneb: default_max_request_blocks_deneb(), max_request_blob_sidecars: default_max_request_blob_sidecars(), + max_request_data_column_sidecars: default_max_request_data_column_sidecars(), min_epochs_for_blob_sidecars_requests: default_min_epochs_for_blob_sidecars_requests(), blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(), @@ -817,6 +843,7 @@ impl ChainSpec { max_blocks_by_root_request: default_max_blocks_by_root_request(), max_blocks_by_root_request_deneb: default_max_blocks_by_root_request_deneb(), max_blobs_by_root_request: default_max_blobs_by_root_request(), + max_data_columns_by_root_request: default_data_columns_by_root_request(), /* * Application specific @@ -888,6 +915,8 @@ impl ChainSpec { u64::checked_pow(2, 7)?.checked_mul(u64::checked_pow(10, 9)?) }) .expect("calculation does not overflow"), + // PeerDAS + eip7594_fork_epoch: None, // Other network_id: 2, // lighthouse testnet network id deposit_chain_id: 5, @@ -1089,8 +1118,13 @@ impl ChainSpec { }) .expect("calculation does not overflow"), + /* + * DAS params + */ + eip7594_fork_epoch: None, + custody_requirement: 1, + data_column_sidecar_subnet_count: 32, number_of_columns: 128, - /* * Network specific */ @@ -1120,6 +1154,7 @@ impl ChainSpec { */ max_request_blocks_deneb: default_max_request_blocks_deneb(), max_request_blob_sidecars: default_max_request_blob_sidecars(), + max_request_data_column_sidecars: default_max_request_data_column_sidecars(), min_epochs_for_blob_sidecars_requests: 16384, blob_sidecar_subnet_count: default_blob_sidecar_subnet_count(), @@ -1129,6 +1164,7 @@ impl ChainSpec { max_blocks_by_root_request: default_max_blocks_by_root_request(), max_blocks_by_root_request_deneb: default_max_blocks_by_root_request_deneb(), max_blobs_by_root_request: default_max_blobs_by_root_request(), + max_data_columns_by_root_request: default_data_columns_by_root_request(), /* * Application specific @@ -1222,6 +1258,11 @@ pub struct Config { #[serde(deserialize_with = "deserialize_fork_epoch")] pub electra_fork_epoch: Option>, + #[serde(default)] + #[serde(serialize_with = "serialize_fork_epoch")] + #[serde(deserialize_with = "deserialize_fork_epoch")] + pub eip7594_fork_epoch: Option>, + #[serde(with = "serde_utils::quoted_u64")] seconds_per_slot: u64, #[serde(with = "serde_utils::quoted_u64")] @@ -1307,6 +1348,9 @@ pub struct Config { #[serde(default = "default_max_request_blob_sidecars")] #[serde(with = "serde_utils::quoted_u64")] max_request_blob_sidecars: u64, + #[serde(default = "default_max_request_data_column_sidecars")] + #[serde(with = "serde_utils::quoted_u64")] + max_request_data_column_sidecars: u64, #[serde(default = "default_min_epochs_for_blob_sidecars_requests")] #[serde(with = "serde_utils::quoted_u64")] min_epochs_for_blob_sidecars_requests: u64, @@ -1320,6 +1364,13 @@ pub struct Config { #[serde(default = "default_max_per_epoch_activation_exit_churn_limit")] #[serde(with = "serde_utils::quoted_u64")] max_per_epoch_activation_exit_churn_limit: u64, + + #[serde(with = "serde_utils::quoted_u64")] + custody_requirement: u64, + #[serde(with = "serde_utils::quoted_u64")] + data_column_sidecar_subnet_count: u64, + #[serde(with = "serde_utils::quoted_u64")] + number_of_columns: u64, } fn default_bellatrix_fork_version() -> [u8; 4] { @@ -1426,6 +1477,10 @@ const fn default_max_request_blob_sidecars() -> u64 { 768 } +const fn default_max_request_data_column_sidecars() -> u64 { + 512 +} + const fn default_min_epochs_for_blob_sidecars_requests() -> u64 { 4096 } @@ -1479,6 +1534,20 @@ fn max_blobs_by_root_request_common(max_request_blob_sidecars: u64) -> usize { .len() } +fn max_data_columns_by_root_request_common(max_request_data_column_sidecars: u64) -> usize { + let max_request_data_column_sidecars = max_request_data_column_sidecars as usize; + let empty_data_column_id = DataColumnIdentifier { + block_root: Hash256::zero(), + index: 0, + }; + RuntimeVariableList::from_vec( + vec![empty_data_column_id; max_request_data_column_sidecars], + max_request_data_column_sidecars, + ) + .as_ssz_bytes() + .len() +} + fn default_max_blocks_by_root_request() -> usize { max_blocks_by_root_request_common(default_max_request_blocks()) } @@ -1491,6 +1560,10 @@ fn default_max_blobs_by_root_request() -> usize { max_blobs_by_root_request_common(default_max_request_blob_sidecars()) } +fn default_data_columns_by_root_request() -> usize { + max_data_columns_by_root_request_common(default_max_request_data_column_sidecars()) +} + impl Default for Config { fn default() -> Self { let chain_spec = MainnetEthSpec::default_spec(); @@ -1580,6 +1653,10 @@ impl Config { .electra_fork_epoch .map(|epoch| MaybeQuoted { value: epoch }), + eip7594_fork_epoch: spec + .eip7594_fork_epoch + .map(|epoch| MaybeQuoted { value: epoch }), + seconds_per_slot: spec.seconds_per_slot, seconds_per_eth1_block: spec.seconds_per_eth1_block, min_validator_withdrawability_delay: spec.min_validator_withdrawability_delay, @@ -1616,12 +1693,17 @@ impl Config { attestation_subnet_shuffling_prefix_bits: spec.attestation_subnet_shuffling_prefix_bits, max_request_blocks_deneb: spec.max_request_blocks_deneb, max_request_blob_sidecars: spec.max_request_blob_sidecars, + max_request_data_column_sidecars: spec.max_request_data_column_sidecars, min_epochs_for_blob_sidecars_requests: spec.min_epochs_for_blob_sidecars_requests, blob_sidecar_subnet_count: spec.blob_sidecar_subnet_count, min_per_epoch_churn_limit_electra: spec.min_per_epoch_churn_limit_electra, max_per_epoch_activation_exit_churn_limit: spec .max_per_epoch_activation_exit_churn_limit, + + custody_requirement: spec.custody_requirement, + data_column_sidecar_subnet_count: spec.data_column_sidecar_subnet_count, + number_of_columns: spec.number_of_columns as u64, } } @@ -1655,6 +1737,7 @@ impl Config { deneb_fork_version, electra_fork_epoch, electra_fork_version, + eip7594_fork_epoch, seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay, @@ -1687,10 +1770,15 @@ impl Config { maximum_gossip_clock_disparity_millis, max_request_blocks_deneb, max_request_blob_sidecars, + max_request_data_column_sidecars, min_epochs_for_blob_sidecars_requests, blob_sidecar_subnet_count, + min_per_epoch_churn_limit_electra, max_per_epoch_activation_exit_churn_limit, + custody_requirement, + data_column_sidecar_subnet_count, + number_of_columns, } = self; if preset_base != E::spec_name().to_string().as_str() { @@ -1713,6 +1801,7 @@ impl Config { deneb_fork_version, electra_fork_epoch: electra_fork_epoch.map(|q| q.value), electra_fork_version, + eip7594_fork_epoch: eip7594_fork_epoch.map(|q| q.value), seconds_per_slot, seconds_per_eth1_block, min_validator_withdrawability_delay, @@ -1749,8 +1838,10 @@ impl Config { maximum_gossip_clock_disparity_millis, max_request_blocks_deneb, max_request_blob_sidecars, + max_request_data_column_sidecars, min_epochs_for_blob_sidecars_requests, blob_sidecar_subnet_count, + min_per_epoch_churn_limit_electra, max_per_epoch_activation_exit_churn_limit, @@ -1760,6 +1851,13 @@ impl Config { max_request_blocks_deneb, ), max_blobs_by_root_request: max_blobs_by_root_request_common(max_request_blob_sidecars), + max_data_columns_by_root_request: max_data_columns_by_root_request_common( + max_request_data_column_sidecars, + ), + + custody_requirement, + data_column_sidecar_subnet_count, + number_of_columns: number_of_columns as usize, ..chain_spec.clone() }) @@ -2001,6 +2099,9 @@ mod yaml_tests { DEPOSIT_CHAIN_ID: 1 DEPOSIT_NETWORK_ID: 1 DEPOSIT_CONTRACT_ADDRESS: 0x00000000219ab540356cBB839Cbe05303d7705Fa + CUSTODY_REQUIREMENT: 1 + DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 + NUMBER_OF_COLUMNS: 128 "#; let chain_spec: Config = serde_yaml::from_str(spec).unwrap(); diff --git a/consensus/types/src/preset.rs b/consensus/types/src/preset.rs index 9e9c5aaf410..b51928d165e 100644 --- a/consensus/types/src/preset.rs +++ b/consensus/types/src/preset.rs @@ -278,6 +278,28 @@ impl ElectraPreset { } } +#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] +#[serde(rename_all = "UPPERCASE")] +pub struct Eip7594Preset { + #[serde(with = "serde_utils::quoted_u64")] + pub field_elements_per_cell: u64, + #[serde(with = "serde_utils::quoted_u64")] + pub field_elements_per_ext_blob: u64, + #[serde(with = "serde_utils::quoted_u64")] + pub kzg_commitments_inclusion_proof_depth: u64, +} + +impl Eip7594Preset { + pub fn from_chain_spec(_spec: &ChainSpec) -> Self { + Self { + field_elements_per_cell: E::field_elements_per_cell() as u64, + field_elements_per_ext_blob: E::field_elements_per_ext_blob() as u64, + kzg_commitments_inclusion_proof_depth: E::kzg_commitments_inclusion_proof_depth() + as u64, + } + } +} + #[cfg(test)] mod test { use super::*; @@ -322,6 +344,9 @@ mod test { let electra: ElectraPreset = preset_from_file(&preset_name, "electra.yaml"); assert_eq!(electra, ElectraPreset::from_chain_spec::(&spec)); + + let eip7594: Eip7594Preset = preset_from_file(&preset_name, "eip7594.yaml"); + assert_eq!(eip7594, Eip7594Preset::from_chain_spec::(&spec)); } #[test] diff --git a/lighthouse/environment/tests/testnet_dir/config.yaml b/lighthouse/environment/tests/testnet_dir/config.yaml index c71feaa7dc5..4fc7bc2dcff 100644 --- a/lighthouse/environment/tests/testnet_dir/config.yaml +++ b/lighthouse/environment/tests/testnet_dir/config.yaml @@ -98,3 +98,8 @@ ATTESTATION_SUBNET_COUNT: 64 ATTESTATION_SUBNET_EXTRA_BITS: 0 ATTESTATION_SUBNET_PREFIX_BITS: 6 ATTESTATION_SUBNET_SHUFFLING_PREFIX_BITS: 3 + +# DAS +CUSTODY_REQUIREMENT: 1 +DATA_COLUMN_SIDECAR_SUBNET_COUNT: 32 +NUMBER_OF_COLUMNS: 128 \ No newline at end of file From a5e027947450772930aae891e7c0d3c4650f0c2d Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Fri, 19 Jul 2024 11:44:47 +1000 Subject: [PATCH 2/2] Update default value for `max_request_data_column_sidecars`. --- consensus/types/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/types/src/chain_spec.rs b/consensus/types/src/chain_spec.rs index 11c7e5ae178..ca4df32d1e5 100644 --- a/consensus/types/src/chain_spec.rs +++ b/consensus/types/src/chain_spec.rs @@ -1478,7 +1478,7 @@ const fn default_max_request_blob_sidecars() -> u64 { } const fn default_max_request_data_column_sidecars() -> u64 { - 512 + 16384 } const fn default_min_epochs_for_blob_sidecars_requests() -> u64 {