Skip to content

Commit

Permalink
Add default implementation of aggregate()
Browse files Browse the repository at this point in the history
  • Loading branch information
divergentdave committed Dec 19, 2024
1 parent b26af2b commit 7b95561
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 64 deletions.
8 changes: 7 additions & 1 deletion src/vdaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ 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;
Expand Down
12 changes: 0 additions & 12 deletions src/vdaf/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,6 @@ 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 = self.aggregate_init(aggregation_param);
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)
}
Expand Down
12 changes: 0 additions & 12 deletions src/vdaf/mastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,18 +641,6 @@ 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 = self.aggregate_init(agg_param);
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 {
MasticAggregateShare::<T::Field>::from(vec![
T::Field::zero();
Expand Down
12 changes: 0 additions & 12 deletions src/vdaf/poplar1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,18 +1251,6 @@ 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(
usize::from(agg_param.level) == self.bits - 1,
agg_param.prefixes.len(),
output_shares,
)
}

fn aggregate_init(&self, agg_param: &Self::AggregationParam) -> Self::AggregateShare {
Poplar1FieldVec::zero(
usize::from(agg_param.level) == self.bits - 1,
Expand Down
13 changes: 0 additions & 13 deletions src/vdaf/prio2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,19 +317,6 @@ 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 = self.aggregate_init(&());
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])
}
Expand Down
14 changes: 0 additions & 14 deletions src/vdaf/prio3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,20 +1440,6 @@ 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 = self.aggregate_init(&());
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()])
}
Expand Down

0 comments on commit 7b95561

Please sign in to comment.