From 10884359afea087e5d80a3c6ec65c0f976229eb1 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 4 Jun 2019 11:04:53 +1000 Subject: [PATCH] spec v0.6: check custody bitfield length --- eth2/state_processing/src/common/convert_to_indexed.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eth2/state_processing/src/common/convert_to_indexed.rs b/eth2/state_processing/src/common/convert_to_indexed.rs index 5492252f7..1854d32d1 100644 --- a/eth2/state_processing/src/common/convert_to_indexed.rs +++ b/eth2/state_processing/src/common/convert_to_indexed.rs @@ -1,10 +1,10 @@ -use super::get_attesting_indices; +use super::{get_attesting_indices, get_attesting_indices_unsorted}; use itertools::{Either, Itertools}; use types::*; /// Convert `attestation` to (almost) indexed-verifiable form. /// -/// Spec v0.6.1 +/// Spec v0.6.3 pub fn convert_to_indexed( state: &BeaconState, attestation: &Attestation, @@ -12,6 +12,10 @@ pub fn convert_to_indexed( let attesting_indices = 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) = attesting_indices.into_iter().enumerate().partition_map( |(committee_idx, validator_idx)| match attestation.custody_bitfield.get(committee_idx) {