//! Implementation of a dummy VDAF which conforms to the specification in [draft-irtf-cfrg-vdaf-06] //! but does nothing. Useful for testing. //! //! [draft-irtf-cfrg-vdaf-06]: https://datatracker.ietf.org/doc/draft-irtf-cfrg-vdaf/06/
usecrate::{
codec::{CodecError, Decode, Encode},
vdaf::{self, Aggregatable, PrepareTransition, VdafError},
}; use rand::random; use std::{fmt::Debug, io::Cursor, sync::Arc};
/// The Dummy VDAF does summation modulus 256 so we can predict aggregation results. const MODULUS: u64 = u8::MAX as u64 + 1;
impl vdaf::Vdaf for Vdaf { type Measurement = u8; type AggregateResult = u64; type AggregationParam = AggregationParam; type PublicShare = (); type InputShare = InputShare; type OutputShare = OutputShare; type AggregateShare = AggregateShare;
fn algorithm_id(&self) -> u32 { 0xFFFF0000
}
fn num_aggregators(&self) -> usize { 2
}
}
impl vdaf::Aggregator<0, 16> for Vdaf { type PrepareState = PrepareState; type PrepareShare = (); type PrepareMessage = ();
impl vdaf::Collector for Vdaf { fn unshard<M: IntoIterator<Item = Self::AggregateShare>>(
&self,
aggregation_param: &Self::AggregationParam,
agg_shares: M,
_num_measurements: usize,
) -> Result<Self::AggregateResult, VdafError> {
Ok(agg_shares
.into_iter()
.fold(0, |acc, share| (acc + share.0) % MODULUS) // Sum in the aggregation parameter so that collections over the same measurements with // varying parameters will yield predictable but distinct results.
+ u64::from(aggregation_param.0))
}
}
/// Returns the aggregate result that the dummy VDAF would compute over the provided measurements, /// for the provided aggregation parameter. pubfn expected_aggregate_result<M>(aggregation_parameter: u8, measurements: M) -> u64 where
M: IntoIterator<Item = u8>,
{
(measurements.into_iter().map(u64::from).sum::<u64>()) % MODULUS
+ u64::from(aggregation_parameter)
}
#[cfg(test)] mod tests { usesuper::*; usecrate::vdaf::{test_utils::run_vdaf_sharded, Client}; use rand::prelude::*;
letmut sharded_measurements = Vec::new(); for measurement in measurements { let nonce = thread_rng().gen(); let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.