Skip to content

Commit

Permalink
Add aggegation initialization method (#1172)
Browse files Browse the repository at this point in the history
* Add method to construct an empty aggregate share

* Add default implementation of aggregate()
  • Loading branch information
divergentdave authored Jan 6, 2025
1 parent cc2eb8f commit 2c44f2f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 52 deletions.
11 changes: 10 additions & 1 deletion src/vdaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,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 @@ -725,23 +725,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 @@ -1573,18 +1573,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

0 comments on commit 2c44f2f

Please sign in to comment.