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

Implement Verifiable Incremental Distributed Point Function (VIDPF). #954

Merged
merged 1 commit into from
Mar 11, 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
47 changes: 46 additions & 1 deletion benches/speed_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,53 @@ fn poplar1(c: &mut Criterion) {
group.finish();
}

/// Benchmark VIDPF performance.
#[cfg(feature = "experimental")]
criterion_group!(benches, poplar1, prio3, prio2, poly_mul, prng, idpf, dp_noise);
fn vidpf(c: &mut Criterion) {
use prio::vidpf::{Vidpf, VidpfInput, VidpfWeight};

let test_sizes = [8usize, 8 * 16, 8 * 256];
const NONCE_SIZE: usize = 16;
const NONCE: &[u8; NONCE_SIZE] = b"Test Nonce VIDPF";

let mut group = c.benchmark_group("vidpf_gen");
for size in test_sizes.iter() {
group.throughput(Throughput::Bytes(*size as u64 / 8));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
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);

b.iter(|| {
let _ = vidpf.gen(&input, &weight, NONCE).unwrap();
});
});
}
group.finish();

let mut group = c.benchmark_group("vidpf_eval");
for size in test_sizes.iter() {
group.throughput(Throughput::Bytes(*size as u64 / 8));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
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 (public, keys) = vidpf.gen(&input, &weight, NONCE).unwrap();

b.iter(|| {
let _ = vidpf.eval(&keys[0], &public, &input, NONCE).unwrap();
});
});
}
group.finish();
}

#[cfg(feature = "experimental")]
criterion_group!(benches, poplar1, prio3, prio2, poly_mul, prng, idpf, dp_noise, vidpf);
#[cfg(not(feature = "experimental"))]
criterion_group!(benches, prio3, prng, poly_mul);

Expand Down
19 changes: 15 additions & 4 deletions src/idpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::{
collections::{HashMap, VecDeque},
fmt::Debug,
io::{Cursor, Read},
iter::zip,
ops::{Add, AddAssign, ControlFlow, Index, Sub},
};
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};
Expand Down Expand Up @@ -108,6 +109,11 @@ impl IdpfInput {
index: self.index[..=level].to_owned().into(),
}
}

/// Return the bit at the specified level if the level is in bounds.
pub fn get(&self, level: usize) -> Option<bool> {
self.index.get(level).as_deref().copied()
}
}

impl From<BitVec<usize, Lsb0>> for IdpfInput {
Expand Down Expand Up @@ -147,7 +153,7 @@ pub trait IdpfValue:
+ Sub<Output = Self>
+ ConditionallyNegatable
+ Encode
+ Decode
+ ParameterizedDecode<Self::ValueParameter>
+ Sized
{
/// Any run-time parameters needed to produce a value.
Expand Down Expand Up @@ -788,7 +794,7 @@ where

impl<V> Eq for IdpfCorrectionWord<V> where V: ConstantTimeEq {}

fn xor_seeds(left: &[u8; 16], right: &[u8; 16]) -> [u8; 16] {
pub(crate) fn xor_seeds(left: &[u8; 16], right: &[u8; 16]) -> [u8; 16] {
let mut seed = [0u8; 16];
for (a, (b, c)) in left.iter().zip(right.iter().zip(seed.iter_mut())) {
*c = a ^ b;
Expand Down Expand Up @@ -822,7 +828,7 @@ fn control_bit_to_seed_mask(control: Choice) -> [u8; 16] {

/// Take two seeds and a control bit, and return the first seed if the control bit is zero, or the
/// XOR of the two seeds if the control bit is one. This does not branch on the control bit.
fn conditional_xor_seeds(
pub(crate) fn conditional_xor_seeds(
normal_input: &[u8; 16],
switched_input: &[u8; 16],
control: Choice,
Expand All @@ -835,13 +841,18 @@ fn conditional_xor_seeds(

/// Returns one of two seeds, depending on the value of a selector bit. Does not branch on the
/// selector input or make selector-dependent memory accesses.
fn conditional_select_seed(select: Choice, seeds: &[[u8; 16]; 2]) -> [u8; 16] {
pub(crate) fn conditional_select_seed(select: Choice, seeds: &[[u8; 16]; 2]) -> [u8; 16] {
or_seeds(
&and_seeds(&control_bit_to_seed_mask(!select), &seeds[0]),
&and_seeds(&control_bit_to_seed_mask(select), &seeds[1]),
)
}

/// Interchange the contents of seeds if the choice is 1, otherwise seeds remain unchanged.
pub(crate) fn conditional_swap_seed(lhs: &mut [u8; 16], rhs: &mut [u8; 16], choice: Choice) {
zip(lhs, rhs).for_each(|(a, b)| u8::conditional_swap(a, b, choice));
}

/// An interface that provides memoization of IDPF computations.
///
/// Each instance of a type implementing `IdpfCache` should only be used with one IDPF key and
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ mod polynomial;
mod prng;
pub mod topology;
pub mod vdaf;
#[cfg(all(feature = "crypto-dependencies", feature = "experimental"))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "crypto-dependencies", feature = "experimental")))
)]
pub mod vidpf;
armfazh marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions src/vdaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use crate::dp::DifferentialPrivacyStrategy;
#[cfg(all(feature = "crypto-dependencies", feature = "experimental"))]
use crate::idpf::IdpfError;
#[cfg(all(feature = "crypto-dependencies", feature = "experimental"))]
use crate::vidpf::VidpfError;
use crate::{
codec::{CodecError, Decode, Encode, ParameterizedDecode},
field::{encode_fieldvec, merge_vector, FieldElement, FieldError},
Expand Down Expand Up @@ -57,6 +59,11 @@ pub enum VdafError {
#[error("idpf error: {0}")]
Idpf(#[from] IdpfError),

/// VIDPF error.
#[cfg(all(feature = "crypto-dependencies", feature = "experimental"))]
#[error("vidpf error: {0}")]
Vidpf(#[from] VidpfError),

/// Errors from other VDAFs.
#[error(transparent)]
Other(Box<dyn Error + 'static + Send + Sync>),
Expand Down
Loading