Skip to content

Commit 42c64a2

Browse files
authored
Ensure non-zero bits for each committee bitfield comprising an aggregate (#6603)
* add new validation
1 parent 5022398 commit 42c64a2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

consensus/state_processing/src/common/get_attesting_indices.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ pub mod attesting_indices_electra {
103103

104104
let committee_count_per_slot = committees.len() as u64;
105105
let mut participant_count = 0;
106-
for index in committee_indices {
106+
for committee_index in committee_indices {
107107
let beacon_committee = committees
108-
.get(index as usize)
109-
.ok_or(Error::NoCommitteeFound(index))?;
108+
.get(committee_index as usize)
109+
.ok_or(Error::NoCommitteeFound(committee_index))?;
110110

111111
// This check is new to the spec's `process_attestation` in Electra.
112-
if index >= committee_count_per_slot {
113-
return Err(BeaconStateError::InvalidCommitteeIndex(index));
112+
if committee_index >= committee_count_per_slot {
113+
return Err(BeaconStateError::InvalidCommitteeIndex(committee_index));
114114
}
115115
participant_count.safe_add_assign(beacon_committee.committee.len() as u64)?;
116116
let committee_attesters = beacon_committee
@@ -127,6 +127,12 @@ pub mod attesting_indices_electra {
127127
})
128128
.collect::<HashSet<u64>>();
129129

130+
// Require at least a single non-zero bit for each attesting committee bitfield.
131+
// This check is new to the spec's `process_attestation` in Electra.
132+
if committee_attesters.is_empty() {
133+
return Err(BeaconStateError::EmptyCommittee);
134+
}
135+
130136
attesting_indices.extend(committee_attesters);
131137
committee_offset.safe_add_assign(beacon_committee.committee.len())?;
132138
}

consensus/types/src/beacon_state.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub enum Error {
5959
UnknownValidator(usize),
6060
UnableToDetermineProducer,
6161
InvalidBitfield,
62+
EmptyCommittee,
6263
ValidatorIsWithdrawable,
6364
ValidatorIsInactive {
6465
val_index: usize,

0 commit comments

Comments
 (0)