From 05278437ff021885a1be3a37f3269c08b306eeff Mon Sep 17 00:00:00 2001 From: Hussein Ait Lahcen Date: Thu, 12 Dec 2024 12:12:19 +0100 Subject: [PATCH] fix(eth-lc): sum of bits for participants --- lib/ethereum-sync-protocol/src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/ethereum-sync-protocol/src/lib.rs b/lib/ethereum-sync-protocol/src/lib.rs index 6fe475418d..ba2fba8c45 100644 --- a/lib/ethereum-sync-protocol/src/lib.rs +++ b/lib/ethereum-sync-protocol/src/lib.rs @@ -73,11 +73,9 @@ pub fn validate_light_client_update( ) -> Result<(), Error> { // verify that the sync committee has sufficient participants let sync_aggregate = &update.sync_aggregate; - let set_bits = sync_aggregate - .sync_committee_bits - .iter() - .map(|i| *i as usize) - .sum::(); + let set_bits = BytesBitIterator::new(&sync_aggregate.sync_committee_bits) + .filter(|included| *included) + .count(); ensure( set_bits >= C::MIN_SYNC_COMMITTEE_PARTICIPANTS::USIZE, Error::InsufficientSyncCommitteeParticipants(set_bits), @@ -166,11 +164,10 @@ pub fn validate_light_client_update( // to match the finalized checkpoint root saved in the state of `attested_header`. // NOTE(aeryz): We always expect to get `finalized_header` and it's embedded into the type definition. is_valid_light_client_header::(fork_parameters, &update.finalized_header)?; - let finalized_root = update.finalized_header.beacon.tree_hash_root(); // This confirms that the `finalized_header` is really finalized. validate_merkle_branch( - &finalized_root.into(), + &update.finalized_header.beacon.tree_hash_root().into(), &update.finality_branch, floorlog2(FINALIZED_ROOT_INDEX), get_subtree_index(FINALIZED_ROOT_INDEX), @@ -213,7 +210,7 @@ pub fn validate_light_client_update( // It's not mandatory for all of the members of the sync committee to participate. So we are extracting the // public keys of the ones who participated. - let participant_pubkeys = BytesBitIterator::new(&&*update.sync_aggregate.sync_committee_bits) + let participant_pubkeys = BytesBitIterator::new(&sync_aggregate.sync_committee_bits) .zip(sync_committee.pubkeys.iter()) .filter_map(|(included, pubkey)| if included { Some(pubkey) } else { None }) .collect::>();