spec v0.6: check custody bitfield length

This commit is contained in:
Michael Sproul 2019-06-04 11:04:53 +10:00
parent a3a941efdf
commit 10884359af
No known key found for this signature in database
GPG Key ID: 77B1309D2E54E914

View File

@ -1,10 +1,10 @@
use super::get_attesting_indices; use super::{get_attesting_indices, get_attesting_indices_unsorted};
use itertools::{Either, Itertools}; use itertools::{Either, Itertools};
use types::*; use types::*;
/// Convert `attestation` to (almost) indexed-verifiable form. /// Convert `attestation` to (almost) indexed-verifiable form.
/// ///
/// Spec v0.6.1 /// Spec v0.6.3
pub fn convert_to_indexed<T: EthSpec>( pub fn convert_to_indexed<T: EthSpec>(
state: &BeaconState<T>, state: &BeaconState<T>,
attestation: &Attestation, attestation: &Attestation,
@ -12,6 +12,10 @@ pub fn convert_to_indexed<T: EthSpec>(
let attesting_indices = let attesting_indices =
get_attesting_indices(state, &attestation.data, &attestation.aggregation_bitfield)?; get_attesting_indices(state, &attestation.data, &attestation.aggregation_bitfield)?;
// We verify the custody bitfield by calling `get_attesting_indices_unsorted` and throwing
// away the result. This avoids double-sorting - the partition below takes care of the ordering.
get_attesting_indices_unsorted(state, &attestation.data, &attestation.custody_bitfield)?;
let (custody_bit_0_indices, custody_bit_1_indices) = let (custody_bit_0_indices, custody_bit_1_indices) =
attesting_indices.into_iter().enumerate().partition_map( attesting_indices.into_iter().enumerate().partition_map(
|(committee_idx, validator_idx)| match attestation.custody_bitfield.get(committee_idx) { |(committee_idx, validator_idx)| match attestation.custody_bitfield.get(committee_idx) {