Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aggegation initialization method #1172

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/vdaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,16 @@ pub trait Aggregator<const VERIFY_KEY_SIZE: usize, const NONCE_SIZE: usize>: Vda
&self,
agg_param: &Self::AggregationParam,
output_shares: M,
) -> Result<Self::AggregateShare, VdafError>;
) -> Result<Self::AggregateShare, VdafError> {
let mut share = self.aggregate_init(agg_param);
for output_share in output_shares {
share.accumulate(&output_share)?;
}
Ok(share)
}

/// Create an empty aggregate share.
fn aggregate_init(&self, agg_param: &Self::AggregationParam) -> Self::AggregateShare;

/// Validates an aggregation parameter with respect to all previous aggregaiton parameters used
/// for the same input share. `prev` MUST be sorted from least to most recently used.
Expand Down
12 changes: 2 additions & 10 deletions src/vdaf/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,8 @@ impl vdaf::Aggregator<0, 16> for Vdaf {
(self.prep_step_fn)(&state)
}

fn aggregate<M: IntoIterator<Item = Self::OutputShare>>(
&self,
_aggregation_param: &Self::AggregationParam,
output_shares: M,
) -> Result<Self::AggregateShare, VdafError> {
let mut aggregate_share = AggregateShare(0);
for output_share in output_shares {
aggregate_share.accumulate(&output_share)?;
}
Ok(aggregate_share)
fn aggregate_init(&self, _agg_param: &Self::AggregationParam) -> Self::AggregateShare {
AggregateShare(0)
}

fn is_agg_param_valid(_cur: &Self::AggregationParam, _prev: &[Self::AggregationParam]) -> bool {
Expand Down
14 changes: 3 additions & 11 deletions src/vdaf/mastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,23 +641,15 @@ where
Ok(PrepareTransition::Finish(output_shares))
}

fn aggregate<M: IntoIterator<Item = MasticOutputShare<T::Field>>>(
&self,
agg_param: &MasticAggregationParam,
output_shares: M,
) -> Result<MasticAggregateShare<T::Field>, VdafError> {
let mut agg_share = MasticAggregateShare::<T::Field>::from(vec![
fn aggregate_init(&self, agg_param: &Self::AggregationParam) -> Self::AggregateShare {
MasticAggregateShare::<T::Field>::from(vec![
T::Field::zero();
self.vidpf.weight_parameter
* agg_param
.level_and_prefixes
.prefixes()
.len()
]);
for output_share in output_shares.into_iter() {
agg_share.accumulate(&output_share)?;
}
Ok(agg_share)
])
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/vdaf/poplar1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,15 +1251,10 @@ impl<P: Xof<SEED_SIZE>, const SEED_SIZE: usize> Aggregator<SEED_SIZE, 16>
}
}

fn aggregate<M: IntoIterator<Item = Poplar1FieldVec>>(
&self,
agg_param: &Poplar1AggregationParam,
output_shares: M,
) -> Result<Poplar1FieldVec, VdafError> {
aggregate(
fn aggregate_init(&self, agg_param: &Self::AggregationParam) -> Self::AggregateShare {
Poplar1FieldVec::zero(
usize::from(agg_param.level) == self.bits - 1,
agg_param.prefixes.len(),
output_shares,
)
}

Expand Down
13 changes: 2 additions & 11 deletions src/vdaf/prio2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,8 @@ impl Aggregator<32, 16> for Prio2 {
Ok(PrepareTransition::Finish(OutputShare::from(data)))
}

fn aggregate<M: IntoIterator<Item = OutputShare<FieldPrio2>>>(
&self,
_agg_param: &Self::AggregationParam,
out_shares: M,
) -> Result<AggregateShare<FieldPrio2>, VdafError> {
let mut agg_share = AggregateShare(vec![FieldPrio2::zero(); self.input_len]);
for out_share in out_shares.into_iter() {
agg_share.accumulate(&out_share)?;
}

Ok(agg_share)
fn aggregate_init(&self, _agg_param: &Self::AggregationParam) -> Self::AggregateShare {
AggregateShare(vec![FieldPrio2::zero(); self.input_len])
}

/// Returns `true` iff `prev.is_empty()`
Expand Down
14 changes: 2 additions & 12 deletions src/vdaf/prio3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,18 +1440,8 @@ where
Ok(PrepareTransition::Finish(output_share))
}

/// Aggregates a sequence of output shares into an aggregate share.
fn aggregate<It: IntoIterator<Item = OutputShare<T::Field>>>(
&self,
_agg_param: &(),
output_shares: It,
) -> Result<AggregateShare<T::Field>, VdafError> {
let mut agg_share = AggregateShare(vec![T::Field::zero(); self.typ.output_len()]);
for output_share in output_shares.into_iter() {
agg_share.accumulate(&output_share)?;
}

Ok(agg_share)
fn aggregate_init(&self, _agg_param: &Self::AggregationParam) -> Self::AggregateShare {
AggregateShare(vec![T::Field::zero(); self.typ.output_len()])
}

/// Returns `true` iff `prev.is_empty()`
Expand Down
Loading