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

Added max_measurement field to Prio3Sum type #1150

Merged
merged 4 commits into from
Dec 9, 2024
Merged
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
3 changes: 2 additions & 1 deletion benches/cycle_counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ fn prio3_client_histogram_10() -> Vec<Prio3InputShare<Field128, 16>> {
}

fn prio3_client_sum_32() -> Vec<Prio3InputShare<Field128, 16>> {
let prio3 = Prio3::new_sum(2, 16).unwrap();
let bits = 16;
let prio3 = Prio3::new_sum(2, (1 << bits) - 1).unwrap();
let measurement = 1337;
let nonce = [0; 16];
prio3
Expand Down
11 changes: 7 additions & 4 deletions benches/speed_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ fn prio3(c: &mut Criterion) {
let mut group = c.benchmark_group("prio3sum_shard");
for bits in [8, 32] {
group.bench_with_input(BenchmarkId::from_parameter(bits), &bits, |b, bits| {
let vdaf = Prio3::new_sum(num_shares, *bits).unwrap();
let measurement = (1 << bits) - 1;
// Doesn't matter for speed what we use for max measurement, or measurement
let max_measurement = (1 << bits) - 1;
let vdaf = Prio3::new_sum(num_shares, max_measurement).unwrap();
let measurement = max_measurement;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
});
Expand All @@ -209,8 +211,9 @@ fn prio3(c: &mut Criterion) {
let mut group = c.benchmark_group("prio3sum_prepare_init");
for bits in [8, 32] {
group.bench_with_input(BenchmarkId::from_parameter(bits), &bits, |b, bits| {
let vdaf = Prio3::new_sum(num_shares, *bits).unwrap();
let measurement = (1 << bits) - 1;
let max_measurement = (1 << bits) - 1;
let vdaf = Prio3::new_sum(num_shares, max_measurement).unwrap();
let measurement = max_measurement;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions binaries/src/bin/vdaf_message_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ fn main() {
)
);

let bits = 32;
let prio3 = Prio3::new_sum(num_shares, bits).unwrap();
let max_measurement = 0xffff_ffff;
let prio3 = Prio3::new_sum(num_shares, max_measurement).unwrap();
let measurement = 1337;
println!(
"prio3 sum ({} bits) share size = {}",
bits,
max_measurement.ilog2() + 1,
vdaf_input_share_size::<Prio3Sum, 16>(
prio3.shard(PRIO3_CTX_STR, &measurement, &nonce).unwrap()
)
Expand Down
15 changes: 15 additions & 0 deletions src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ pub trait Integer:

/// Returns one.
fn one() -> Self;

/// Returns ⌊log₂(self)⌋, or `None` if `self == 0`
fn checked_ilog2(&self) -> Option<u32>;
}

/// Extension trait for field elements that can be converted back and forth to an integer type.
Expand Down Expand Up @@ -785,6 +788,10 @@ impl Integer for u32 {
fn one() -> Self {
1
}

fn checked_ilog2(&self) -> Option<u32> {
u32::checked_ilog2(*self)
}
}

impl Integer for u64 {
Expand All @@ -798,6 +805,10 @@ impl Integer for u64 {
fn one() -> Self {
1
}

fn checked_ilog2(&self) -> Option<u32> {
u64::checked_ilog2(*self)
}
}

impl Integer for u128 {
Expand All @@ -811,6 +822,10 @@ impl Integer for u128 {
fn one() -> Self {
1
}

fn checked_ilog2(&self) -> Option<u32> {
u128::checked_ilog2(*self)
}
}

make_field!(
Expand Down
6 changes: 6 additions & 0 deletions src/field/field255.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,12 @@ mod tests {
fn one() -> Self {
Self::new(Vec::from([1]))
}

fn checked_ilog2(&self) -> Option<u32> {
// This is a test module, and this code is never used. If we need this in the future,
// use BigUint::bits()
unimplemented!()
}
}

impl TestFieldElementWithInteger for Field255 {
Expand Down
12 changes: 8 additions & 4 deletions src/flp/szk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,9 @@ mod tests {
#[test]
fn test_sum_proof_share_encode() {
let mut nonce = [0u8; 16];
let max_measurement = 13;
thread_rng().fill(&mut nonce[..]);
let sum = Sum::<Field128>::new(5).unwrap();
let sum = Sum::<Field128>::new(max_measurement).unwrap();
let encoded_measurement = sum.encode_measurement(&9).unwrap();
let algorithm_id = 5;
let szk_typ = Szk::new_turboshake128(sum, algorithm_id);
Expand Down Expand Up @@ -896,9 +897,10 @@ mod tests {

#[test]
fn test_sum_leader_proof_share_roundtrip() {
let max_measurement = 13;
let mut nonce = [0u8; 16];
thread_rng().fill(&mut nonce[..]);
let sum = Sum::<Field128>::new(5).unwrap();
let sum = Sum::<Field128>::new(max_measurement).unwrap();
let encoded_measurement = sum.encode_measurement(&9).unwrap();
let algorithm_id = 5;
let szk_typ = Szk::new_turboshake128(sum, algorithm_id);
Expand Down Expand Up @@ -936,9 +938,10 @@ mod tests {

#[test]
fn test_sum_helper_proof_share_roundtrip() {
let max_measurement = 13;
let mut nonce = [0u8; 16];
thread_rng().fill(&mut nonce[..]);
let sum = Sum::<Field128>::new(5).unwrap();
let sum = Sum::<Field128>::new(max_measurement).unwrap();
let encoded_measurement = sum.encode_measurement(&9).unwrap();
let algorithm_id = 5;
let szk_typ = Szk::new_turboshake128(sum, algorithm_id);
Expand Down Expand Up @@ -1138,7 +1141,8 @@ mod tests {

#[test]
fn test_sum() {
let sum = Sum::<Field128>::new(5).unwrap();
let max_measurement = 13;
let sum = Sum::<Field128>::new(max_measurement).unwrap();

let five = Field128::from(5);
let nine = sum.encode_measurement(&9).unwrap();
Expand Down
Loading
Loading