Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Rosenberg committed Dec 5, 2024
1 parent 828a4cb commit c3ff955
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion binaries/src/bin/vdaf_message_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() {
)
);

let max_measurement = 987_234;
let max_measurement = 0xffff_ffff;
let prio3 = Prio3::new_sum(num_shares, max_measurement).unwrap();
let measurement = 1337;
println!(
Expand Down
18 changes: 8 additions & 10 deletions src/flp/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ impl<F: FftFriendlyFieldElement> Type for Sum<F> {
)));
}

let enc_summand: Vec<F> = F::encode_as_bitvector(*summand, self.bits)?.collect();
let enc_summand_plus_offset =
F::encode_as_bitvector(self.offset + *summand, self.bits)?.collect();
let enc_summand = F::encode_as_bitvector(*summand, self.bits)?;
let enc_summand_plus_offset = F::encode_as_bitvector(self.offset + *summand, self.bits)?;

Ok([enc_summand, enc_summand_plus_offset].concat())
Ok(enc_summand.chain(enc_summand_plus_offset).collect())
}

fn decode_result(&self, data: &[F], _num_measurements: usize) -> Result<F::Integer, FlpError> {
Expand Down Expand Up @@ -264,7 +263,7 @@ impl<F: FftFriendlyFieldElement> Type for Sum<F> {
}
}

/// The average type. Each measurement is a integer in `[0, max_measurement]` and the aggregate is
/// The average type. Each measurement is an integer in `[0, max_measurement]` and the aggregate is
/// the arithmetic average of the measurements.
// This is just a `Sum` object under the hood. The only difference is that the aggregate result is
// an f64, which we get by dividing by `num_measurements`
Expand Down Expand Up @@ -640,20 +639,19 @@ where
}

// Convert bool vector to field elems
let multihot_vec: Vec<F> = measurement
let multihot_vec = measurement
.iter()
// We can unwrap because any Integer type can cast from bool
.map(|bit| F::from(F::valid_integer_try_from(*bit as usize).unwrap()))
.collect();
.map(|bit| F::from(F::valid_integer_try_from(*bit as usize).unwrap()));

// Encode the measurement weight in binary (actually, the weight plus some offset)
let offset_weight_bits = {
let offset_weight_reported = F::valid_integer_try_from(self.offset + weight_reported)?;
F::encode_as_bitvector(offset_weight_reported, self.bits_for_weight)?.collect()
F::encode_as_bitvector(offset_weight_reported, self.bits_for_weight)?
};

// Report the concat of the two
Ok([multihot_vec, offset_weight_bits].concat())
Ok(multihot_vec.chain(offset_weight_bits).collect())
}

fn decode_result(
Expand Down
8 changes: 4 additions & 4 deletions src/vdaf/prio3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub type Prio3Sum = Prio3<Sum<Field128>, XofTurboShake128, 16>;

impl Prio3Sum {
/// Construct an instance of `Prio3Sum` with the given number of aggregators, where each summand
/// must be in the range `[0, max_measurement)`.
/// must be in the range `[0, max_measurement]`.
///
/// # Panics
/// Panics if `max_measurement == 0`
Expand Down Expand Up @@ -343,7 +343,7 @@ pub type Prio3Average = Prio3<Average<Field128>, XofTurboShake128, 16>;

impl Prio3Average {
/// Construct an instance of `Prio3Average` with the given number of aggregators, where each
/// summand must be in the range `[0, max_measurement)`.
/// summand must be in the range `[0, max_measurement]`.
///
/// # Panics
/// Panics if `max_measurement == 0`
Expand Down Expand Up @@ -1707,8 +1707,8 @@ mod tests {
let prio3 = Prio3::new_sum(3, max_measurement).unwrap();

assert_eq!(
run_vdaf(CTX_STR, &prio3, &(), [0, max_measurement - 2, 0, 1, 1]).unwrap(),
max_measurement
run_vdaf(CTX_STR, &prio3, &(), [0, max_measurement, 0, 1, 1]).unwrap(),
max_measurement + 2,
);

let mut verify_key = [0; 16];
Expand Down

0 comments on commit c3ff955

Please sign in to comment.