Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 3d5f759
Author: ovi <ovi@posteo.de>
Date:   Fri Sep 8 17:57:46 2023 +0200

    ordering ZCdpBudget

commit d6a9985
Author: ovi <ovi@posteo.de>
Date:   Fri Sep 8 17:53:18 2023 +0200

    ordering ZCdpDiscreteGaussians

commit d2cdd4c
Author: ovi <ovi@posteo.de>
Date:   Mon Sep 4 16:17:38 2023 +0200

    non-pub epsilon

commit cfef6a7
Author: ovi <ovi@posteo.de>
Date:   Mon Sep 4 15:07:01 2023 +0200

    pub budget

commit eae7e4e
Author: ovi <ovi@posteo.de>
Date:   Mon Sep 4 14:32:57 2023 +0200

    Display for error

commit 410427e
Author: ovi <ovi@posteo.de>
Date:   Mon Sep 4 13:53:37 2023 +0200

    FromStr for Rational

commit 59f5522
Author: ovi <ovi@posteo.de>
Date:   Sun Sep 3 14:13:20 2023 +0200

    Display Rational

commit 3ac128d
Author: ovi <ovi@posteo.de>
Date:   Sun Sep 3 13:11:47 2023 +0200

    trying a thing

commit 42e6cad
Author: ovi <ovi@posteo.de>
Date:   Sat Sep 2 03:07:45 2023 +0200

    yet more derives

commit d43961a
Author: ovi <ovi@posteo.de>
Date:   Sat Sep 2 01:39:16 2023 +0200

    yet more derives

commit 76d20d9
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Thu Aug 31 08:59:19 2023 +0200

    Add more derives.

commit 7bced48
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Thu Aug 31 08:53:04 2023 +0200

    Add derive.

commit fcdc568
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Tue Aug 29 11:51:53 2023 +0200

    Add serialize for rational.

commit bd41119
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Sun Aug 27 18:25:33 2023 +0200

    Add default impl for poplar.

commit 2437364
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Sun Aug 27 18:21:15 2023 +0200

    Add default implementations.

commit 7c45460
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Sun Aug 27 17:47:41 2023 +0200

    Add default implementation for `TypeWithNoise`.

commit e5bdff3
Author: Maxim Urschumzew <u.maxim@live.de>
Date:   Mon Aug 14 13:34:03 2023 +0200

    Add differential privacy to `FixedPointBoundedL2VecSum` (divviup#578).

    Co-Authored-By: Olivia <ovi@posteo.de>
    Co-Authored-By: Maxim Urschumzew <u.maxim@live.de>
  • Loading branch information
MxmUrw committed Sep 12, 2023
1 parent e2751fe commit ca0a72f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ hmac = { version = "0.12.1", optional = true }
num-bigint = { version = "0.4.4", optional = true, features = ["rand", "serde"] }
num-integer = { version = "0.1.45", optional = true }
num-iter = { version = "0.1.43", optional = true }
num-rational = { version = "0.4.1", optional = true }
num-rational = { version = "0.4.1", optional = true, features = ["serde"] }
num-traits = { version = "0.2.16", optional = true }
rand = { version = "0.8", optional = true }
rand_core = "0.6.4"
Expand Down
36 changes: 35 additions & 1 deletion src/dp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
//!
use num_bigint::{BigInt, BigUint, TryFromBigIntError};
use num_rational::{BigRational, Ratio};
use serde::{Deserialize, Serialize};
use std::{fmt, str::FromStr};

/// Errors propagated by methods in this module.
#[derive(Debug, thiserror::Error)]
Expand All @@ -38,9 +40,35 @@ pub enum DpError {

/// Positive arbitrary precision rational number to represent DP and noise distribution parameters in
/// protocol messages and manipulate them without rounding errors.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct Rational(Ratio<BigUint>);

impl fmt::Display for Rational {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}

/// An error indicating a string could not be parsed as Rational.
#[derive(Debug)]
pub struct RationalParseError;

impl fmt::Display for RationalParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "RationalParseError")
}
}

impl FromStr for Rational {
type Err = RationalParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match Ratio::<BigUint>::from_str(s) {
Ok(r) => Ok(Rational(r)),
Err(_) => Err(RationalParseError),
}
}
}

impl Rational {
/// Construct a [`Rational`] number from numerator `n` and denominator `d`. Errors if denominator is zero.
pub fn from_unsigned<T>(n: T, d: T) -> Result<Self, DpError>
Expand Down Expand Up @@ -83,6 +111,7 @@ pub trait DifferentialPrivacyDistribution {}
/// Zero-concentrated differential privacy (ZCDP) budget as defined in [[BS16]].
///
/// [BS16]: https://arxiv.org/pdf/1605.02065.pdf
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Ord, PartialOrd)]
pub struct ZCdpBudget {
epsilon: Ratio<BigUint>,
}
Expand All @@ -95,6 +124,11 @@ impl ZCdpBudget {
pub fn new(epsilon: Rational) -> Self {
Self { epsilon: epsilon.0 }
}

/// Return the `epsilon` parameter of this strategy.
pub fn get_epsilon(&self) -> Rational {
Rational(self.epsilon.clone())
}
}

impl DifferentialPrivacyBudget for ZCdpBudget {}
Expand Down
6 changes: 4 additions & 2 deletions src/dp/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use num_iter::range_inclusive;
use num_rational::Ratio;
use num_traits::{One, Zero};
use rand::{distributions::uniform::UniformSampler, distributions::Distribution, Rng};
use serde::{Deserialize, Serialize};

use super::{
DifferentialPrivacyBudget, DifferentialPrivacyDistribution, DifferentialPrivacyStrategy,
Expand Down Expand Up @@ -252,11 +253,12 @@ impl Distribution<BigInt> for DiscreteGaussian {
impl DifferentialPrivacyDistribution for DiscreteGaussian {}

/// A DP strategy using the discrete gaussian distribution.
#[derive(Clone, PartialEq, Serialize, Deserialize, Eq, Debug, Ord, PartialOrd)]
pub struct DiscreteGaussianDpStrategy<B>
where
B: DifferentialPrivacyBudget,
B: DifferentialPrivacyBudget + std::fmt::Debug,
{
budget: B,
pub budget: B,
}

/// A DP strategy using the discrete gaussian distribution providing zero-concentrated DP.
Expand Down
5 changes: 5 additions & 0 deletions src/flp/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

//! A collection of [`Type`] implementations.

#[cfg(feature = "experimental")]
use crate::dp::distributions::ZCdpDiscreteGaussian;
use crate::field::{FftFriendlyFieldElement, FieldElementWithIntegerExt};
use crate::flp::gadgets::{Mul, ParallelSumGadget, PolyEval};
use crate::flp::{FlpError, Gadget, Type};
use crate::polynomial::poly_range_check;
use std::convert::TryInto;
use std::fmt::{self, Debug};
use std::marker::PhantomData;

/// The counter data type. Each measurement is `0` or `1` and the aggregate result is the sum of the measurements (i.e., the total number of `1s`).
#[derive(Clone, PartialEq, Eq)]
pub struct Count<F> {
Expand Down Expand Up @@ -569,6 +573,7 @@ impl<F: FftFriendlyFieldElement, S> Clone for SumVec<F, S> {
}
}


impl<F, S> Type for SumVec<F, S>
where
F: FftFriendlyFieldElement,
Expand Down
4 changes: 3 additions & 1 deletion src/vdaf/poplar1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
vdaf::{
xof::{Seed, Xof, XofShake128},
Aggregatable, Aggregator, Client, Collector, PrepareTransition, Vdaf, VdafError,
},
}, dp::distributions::ZCdpDiscreteGaussian,
};
use bitvec::{prelude::Lsb0, vec::BitVec};
use rand_core::RngCore;
Expand All @@ -27,6 +27,8 @@ use std::{
};
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq};

use super::AggregatorWithNoise;

const DST_SHARD_RANDOMNESS: u16 = 1;
const DST_CORR_INNER: u16 = 2;
const DST_CORR_LEAF: u16 = 3;
Expand Down

0 comments on commit ca0a72f

Please sign in to comment.