Skip to content

Commit

Permalink
Add context string to VDAF (#1145)
Browse files Browse the repository at this point in the history
* Added ctx argument for sharding methods

* Added ctx to domain_separation_tag, and propagated changes from there

Co-authored-by: Michael Rosenberg <[email protected]>
  • Loading branch information
rozbb and Michael Rosenberg authored Nov 20, 2024
1 parent d57731b commit c85e537
Show file tree
Hide file tree
Showing 12 changed files with 501 additions and 186 deletions.
29 changes: 21 additions & 8 deletions benches/cycle_counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ fn prio2_client(size: usize) -> Vec<Share<FieldPrio2, 32>> {
let prio2 = Prio2::new(size).unwrap();
let input = vec![0u32; size];
let nonce = [0; 16];
prio2.shard(&black_box(input), &black_box(nonce)).unwrap().1
prio2
.shard(b"", &black_box(input), &black_box(nonce))
.unwrap()
.1
}

#[cfg(feature = "experimental")]
Expand All @@ -70,9 +73,19 @@ fn prio2_shard_and_prepare(size: usize) -> Prio2PrepareShare {
let prio2 = Prio2::new(size).unwrap();
let input = vec![0u32; size];
let nonce = [0; 16];
let (public_share, input_shares) = prio2.shard(&black_box(input), &black_box(nonce)).unwrap();
let (public_share, input_shares) = prio2
.shard(b"", &black_box(input), &black_box(nonce))
.unwrap();
prio2
.prepare_init(&[0; 32], 0, &(), &nonce, &public_share, &input_shares[0])
.prepare_init(
&[0; 32],
b"",
0,
&(),
&nonce,
&public_share,
&input_shares[0],
)
.unwrap()
.1
}
Expand All @@ -97,7 +110,7 @@ fn prio3_client_count() -> Vec<Prio3InputShare<Field64, 16>> {
let measurement = true;
let nonce = [0; 16];
prio3
.shard(&black_box(measurement), &black_box(nonce))
.shard(b"", &black_box(measurement), &black_box(nonce))
.unwrap()
.1
}
Expand All @@ -107,7 +120,7 @@ fn prio3_client_histogram_10() -> Vec<Prio3InputShare<Field128, 16>> {
let measurement = 9;
let nonce = [0; 16];
prio3
.shard(&black_box(measurement), &black_box(nonce))
.shard(b"", &black_box(measurement), &black_box(nonce))
.unwrap()
.1
}
Expand All @@ -117,7 +130,7 @@ fn prio3_client_sum_32() -> Vec<Prio3InputShare<Field128, 16>> {
let measurement = 1337;
let nonce = [0; 16];
prio3
.shard(&black_box(measurement), &black_box(nonce))
.shard(b"", &black_box(measurement), &black_box(nonce))
.unwrap()
.1
}
Expand All @@ -128,7 +141,7 @@ fn prio3_client_count_vec_1000() -> Vec<Prio3InputShare<Field128, 16>> {
let measurement = vec![0; len];
let nonce = [0; 16];
prio3
.shard(&black_box(measurement), &black_box(nonce))
.shard(b"", &black_box(measurement), &black_box(nonce))
.unwrap()
.1
}
Expand All @@ -140,7 +153,7 @@ fn prio3_client_count_vec_multithreaded_1000() -> Vec<Prio3InputShare<Field128,
let measurement = vec![0; len];
let nonce = [0; 16];
prio3
.shard(&black_box(measurement), &black_box(nonce))
.shard(b"", &black_box(measurement), &black_box(nonce))
.unwrap()
.1
}
Expand Down
119 changes: 85 additions & 34 deletions benches/speed_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn prio2(c: &mut Criterion) {
.map(|i| i & 1)
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -145,10 +145,18 @@ fn prio2(c: &mut Criterion) {
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(&verify_key, 0, &(), &nonce, &public_share, &input_shares[0])
.unwrap();
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
&public_share,
&input_shares[0],
)
.unwrap();
});
},
);
Expand All @@ -164,18 +172,26 @@ fn prio3(c: &mut Criterion) {
let vdaf = Prio3::new_count(num_shares).unwrap();
let measurement = black_box(true);
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
});

c.bench_function("prio3count_prepare_init", |b| {
let vdaf = Prio3::new_count(num_shares).unwrap();
let measurement = black_box(true);
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(&verify_key, 0, &(), &nonce, &public_share, &input_shares[0])
.unwrap()
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
&public_share,
&input_shares[0],
)
.unwrap()
});
});

Expand All @@ -185,7 +201,7 @@ fn prio3(c: &mut Criterion) {
let vdaf = Prio3::new_sum(num_shares, *bits).unwrap();
let measurement = (1 << bits) - 1;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
});
}
group.finish();
Expand All @@ -197,10 +213,18 @@ fn prio3(c: &mut Criterion) {
let measurement = (1 << bits) - 1;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(&verify_key, 0, &(), &nonce, &public_share, &input_shares[0])
.unwrap()
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
&public_share,
&input_shares[0],
)
.unwrap()
});
});
}
Expand All @@ -217,7 +241,7 @@ fn prio3(c: &mut Criterion) {
.map(|i| i & 1)
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -240,7 +264,7 @@ fn prio3(c: &mut Criterion) {
.map(|i| i & 1)
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -259,10 +283,18 @@ fn prio3(c: &mut Criterion) {
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(&verify_key, 0, &(), &nonce, &public_share, &input_shares[0])
.unwrap()
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
&public_share,
&input_shares[0],
)
.unwrap()
});
},
);
Expand All @@ -287,10 +319,12 @@ fn prio3(c: &mut Criterion) {
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
Expand Down Expand Up @@ -323,7 +357,7 @@ fn prio3(c: &mut Criterion) {
let vdaf = Prio3::new_histogram(num_shares, *input_length, *chunk_length).unwrap();
let measurement = black_box(0);
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand Down Expand Up @@ -352,7 +386,7 @@ fn prio3(c: &mut Criterion) {
.unwrap();
let measurement = black_box(0);
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -378,10 +412,18 @@ fn prio3(c: &mut Criterion) {
let measurement = black_box(0);
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(&verify_key, 0, &(), &nonce, &public_share, &input_shares[0])
.unwrap()
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
&public_share,
&input_shares[0],
)
.unwrap()
});
},
);
Expand Down Expand Up @@ -412,10 +454,12 @@ fn prio3(c: &mut Criterion) {
let measurement = black_box(0);
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
Expand Down Expand Up @@ -448,7 +492,7 @@ fn prio3(c: &mut Criterion) {
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -468,7 +512,7 @@ fn prio3(c: &mut Criterion) {
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -487,10 +531,12 @@ fn prio3(c: &mut Criterion) {
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
Expand Down Expand Up @@ -520,10 +566,11 @@ fn prio3(c: &mut Criterion) {
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) =
vdaf.shard(&measurement, &nonce).unwrap();
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
Expand All @@ -549,7 +596,7 @@ fn prio3(c: &mut Criterion) {
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -569,7 +616,7 @@ fn prio3(c: &mut Criterion) {
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
b.iter(|| vdaf.shard(&measurement, &nonce).unwrap());
b.iter(|| vdaf.shard(b"", &measurement, &nonce).unwrap());
},
);
}
Expand All @@ -588,10 +635,12 @@ fn prio3(c: &mut Criterion) {
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) = vdaf.shard(&measurement, &nonce).unwrap();
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
Expand Down Expand Up @@ -621,10 +670,11 @@ fn prio3(c: &mut Criterion) {
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let (public_share, input_shares) =
vdaf.shard(&measurement, &nonce).unwrap();
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&(),
&nonce,
Expand Down Expand Up @@ -724,7 +774,7 @@ fn poplar1(c: &mut Criterion) {
let measurement = IdpfInput::from_bools(&bits);

b.iter(|| {
vdaf.shard(&measurement, &nonce).unwrap();
vdaf.shard(b"", &measurement, &nonce).unwrap();
});
});
}
Expand Down Expand Up @@ -753,7 +803,7 @@ fn poplar1(c: &mut Criterion) {
// We are benchmarking preparation of a single report. For this test, it doesn't matter
// which measurement we generate a report for, so pick the first measurement
// arbitrarily.
let (public_share, input_shares) = vdaf.shard(&measurements[0], &nonce).unwrap();
let (public_share, input_shares) = vdaf.shard(b"", &measurements[0], &nonce).unwrap();
let input_share = input_shares.into_iter().next().unwrap();

// For the aggregation paramter, we use the candidate prefixes from the prefix tree for
Expand All @@ -765,6 +815,7 @@ fn poplar1(c: &mut Criterion) {
b.iter(|| {
vdaf.prepare_init(
&verify_key,
b"",
0,
&agg_param,
&nonce,
Expand Down
Loading

0 comments on commit c85e537

Please sign in to comment.