Skip to content

Commit

Permalink
Merge branch 'main' into combine-meas-and-proof-seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Rosenberg committed Jan 6, 2025
2 parents 606c72a + 6a7a916 commit 392f68d
Show file tree
Hide file tree
Showing 71 changed files with 7,352 additions and 2,780 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions benches/cycle_counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn prio2_shard_and_prepare_1000() -> Prio2PrepareShare {
prio2_shard_and_prepare(1000)
}

fn prio3_client_count() -> Vec<Prio3InputShare<Field64, 16>> {
fn prio3_client_count() -> Vec<Prio3InputShare<Field64, 32>> {
let prio3 = Prio3::new_count(2).unwrap();
let measurement = true;
let nonce = [0; 16];
Expand All @@ -115,7 +115,7 @@ fn prio3_client_count() -> Vec<Prio3InputShare<Field64, 16>> {
.1
}

fn prio3_client_histogram_10() -> Vec<Prio3InputShare<Field128, 16>> {
fn prio3_client_histogram_10() -> Vec<Prio3InputShare<Field128, 32>> {
let prio3 = Prio3::new_histogram(2, 10, 3).unwrap();
let measurement = 9;
let nonce = [0; 16];
Expand All @@ -125,8 +125,9 @@ fn prio3_client_histogram_10() -> Vec<Prio3InputShare<Field128, 16>> {
.1
}

fn prio3_client_sum_32() -> Vec<Prio3InputShare<Field128, 16>> {
let prio3 = Prio3::new_sum(2, 16).unwrap();
fn prio3_client_sum_32() -> Vec<Prio3InputShare<Field64, 32>> {
let bits = 16;
let prio3 = Prio3::new_sum(2, (1 << bits) - 1).unwrap();
let measurement = 1337;
let nonce = [0; 16];
prio3
Expand All @@ -135,7 +136,7 @@ fn prio3_client_sum_32() -> Vec<Prio3InputShare<Field128, 16>> {
.1
}

fn prio3_client_count_vec_1000() -> Vec<Prio3InputShare<Field128, 16>> {
fn prio3_client_count_vec_1000() -> Vec<Prio3InputShare<Field128, 32>> {
let len = 1000;
let prio3 = Prio3::new_sum_vec(2, 1, len, 31).unwrap();
let measurement = vec![0; len];
Expand All @@ -147,7 +148,7 @@ fn prio3_client_count_vec_1000() -> Vec<Prio3InputShare<Field128, 16>> {
}

#[cfg(feature = "multithreaded")]
fn prio3_client_count_vec_multithreaded_1000() -> Vec<Prio3InputShare<Field128, 16>> {
fn prio3_client_count_vec_multithreaded_1000() -> Vec<Prio3InputShare<Field128, 32>> {
let len = 1000;
let prio3 = Prio3::new_sum_vec_multithreaded(2, 1, len, 31).unwrap();
let measurement = vec![0; len];
Expand Down
74 changes: 46 additions & 28 deletions benches/speed_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use prio::dp::distributions::DiscreteGaussian;
use prio::idpf::test_utils::generate_zipf_distributed_batch;
#[cfg(feature = "experimental")]
use prio::vdaf::prio2::Prio2;
#[cfg(feature = "experimental")]
use prio::vidpf::VidpfServerId;
use prio::{
benchmarked::*,
field::{random_vector, Field128 as F, FieldElement},
Expand Down Expand Up @@ -179,7 +181,7 @@ fn prio3(c: &mut Criterion) {
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 verify_key = black_box([0u8; 32]);
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
Expand All @@ -198,8 +200,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,10 +213,11 @@ 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 verify_key = black_box([0u8; 32]);
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
Expand Down Expand Up @@ -282,7 +287,7 @@ fn prio3(c: &mut Criterion) {
.map(|i| i & 1)
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
Expand Down Expand Up @@ -318,7 +323,7 @@ fn prio3(c: &mut Criterion) {
.map(|i| i & 1)
.collect::<Vec<_>>();
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
Expand Down Expand Up @@ -411,7 +416,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]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) = vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
vdaf.prepare_init(
Expand Down Expand Up @@ -453,7 +458,7 @@ fn prio3(c: &mut Criterion) {
.unwrap();
let measurement = black_box(0);
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
Expand Down Expand Up @@ -487,7 +492,7 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("serial", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
Expand All @@ -504,7 +509,7 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("parallel", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum_multithreaded(
num_shares, *dimension,
)
Expand All @@ -525,12 +530,12 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("series", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
Expand All @@ -556,15 +561,15 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("parallel", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F15, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum_multithreaded(
num_shares, *dimension,
)
.unwrap();
let mut measurement = vec![FP16_ZERO; *dimension];
measurement[0] = FP16_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
Expand All @@ -591,7 +596,7 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("serial", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
Expand All @@ -608,7 +613,7 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("parallel", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum_multithreaded(
num_shares, *dimension,
)
Expand All @@ -629,12 +634,12 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("series", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum(num_shares, *dimension).unwrap();
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
Expand All @@ -660,15 +665,15 @@ fn prio3(c: &mut Criterion) {
BenchmarkId::new("parallel", dimension),
&dimension,
|b, dimension| {
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 16> =
let vdaf: Prio3<FixedPointBoundedL2VecSum<I1F31, _, _>, _, 32> =
Prio3::new_fixedpoint_boundedl2_vec_sum_multithreaded(
num_shares, *dimension,
)
.unwrap();
let mut measurement = vec![FP32_ZERO; *dimension];
measurement[0] = FP32_HALF;
let nonce = black_box([0u8; 16]);
let verify_key = black_box([0u8; 16]);
let verify_key = black_box([0u8; 32]);
let (public_share, input_shares) =
vdaf.shard(b"", &measurement, &nonce).unwrap();
b.iter(|| {
Expand Down Expand Up @@ -794,7 +799,7 @@ fn poplar1(c: &mut Criterion) {
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let vdaf = Poplar1::new_turboshake128(size);
let mut rng = StdRng::seed_from_u64(RNG_SEED);
let verify_key: [u8; 16] = rng.gen();
let verify_key: [u8; 32] = rng.gen();
let nonce: [u8; 16] = rng.gen();

// Parameters are chosen to match Chris Wood's experimental setup:
Expand Down Expand Up @@ -854,10 +859,12 @@ fn vidpf(c: &mut Criterion) {
let input = VidpfInput::from_bools(&bits);
let weight = VidpfWeight::from(vec![Field255::one(), Field255::one()]);

let vidpf = Vidpf::<VidpfWeight<Field255>, NONCE_SIZE>::new(2);
let vidpf = Vidpf::<VidpfWeight<Field255>>::new(bits.len(), 2).unwrap();

b.iter(|| {
let _ = vidpf.gen(&input, &weight, NONCE).unwrap();
let _ = vidpf
.gen(b"some application", &input, &weight, NONCE)
.unwrap();
});
});
}
Expand All @@ -870,12 +877,23 @@ fn vidpf(c: &mut Criterion) {
let bits = iter::repeat_with(random).take(size).collect::<Vec<bool>>();
let input = VidpfInput::from_bools(&bits);
let weight = VidpfWeight::from(vec![Field255::one(), Field255::one()]);
let vidpf = Vidpf::<VidpfWeight<Field255>, NONCE_SIZE>::new(2);
let vidpf = Vidpf::<VidpfWeight<Field255>>::new(bits.len(), 2).unwrap();

let (public, keys) = vidpf.gen(&input, &weight, NONCE).unwrap();
let (public, keys) = vidpf
.gen(b"some application", &input, &weight, NONCE)
.unwrap();

b.iter(|| {
let _ = vidpf.eval(&keys[0], &public, &input, NONCE).unwrap();
let _ = vidpf
.eval(
b"some application",
VidpfServerId::S0,
&keys[0],
&public,
&input,
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
12 changes: 5 additions & 7 deletions src/bt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
// TODO(#947): Remove these lines once the module gets used by Mastic implementation.
#![allow(dead_code)]
#![allow(unused_variables)]

use core::fmt::Debug;
use std::io::Cursor;

Expand All @@ -78,13 +76,13 @@ type SubTree<V> = Option<Box<Node<V>>>;

/// Represents a node of a binary tree.
pub struct Node<V> {
value: V,
left: SubTree<V>,
right: SubTree<V>,
pub(crate) value: V,
pub(crate) left: SubTree<V>,
pub(crate) right: SubTree<V>,
}

impl<V> Node<V> {
fn new(value: V) -> Self {
pub(crate) fn new(value: V) -> Self {
Self {
value,
left: None,
Expand Down Expand Up @@ -181,7 +179,7 @@ impl<V> Node<V> {

/// Represents an append-only binary tree.
pub struct BinaryTree<V> {
root: SubTree<V>,
pub(crate) root: SubTree<V>,
}

impl<V> BinaryTree<V> {
Expand Down
Loading

0 comments on commit 392f68d

Please sign in to comment.