From df82181f2ab9c71167b355271c58c9416ebf4e68 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 8 May 2024 14:25:10 -0400 Subject: [PATCH 1/4] fix get attesting indices --- .../src/common/get_attesting_indices.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/consensus/state_processing/src/common/get_attesting_indices.rs b/consensus/state_processing/src/common/get_attesting_indices.rs index 595cc69f87c..0c5f56077a5 100644 --- a/consensus/state_processing/src/common/get_attesting_indices.rs +++ b/consensus/state_processing/src/common/get_attesting_indices.rs @@ -113,11 +113,15 @@ pub mod attesting_indices_electra { .map(|committee| (committee.index, committee)) .collect(); + let committee_count_per_slot = committees.len() as u64; + let mut participant_count = 0; for index in committee_indices { if let Some(&beacon_committee) = committees_map.get(&index) { - if aggregation_bits.len() != beacon_committee.committee.len() { + // This check is new to the spec's `process_attestation` in Electra. + if index >= committee_count_per_slot { return Err(BeaconStateError::InvalidBitfield); } + participant_count.safe_add_assign(beacon_committee.committee.len() as u64)?; let committee_attesters = beacon_committee .committee .iter() @@ -138,8 +142,11 @@ pub mod attesting_indices_electra { } else { return Err(Error::NoCommitteeFound); } + } - // TODO(electra) what should we do when theres no committee found for a given index? + // This check is new to the spec's `process_attestation` in Electra. + if participant_count as usize != aggregation_bits.len() { + return Err(BeaconStateError::InvalidBitfield); } let mut indices = output.into_iter().collect_vec(); From 41b0c69fb055b9f7f56df7cfd5e308fe45a75cc0 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 8 May 2024 14:31:12 -0400 Subject: [PATCH 2/4] better errors --- .../state_processing/src/common/get_attesting_indices.rs | 4 ++-- consensus/types/src/beacon_state.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/consensus/state_processing/src/common/get_attesting_indices.rs b/consensus/state_processing/src/common/get_attesting_indices.rs index 0c5f56077a5..9848840e96d 100644 --- a/consensus/state_processing/src/common/get_attesting_indices.rs +++ b/consensus/state_processing/src/common/get_attesting_indices.rs @@ -119,7 +119,7 @@ pub mod attesting_indices_electra { if let Some(&beacon_committee) = committees_map.get(&index) { // This check is new to the spec's `process_attestation` in Electra. if index >= committee_count_per_slot { - return Err(BeaconStateError::InvalidBitfield); + return Err(BeaconStateError::InvalidCommitteeIndex(index)); } participant_count.safe_add_assign(beacon_committee.committee.len() as u64)?; let committee_attesters = beacon_committee @@ -140,7 +140,7 @@ pub mod attesting_indices_electra { committee_offset.safe_add(beacon_committee.committee.len())?; } else { - return Err(Error::NoCommitteeFound); + return Err(Error::NoCommitteeFound(index)); } } diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 599c0bfc39c..d9c7a78537a 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -159,7 +159,8 @@ pub enum Error { IndexNotSupported(usize), InvalidFlagIndex(usize), MerkleTreeError(merkle_proof::MerkleTreeError), - NoCommitteeFound, + NoCommitteeFound(CommitteeIndex), + InvalidCommitteeIndex(CommitteeIndex), } /// Control whether an epoch-indexed field can be indexed at the next epoch or not. From 94ea65f2873dd529b3f6d37ce8c34af6afb86bd6 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 8 May 2024 14:33:43 -0400 Subject: [PATCH 3/4] fix compile --- beacon_node/beacon_chain/src/attestation_verification.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/beacon_node/beacon_chain/src/attestation_verification.rs b/beacon_node/beacon_chain/src/attestation_verification.rs index 62e65d5f87a..fd583e6adb5 100644 --- a/beacon_node/beacon_chain/src/attestation_verification.rs +++ b/beacon_node/beacon_chain/src/attestation_verification.rs @@ -1309,7 +1309,9 @@ pub fn obtain_indexed_attestation_and_committees_per_slot( attesting_indices_electra::get_indexed_attestation(&committees, att) .map(|attestation| (attestation, committees_per_slot)) .map_err(|e| { - if e == BlockOperationError::BeaconStateError(NoCommitteeFound) { + if e == BlockOperationError::BeaconStateError(NoCommitteeFound( + att.committee_index(), + )) { Error::NoCommitteeForSlotAndIndex { slot: att.data.slot, index: att.committee_index(), From 4c6cac8b799a1b3e598e053d366d62d118825271 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Wed, 8 May 2024 14:37:52 -0400 Subject: [PATCH 4/4] only get committee index once --- beacon_node/beacon_chain/src/attestation_verification.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/beacon_node/beacon_chain/src/attestation_verification.rs b/beacon_node/beacon_chain/src/attestation_verification.rs index fd583e6adb5..3d722a534be 100644 --- a/beacon_node/beacon_chain/src/attestation_verification.rs +++ b/beacon_node/beacon_chain/src/attestation_verification.rs @@ -1309,12 +1309,11 @@ pub fn obtain_indexed_attestation_and_committees_per_slot( attesting_indices_electra::get_indexed_attestation(&committees, att) .map(|attestation| (attestation, committees_per_slot)) .map_err(|e| { - if e == BlockOperationError::BeaconStateError(NoCommitteeFound( - att.committee_index(), - )) { + let index = att.committee_index(); + if e == BlockOperationError::BeaconStateError(NoCommitteeFound(index)) { Error::NoCommitteeForSlotAndIndex { slot: att.data.slot, - index: att.committee_index(), + index, } } else { Error::Invalid(e)