From 80c2ad438a8ceb2d7a9e25a21325e33cea92e055 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Mon, 13 Mar 2023 23:05:57 +0200 Subject: [PATCH] Make `snowbridge-ethereum-beacon-client` generic over the network it is built for --- .../pallets/ethereum-beacon-client/Cargo.toml | 1 + .../ethereum-beacon-client/src/config.rs | 13 +--- .../pallets/ethereum-beacon-client/src/lib.rs | 71 +++++++++++++------ .../src/merkleization.rs | 28 ++++---- .../ethereum-beacon-client/src/mock.rs | 29 +++++--- .../pallets/ethereum-beacon-client/src/ssz.rs | 8 +-- .../ethereum-beacon-client/src/tests.rs | 15 +++- .../src/tests_mainnet.rs | 18 +++-- .../src/tests_minimal.rs | 16 +++-- parachain/runtime/snowbase/Cargo.toml | 2 +- parachain/runtime/snowbase/src/lib.rs | 12 +++- parachain/runtime/snowblink/src/lib.rs | 12 +++- parachain/runtime/snowbridge/src/lib.rs | 12 +++- 13 files changed, 157 insertions(+), 80 deletions(-) diff --git a/parachain/pallets/ethereum-beacon-client/Cargo.toml b/parachain/pallets/ethereum-beacon-client/Cargo.toml index 1dcc956353..d5e4c75220 100644 --- a/parachain/pallets/ethereum-beacon-client/Cargo.toml +++ b/parachain/pallets/ethereum-beacon-client/Cargo.toml @@ -67,4 +67,5 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "hex-literal" ] +# Feature only used for testing and benchmarking minimal = [] diff --git a/parachain/pallets/ethereum-beacon-client/src/config.rs b/parachain/pallets/ethereum-beacon-client/src/config.rs index 0eb2ae5ca0..f78552154f 100644 --- a/parachain/pallets/ethereum-beacon-client/src/config.rs +++ b/parachain/pallets/ethereum-beacon-client/src/config.rs @@ -1,14 +1,5 @@ -#[cfg(feature = "minimal")] -mod minimal; - -#[cfg(not(feature = "minimal"))] -mod mainnet; - -#[cfg(feature = "minimal")] -pub use minimal::*; - -#[cfg(not(feature = "minimal"))] -pub use mainnet::*; +pub mod mainnet; +pub mod minimal; pub const CURRENT_SYNC_COMMITTEE_INDEX: u64 = 22; pub const CURRENT_SYNC_COMMITTEE_DEPTH: u64 = 5; diff --git a/parachain/pallets/ethereum-beacon-client/src/lib.rs b/parachain/pallets/ethereum-beacon-client/src/lib.rs index 3b69bcb7fd..6a0139f896 100644 --- a/parachain/pallets/ethereum-beacon-client/src/lib.rs +++ b/parachain/pallets/ethereum-beacon-client/src/lib.rs @@ -1,5 +1,7 @@ //! # Ethereum Beacon Client #![cfg_attr(not(feature = "std"), no_std)] +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] pub mod config; mod merkleization; @@ -102,6 +104,11 @@ pub mod pallet { type ForkVersions: Get; type WeightInfo: WeightInfo; type WeakSubjectivityPeriodSeconds: Get; + + const SLOTS_PER_EPOCH: u64; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64; + const SYNC_COMMITTEE_SIZE: usize; + const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64; } #[pallet::event] @@ -211,12 +218,15 @@ pub mod pallet { } #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl GenesisBuild for GenesisConfig + where + [(); T::SYNC_COMMITTEE_SIZE]: Sized, + { fn build(&self) { log::info!( target: "ethereum-beacon-client", "💫 Sync committee size is: {}", - config::SYNC_COMMITTEE_SIZE + T::SYNC_COMMITTEE_SIZE ); if let Some(initial_sync) = self.initial_sync.clone() { @@ -226,7 +236,10 @@ pub mod pallet { } #[pallet::call] - impl Pallet { + impl Pallet + where + [(); T::SYNC_COMMITTEE_SIZE]: Sized, + { #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::sync_committee_period_update())] #[transactional] @@ -355,9 +368,12 @@ pub mod pallet { } } - impl Pallet { + impl Pallet + where + [(); T::SYNC_COMMITTEE_SIZE]: Sized, + { fn process_initial_sync(initial_sync: InitialSyncOf) -> DispatchResult { - Self::verify_sync_committee( + Self::verify_sync_committee::<{ T::SYNC_COMMITTEE_SIZE }>( initial_sync.current_sync_committee.clone(), initial_sync.current_sync_committee_branch, initial_sync.header.state_root, @@ -398,11 +414,12 @@ pub mod pallet { update.attested_header.slot >= update.finalized_header.slot, Error::::InvalidSyncCommitteeHeaderUpdate ); - let sync_committee_bits = - get_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone()) - .map_err(|_| Error::::InvalidSyncCommitteeBits)?; + let sync_committee_bits = get_sync_committee_bits::<_, { T::SYNC_COMMITTEE_SIZE }>( + update.sync_aggregate.sync_committee_bits.clone(), + ) + .map_err(|_| Error::::InvalidSyncCommitteeBits)?; Self::sync_committee_participation_is_supermajority(sync_committee_bits.clone())?; - Self::verify_sync_committee( + Self::verify_sync_committee::<{ T::SYNC_COMMITTEE_SIZE }>( update.next_sync_committee.clone(), update.next_sync_committee_branch, update.attested_header.state_root, @@ -501,9 +518,10 @@ pub mod pallet { return Err(Error::::BridgeBlocked.into()) } - let sync_committee_bits = - get_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone()) - .map_err(|_| Error::::InvalidSyncCommitteeBits)?; + let sync_committee_bits = get_sync_committee_bits::<_, { T::SYNC_COMMITTEE_SIZE }>( + update.sync_aggregate.sync_committee_bits.clone(), + ) + .map_err(|_| Error::::InvalidSyncCommitteeBits)?; Self::sync_committee_participation_is_supermajority(sync_committee_bits.clone())?; let block_root: H256 = @@ -608,9 +626,10 @@ pub mod pallet { let sync_committee = Self::get_sync_committee_for_period(current_period)?; let validators_root = >::get(); - let sync_committee_bits = - get_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone()) - .map_err(|_| Error::::InvalidSyncCommitteeBits)?; + let sync_committee_bits = get_sync_committee_bits::<_, { T::SYNC_COMMITTEE_SIZE }>( + update.sync_aggregate.sync_committee_bits.clone(), + ) + .map_err(|_| Error::::InvalidSyncCommitteeBits)?; Self::verify_signed_header( sync_committee_bits, @@ -706,14 +725,14 @@ pub mod pallet { log::info!( target: "ethereum-beacon-client", - "💫 Depth: {} leaf_index: {}", config::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH, leaf_index + "💫 Depth: {} leaf_index: {}", T::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH, leaf_index ); ensure!( Self::is_valid_merkle_branch( beacon_block_root, block_root_proof, - config::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH, + T::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH, leaf_index, finalized_block_root_hash ), @@ -751,7 +770,7 @@ pub mod pallet { let fork_version = Self::compute_fork_version(Self::compute_epoch_at_slot( signature_slot, - config::SLOTS_PER_EPOCH, + T::SLOTS_PER_EPOCH, )); let domain_type = config::DOMAIN_SYNC_COMMITTEE.to_vec(); // Domains are used for for seeds, for signatures, and for selecting aggregators. @@ -831,15 +850,18 @@ pub mod pallet { Ok(hash_root.into()) } - fn verify_sync_committee( + fn verify_sync_committee( sync_committee: SyncCommitteeOf, sync_committee_branch: BoundedVec, header_state_root: H256, depth: u64, index: u64, ) -> DispatchResult { - let sync_committee_root = merkleization::hash_tree_root_sync_committee(sync_committee) - .map_err(|_| Error::::SyncCommitteeHashTreeRootFailed)?; + let sync_committee_root = merkleization::hash_tree_root_sync_committee::< + _, + SYNC_COMMITTEE_SIZE, + >(sync_committee) + .map_err(|_| Error::::SyncCommitteeHashTreeRootFailed)?; ensure!( Self::is_valid_merkle_branch( @@ -968,7 +990,7 @@ pub mod pallet { } pub(super) fn compute_current_sync_period(slot: u64) -> u64 { - slot / config::SLOTS_PER_EPOCH / config::EPOCHS_PER_SYNC_COMMITTEE_PERIOD + slot / T::SLOTS_PER_EPOCH / T::EPOCHS_PER_SYNC_COMMITTEE_PERIOD } /// Return the domain for the domain_type and fork_version. @@ -1127,7 +1149,10 @@ pub mod pallet { } } - impl Verifier for Pallet { + impl Verifier for Pallet + where + [(); T::SYNC_COMMITTEE_SIZE]: Sized, + { /// Verify a message by verifying the existence of the corresponding /// Ethereum log in a block. Returns the log if successful. fn verify(message: &Message) -> Result<(Log, u64), DispatchError> { diff --git a/parachain/pallets/ethereum-beacon-client/src/merkleization.rs b/parachain/pallets/ethereum-beacon-client/src/merkleization.rs index 07f2768375..a47211f165 100644 --- a/parachain/pallets/ethereum-beacon-client/src/merkleization.rs +++ b/parachain/pallets/ethereum-beacon-client/src/merkleization.rs @@ -82,8 +82,12 @@ impl TryFrom for SSZBeaconBlockHeader { } } -impl, SignatureSize: Get> - TryFrom> for SSZSyncAggregate +impl< + SyncCommitteeBitsSize: Get, + SignatureSize: Get, + const SYNC_COMMITTEE_SIZE: usize, + > TryFrom> + for SSZSyncAggregate { type Error = MerkleizationError; @@ -91,9 +95,7 @@ impl, SignatureSize: Get> sync_aggregate: SyncAggregate, ) -> Result { Ok(SSZSyncAggregate { - sync_committee_bits: Bitvector::<{ config::SYNC_COMMITTEE_SIZE }>::deserialize( - &sync_aggregate.sync_committee_bits, - )?, + sync_committee_bits: Bitvector::deserialize(&sync_aggregate.sync_committee_bits)?, sync_committee_signature: Vector::::from_iter( sync_aggregate.sync_committee_signature, ), @@ -121,7 +123,7 @@ pub fn hash_tree_root_execution_header< hash_tree_root(ssz_execution_payload) } -pub fn hash_tree_root_sync_committee>( +pub fn hash_tree_root_sync_committee, const SYNC_COMMITTEE_SIZE: usize>( sync_committee: SyncCommittee, ) -> Result<[u8; 32], MerkleizationError> { let mut pubkeys_vec = Vec::new(); @@ -132,10 +134,9 @@ pub fn hash_tree_root_sync_committee>( pubkeys_vec.push(conv_pubkey); } - let pubkeys = - Vector::, { config::SYNC_COMMITTEE_SIZE }>::from_iter( - pubkeys_vec.clone(), - ); + let pubkeys = Vector::, SYNC_COMMITTEE_SIZE>::from_iter( + pubkeys_vec.clone(), + ); let agg = Vector::::from_iter(sync_committee.aggregate_pubkey.0); @@ -170,10 +171,13 @@ pub fn hash_tree_root( } } -pub fn get_sync_committee_bits>( +pub fn get_sync_committee_bits< + SyncCommitteeBitsSize: Get, + const SYNC_COMMITTEE_SIZE: usize, +>( bits_hex: BoundedVec, ) -> Result, MerkleizationError> { - let bitv = Bitvector::<{ config::SYNC_COMMITTEE_SIZE }>::deserialize(&bits_hex).map_err( + let bitv = Bitvector::::deserialize(&bits_hex).map_err( //|_| MerkleizationError::InvalidInput |e| -> MerkleizationError { match e { diff --git a/parachain/pallets/ethereum-beacon-client/src/mock.rs b/parachain/pallets/ethereum-beacon-client/src/mock.rs index 3f5537de24..19133312b1 100644 --- a/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -13,7 +13,7 @@ use std::{fs::File, path::PathBuf}; pub mod mock_minimal { use super::*; - + use crate::config::minimal; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -69,7 +69,7 @@ pub mod mock_minimal { } parameter_types! { - pub const MaxSyncCommitteeSize: u32 = config::SYNC_COMMITTEE_SIZE as u32; + pub const MaxSyncCommitteeSize: u32 = minimal::SYNC_COMMITTEE_SIZE as u32; pub const MaxProofBranchSize: u32 = 20; pub const MaxExtraDataSize: u32 = config::MAX_EXTRA_DATA_BYTES as u32; pub const MaxLogsBloomSize: u32 = config::MAX_LOGS_BLOOM_SIZE as u32; @@ -110,11 +110,17 @@ pub mod mock_minimal { type ForkVersions = ChainForkVersions; type WeakSubjectivityPeriodSeconds = WeakSubjectivityPeriodSeconds; type WeightInfo = (); + + const SLOTS_PER_EPOCH: u64 = minimal::SLOTS_PER_EPOCH; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = minimal::EPOCHS_PER_SYNC_COMMITTEE_PERIOD; + const SYNC_COMMITTEE_SIZE: usize = minimal::SYNC_COMMITTEE_SIZE; + const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = minimal::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH; } } pub mod mock_mainnet { use super::*; + use crate::config::mainnet; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -171,7 +177,7 @@ pub mod mock_mainnet { } parameter_types! { - pub const MaxSyncCommitteeSize: u32 = config::SYNC_COMMITTEE_SIZE as u32; + pub const MaxSyncCommitteeSize: u32 = mainnet::SYNC_COMMITTEE_SIZE as u32; pub const MaxProofBranchSize: u32 = 20; pub const MaxExtraDataSize: u32 = config::MAX_EXTRA_DATA_BYTES as u32; pub const MaxLogsBloomSize: u32 = config::MAX_LOGS_BLOOM_SIZE as u32; @@ -212,6 +218,11 @@ pub mod mock_mainnet { type ForkVersions = ChainForkVersions; type WeakSubjectivityPeriodSeconds = WeakSubjectivityPeriodSeconds; type WeightInfo = (); + + const SLOTS_PER_EPOCH: u64 = mainnet::SLOTS_PER_EPOCH; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = mainnet::EPOCHS_PER_SYNC_COMMITTEE_PERIOD; + const SYNC_COMMITTEE_SIZE: usize = mainnet::SYNC_COMMITTEE_SIZE; + const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = mainnet::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH; } } @@ -276,11 +287,13 @@ fn header_update_from_file( serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } -fn get_config_setting() -> String { - return match config::IS_MINIMAL { - true => "minimal".to_owned(), - false => "mainnet".to_owned(), - } +#[cfg(feature = "minimal")] +fn get_config_setting() -> &'static str { + "minimal" +} +#[cfg(not(feature = "minimal"))] +fn get_config_setting() -> &'static str { + "mainnet" } fn add_file_prefix(name: &str) -> String { diff --git a/parachain/pallets/ethereum-beacon-client/src/ssz.rs b/parachain/pallets/ethereum-beacon-client/src/ssz.rs index a04ba99d59..2a634bf0e2 100644 --- a/parachain/pallets/ethereum-beacon-client/src/ssz.rs +++ b/parachain/pallets/ethereum-beacon-client/src/ssz.rs @@ -16,14 +16,14 @@ pub struct SSZBeaconBlockHeader { } #[derive(Default, SimpleSerialize)] -pub struct SSZSyncCommittee { - pub pubkeys: Vector, { config::SYNC_COMMITTEE_SIZE }>, +pub struct SSZSyncCommittee { + pub pubkeys: Vector, SYNC_COMMITTEE_SIZE>, pub aggregate_pubkey: Vector, } #[derive(Default, Debug, SimpleSerialize, Clone)] -pub struct SSZSyncAggregate { - pub sync_committee_bits: Bitvector<{ config::SYNC_COMMITTEE_SIZE }>, +pub struct SSZSyncAggregate { + pub sync_committee_bits: Bitvector, pub sync_committee_signature: Vector, } diff --git a/parachain/pallets/ethereum-beacon-client/src/tests.rs b/parachain/pallets/ethereum-beacon-client/src/tests.rs index bf117adeff..079aaa9ba1 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests.rs @@ -1,7 +1,7 @@ mod beacon_tests { use crate as ethereum_beacon_client; use crate::{ - config, merkleization, + merkleization, merkleization::MerkleizationError, mock::*, ssz::{SSZExecutionPayload, SSZSyncAggregate}, @@ -13,6 +13,13 @@ mod beacon_tests { use sp_core::{H256, U256}; use ssz_rs::prelude::Vector; + pub(crate) mod config { + #[cfg(not(feature = "minimal"))] + pub(crate) use crate::config::mainnet::*; + #[cfg(feature = "minimal")] + pub(crate) use crate::config::minimal::*; + } + #[test] pub fn test_get_sync_committee_sum() { new_tester::().execute_with(|| { @@ -300,6 +307,7 @@ mod beacon_tests { let sync_committee_bits = merkleization::get_sync_committee_bits::< mock_minimal::MaxSyncCommitteeSize, + { config::SYNC_COMMITTEE_SIZE }, >(bits.try_into().expect("too many sync committee bits")); assert_ok!(&sync_committee_bits); @@ -328,6 +336,7 @@ mod beacon_tests { let sync_committee_bits = merkleization::get_sync_committee_bits::< mock_minimal::MaxSyncCommitteeSize, + { config::SYNC_COMMITTEE_SIZE }, >(bits.try_into().expect("invalid sync committee bits")); assert_err!( @@ -353,6 +362,7 @@ mod beacon_tests { let sync_committee_bits = merkleization::get_sync_committee_bits::< mock_minimal::MaxSyncCommitteeSize, + { config::SYNC_COMMITTEE_SIZE }, >(bits.try_into().expect("invalid sync committee bits")); assert_err!( @@ -499,7 +509,8 @@ mod beacon_tests { hex!("e6dcad4f60ce9ff8a587b110facbaf94721f06cd810b6d8bf6cffa641272808d").into(), }; - let payload: Result = sync_aggregate.try_into(); + let payload: Result, MerkleizationError> = + sync_aggregate.try_into(); assert_ok!(&payload); let hash_root_result = merkleization::hash_tree_root(payload.unwrap()); diff --git a/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs b/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs index c612076757..f98a935d1a 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "minimal"))] mod beacon_mainnet_tests { use crate::{ - config, merkleization, mock::*, Error, ExecutionHeaders, FinalizedBeaconHeaders, + config::mainnet, merkleization, mock::*, Error, ExecutionHeaders, FinalizedBeaconHeaders, FinalizedBeaconHeadersBlockRoot, FinalizedHeaderState, LatestFinalizedHeaderState, LatestSyncCommitteePeriod, SyncCommittees, ValidatorsRoot, }; @@ -66,7 +66,7 @@ mod beacon_mainnet_tests { ); let slot = update.finalized_header.slot; - let import_time = 1616508000u64 + (slot * config::SECONDS_PER_SLOT); // Goerli genesis time + finalized header update time + let import_time = 1616508000u64 + (slot * mainnet::SECONDS_PER_SLOT); // Goerli genesis time + finalized header update time let mock_pallet_time = import_time + 3600; // plus one hour new_tester::().execute_with(|| { @@ -104,7 +104,7 @@ mod beacon_mainnet_tests { ); let slot = update.finalized_header.slot; - let import_time = 1616508000u64 + (slot * config::SECONDS_PER_SLOT); + let import_time = 1616508000u64 + (slot * mainnet::SECONDS_PER_SLOT); let mock_pallet_time = import_time + 100800; // plus 28 hours new_tester::().execute_with(|| { @@ -172,7 +172,10 @@ mod beacon_mainnet_tests { #[test] pub fn test_hash_tree_root_sync_committee() { let sync_committee = get_committee_sync_ssz_test_data::(); - let hash_root_result = merkleization::hash_tree_root_sync_committee(sync_committee); + let hash_root_result = merkleization::hash_tree_root_sync_committee::< + _, + { mainnet::SYNC_COMMITTEE_SIZE }, + >(sync_committee); assert_ok!(&hash_root_result); let hash_root: H256 = hash_root_result.unwrap().into(); @@ -187,9 +190,10 @@ mod beacon_mainnet_tests { let test_data = get_bls_signature_verify_test_data::(); let sync_committee_bits = - merkleization::get_sync_committee_bits::( - test_data.sync_committee_bits.try_into().expect("too many sync committee bits"), - ); + merkleization::get_sync_committee_bits::< + mock_mainnet::MaxSyncCommitteeSize, + { mainnet::SYNC_COMMITTEE_SIZE }, + >(test_data.sync_committee_bits.try_into().expect("too many sync committee bits")); assert_ok!(&sync_committee_bits); diff --git a/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs b/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs index 807b19a166..3544ac01d2 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs @@ -1,7 +1,7 @@ #[cfg(feature = "minimal")] mod beacon_minimal_tests { use crate::{ - config, merkleization, mock::*, pallet::FinalizedBeaconHeadersBlockRoot, Error, + config::minimal, merkleization, mock::*, pallet::FinalizedBeaconHeadersBlockRoot, Error, ExecutionHeaderState, ExecutionHeaders, FinalizedBeaconHeaders, FinalizedHeaderState, LatestExecutionHeaderState, LatestFinalizedHeaderState, LatestSyncCommitteePeriod, SyncCommittees, ValidatorsRoot, @@ -163,7 +163,7 @@ mod beacon_minimal_tests { .expect("Time went backwards") .as_secs(); - let import_time = time_now + (update.finalized_header.slot * config::SECONDS_PER_SLOT); // Goerli genesis time + finalized header update time + let import_time = time_now + (update.finalized_header.slot * minimal::SECONDS_PER_SLOT); // Goerli genesis time + finalized header update time let mock_pallet_time = import_time + 3600; // plus one hour new_tester::().execute_with(|| { @@ -364,7 +364,10 @@ mod beacon_minimal_tests { #[test] pub fn test_hash_tree_root_sync_committee() { let sync_committee = get_committee_sync_ssz_test_data::(); - let hash_root_result = merkleization::hash_tree_root_sync_committee(sync_committee); + let hash_root_result = merkleization::hash_tree_root_sync_committee::< + _, + { minimal::SYNC_COMMITTEE_SIZE }, + >(sync_committee); assert_ok!(&hash_root_result); let hash_root: H256 = hash_root_result.unwrap().into(); @@ -379,9 +382,10 @@ mod beacon_minimal_tests { let test_data = get_bls_signature_verify_test_data::(); let sync_committee_bits = - merkleization::get_sync_committee_bits::( - test_data.sync_committee_bits.try_into().expect("too many sync committee bits"), - ); + merkleization::get_sync_committee_bits::< + mock_minimal::MaxSyncCommitteeSize, + { minimal::SYNC_COMMITTEE_SIZE }, + >(test_data.sync_committee_bits.try_into().expect("too many sync committee bits")); assert_ok!(&sync_committee_bits); diff --git a/parachain/runtime/snowbase/Cargo.toml b/parachain/runtime/snowbase/Cargo.toml index 9093a9c55d..a5d73cbea9 100644 --- a/parachain/runtime/snowbase/Cargo.toml +++ b/parachain/runtime/snowbase/Cargo.toml @@ -72,7 +72,7 @@ runtime-primitives = { path = "../../primitives/runtime", default-features = fal snowbridge-basic-channel = { path = "../../pallets/basic-channel", default-features = false } dispatch = { path = "../../pallets/dispatch", package = "snowbridge-dispatch", default-features = false } -ethereum-beacon-client = { path = "../../pallets/ethereum-beacon-client", package = "snowbridge-ethereum-beacon-client", default-features = false, features=["minimal"]} +ethereum-beacon-client = { path = "../../pallets/ethereum-beacon-client", package = "snowbridge-ethereum-beacon-client", default-features = false } runtime-common = { path = "../common", package = "snowbridge-runtime-common", default-features = false } snowbridge-beacon-primitives = { path = "../../primitives/beacon", default-features = false } diff --git a/parachain/runtime/snowbase/src/lib.rs b/parachain/runtime/snowbase/src/lib.rs index 790c7693ea..be15646233 100644 --- a/parachain/runtime/snowbase/src/lib.rs +++ b/parachain/runtime/snowbase/src/lib.rs @@ -2,6 +2,8 @@ #![cfg_attr(not(feature = "std"), no_std)] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] // Make the WASM binary available. #[cfg(feature = "std")] @@ -10,6 +12,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod weights; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use ethereum_beacon_client::config::minimal; use snowbridge_beacon_primitives::{Fork, ForkVersions}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, ConstU32, OpaqueMetadata}; @@ -599,14 +602,14 @@ impl basic_channel_outbound::Config for Runtime { } parameter_types! { - pub const MaxSyncCommitteeSize: u32 = 32; + pub const MaxSyncCommitteeSize: u32 = minimal::SYNC_COMMITTEE_SIZE as u32; pub const MaxProofBranchSize: u32 = 20; pub const MaxExtraDataSize: u32 = 32; pub const MaxLogsBloomSize: u32 = 256; pub const MaxFeeRecipientSize: u32 = 20; pub const MaxPublicKeySize: u32 = 48; pub const MaxSignatureSize: u32 = 96; - pub const MaxSlotsPerHistoricalRoot: u64 = 64; + pub const MaxSlotsPerHistoricalRoot: u64 = minimal::SLOTS_PER_HISTORICAL_ROOT as u64; pub const MaxFinalizedHeaderSlotArray: u32 = 1000; pub const WeakSubjectivityPeriodSeconds: u32 = 97200; pub const ChainForkVersions: ForkVersions = ForkVersions{ @@ -640,6 +643,11 @@ impl ethereum_beacon_client::Config for Runtime { type ForkVersions = ChainForkVersions; type WeakSubjectivityPeriodSeconds = WeakSubjectivityPeriodSeconds; type WeightInfo = weights::ethereum_beacon_client::SnowbridgeWeight; + + const SLOTS_PER_EPOCH: u64 = minimal::SLOTS_PER_EPOCH; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = minimal::EPOCHS_PER_SYNC_COMMITTEE_PERIOD; + const SYNC_COMMITTEE_SIZE: usize = minimal::SYNC_COMMITTEE_SIZE; + const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = minimal::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH; } parameter_types! { diff --git a/parachain/runtime/snowblink/src/lib.rs b/parachain/runtime/snowblink/src/lib.rs index d79f5cfaaa..eeb96f9399 100644 --- a/parachain/runtime/snowblink/src/lib.rs +++ b/parachain/runtime/snowblink/src/lib.rs @@ -2,12 +2,15 @@ #![cfg_attr(not(feature = "std"), no_std)] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] // Make the WASM binary available. #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; +use ethereum_beacon_client::config::mainnet; use snowbridge_beacon_primitives::{Fork, ForkVersions}; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, ConstU32, OpaqueMetadata}; @@ -597,14 +600,14 @@ impl basic_channel_outbound::Config for Runtime { } parameter_types! { - pub const MaxSyncCommitteeSize: u32 = 512; + pub const MaxSyncCommitteeSize: u32 = mainnet::SYNC_COMMITTEE_SIZE as u32; pub const MaxProofBranchSize: u32 = 20; pub const MaxExtraDataSize: u32 = 32; pub const MaxLogsBloomSize: u32 = 256; pub const MaxFeeRecipientSize: u32 = 20; pub const MaxPublicKeySize: u32 = 48; pub const MaxSignatureSize: u32 = 96; - pub const MaxSlotsPerHistoricalRoot: u64 = 8192; + pub const MaxSlotsPerHistoricalRoot: u64 = mainnet::SLOTS_PER_HISTORICAL_ROOT as u64; pub const MaxFinalizedHeaderSlotArray: u32 = 1000; pub const WeakSubjectivityPeriodSeconds: u32 = 97200; pub const ChainForkVersions: ForkVersions = ForkVersions{ @@ -638,6 +641,11 @@ impl ethereum_beacon_client::Config for Runtime { type ForkVersions = ChainForkVersions; type WeakSubjectivityPeriodSeconds = WeakSubjectivityPeriodSeconds; type WeightInfo = ethereum_beacon_client::weights::SnowbridgeWeight; + + const SLOTS_PER_EPOCH: u64 = mainnet::SLOTS_PER_EPOCH; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = mainnet::EPOCHS_PER_SYNC_COMMITTEE_PERIOD; + const SYNC_COMMITTEE_SIZE: usize = mainnet::SYNC_COMMITTEE_SIZE; + const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = mainnet::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH; } parameter_types! { diff --git a/parachain/runtime/snowbridge/src/lib.rs b/parachain/runtime/snowbridge/src/lib.rs index 6edbf013dc..0716316174 100644 --- a/parachain/runtime/snowbridge/src/lib.rs +++ b/parachain/runtime/snowbridge/src/lib.rs @@ -2,6 +2,8 @@ #![cfg_attr(not(feature = "std"), no_std)] // `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. #![recursion_limit = "256"] +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] // Make the WASM binary available. #[cfg(feature = "std")] @@ -65,6 +67,7 @@ use xcm_builder::{ UsingComponents, }; +use ethereum_beacon_client::config::mainnet; use xcm_executor::{traits::JustTry, Config, XcmExecutor}; use runtime_common::{fee::WeightToFee, MaxMessagePayloadSize, MaxMessagesPerCommit}; @@ -597,14 +600,14 @@ impl basic_channel_outbound::Config for Runtime { } parameter_types! { - pub const MaxSyncCommitteeSize: u32 = 512; + pub const MaxSyncCommitteeSize: u32 = mainnet::SYNC_COMMITTEE_SIZE as u32; pub const MaxProofBranchSize: u32 = 20; pub const MaxExtraDataSize: u32 = 32; pub const MaxLogsBloomSize: u32 = 256; pub const MaxFeeRecipientSize: u32 = 20; pub const MaxPublicKeySize: u32 = 48; pub const MaxSignatureSize: u32 = 96; - pub const MaxSlotsPerHistoricalRoot: u64 = 8192; + pub const MaxSlotsPerHistoricalRoot: u64 = mainnet::SLOTS_PER_HISTORICAL_ROOT as u64; pub const MaxFinalizedHeaderSlotArray: u32 = 1000; pub const WeakSubjectivityPeriodSeconds: u32 = 97200; pub const ChainForkVersions: ForkVersions = ForkVersions{ @@ -638,6 +641,11 @@ impl ethereum_beacon_client::Config for Runtime { type ForkVersions = ChainForkVersions; type WeakSubjectivityPeriodSeconds = WeakSubjectivityPeriodSeconds; type WeightInfo = ethereum_beacon_client::weights::SnowbridgeWeight; + + const SLOTS_PER_EPOCH: u64 = mainnet::SLOTS_PER_EPOCH; + const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: u64 = mainnet::EPOCHS_PER_SYNC_COMMITTEE_PERIOD; + const SYNC_COMMITTEE_SIZE: usize = mainnet::SYNC_COMMITTEE_SIZE; + const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: u64 = mainnet::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH; } parameter_types! {