From 820ec5d8d8e1a9973790e05ccc9f7d3ca88fac53 Mon Sep 17 00:00:00 2001 From: Clara van Staden Date: Thu, 15 Sep 2022 09:22:50 +0200 Subject: [PATCH] Implements MaxEncodedLen for beacon client (#684) * Progress on MaxEncodedLen. * Rename generics to actual words since characters dont make sense anymore * Wading through compiler errors... * Cleans up constants * Separate structs using Serialize and maxEncodedLen * Progress * Finish up with MaxEncodedLen work * Cleanup. * Fix whitespace * Missed whitespace. * More whitespace. * Alias bounded structs. Minor cleanup. * Public aliases. --- .../ethereum-beacon-client/src/config.rs | 7 +- .../pallets/ethereum-beacon-client/src/lib.rs | 91 ++-- .../src/merkleization.rs | 83 +++- .../ethereum-beacon-client/src/mock.rs | 108 ++++- .../pallets/ethereum-beacon-client/src/ssz.rs | 22 +- .../ethereum-beacon-client/src/tests.rs | 44 +- parachain/primitives/beacon/src/lib.rs | 437 ++++++++++++++---- parachain/runtime/snowbase/src/lib.rs | 33 +- parachain/runtime/snowblink/src/lib.rs | 33 +- parachain/runtime/snowbridge/src/lib.rs | 33 +- 10 files changed, 700 insertions(+), 191 deletions(-) diff --git a/parachain/pallets/ethereum-beacon-client/src/config.rs b/parachain/pallets/ethereum-beacon-client/src/config.rs index 0caa56735503e..eda2b770c4b89 100644 --- a/parachain/pallets/ethereum-beacon-client/src/config.rs +++ b/parachain/pallets/ethereum-beacon-client/src/config.rs @@ -28,6 +28,8 @@ pub const MAX_DEPOSITS: usize = 16; pub const MAX_VOLUNTARY_EXITS: usize = 16; pub const MAX_VALIDATORS_PER_COMMITTEE: usize = 2048; pub const MAX_EXTRA_DATA_BYTES: usize = 32; +pub const MAX_LOGS_BLOOM_SIZE: usize = 256; +pub const MAX_FEE_RECIPIENT_SIZE: usize = 20; pub const DEPOSIT_CONTRACT_TREE_DEPTH: usize = 32; @@ -36,4 +38,7 @@ pub const GENESIS_FORK_VERSION: ForkVersion = [30, 30, 30, 30]; /// DomainType('0x07000000') /// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#domain-types -pub const DOMAIN_SYNC_COMMITTEE: [u8; 4] = [7, 0, 0, 0]; \ No newline at end of file +pub const DOMAIN_SYNC_COMMITTEE: [u8; 4] = [7, 0, 0, 0]; + +pub const PUBKEY_SIZE: usize = 48; +pub const SIGNATURE_SIZE: usize = 96; diff --git a/parachain/pallets/ethereum-beacon-client/src/lib.rs b/parachain/pallets/ethereum-beacon-client/src/lib.rs index 1beb02c01de23..0067f340335b0 100644 --- a/parachain/pallets/ethereum-beacon-client/src/lib.rs +++ b/parachain/pallets/ethereum-beacon-client/src/lib.rs @@ -14,13 +14,21 @@ use frame_system::ensure_signed; use sp_core::H256; use sp_io::hashing::sha2_256; use sp_std::prelude::*; -use snowbridge_beacon_primitives::{SyncCommittee, BeaconHeader, ForkData, Root, Domain, PublicKey, SigningData, ExecutionHeader, - ProofBranch, ForkVersion, SyncCommitteePeriodUpdate, FinalizedHeaderUpdate, InitialSync, BlockUpdate}; +use snowbridge_beacon_primitives::{SyncCommittee, BeaconHeader, ForkData, Root, Domain, PublicKey, SigningData, ExecutionHeader, ForkVersion, SyncCommitteePeriodUpdate, FinalizedHeaderUpdate, InitialSync, BlockUpdate}; use snowbridge_core::{Message, Verifier}; use crate::merkleization::get_sync_committee_bits; pub use pallet::*; +pub type BlockUpdateOf = BlockUpdate<::MaxFeeRecipientSize, ::MaxLogsBloomSize, ::MaxExtraDataSize, ::MaxDepositDataSize, +::MaxPublicKeySize, ::MaxSignatureSize, ::MaxProofBranchSize, ::MaxProposerSlashingSize, ::MaxAttesterSlashingSize, +::MaxVoluntaryExitSize, ::MaxAttestationSize,::MaxValidatorsPerCommittee, ::MaxSyncCommitteeSize>; +pub type InitialSyncOf = InitialSync<::MaxSyncCommitteeSize, ::MaxProofBranchSize>; +pub type SyncCommitteePeriodUpdateOf = SyncCommitteePeriodUpdate<::MaxSignatureSize, ::MaxProofBranchSize, ::MaxSyncCommitteeSize>; +pub type FinalizedHeaderUpdateOf = FinalizedHeaderUpdate<::MaxSignatureSize, ::MaxProofBranchSize, ::MaxSyncCommitteeSize>; +pub type ExecutionHeaderOf = ExecutionHeader<::MaxLogsBloomSize, ::MaxExtraDataSize>; +pub type SyncCommitteeOf = SyncCommittee<::MaxSyncCommitteeSize>; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -35,12 +43,37 @@ pub mod pallet { #[pallet::pallet] #[pallet::generate_store(pub(super) trait Store)] - #[pallet::without_storage_info] pub struct Pallet(_); #[pallet::config] pub trait Config: frame_system::Config { type Event: From> + IsType<::Event>; + #[pallet::constant] + type MaxSyncCommitteeSize: Get; + #[pallet::constant] + type MaxProofBranchSize: Get; + #[pallet::constant] + type MaxExtraDataSize: Get; + #[pallet::constant] + type MaxLogsBloomSize: Get; + #[pallet::constant] + type MaxFeeRecipientSize: Get; + #[pallet::constant] + type MaxDepositDataSize: Get; + #[pallet::constant] + type MaxPublicKeySize: Get; + #[pallet::constant] + type MaxSignatureSize: Get; + #[pallet::constant] + type MaxProposerSlashingSize: Get; + #[pallet::constant] + type MaxAttesterSlashingSize: Get; + #[pallet::constant] + type MaxVoluntaryExitSize: Get; + #[pallet::constant] + type MaxAttestationSize: Get; + #[pallet::constant] + type MaxValidatorsPerCommittee: Get; } #[pallet::event] @@ -81,13 +114,13 @@ pub mod pallet { #[pallet::storage] pub(super) type ExecutionHeaders = - StorageMap<_, Identity, H256, ExecutionHeader, OptionQuery>; + StorageMap<_, Identity, H256, ExecutionHeaderOf, OptionQuery>; /// Current sync committee corresponding to the active header. /// TODO prune older sync committees than xxx #[pallet::storage] pub(super) type SyncCommittees = - StorageMap<_, Identity, u64, SyncCommittee, ValueQuery>; + StorageMap<_, Identity, u64, SyncCommitteeOf, ValueQuery>; #[pallet::storage] pub(super) type ValidatorsRoot = StorageValue<_, H256, ValueQuery>; @@ -102,19 +135,19 @@ pub mod pallet { pub(super) type LatestSyncCommitteePeriod = StorageValue<_, u64, ValueQuery>; #[pallet::genesis_config] - pub struct GenesisConfig { - pub initial_sync: InitialSync, + pub struct GenesisConfig { + pub initial_sync: InitialSyncOf, } #[cfg(feature = "std")] - impl Default for GenesisConfig { + impl Default for GenesisConfig { fn default() -> Self { GenesisConfig { initial_sync: Default::default(), }} } #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl GenesisBuild for GenesisConfig { fn build(&self) { log::info!( target: "ethereum-beacon-client", @@ -135,7 +168,7 @@ pub mod pallet { #[transactional] pub fn sync_committee_period_update( origin: OriginFor, - sync_committee_period_update: SyncCommitteePeriodUpdate, + sync_committee_period_update: SyncCommitteePeriodUpdateOf, ) -> DispatchResult { let _sender = ensure_signed(origin)?; @@ -168,7 +201,7 @@ pub mod pallet { #[transactional] pub fn import_finalized_header( origin: OriginFor, - finalized_header_update: FinalizedHeaderUpdate, + finalized_header_update: FinalizedHeaderUpdateOf, ) -> DispatchResult { let _sender = ensure_signed(origin)?; @@ -202,7 +235,7 @@ pub mod pallet { #[transactional] pub fn import_execution_header( origin: OriginFor, - update: BlockUpdate, + update: BlockUpdateOf, ) -> DispatchResult { let _sender = ensure_signed(origin)?; @@ -236,7 +269,7 @@ pub mod pallet { } impl Pallet { - fn process_initial_sync(initial_sync: InitialSync) -> DispatchResult { + fn process_initial_sync(initial_sync: InitialSyncOf) -> DispatchResult { Self::verify_sync_committee( initial_sync.current_sync_committee.clone(), initial_sync.current_sync_committee_branch, @@ -258,7 +291,7 @@ pub mod pallet { } fn process_sync_committee_period_update( - update: SyncCommitteePeriodUpdate, + update: SyncCommitteePeriodUpdateOf, ) -> DispatchResult { let sync_committee_bits = get_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone()) .map_err(|_| DispatchError::Other("Couldn't process sync committee bits"))?; @@ -300,7 +333,7 @@ pub mod pallet { Ok(()) } - fn process_finalized_header(update: FinalizedHeaderUpdate) -> DispatchResult { + fn process_finalized_header(update: FinalizedHeaderUpdateOf) -> DispatchResult { let sync_committee_bits = get_sync_committee_bits(update.sync_aggregate.sync_committee_bits.clone()) .map_err(|_| DispatchError::Other("Couldn't process sync committee bits"))?; Self::sync_committee_participation_is_supermajority(sync_committee_bits.clone())?; @@ -333,7 +366,7 @@ pub mod pallet { Ok(()) } - fn process_header(update: BlockUpdate) -> DispatchResult { + fn process_header(update: BlockUpdateOf) -> DispatchResult { let latest_finalized_header_slot = >::get(); let block_slot = update.block.slot; if block_slot > latest_finalized_header_slot { @@ -410,8 +443,8 @@ pub mod pallet { pub(super) fn verify_signed_header( sync_committee_bits: Vec, - sync_committee_signature: Vec, - sync_committee_pubkeys: Vec, + sync_committee_signature: BoundedVec, + sync_committee_pubkeys: BoundedVec, fork_version: ForkVersion, header: BeaconHeader, validators_root: H256, @@ -444,7 +477,7 @@ pub mod pallet { pub(super) fn bls_fast_aggregate_verify( pubkeys: Vec, message: H256, - signature: Vec, + signature: BoundedVec, ) -> DispatchResult { let sig = Signature::from_bytes(&signature[..]); if let Err(_e) = sig { @@ -498,8 +531,8 @@ pub mod pallet { } fn verify_sync_committee( - sync_committee: SyncCommittee, - sync_committee_branch: ProofBranch, + sync_committee: SyncCommitteeOf, + sync_committee_branch: BoundedVec, header_state_root: H256, depth: u64, index: u64, @@ -524,7 +557,7 @@ pub mod pallet { fn verify_header( block_root: H256, - proof_branch: ProofBranch, + proof_branch: BoundedVec, attested_header_state_root: H256, depth: u64, index: u64, @@ -543,7 +576,7 @@ pub mod pallet { Ok(()) } - fn store_sync_committee(period: u64, sync_committee: SyncCommittee) { + fn store_sync_committee(period: u64, sync_committee: SyncCommitteeOf) { >::insert(period, sync_committee); let latest_committee_period = >::get(); @@ -591,7 +624,7 @@ pub mod pallet { Self::deposit_event(Event::BeaconHeaderImported{block_hash: block_root, slot: slot}); } - fn store_execution_header(block_root: H256, header: ExecutionHeader) { + fn store_execution_header(block_root: H256, header: ExecutionHeaderOf) { let block_number = header.block_number; >::insert(block_root, header); @@ -655,7 +688,7 @@ pub mod pallet { pub(super) fn is_valid_merkle_branch( leaf: H256, - branch: Vec, + branch: BoundedVec, depth: u64, index: u64, root: Root, @@ -704,7 +737,7 @@ pub mod pallet { Ok(()) } - pub(super) fn get_sync_committee_for_period(period: u64) -> Result { + pub(super) fn get_sync_committee_for_period(period: u64) -> Result, DispatchError> { let sync_committee = >::get(period); if sync_committee.pubkeys.len() == 0 { @@ -716,7 +749,7 @@ pub mod pallet { } pub(super) fn initial_sync( - initial_sync: InitialSync, + initial_sync: InitialSyncOf, ) -> Result<(), &'static str> { log::info!( target: "ethereum-beacon-client", @@ -743,7 +776,7 @@ pub mod pallet { // Verifies that the receipt encoded in proof.data is included // in the block given by proof.block_hash. Inclusion is only // recognized if the block has been finalized. - fn verify_receipt_inclusion(stored_header: ExecutionHeader, proof: &Proof) -> Result { + fn verify_receipt_inclusion(stored_header: ExecutionHeaderOf, proof: &Proof) -> Result { let result = stored_header .check_receipt_proof(&proof.data.1) .ok_or(Error::::InvalidProof)?; @@ -837,4 +870,4 @@ pub mod pallet { Ok(()) } } -} +} \ No newline at end of file diff --git a/parachain/pallets/ethereum-beacon-client/src/merkleization.rs b/parachain/pallets/ethereum-beacon-client/src/merkleization.rs index 176f698a89439..3bb3a81edf2fa 100644 --- a/parachain/pallets/ethereum-beacon-client/src/merkleization.rs +++ b/parachain/pallets/ethereum-beacon-client/src/merkleization.rs @@ -1,3 +1,5 @@ +use frame_support::BoundedVec; +use frame_support::traits::Get; use ssz_rs::{Deserialize, SimpleSerialize as SimpleSerializeTrait, Bitlist, Bitvector}; use ssz_rs::prelude::{Vector, List}; use sp_std::convert::TryInto; @@ -16,7 +18,33 @@ pub enum MerkleizationError { InvalidLength, } -pub fn get_ssz_beacon_block_body(body: Body) -> Result { +pub fn get_ssz_beacon_block_body< + FeeRecipientSize: Get, + LogsBloomSize: Get, + ExtraDataSize: Get, + DepositDataSize: Get, + PublicKeySize: Get, + SignatureSize: Get, + ProofSize: Get, + ProposerSlashingSize: Get, + AttesterSlashingSize: Get, + VoluntaryExitSize: Get, + AttestationSize: Get, + AggregationBitsSize: Get, + ValidatorCommitteeSize: Get> + (body: Body) -> Result { Ok(SSZBeaconBlockBody{ randao_reveal: Vector::::from_iter(body.randao_reveal), eth1_data: get_ssz_eth1_data(body.eth1_data)?, @@ -31,7 +59,7 @@ pub fn get_ssz_beacon_block_body(body: Body) -> Result Result { +pub fn get_ssz_execution_payload, LogsBloomSize: Get, ExtraDataSize: Get>(execution_payload: ExecutionPayload) -> Result { let ssz_execution_payload = SSZExecutionPayload{ parent_hash: execution_payload.parent_hash.as_bytes().try_into().map_err(|_| MerkleizationError::InvalidLength)?, fee_recipient: Vector::::from_iter(execution_payload.fee_recipient), @@ -43,7 +71,7 @@ pub fn get_ssz_execution_payload(execution_payload: ExecutionPayload) -> Result< gas_limit: execution_payload.gas_limit, gas_used: execution_payload.gas_used, timestamp: execution_payload.timestamp, - extra_data: List::::try_from(execution_payload.extra_data).map_err(|_| MerkleizationError::InvalidLength)?, + extra_data: List::::try_from(execution_payload.extra_data.into_inner()).map_err(|_| MerkleizationError::InvalidLength)?, base_fee_per_gas: U256::try_from_bytes_le(&(execution_payload.base_fee_per_gas.as_byte_slice())).map_err(|_| MerkleizationError::InvalidLength)?, block_hash: execution_payload.block_hash.as_bytes().try_into().map_err(|_| MerkleizationError::InvalidLength)?, transactions_root: execution_payload.transactions_root.as_bytes().try_into().map_err(|_| MerkleizationError::InvalidLength)?, @@ -52,7 +80,7 @@ pub fn get_ssz_execution_payload(execution_payload: ExecutionPayload) -> Result< Ok(ssz_execution_payload) } -pub fn get_ssz_deposits(deposits: Vec) -> Result, MerkleizationError> { +pub fn get_ssz_deposits, SignatureSize: Get, ProofSize: Get, DepositSize: Get>(deposits: BoundedVec, DepositSize>) -> Result, MerkleizationError> { let mut deposits_dev = Vec::new(); for deposit in deposits.iter() { @@ -78,7 +106,7 @@ pub fn get_ssz_deposits(deposits: Vec) -> Result::from_iter(deposits_dev)) } -pub fn get_ssz_voluntary_exits(voluntary_exits: Vec) -> Result, MerkleizationError> { +pub fn get_ssz_voluntary_exits>(voluntary_exits: BoundedVec) -> Result, MerkleizationError> { let mut voluntary_exits_vec = Vec::new(); for voluntary_exit in voluntary_exits.iter() { @@ -91,7 +119,7 @@ pub fn get_ssz_voluntary_exits(voluntary_exits: Vec) -> Result
  • ::from_iter(voluntary_exits_vec)) } -pub fn get_ssz_attestations(attestations: Vec) -> Result, MerkleizationError> { +pub fn get_ssz_attestations, SignatureSize: Get, AttestationSize: Get>(attestations: BoundedVec, AttestationSize>) -> Result, MerkleizationError> { let mut attestations_vec = Vec::new(); for attestation in attestations.iter() { @@ -101,7 +129,7 @@ pub fn get_ssz_attestations(attestations: Vec) -> Result::from_iter(attestations_vec)) } -pub fn get_ssz_attestation(attestation: Attestation) -> Result { +pub fn get_ssz_attestation, SignatureSize: Get>(attestation: Attestation) -> Result { let signature = Vector::::from_iter(attestation.signature.clone()); Ok(SSZAttestation{ @@ -121,7 +149,7 @@ pub fn get_ssz_attestation_data(attestation_data: AttestationData) -> Result) -> Result, MerkleizationError> { +pub fn get_ssz_proposer_slashings, SignatureSize: Get>(proposer_slashings: BoundedVec, ProposerSlashingSize>) -> Result, MerkleizationError> { let mut proposer_slashings_vec = Vec::new(); for proposer_slashing in proposer_slashings.iter() { @@ -131,7 +159,7 @@ pub fn get_ssz_proposer_slashings(proposer_slashings: Vec) -> Ok(List::::from_iter(proposer_slashings_vec)) } -pub fn get_ssz_proposer_slashing(proposer_slashing: ProposerSlashing) -> Result { +pub fn get_ssz_proposer_slashing>(proposer_slashing: ProposerSlashing) -> Result { let signature1 = Vector::::from_iter(proposer_slashing.signed_header_1.signature.clone()); let signature2 = Vector::::from_iter(proposer_slashing.signed_header_2.signature.clone()); @@ -147,7 +175,7 @@ pub fn get_ssz_proposer_slashing(proposer_slashing: ProposerSlashing) -> Result< }) } -pub fn get_ssz_attester_slashings(attester_slashings: Vec) -> Result, MerkleizationError> { +pub fn get_ssz_attester_slashings, SignatureSize: Get, AttesterSlashingSize: Get>(attester_slashings: BoundedVec, AttesterSlashingSize>) -> Result, MerkleizationError> { let mut attester_slashings_vec = Vec::new(); for attester_slashing in attester_slashings.iter() { @@ -157,7 +185,7 @@ pub fn get_ssz_attester_slashings(attester_slashings: Vec) -> Ok(List::::from_iter(attester_slashings_vec)) } -pub fn get_ssz_attester_slashing(attester_slashing: AttesterSlashing) -> Result { +pub fn get_ssz_attester_slashing, SignatureSize: Get>(attester_slashing: AttesterSlashing) -> Result { let signature1 = Vector::::from_iter(attester_slashing.attestation_1.signature.clone()); let signature2 = Vector::::from_iter(attester_slashing.attestation_2.signature.clone()); @@ -195,7 +223,7 @@ pub fn get_ssz_beacon_header(beacon_header: BeaconHeader) -> Result Result { +pub fn get_ssz_sync_aggregate, SignatureSize: Get>(sync_aggregate: SyncAggregate) -> Result { Ok(SSZSyncAggregate{ sync_committee_bits: Bitvector::<{ config::SYNC_COMMITTEE_SIZE }>::deserialize(&sync_aggregate.sync_committee_bits).map_err(|_| MerkleizationError::InvalidLength)?, @@ -215,11 +243,36 @@ pub fn hash_tree_root_beacon_header(beacon_header: BeaconHeader) -> Result<[u8; hash_tree_root(get_ssz_beacon_header(beacon_header)?) } -pub fn hash_tree_root_beacon_body(body: Body) -> Result<[u8; 32], MerkleizationError> { +pub fn hash_tree_root_beacon_body< + FeeRecipientSize: Get, + LogsBloomSize: Get, + ExtraDataSize: Get, + DepositDataSize: Get, + PublicKeySize: Get, + SignatureSize: Get, + ProofSize: Get, + ProposerSlashingSize: Get, + AttesterSlashingSize: Get, + VoluntaryExitSize: Get, + AttestationSize: Get, + ValidatorCommitteeSize: Get, + SyncCommitteeSize: Get>(body: Body) -> Result<[u8; 32], MerkleizationError> { hash_tree_root(get_ssz_beacon_block_body(body)?) } -pub fn hash_tree_root_sync_committee(sync_committee: SyncCommittee) -> Result<[u8; 32], MerkleizationError> { +pub fn hash_tree_root_sync_committee>(sync_committee: SyncCommittee) -> Result<[u8; 32], MerkleizationError> { let mut pubkeys_vec = Vec::new(); for pubkey in sync_committee.pubkeys.iter() { @@ -259,7 +312,7 @@ pub fn hash_tree_root(mut object: T) -> Result<[u8; 32] } } -pub fn get_sync_committee_bits(bits_hex: Vec) -> Result, MerkleizationError> { +pub fn get_sync_committee_bits>(bits_hex: BoundedVec) -> Result, MerkleizationError> { let bitv = Bitvector::<{ config::SYNC_COMMITTEE_SIZE }>::deserialize(&bits_hex).map_err(|_| MerkleizationError::InvalidLength)?; let result = bitv.iter().map(|bit| { diff --git a/parachain/pallets/ethereum-beacon-client/src/mock.rs b/parachain/pallets/ethereum-beacon-client/src/mock.rs index 4ccd3e9e2f8b1..5e9decda4eaa6 100644 --- a/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -24,7 +24,7 @@ frame_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system::{Pallet, Call, Storage, Event}, - EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event}, + EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event}, } ); @@ -60,8 +60,37 @@ impl frame_system::Config for Test { type MaxConsumers = frame_support::traits::ConstU32<16>; } +parameter_types! { + pub const MaxSyncCommitteeSize: u32 = config::SYNC_COMMITTEE_SIZE as u32; + pub const MaxProofBranchSize: u32 = 6; + pub const MaxExtraDataSize: u32 = config::MAX_EXTRA_DATA_BYTES as u32; + pub const MaxLogsBloomSize: u32 = config::MAX_LOGS_BLOOM_SIZE as u32; + pub const MaxFeeRecipientSize: u32 = config::MAX_FEE_RECIPIENT_SIZE as u32; + pub const MaxDepositDataSize: u32 = config::MAX_DEPOSITS as u32; + pub const MaxPublicKeySize: u32 = config::PUBKEY_SIZE as u32; + pub const MaxSignatureSize: u32 = config::SIGNATURE_SIZE as u32; + pub const MaxProposerSlashingSize: u32 = config::MAX_PROPOSER_SLASHINGS as u32; + pub const MaxAttesterSlashingSize: u32 = config::MAX_ATTESTER_SLASHINGS as u32; + pub const MaxVoluntaryExitSize: u32 = config::MAX_VOLUNTARY_EXITS as u32; + pub const MaxAttestationSize: u32 = config::MAX_ATTESTATIONS as u32; + pub const MaxValidatorsPerCommittee: u32 = config::MAX_VALIDATORS_PER_COMMITTEE as u32; +} + impl ethereum_beacon_client::Config for Test { - type Event = Event; + type Event = Event; + type MaxSyncCommitteeSize = MaxSyncCommitteeSize; + type MaxProofBranchSize = MaxProofBranchSize; + type MaxExtraDataSize = MaxExtraDataSize; + type MaxLogsBloomSize = MaxLogsBloomSize; + type MaxFeeRecipientSize = MaxFeeRecipientSize; + type MaxDepositDataSize = MaxDepositDataSize; + type MaxPublicKeySize = MaxPublicKeySize; + type MaxSignatureSize = MaxSignatureSize; + type MaxProposerSlashingSize = MaxProposerSlashingSize; + type MaxAttesterSlashingSize = MaxAttesterSlashingSize; + type MaxVoluntaryExitSize = MaxVoluntaryExitSize; + type MaxAttestationSize = MaxAttestationSize; + type MaxValidatorsPerCommittee = MaxValidatorsPerCommittee; } // Build genesis storage according to the mock runtime. @@ -70,13 +99,26 @@ pub fn new_tester() -> sp_io::TestExternalities { } pub struct SyncCommitteeTest { - pub sync_committee: SyncCommittee, + pub sync_committee: SyncCommittee, pub result: H256, } #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] pub struct BlockBodyTest { - pub body: Body, + pub body: Body< + MaxFeeRecipientSize, + MaxLogsBloomSize, + MaxExtraDataSize, + MaxDepositDataSize, + MaxPublicKeySize, + MaxSignatureSize, + MaxProofBranchSize, + MaxProposerSlashingSize, + MaxAttesterSlashingSize, + MaxVoluntaryExitSize, + MaxAttestationSize, + MaxValidatorsPerCommittee, + MaxSyncCommitteeSize>, pub result: H256, } @@ -93,27 +135,40 @@ fn fixture_path(name: &str) -> PathBuf { [env!("CARGO_MANIFEST_DIR"), "tests", "fixtures", name].iter().collect() } -fn initial_sync_from_file(name: &str) -> InitialSync { +fn initial_sync_from_file(name: &str) -> InitialSync { let filepath = fixture_path(name); serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } -fn sync_committee_update_from_file(name: &str) -> SyncCommitteePeriodUpdate { +fn sync_committee_update_from_file(name: &str) -> SyncCommitteePeriodUpdate { let filepath = fixture_path(name); serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } -fn finalized_header_update_from_file(name: &str) -> FinalizedHeaderUpdate { +fn finalized_header_update_from_file(name: &str) -> FinalizedHeaderUpdate { let filepath = fixture_path(name); serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } -fn block_update_from_file(name: &str) -> BlockUpdate { +fn block_update_from_file(name: &str) -> BlockUpdate< + MaxFeeRecipientSize, + MaxLogsBloomSize, + MaxExtraDataSize, + MaxDepositDataSize, + MaxPublicKeySize, + MaxSignatureSize, + MaxProofBranchSize, + MaxProposerSlashingSize, + MaxAttesterSlashingSize, + MaxVoluntaryExitSize, + MaxAttestationSize, + MaxValidatorsPerCommittee, + MaxSyncCommitteeSize> { let filepath = fixture_path(name); serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } -fn attester_slashing_from_file(name: &str) -> AttesterSlashing { +fn attester_slashing_from_file(name: &str) -> AttesterSlashing { let filepath = fixture_path(name); serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } @@ -129,19 +184,32 @@ fn add_file_prefix(name: &str) -> String { result } -pub fn get_initial_sync() -> InitialSync { +pub fn get_initial_sync() -> InitialSync { initial_sync_from_file(&add_file_prefix("initial_sync.json")) } -pub fn get_committee_sync_period_update() -> SyncCommitteePeriodUpdate { +pub fn get_committee_sync_period_update() -> SyncCommitteePeriodUpdate { sync_committee_update_from_file(&add_file_prefix("sync_committee_update.json")) } -pub fn get_header_update() -> BlockUpdate { +pub fn get_header_update() -> BlockUpdate< + MaxFeeRecipientSize, + MaxLogsBloomSize, + MaxExtraDataSize, + MaxDepositDataSize, + MaxPublicKeySize, + MaxSignatureSize, + MaxProofBranchSize, + MaxProposerSlashingSize, + MaxAttesterSlashingSize, + MaxVoluntaryExitSize, + MaxAttestationSize, + MaxValidatorsPerCommittee, + MaxSyncCommitteeSize> { block_update_from_file(&add_file_prefix("block_update.json")) } -pub fn get_finalized_header_update() -> FinalizedHeaderUpdate { +pub fn get_finalized_header_update() -> FinalizedHeaderUpdate { finalized_header_update_from_file(&add_file_prefix("finalized_header_update.json")) } @@ -149,11 +217,11 @@ pub fn get_validators_root() -> H256 { get_initial_sync().validators_root } -pub fn get_current_sync_committee_for_current_committee_update() -> SyncCommittee { +pub fn get_current_sync_committee_for_current_committee_update() -> SyncCommittee { get_initial_sync().current_sync_committee } -pub fn get_current_sync_committee_for_finalized_header_update() -> SyncCommittee { +pub fn get_current_sync_committee_for_finalized_header_update() -> SyncCommittee { get_initial_sync().current_sync_committee } @@ -177,7 +245,7 @@ pub fn get_block_body_test_data() -> BlockBodyTest { BlockBodyTest { body, result } } -pub fn get_current_sync_committee_for_header_update() -> SyncCommittee { +pub fn get_current_sync_committee_for_header_update() -> SyncCommittee { get_initial_sync().current_sync_committee } @@ -186,15 +254,15 @@ pub fn get_bls_signature_verify_test_data() -> BLSSignatureVerifyTest { let initial_sync = get_initial_sync(); BLSSignatureVerifyTest { - sync_committee_bits: finalized_update.sync_aggregate.sync_committee_bits, - sync_committee_signature: finalized_update.sync_aggregate.sync_committee_signature, - pubkeys: initial_sync.current_sync_committee.pubkeys, + sync_committee_bits: finalized_update.sync_aggregate.sync_committee_bits.try_into().expect("sync committee bits are too long"), + sync_committee_signature: finalized_update.sync_aggregate.sync_committee_signature.to_vec().try_into().expect("signature is too long"), + pubkeys: initial_sync.current_sync_committee.pubkeys.to_vec().try_into().expect("pubkeys are too long"), fork_version: finalized_update.fork_version, header: finalized_update.attested_header, validators_root: initial_sync.validators_root, } } -pub fn get_attester_slashing() -> AttesterSlashing { +pub fn get_attester_slashing() -> AttesterSlashing { attester_slashing_from_file("attester_slashing.json") } \ No newline at end of file diff --git a/parachain/pallets/ethereum-beacon-client/src/ssz.rs b/parachain/pallets/ethereum-beacon-client/src/ssz.rs index de501e60f0cb4..28028164196e1 100644 --- a/parachain/pallets/ethereum-beacon-client/src/ssz.rs +++ b/parachain/pallets/ethereum-beacon-client/src/ssz.rs @@ -12,10 +12,10 @@ pub struct SSZVoluntaryExit { #[derive(Default, Debug, SimpleSerialize, Clone)] pub struct SSZDepositData { - pub pubkey: Vector, + pub pubkey: Vector, pub withdrawal_credentials: [u8; 32], pub amount: u64, - pub signature: Vector, + pub signature: Vector, } #[derive(Default, Debug, SimpleSerialize, Clone)] @@ -42,14 +42,14 @@ pub struct SSZAttestationData { #[derive(Default, Debug, SimpleSerialize, Clone)] pub struct SignedBeaconBlockHeader { pub message: SSZBeaconBlockHeader, - pub signature: Vector, + pub signature: Vector, } #[derive(Default, Debug, SimpleSerialize, Clone)] pub struct SSZIndexedAttestation { pub attesting_indices: List, pub data: SSZAttestationData, - pub signature: Vector, + pub signature: Vector, } #[derive(Default, Debug, SimpleSerialize, Clone)] @@ -75,7 +75,7 @@ pub struct SSZEth1Data { pub struct SSZAttestation { pub aggregation_bits: Bitlist<{ config::MAX_VALIDATORS_PER_COMMITTEE} >, pub data: SSZAttestationData, - pub signature: Vector, + pub signature: Vector, } #[derive(Default, SimpleSerialize)] @@ -98,14 +98,14 @@ pub struct SSZBeaconBlockHeader { #[derive(Default, SimpleSerialize)] pub struct SSZSyncCommittee { - pub pubkeys: Vector, { config::SYNC_COMMITTEE_SIZE }>, - pub aggregate_pubkey: Vector, + pub pubkeys: Vector, { config::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 sync_committee_signature: Vector, + pub sync_committee_signature: Vector, } #[derive(Default, SimpleSerialize)] @@ -123,10 +123,10 @@ pub struct SSZSigningData { #[derive(Default, SimpleSerialize, Clone, Debug)] pub struct SSZExecutionPayload { pub parent_hash: [u8; 32], - pub fee_recipient: Vector, + pub fee_recipient: Vector, pub state_root: [u8; 32], pub receipts_root: [u8; 32], - pub logs_bloom: Vector, + pub logs_bloom: Vector, pub prev_randao: [u8; 32], pub block_number: u64, pub gas_limit: u64, @@ -140,7 +140,7 @@ pub struct SSZExecutionPayload { #[derive(Default, Debug, SimpleSerialize, Clone)] pub struct SSZBeaconBlockBody { - pub randao_reveal: Vector, + pub randao_reveal: Vector, pub eth1_data: SSZEth1Data, pub graffiti: [u8; 32], pub proposer_slashings: List, diff --git a/parachain/pallets/ethereum-beacon-client/src/tests.rs b/parachain/pallets/ethereum-beacon-client/src/tests.rs index c9ad106821510..a6ad1dcdaf57f 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests.rs @@ -298,7 +298,7 @@ mod beacon { .into(), hex!("91f77a19d8afa4a08e81164bb2e570ecd10477b3b65c305566a6d2be88510584") .into(), - ], + ].to_vec().try_into().expect("proof branch is too long"), 6, 41, hex!("e46559327592741956f6beaa0f52e49625eb85dce037a0bd2eff333c743b287f").into() @@ -321,7 +321,7 @@ mod beacon { .into(), hex!("e7125ff9ab5a840c44bedb4731f440a405b44e15f2d1a89e27341b432fabe13d") .into(), - ], + ].to_vec().try_into().expect("proof branch is too long"), 6, 41, hex!("e46559327592741956f6beaa0f52e49625eb85dce037a0bd2eff333c743b287f").into() @@ -342,7 +342,7 @@ mod beacon { PublicKey(hex!("9446407bcd8e5efe9f2ac0efbfa9e07d136e68b03c5ebc5bde43db3b94773de8605c30419eb2596513707e4e7448bb50").into()), ], hex!("69241e7146cdcc5a5ddc9a60bab8f378c0271e548065a38bcc60624e1dbed97f").into(), - hex!("b204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec(), + hex!("b204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec().try_into().expect("signature is too long"), )); }); } @@ -358,7 +358,7 @@ mod beacon { PublicKey(hex!("9446407bcd8e5efe9f2ac0efbfa9e07d136e68b03c5ebc5bde43db3b94773de8605c30419eb2596513707e4e7448bb50").into()), ], hex!("69241e7146cdcc5a5ddc9a60bab8f378c0271e548065a38bcc60624e1dbed97f").into(), - hex!("b204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec(), + hex!("b204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec().try_into().expect("signature is too long"), ), Error::::InvalidSignaturePoint); }); } @@ -374,7 +374,7 @@ mod beacon { PublicKey(hex!("9446407bcd8e5efe9f2ac0efbfa9e07d136e68b03c5ebc5bde43db3b94773de8605c30419eb2596513707e4e7448bb50").into()), ], hex!("99241e7146cdcc5a5ddc9a60bab8f378c0271e548065a38bcc60624e1dbed97f").into(), - hex!("b204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec(), + hex!("b204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec().try_into().expect("signature is too long"), ), Error::::SignatureVerificationFailed); }); } @@ -390,7 +390,7 @@ mod beacon { PublicKey(hex!("9446407bcd8e5efe9f2ac0efbfa9e07d136e68b03c5ebc5bde43db3b94773de8605c30419eb2596513707e4e7448bb50").into()), ], hex!("69241e7146cdcc5a5ddc9a60bab8f378c0271e548065a38bcc60624e1dbed97f").into(), - hex!("c204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec(), + hex!("c204e9656cbeb79a9a8e397920fd8e60c5f5d9443f58d42186f773c6ade2bd263e2fe6dbdc47f148f871ed9a00b8ac8b17a40d65c8d02120c00dca77495888366b4ccc10f1c6daa02db6a7516555ca0665bca92a647b5f3a514fa083fdc53b6e").to_vec().try_into().expect("signature is too long"), ), Error::::InvalidSignature); }); } @@ -399,14 +399,14 @@ mod beacon { pub fn test_bls_fast_aggregate_verify() { let test_data = get_bls_signature_verify_test_data(); - let sync_committee_bits = merkleization::get_sync_committee_bits(test_data.sync_committee_bits); + let sync_committee_bits = merkleization::get_sync_committee_bits::(test_data.sync_committee_bits.try_into().expect("too many sync committee bits")); assert_ok!(&sync_committee_bits); assert_ok!(EthereumBeaconClient::verify_signed_header( sync_committee_bits.unwrap(), - test_data.sync_committee_signature, - test_data.pubkeys, + test_data.sync_committee_signature.try_into().expect("signature is too long"), + test_data.pubkeys.to_vec().try_into().expect("to many pubkeys"), test_data.fork_version, test_data.header, test_data.validators_root @@ -420,7 +420,7 @@ mod beacon { false => hex!("bffffffff7f1ffdfcfeffeffbfdffffbfffffdffffefefffdffff7f7ffff77fffdf7bff77ffdf7fffafffffff77fefffeff7effffffff5f7fedfffdfb6ddff7b").to_vec(), }; - let sync_committee_bits = merkleization::get_sync_committee_bits(bits); + let sync_committee_bits = merkleization::get_sync_committee_bits::(bits.try_into().expect("too many sync committee bits")); assert_ok!(&sync_committee_bits); @@ -596,14 +596,14 @@ mod beacon { #[test] pub fn test_hash_sync_aggregrate() { - let sync_aggregate = match config::IS_MINIMAL { + let sync_aggregate: SyncAggregate = match config::IS_MINIMAL { true => SyncAggregate{ - sync_committee_bits: hex!("ffffffff").to_vec(), - sync_committee_signature: hex!("99b0a4c6b69f17a876c65364e164c74b9cdd75dfd3b7f9b60b850cfb9394091ed501e2c190b8349f1b903bca44dd556a0c20fd9cd34dec3906921f1424359a4870356557b70261eee14bf49d8f3c62dfcdb37206cb34991c379eee46510602bd").to_vec(), + sync_committee_bits: hex!("ffffffff").to_vec().try_into().expect("sync committee bits are too long"), + sync_committee_signature: hex!("99b0a4c6b69f17a876c65364e164c74b9cdd75dfd3b7f9b60b850cfb9394091ed501e2c190b8349f1b903bca44dd556a0c20fd9cd34dec3906921f1424359a4870356557b70261eee14bf49d8f3c62dfcdb37206cb34991c379eee46510602bd").to_vec().try_into().expect("signature is too long"), }, false => SyncAggregate{ - sync_committee_bits: hex!("cefffffefffffff767fffbedffffeffffeeffdffffdebffffff7f7dbdf7fffdffffbffcfffdff79dfffbbfefff2ffffff7ddeff7ffffc98ff7fbfffffffffff7").to_vec(), - sync_committee_signature: hex!("8af1a8577bba419fe054ee49b16ed28e081dda6d3ba41651634685e890992a0b675e20f8d9f2ec137fe9eb50e838aa6117f9f5410e2e1024c4b4f0e098e55144843ce90b7acde52fe7b94f2a1037342c951dc59f501c92acf7ed944cb6d2b5f7").to_vec(), + sync_committee_bits: hex!("cefffffefffffff767fffbedffffeffffeeffdffffdebffffff7f7dbdf7fffdffffbffcfffdff79dfffbbfefff2ffffff7ddeff7ffffc98ff7fbfffffffffff7").to_vec().try_into().expect("sync committee bits are too long"), + sync_committee_signature: hex!("8af1a8577bba419fe054ee49b16ed28e081dda6d3ba41651634685e890992a0b675e20f8d9f2ec137fe9eb50e838aa6117f9f5410e2e1024c4b4f0e098e55144843ce90b7acde52fe7b94f2a1037342c951dc59f501c92acf7ed944cb6d2b5f7").to_vec().try_into().expect("signature is too long"), }, }; let expected_hash_root: H256 = match config::IS_MINIMAL { @@ -639,18 +639,18 @@ mod beacon { #[test] pub fn test_hash_tree_root_execution_payload() { let payload = merkleization::get_ssz_execution_payload( - ExecutionPayload{ + ExecutionPayload::{ parent_hash: hex!("eadee5ab098dde64e9fd02ae5858064bad67064070679625b09f8d82dec183f7").into(), - fee_recipient: hex!("f97e180c050e5ab072211ad2c213eb5aee4df134").to_vec(), + fee_recipient: hex!("f97e180c050e5ab072211ad2c213eb5aee4df134").to_vec().try_into().expect("fee recipient bits are too long"), state_root: hex!("564fa064c2a324c2b5978d7fdfc5d4224d4f421a45388af1ed405a399c845dff").into(), receipts_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), - logs_bloom: hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec(), + logs_bloom: hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec().try_into().expect("logs bloom is too long"), prev_randao: hex!("6bf538bdfbdf1c96ff528726a40658a91d0bda0f1351448c4c4f3604db2a0ccf").into(), block_number: 477434, gas_limit: 8154925, gas_used: 0, timestamp: 1652816940, - extra_data: vec![], + extra_data: vec![].try_into().expect("extra data field is too long"), base_fee_per_gas: U256::from(7 as i16), block_hash: hex!("cd8df91b4503adb8f2f1c7a4f60e07a1f1a2cbdfa2a95bceba581f3ff65c1968").into(), transactions_root: hex!("7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1").into(), @@ -668,8 +668,8 @@ mod beacon { #[test] pub fn test_hash_tree_root_attestation() { let payload = merkleization::get_ssz_attestation( - Attestation{ - aggregation_bits: hex!("ffcffeff7ffffffffefbf7ffffffdff73e").to_vec(), + Attestation::{ + aggregation_bits: hex!("ffcffeff7ffffffffefbf7ffffffdff73e").to_vec().try_into().expect("aggregation bits are too long"), data: AttestationData{ slot: 484119, index: 0, @@ -683,7 +683,7 @@ mod beacon { root: hex!("3a667c20c78352228169181f19757c774ca93d81047a6c121a0e88b2c385c7f7").into(), } }, - signature: hex!("af8e57aadf092443bd6675927ca84875419233fb7a5eb3ae626621d3339fe738b00af4a0edcc55efbe1198a815600784074388d366c4add789aa6126bb1ec5ed63ad8d8f22b5f158ae4c25d46b08d46d1188f7ed7e8f99d96ff6c3c69a240c18").to_vec(), + signature: hex!("af8e57aadf092443bd6675927ca84875419233fb7a5eb3ae626621d3339fe738b00af4a0edcc55efbe1198a815600784074388d366c4add789aa6126bb1ec5ed63ad8d8f22b5f158ae4c25d46b08d46d1188f7ed7e8f99d96ff6c3c69a240c18").to_vec().try_into().expect("signature is too long"), }, ); diff --git a/parachain/primitives/beacon/src/lib.rs b/parachain/primitives/beacon/src/lib.rs index ec585e6e1aba3..228244b035072 100644 --- a/parachain/primitives/beacon/src/lib.rs +++ b/parachain/primitives/beacon/src/lib.rs @@ -1,12 +1,13 @@ #![cfg_attr(not(feature = "std"), no_std)] -use codec::{Decode, Encode}; +use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use snowbridge_ethereum::mpt; use sp_core::{H160, H256, U256}; use sp_io::hashing::keccak_256; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; +use frame_support::{BoundedVec, traits::Get, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound}; #[cfg(feature = "std")] use core::fmt::Formatter; @@ -18,18 +19,43 @@ use sp_std::fmt::Result as StdResult; pub type Root = H256; pub type Domain = H256; pub type ValidatorIndex = u64; -pub type ProofBranch = Vec; pub type ForkVersion = [u8; 4]; #[derive(Clone, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] pub struct PublicKey(pub [u8; 48]); +impl , ProofSize: Get>Default for InitialSync { + fn default() -> Self { + InitialSync { + header: Default::default(), + current_sync_committee: Default::default(), + current_sync_committee_branch: Default::default(), + validators_root: Default::default(), + } + } +} + +impl >Default for SyncCommittee { + fn default() -> Self { + SyncCommittee { + pubkeys: Default::default(), + aggregate_pubkey: Default::default(), + } + } +} + impl Default for PublicKey { fn default() -> Self { PublicKey([0u8; 48]) } } +impl MaxEncodedLen for PublicKey { + fn max_encoded_len() -> usize { + 48 + } +} + #[cfg(feature = "std")] impl Serialize for PublicKey { fn serialize(&self, serializer: S) -> Result @@ -83,95 +109,179 @@ impl<'de> Deserialize<'de> for PublicKey { } } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -pub struct InitialSync { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SyncCommitteeSize, ProofSize))] +#[codec(mel_bound())] +pub struct InitialSync, ProofSize: Get> { pub header: BeaconHeader, - pub current_sync_committee: SyncCommittee, - pub current_sync_committee_branch: ProofBranch, + pub current_sync_committee: SyncCommittee, + pub current_sync_committee_branch: BoundedVec, pub validators_root: Root, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -pub struct SyncCommitteePeriodUpdate { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SignatureSize, ProofSize, SyncCommitteeSize, SyncCommitteeSize))] +#[codec(mel_bound())] +pub struct SyncCommitteePeriodUpdate< + SignatureSize: Get, + ProofSize: Get, + SyncCommitteeSize: Get> { pub attested_header: BeaconHeader, - pub next_sync_committee: SyncCommittee, - pub next_sync_committee_branch: ProofBranch, + pub next_sync_committee: SyncCommittee, + pub next_sync_committee_branch: BoundedVec, pub finalized_header: BeaconHeader, - pub finality_branch: ProofBranch, - pub sync_aggregate: SyncAggregate, + pub finality_branch: BoundedVec, + pub sync_aggregate: SyncAggregate, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_fork_version"))] pub fork_version: ForkVersion, pub sync_committee_period: u64, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -pub struct FinalizedHeaderUpdate { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SignatureSize, ProofSize, SyncCommitteeSize))] +#[codec(mel_bound())] +pub struct FinalizedHeaderUpdate< + SignatureSize: Get, + ProofSize: Get, + SyncCommitteeSize: Get> { pub attested_header: BeaconHeader, pub finalized_header: BeaconHeader, - pub finality_branch: ProofBranch, - pub sync_aggregate: SyncAggregate, + pub finality_branch: BoundedVec, + pub sync_aggregate: SyncAggregate, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_fork_version"))] pub fork_version: ForkVersion, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct BlockUpdate { - pub block: BeaconBlock, +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(FeeRecipientSize, LogsBloomSize, ExtraDataSize, DepositDataSize, PublicKeySize, SignatureSize, ProofSize, ProposerSlashingSize, AttesterSlashingSize, +VoluntaryExitSize, AttestationSize, ValidatorCommitteeSize, SyncCommitteeSize))] +#[codec(mel_bound())] +pub struct BlockUpdate< + FeeRecipientSize: Get, + LogsBloomSize: Get, + ExtraDataSize: Get, + DepositDataSize: Get, + PublicKeySize: Get, + SignatureSize: Get, + ProofSize: Get, + ProposerSlashingSize: Get, + AttesterSlashingSize: Get, + VoluntaryExitSize: Get, + AttestationSize: Get, + ValidatorCommitteeSize: Get, + SyncCommitteeSize: Get> { + pub block: BeaconBlock, // // Only used for debugging purposes, to compare the hash tree // root of the block body to the body hash retrieved from the API. // Can be removed later. pub block_body_root: H256, - pub sync_aggregate: SyncAggregate, + pub sync_aggregate: SyncAggregate, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_fork_version"))] pub fork_version: ForkVersion, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct ForkData { // 1 or 0 bit, indicates whether a sync committee participated in a vote pub current_version: [u8; 4], pub genesis_validators_root: [u8; 32], } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] pub struct SigningData { pub object_root: Root, pub domain: Domain, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] -pub struct ExecutionHeader { +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] +#[scale_info(skip_type_params(LogsBloomSize, ExtraDataSize))] +#[codec(mel_bound())] +pub struct ExecutionHeader, ExtraDataSize: Get> { pub parent_hash: H256, pub fee_recipient: H160, pub state_root: H256, pub receipts_root: H256, - pub logs_bloom: Vec, + pub logs_bloom: BoundedVec, pub prev_randao: H256, pub block_number: u64, pub gas_limit: u64, pub gas_used: u64, pub timestamp: u64, - pub extra_data: Vec, + pub extra_data: BoundedVec, pub base_fee_per_gas: U256, pub block_hash: H256, pub transactions_root: H256, } /// Sync committee as it is stored in the runtime storage. -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, PartialEqNoBound, CloneNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct SyncCommittee { - pub pubkeys: Vec, +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SyncCommitteeSize))] +#[codec(mel_bound())] +pub struct SyncCommittee> { + pub pubkeys: BoundedVec, pub aggregate_pubkey: PublicKey, } /// Beacon block header as it is stored in the runtime storage. The block root is the /// Merklization of a BeaconHeader. -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct BeaconHeader { // The slot for which this block is created. Must be greater than the slot of the block defined @@ -187,32 +297,52 @@ pub struct BeaconHeader { pub body_root: Root, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct DepositData { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(PublicKeySize, SignatureSize))] +#[codec(mel_bound())] +pub struct DepositData, SignatureSize: Get> { #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub pubkey: Vec, + pub pubkey: BoundedVec, pub withdrawal_credentials: H256, pub amount: u64, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub signature: Vec, + pub signature: BoundedVec, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct Deposit { - pub proof: Vec, - pub data: DepositData, +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(PublicKeySize, SignatureSize, ProofSize))] +#[codec(mel_bound())] +pub struct Deposit, SignatureSize: Get, ProofSize: Get> { + pub proof: BoundedVec, + pub data: DepositData, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct Checkpoint { pub epoch: u64, pub root: H256, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct AttestationData { pub slot: u64, @@ -222,55 +352,105 @@ pub struct AttestationData { pub target: Checkpoint, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct IndexedAttestation { - pub attesting_indices: Vec, +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(ValidatorCommitteeSize, SignatureSize))] +#[codec(mel_bound())] +pub struct IndexedAttestation, SignatureSize: Get> { + pub attesting_indices: BoundedVec, pub data: AttestationData, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub signature: Vec, + pub signature: BoundedVec, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive( Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct SignedHeader { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SignatureSize))] +#[codec(mel_bound())] +pub struct SignedHeader> { pub message: crate::BeaconHeader, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub signature: Vec, + pub signature: BoundedVec, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct ProposerSlashing { - pub signed_header_1: SignedHeader, - pub signed_header_2: SignedHeader, +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SignatureSize))] +#[codec(mel_bound())] +pub struct ProposerSlashing> { + pub signed_header_1: SignedHeader, + pub signed_header_2: SignedHeader, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct AttesterSlashing { - pub attestation_1: IndexedAttestation, - pub attestation_2: IndexedAttestation, +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(AttestingIndicesSize, SignatureSize))] +#[codec(mel_bound())] +pub struct AttesterSlashing, SignatureSize: Get> { + pub attestation_1: IndexedAttestation, + pub attestation_2: IndexedAttestation, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct Attestation { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(ValidatorCommitteeSize, SignatureSize))] +#[codec(mel_bound())] +pub struct Attestation, SignatureSize: Get> { #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub aggregation_bits: Vec, + pub aggregation_bits: BoundedVec, pub data: AttestationData, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub signature: Vec, + pub signature: BoundedVec, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct VoluntaryExit { pub epoch: u64, pub validator_index: u64, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub struct Eth1Data { pub deposit_root: H256, @@ -278,65 +458,145 @@ pub struct Eth1Data { pub block_hash: H256, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct SyncAggregate { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(SyncCommitteeSize, SignatureSize))] +#[codec(mel_bound())] +pub struct SyncAggregate, SignatureSize: Get> { #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub sync_committee_bits: Vec, + pub sync_committee_bits: BoundedVec, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub sync_committee_signature: Vec, + pub sync_committee_signature: BoundedVec, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct ExecutionPayload { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(FeeRecipientSize, LogsBloomSize, ExtraDataSize))] +#[codec(mel_bound())] +pub struct ExecutionPayload, LogsBloomSize: Get, ExtraDataSize: Get> { pub parent_hash: H256, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub fee_recipient: Vec, + pub fee_recipient: BoundedVec, pub state_root: H256, pub receipts_root: H256, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub logs_bloom: Vec, + pub logs_bloom: BoundedVec, pub prev_randao: H256, pub block_number: u64, pub gas_limit: u64, pub gas_used: u64, pub timestamp: u64, #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub extra_data: Vec, + pub extra_data: BoundedVec, #[cfg_attr(feature = "std", serde(deserialize_with = "from_int_to_u256"))] pub base_fee_per_gas: U256, pub block_hash: H256, pub transactions_root: H256, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct Body { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(FeeRecipientSize, LogsBloomSize, ExtraDataSize, DepositDataSize, PublicKeySize, SignatureSize, ProofSize, RandaoSize, ProposerSlashingSize, AttesterSlashingSize, +VoluntaryExitSize, AttestationSize, ValidatorCommitteeSize, SyncCommitteeSize))] +#[codec(mel_bound())] +pub struct Body< + FeeRecipientSize: Get, + LogsBloomSize: Get, + ExtraDataSize: Get, + DepositDataSize: Get, + PublicKeySize: Get, + SignatureSize: Get, + ProofSize: Get, + ProposerSlashingSize: Get, + AttesterSlashingSize: Get, + VoluntaryExitSize: Get, + AttestationSize: Get, + ValidatorCommitteeSize: Get, + SyncCommitteeSize: Get> { #[cfg_attr(feature = "std", serde(deserialize_with = "from_hex_to_bytes"))] - pub randao_reveal: Vec, + pub randao_reveal: BoundedVec, pub eth1_data: Eth1Data, pub graffiti: H256, - pub proposer_slashings: Vec, - pub attester_slashings: Vec, - pub attestations: Vec, - pub deposits: Vec, - pub voluntary_exits: Vec, - pub sync_aggregate: SyncAggregate, - pub execution_payload: ExecutionPayload, + pub proposer_slashings: BoundedVec, ProposerSlashingSize>, + pub attester_slashings: BoundedVec, AttesterSlashingSize>, + pub attestations: BoundedVec, AttestationSize>, + pub deposits: BoundedVec, DepositDataSize>, + pub voluntary_exits: BoundedVec, + pub sync_aggregate: SyncAggregate, + pub execution_payload: ExecutionPayload, } -#[derive(Clone, Default, Encode, Decode, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Default, Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct BeaconBlock { +#[cfg_attr( + feature = "std", + serde( + deny_unknown_fields, + bound(serialize = ""), + bound(deserialize = "") + ) +)] +#[scale_info(skip_type_params(FeeRecipientSize, LogsBloomSize, ExtraDataSize, DepositDataSize, PublicKeySize, SignatureSize, ProofSize, ProposerSlashingSize, AttesterSlashingSize, +VoluntaryExitSize, AttestationSize, ValidatorCommitteeSize, SyncCommitteeSize))] +#[codec(mel_bound())] +pub struct BeaconBlock< + FeeRecipientSize: Get, + LogsBloomSize: Get, + ExtraDataSize: Get, + DepositDataSize: Get, + PublicKeySize: Get, + SignatureSize: Get, + ProofSize: Get, + ProposerSlashingSize: Get, + AttesterSlashingSize: Get, + VoluntaryExitSize: Get, + AttestationSize: Get, + ValidatorCommitteeSize: Get, + SyncCommitteeSize: Get> { pub slot: u64, pub proposer_index: u64, pub parent_root: H256, pub state_root: H256, - pub body: Body, + pub body: Body } -impl ExecutionHeader { +impl , M: Get>ExecutionHeader { // Copied from ethereum_snowbridge::header pub fn check_receipt_proof( &self, @@ -373,9 +633,9 @@ impl ExecutionHeader { } #[cfg(feature = "std")] -fn from_hex_to_bytes<'de, D>(deserializer: D) -> Result, D::Error> +fn from_hex_to_bytes<'de, D, S>(deserializer: D) -> Result, D::Error> where - D: Deserializer<'de>, + D: Deserializer<'de>, S: Get { let s = String::deserialize(deserializer)?; @@ -389,7 +649,10 @@ where Err(e) => return Err(Error::custom(e.to_string())), }; - Ok(hex_bytes) + match BoundedVec::try_from(hex_bytes){ + Ok(bounded) => return Ok(bounded), + Err(_) => return Err(Error::custom("unable to create bounded vec")), + }; } #[cfg(feature = "std")] diff --git a/parachain/runtime/snowbase/src/lib.rs b/parachain/runtime/snowbase/src/lib.rs index e17ea2b1742f1..3c1d51e8283c9 100644 --- a/parachain/runtime/snowbase/src/lib.rs +++ b/parachain/runtime/snowbase/src/lib.rs @@ -610,8 +610,37 @@ impl incentivized_channel_outbound::Config for Runtime { type WeightInfo = incentivized_channel_outbound::weights::SnowbridgeWeight; } +parameter_types! { + pub const MaxSyncCommitteeSize: u32 = 32; + pub const MaxProofBranchSize: u32 = 10; + pub const MaxExtraDataSize: u32 = 32; + pub const MaxLogsBloomSize: u32 = 256; + pub const MaxFeeRecipientSize: u32 = 20; + pub const MaxDepositDataSize: u32 = 16; + pub const MaxPublicKeySize: u32 = 48; + pub const MaxSignatureSize: u32 = 96; + pub const MaxProposerSlashingSize: u32 = 16; + pub const MaxAttesterSlashingSize: u32 = 2; + pub const MaxVoluntaryExitSize: u32 = 16; + pub const MaxAttestationSize: u32 = 128; + pub const MaxValidatorsPerCommittee: u32 = 2048; +} + impl ethereum_beacon_client::Config for Runtime { - type Event = Event; + type Event = Event; + type MaxSyncCommitteeSize = MaxSyncCommitteeSize; + type MaxProofBranchSize = MaxProofBranchSize; + type MaxExtraDataSize = MaxExtraDataSize; + type MaxLogsBloomSize = MaxLogsBloomSize; + type MaxFeeRecipientSize = MaxFeeRecipientSize; + type MaxDepositDataSize = MaxDepositDataSize; + type MaxPublicKeySize = MaxPublicKeySize; + type MaxSignatureSize = MaxSignatureSize; + type MaxProposerSlashingSize = MaxProposerSlashingSize; + type MaxAttesterSlashingSize = MaxAttesterSlashingSize; + type MaxVoluntaryExitSize = MaxVoluntaryExitSize; + type MaxAttestationSize = MaxAttestationSize; + type MaxValidatorsPerCommittee = MaxValidatorsPerCommittee; } parameter_types! { @@ -742,7 +771,7 @@ construct_runtime!( IncentivizedInboundChannel: incentivized_channel_inbound::{Pallet, Call, Config, Storage, Event} = 14, IncentivizedOutboundChannel: incentivized_channel_outbound::{Pallet, Call, Config, Storage, Event} = 15, Dispatch: dispatch::{Pallet, Call, Storage, Event, Origin} = 16, - EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event} = 18, + EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event} = 18, Assets: pallet_assets::{Pallet, Call, Config, Storage, Event} = 19, AssetRegistry: snowbridge_asset_registry::{Pallet, Storage, Config} = 20, XcmSupport: snowbridge_xcm_support::{Pallet, Storage, Config, Event} = 21, diff --git a/parachain/runtime/snowblink/src/lib.rs b/parachain/runtime/snowblink/src/lib.rs index 7cdc6f85898f0..530f5f435587c 100644 --- a/parachain/runtime/snowblink/src/lib.rs +++ b/parachain/runtime/snowblink/src/lib.rs @@ -610,8 +610,37 @@ impl incentivized_channel_outbound::Config for Runtime { type WeightInfo = incentivized_channel_outbound::weights::SnowbridgeWeight; } +parameter_types! { + pub const MaxSyncCommitteeSize: u32 = 512; + pub const MaxProofBranchSize: u32 = 10; + pub const MaxExtraDataSize: u32 = 32; + pub const MaxLogsBloomSize: u32 = 256; + pub const MaxFeeRecipientSize: u32 = 20; + pub const MaxDepositDataSize: u32 = 16; + pub const MaxPublicKeySize: u32 = 48; + pub const MaxSignatureSize: u32 = 96; + pub const MaxProposerSlashingSize: u32 = 16; + pub const MaxAttesterSlashingSize: u32 = 2; + pub const MaxVoluntaryExitSize: u32 = 16; + pub const MaxAttestationSize: u32 = 128; + pub const MaxValidatorsPerCommittee: u32 = 2048; +} + impl ethereum_beacon_client::Config for Runtime { - type Event = Event; + type Event = Event; + type MaxSyncCommitteeSize = MaxSyncCommitteeSize; + type MaxProofBranchSize = MaxProofBranchSize; + type MaxExtraDataSize = MaxExtraDataSize; + type MaxLogsBloomSize = MaxLogsBloomSize; + type MaxFeeRecipientSize = MaxFeeRecipientSize; + type MaxDepositDataSize = MaxDepositDataSize; + type MaxPublicKeySize = MaxPublicKeySize; + type MaxSignatureSize = MaxSignatureSize; + type MaxProposerSlashingSize = MaxProposerSlashingSize; + type MaxAttesterSlashingSize = MaxAttesterSlashingSize; + type MaxVoluntaryExitSize = MaxVoluntaryExitSize; + type MaxAttestationSize = MaxAttestationSize; + type MaxValidatorsPerCommittee = MaxValidatorsPerCommittee; } parameter_types! { @@ -742,7 +771,7 @@ construct_runtime!( IncentivizedInboundChannel: incentivized_channel_inbound::{Pallet, Call, Config, Storage, Event} = 14, IncentivizedOutboundChannel: incentivized_channel_outbound::{Pallet, Call, Config, Storage, Event} = 15, Dispatch: dispatch::{Pallet, Call, Storage, Event, Origin} = 16, - EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event} = 18, + EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event} = 18, Assets: pallet_assets::{Pallet, Call, Config, Storage, Event} = 19, AssetRegistry: snowbridge_asset_registry::{Pallet, Storage, Config} = 20, XcmSupport: snowbridge_xcm_support::{Pallet, Storage, Config, Event} = 21, diff --git a/parachain/runtime/snowbridge/src/lib.rs b/parachain/runtime/snowbridge/src/lib.rs index 5248bc672766e..49f0f28f5b053 100644 --- a/parachain/runtime/snowbridge/src/lib.rs +++ b/parachain/runtime/snowbridge/src/lib.rs @@ -610,8 +610,37 @@ impl incentivized_channel_outbound::Config for Runtime { type WeightInfo = incentivized_channel_outbound::weights::SnowbridgeWeight; } +parameter_types! { + pub const MaxSyncCommitteeSize: u32 = 512; + pub const MaxProofBranchSize: u32 = 10; + pub const MaxExtraDataSize: u32 = 32; + pub const MaxLogsBloomSize: u32 = 256; + pub const MaxFeeRecipientSize: u32 = 20; + pub const MaxDepositDataSize: u32 = 16; + pub const MaxPublicKeySize: u32 = 48; + pub const MaxSignatureSize: u32 = 96; + pub const MaxProposerSlashingSize: u32 = 16; + pub const MaxAttesterSlashingSize: u32 = 2; + pub const MaxVoluntaryExitSize: u32 = 16; + pub const MaxAttestationSize: u32 = 128; + pub const MaxValidatorsPerCommittee: u32 = 2048; +} + impl ethereum_beacon_client::Config for Runtime { - type Event = Event; + type Event = Event; + type MaxSyncCommitteeSize = MaxSyncCommitteeSize; + type MaxProofBranchSize = MaxProofBranchSize; + type MaxExtraDataSize = MaxExtraDataSize; + type MaxLogsBloomSize = MaxLogsBloomSize; + type MaxFeeRecipientSize = MaxFeeRecipientSize; + type MaxDepositDataSize = MaxDepositDataSize; + type MaxPublicKeySize = MaxPublicKeySize; + type MaxSignatureSize = MaxSignatureSize; + type MaxProposerSlashingSize = MaxProposerSlashingSize; + type MaxAttesterSlashingSize = MaxAttesterSlashingSize; + type MaxVoluntaryExitSize = MaxVoluntaryExitSize; + type MaxAttestationSize = MaxAttestationSize; + type MaxValidatorsPerCommittee = MaxValidatorsPerCommittee; } parameter_types! { @@ -742,7 +771,7 @@ construct_runtime!( IncentivizedInboundChannel: incentivized_channel_inbound::{Pallet, Call, Config, Storage, Event} = 14, IncentivizedOutboundChannel: incentivized_channel_outbound::{Pallet, Call, Config, Storage, Event} = 15, Dispatch: dispatch::{Pallet, Call, Storage, Event, Origin} = 16, - EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event} = 18, + EthereumBeaconClient: ethereum_beacon_client::{Pallet, Call, Config, Storage, Event} = 18, Assets: pallet_assets::{Pallet, Call, Config, Storage, Event} = 19, AssetRegistry: snowbridge_asset_registry::{Pallet, Storage, Config} = 20, XcmSupport: snowbridge_xcm_support::{Pallet, Storage, Config, Event} = 21,