Are We There Yet? Timing and Floating-Point Attacks on Differential Privacy Systems

Jiankai Jin, Eleanor McMurtry, Benjamin I. P. Rubinstein, Olga Ohrimenko

I Introduction

can yy be equal to , 20002000 or 2000020000? Though one may ask “what is zz?”, it is possible to answer this question without knowing zz, if one knows that the arithmetic was computed on a machine using the double-precision floating-point format. While z=2000.1234567890004z=2000.1234567890004 cannot be represented, 2000.12345678900032000.1234567890003 and 2000.12345678900062000.1234567890006 can be. Similarly for z=20000.1234567890004z=20000.1234567890004. In fact without knowing zz at all, we can say definitively that yy must equal if it is known to be one of , 20002000, or 2000020000.

Differential privacy (DP) is a de facto privacy framework that has received significant interest from the research community and has been deployed by the U.S. Census Bureau, Apple, Google, Microsoft, and many others. Research on DP ranges from algorithms with different performance trade-offs, to new models in different settings, and also to practical implementations . Robust implementations are crucial to provide end-to-end privacy that matches on-paper differential privacy guarantees.

Implementations of DP algorithms often raise concerns not considered in theoretical analysis (which focuses on idealized settings). Mironov was first to discuss the implications of the fact that one cannot represent—and thus cannot sample from—all real numbers on a finite-precision computer. Focusing on the Laplace mechanism, Mironov’s attack proceeds by observing that certain floating-point values cannot be generated by a DP computation and hence a release could reveal the (private) noiseless value. On the other hand, Haeberlen et al. and Andrysco et al. showed that DP algorithms may suffer from timing side-channels since such algorithms can take different time depending on sensitive values in a dataset.

In this paper we extend Mironov’s attack to other DP mechanisms and study its effects on real-world DP implementations. We then describe another timing side-channel that can arise in DP implementations due to the timing of the noise samplers.

The Gaussian mechanism (based on additive Gaussian noise) is another well-studied DP mechanism. It achieves what is often called approximate differential privacy, meaning that the mechanism may fail completely to provide pure DP with some small and controllable probability δ\delta. However, the mechanism has advantages over the Laplace mechanism, including lighter tails than the Laplace distribution and superior composition properties when answering many queries with independent noise. Generalizations like Rényi differential privacy can perform tight composition analysis. Recently truncated concentrated differential privacy has emerged as a promising generalization that bounds the residual privacy loss from approximate DP, allows efficiently-computable optimal composition, and captures privacy amplification by subsampling as present in . Because of these advantages, the Gaussian mechanism is often the tool of choice for applications such as deep learning that involve carefully controlled privacy budgets over sequences of releases.

A question arises: are the same attacks as in possible against the Gaussian mechanism? Though several works mention that it may be feasible, to the knowledge of the authors no one has demonstrated this possibility nor shown how to carry out this attack in practice. In this paper we study these two questions and demonstrate an attack confirming that common implementations of Gaussian sampling are subject to floating-point attacks.

Unfortunately directly using the attack from is not possible since Gaussian noise is drawn using very different techniques to Laplace. The main challenge is due to some Gaussian samplers being based on two random values and not one. Such methods produce two independent Gaussian samples, and most implementations cache one of them to be used next time the mechanism is called. We develop an attack that uses both of these values. Due to the two equations with several unknowns that the attacker needs to solve, there can be more than one pair of feasible values. As a result our attack can yield false positives. Nevertheless, we show that the attack is still feasible and has a significant success rate. Additionally, we show that a Gaussian sampler based on a different method that generates only one sample is also susceptible to a floating-point attack, and the attack succeeds at a higher rate than for samplers based on two values.

The most prominent recent use of the Gaussian mechanism is in training machine learning (ML) algorithms using differentially-private stochastic gradient descent (DP-SGD) . We show that we can mount the attack in this setting to determine if a batch contains a particular record or not, violating DP guarantees of DP-SGD. Moreover, ML model training naturally reveals sequential Gaussian samples to an adversary, as it returns a noisy gradient for each parameter of the model.

In the second part of the paper we study the primary method that has been proposed to defend against floating-point attacks: discrete versions of the Laplace and Gaussian mechanisms . These approaches employ sampling algorithms that make no use of floating-point representations. We observe that such mechanisms, though defending against floating-point attacks, are susceptible to a timing side channel: an adversary who observes the time it takes to draw a sample can determine the generated noise’s magnitude. When used within a DP mechanism, our attack reveals the noise contained in the result, and thus reveals the noiseless (private) value.

Our timing attack is possible due to the underlying technique that these discrete samplers rely on: direct simulation of geometric sampling, meaning values are sampled until a coin toss results in a “head”. The number of such coin tosses is tied to the magnitude of the noise returned; timing the sampler reveals this number and thus leaks the noise magnitude. Though timing has been identified as a potential side-channel in DP , to our knowledge we are the first to show that noise distribution samplers and not the mechanisms themselves give rise to secret-dependent runtimes.

We show that the Gaussian mechanism of differential privacy suffers from a side channel due to floating-point representation. To this end, we devise attack methods to show how to exploit this vulnerability since the known floating-point attack against the Laplace mechanism cannot be used directly.

We use the above results to demonstrate empirically that Gaussian samplers as implemented in NumPy, PyTorch and Go are vulnerable to our attack. Focusing on the Opacus DP library implementation by Facebook, we also show that DP-SGD is vulnerable to information leakage under our attack. Since notifying Facebook about the floating-point attack, Opacus library now has proposed a mitigation in https://github.com/pytorch/opacus/pull/260

We then observe that discrete methods developed to protect against floating-point attacks for both the Laplace and Gaussian mechanisms suffer from timing side channels. We show that two libraries are vulnerable to these attacks: a DP library by Google and the implementation accompanying another work on discrete distributions in .

We discuss and evaluate mitigations against each attack.

We have informed maintainers of the DP libraries mentioned above of the results of this paper. They have acknowledged our report and notification of the disclosure dates.

II Background

In this paper we develop attacks on differential privacy based on floating-point representation and timing channels. In this section, we give background on how floating-point values are represented on modern computers, differential privacy, and the Laplace and Gaussian mechanisms for DP.

Floating-point values represent real values using three numbers: a sign bit b\mathsf{b}, an exponent e\mathsf{e}, and a significand d1d2…ddd_{1}d_{2}\ldots d_{\mathsf{d}}. For example, 64-bit (double precision) floating-point numbers allocate 1 bit for b\mathsf{b}, 11 bits for e\mathsf{e}, and 52 bits for the significand. Such a floating-point number is defined to be (−1)b×(1.d1d2…dd)2×2e−1023(-1)^{\mathsf{b}}\times(1.d_{1}d_{2}\ldots d_{\mathsf{d}})_{2}\times 2^{\mathsf{e}-1023}.

Crucially, the number of real values representable using floating-point values in the ranges [a1,b1][a_{1},b_{1}] and [a2,b2][a_{2},b_{2}], ai<bia_{i}<b_{i}, are different even if b1−a1=b2−a2b_{1}-a_{1}=b_{2}-a_{2}. For example, there are approximately 2172^{17} floating-point values in the range [10,10+2−32][10,10+2^{-32}], and there are approximately 2142^{14} floating-point values in [100,100+2−32][100,100+2^{-32}]. Thus, floating-point values are more densely distributed around 0.

II-B Differential Privacy

Consider a collection of datasets D\mathcal{D} and an arbitrary space of output responses R\mathcal{R}. We say that two datasets D,D′D,D^{\prime} are neighboring if they differ on one record. A randomized mechanism M:D→R\mathcal{M}:\mathcal{D}\rightarrow\mathcal{R} is (ϵ,δ)(\epsilon,\delta)-differentially private for ϵ>0\epsilon>0 and δ∈[0,1)\delta\in[0,1) if given any two neighboring datasets D,D′∈DD,D^{\prime}\in\mathcal{D} and any subset of outputs R⊆RR\subseteq\mathcal{R} it holds that Pr⁡[M(D)∈R]≤eϵPr⁡[M(D′)∈R]+δ\Pr[\mathcal{M}(D)\in\mathcal{R}]\leq e^{\epsilon}\Pr[\mathcal{M}(D^{\prime})\in\mathcal{R}]+\delta. That is, the probability of observing the same output yy from M(D)\mathcal{M}(D) and M(D′)\mathcal{M}(D^{\prime}) is bounded. DP therefore guarantees that given an output yy, an attacker cannot determine which of DD or D′D^{\prime} was used for the input. If there is some output that is possible with DD but not D′D^{\prime}, this inequality cannot hold for non-trivial δ\delta, so the mechanism cannot be DP. This is the key fact our attacks exploit.

In this paper, we consider DP mechanisms M\mathcal{M} that provide protection by computing the intended function ff on the data DD and randomizing its output. That is, M(D)=f(D)+s\mathcal{M}(D)=f(D)+s where s←NoiseDists\leftarrow\mathsf{NoiseDist} is noise drawn either from Laplace or Gaussian distributions with appropriate parameters (as discussed below). For example, ff may compute the sum of the set of employee incomes DD, and we may wish to keep the exact values of the incomes private. Our attacks are based on observations about NoiseDist\mathsf{NoiseDist} that can be used to learn the noise sampled from it.

II-C Laplace Mechanism

The Laplace mechanism provides ϵ\epsilon-DP by additive noise drawn from the Laplace distribution Lap(λ)\mathsf{Lap}(\lambda) (i.e., NoiseDist\mathsf{NoiseDist} is Lap(λ)\mathsf{Lap}(\lambda)). In the scalar-valued case M(D)=f(D)+Lap(λ)\mathcal{M}(D)=f(D)+\mathsf{Lap}(\lambda). Here we use a scale parameter λ=Δ/ϵ\lambda=\Delta/\epsilon where Δ\Delta is ff’s sensitivity, meaning any neighboring data sets DD and D′D^{\prime} satisfy ∣f(D)−f(D′)∣≤Δ|f(D)-f(D^{\prime})|\leq\Delta.

II-D Gaussian Mechanism

In addition to applications computing a one-off release of a function output, the Gaussian mechanism is commonly used repeatedly in training machine learning models using mini-batch stochastic gradient descent (SGD). This composite mechanism is called DP-SGD . When used to replace non-private mini-batch SGD, it produces a machine learning model with differential privacy guarantees on sensitive training data. This mechanism has been applied in Bayesian inference , to train deep learning models , and also in logistic regression models . At a high level, a record-level DP-SGD mechanism aims to protect presence of a record in a batch and, hence, in the dataset. DP-SGD has been also used in the Federated Learning setting where each client computes a gradient on their local data batch, adds noise and sends the result to a central server.

III Threat Model

We consider an adversary that obtains an output of an implementation of a differentially-private mechanism, for example a DP-protected average income of people in a database of personal records, or DP-protected gradients used to train a machine learning model. DP aims to defend information about presence (or absence) of a certain record by providing plausible deniability. We show that the attacker can use artefacts of implementations of noise samplers in DP mechanisms to undermine their guarantees. In particular we consider two attacks based on separate artefacts — one on floating-point representation and one on timing.

We envision three scenarios where our attacks can be carried out:

a member of the public observes statistics computed on sensitive data and protected with DP noise (e.g., those released by the US Census Bureau );

an analyst interactively queries a differentially private database which allows them to ask several queries of datasets and which transparently adds noise to preserve privacy of the dataset from the analyst;

a central server who is coordinating federated learning by collecting gradients from clients . Here, a client adds noise to a gradient computed on its data to protect its data from the central server.

For all three scenarios above, our threat model builds on the threat model of DP where (1) the attacker observes a DP-protected output, (2) the attacker may know all the other records in the dataset except for the one record it is trying to guess, and (3) knows how the mechanism is implemented Many DP implementations are open-source including . , but does not know the randomness used by it.

We describe additional adversarial capabilities required for each scenario and attack below.

For one of our two floating-point attacks, in addition to observing a single DP output that the adversary wishes to attack, we assume the adversary has access to an output of a consecutive execution of a DP mechanism or its noise sampling. This is achievable in practice in all scenarios above due to:

multiple queries: In scenario S multiple statistics are released, in scenario DB a (malicious) analyst could query a DP protected database several times.

dd-dimensional query: in all three scenarios, an output being protected can correspond to an output of a dd-dimensional function where independent noise is added to each component such as a histogram or a gradient computed for multiple parameters of ML model . Moreover, gradients are assumed to be revealed as part of the privacy analysis in the central setting as well as in the FL setting.

In contrast to the floating-point attack above, here the threat model assumes that the attacker observes a DP output and can measure the time it takes for the DP mechanism to compute it. The attacker must also be able to measure multiple runs of an algorithm in order to obtain a baseline of running times. However during the attack itself, the attacker only needs to make one observation to make a reasonable guess.

The attack can be deployed in the three scenarios above if an attacker has black-box access to the machine running DP code, similarly to the threat model of other timing side-channels used against DP mechanisms that are not based on noise samplers (see Section IX for more details). For example, the attacker may share a machine based in the cloud or is a cloud provider itself. For the DB scenario specifically, a malicious analyst querying the mechanism hosted locally can readily measure the time it takes for the query to return. For the FL scenario (and remotely hosted databases in the DB scenario) the uncertainty in measuring precise time due to network communication can be reduced with recent attacks exploiting concurrent requests .

IV Floating-Point Attack on Normal Distribution Implementations

We describe the floating-point attack that aims to determine whether a given floating-point value could have been generated by an instance of a Gaussian distribution or not. If not, this eliminates the possibility that a DP mechanism could have used this noise, hence undermining its privacy guarantees. We begin with a description of a generic floating-point attack against DP and then describe two common implementations of Gaussian samplers—polar and Ziggurat—and how they can be attacked.

The DP threat model assumes that the adversary knows neighboring datasets DD, D′D^{\prime} and function ff. Given an output yy of a DP mechanism, where either y=f(D)+sy=f(D)+s or y=f(D′)+s′y=f(D^{\prime})+s^{\prime} and s,s′←NoiseDists,s^{\prime}\leftarrow\mathsf{NoiseDist}, the attacker’s goal is to determine if DD or D′D^{\prime} was used in the computation of yy.

Mironov showed that due to an artefact in the implementation of NoiseDist\mathsf{NoiseDist} for Laplace, some values of ss are impossible. Hence given yy, if the adversary knows that ss is impossible then it must be the case that D′D^{\prime} was used to compute yy (and similarly for s′s^{\prime}). This directly breaks the guarantee of DP which states that there is a non-zero probability for each of the inputs producing the observed output. We will show that mechanisms that use Gaussian noise for NoiseDist\mathsf{NoiseDist} — whose implementation is more complicated than Laplace — are also susceptible to implementation artefacts.

In the rest of this section we develop a function IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) which returns true\mathsf{true} if a given noise value ss could have been drawn from implementations of Gaussian distributions and false\mathsf{false} otherwise. The attacker then runs IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) and IsFeasibleNormal(s′)\mathsf{IsFeasibleNormal}(s^{\prime}). If only one of them returns true\mathsf{true}, the attacker determines that the corresponding dataset was used in the computation. Otherwise, it makes a random guess.

IV-B Warmup: Feasible Random Floating Points

We describe how random double-precision floating-point values (“doubles”) are sampled on modern computers using a function RandomFP\mathsf{RandomFP} and show that given a double xx, one can determine if it was generated using RandomFP\mathsf{RandomFP} or not. This will serve as a warm-up for our attack against the Gaussian distribution over doubles.

Random real values in the range (0,1)(0,1) can be drawn by choosing a random integer uu from [1,R)[1,R) and then dividing it by the resolution R=2pR=2^{p}, where the value of pp varies by system. We abstract this process using a function RandomFP\mathsf{RandomFP} that chooses an integer uu at random from [1,R)[1,R) and returns u/Ru/R. Given a double xx one can determine if it could have been produced by RandomFP\mathsf{RandomFP} by checking if x=?uˉ/Rx\stackrel{{\scriptstyle?}}{{=}}\bar{u}/R for some integer uˉ∈[1,R)\bar{u}\in[1,R). If the equality holds then xx could have been produced from a random integer. Since rounding errors are introduced during multiplication and division, we will later also perform the above check for neighboring values of xx.

IV-C Polar Method: Implementation and Attack

In this section we describe the polar method and the floating-point attack against it.

The Marsaglia polar method is a computational method that generates samples of the standard normal distribution from uniformly distributed random values. PolarMethod\mathsf{PolarMethod} operates as follows:

Choose independent uniform random values x1′x^{\prime}_{1} and x2′x^{\prime}_{2} from (0,1)(0,1) using RandomFP\mathsf{RandomFP}.

Set x1←2x1′−1x_{1}\leftarrow 2x^{\prime}_{1}-1 and x2←2x2′−1x_{2}\leftarrow 2x^{\prime}_{2}-1. (Note that both fall in the interval (−1,1)(-1,1).)

Repeat from Step P1 until r≤1r\leq 1 and r≠0r\neq 0.

Set s1←x1−2log⁡rrs_{1}\leftarrow x_{1}\sqrt{\frac{-2\log{r}}{r}} and s2←x2−2log⁡rrs_{2}\leftarrow x_{2}\sqrt{\frac{-2\log{r}}{r}}.

The procedure generates two independent samples from a normal distribution: s1s_{1} and s2s_{2}. The second value, s2s_{2}, is cached and returned on the next invocation. If the cache is empty, the sampling method is invoked again. The method can generate samples from N(0,σ2)\mathcal{N}(0,\sigma^{2}) by returning σs1\sigma s_{1} and σs2\sigma s_{2} instead.

The polar method is used by both the GNU C++ Library with std::normal_distribution and the Java class java.util.Random (in the nextGaussian method). A related technique called Box-Muller method described in the Appendix -A that relies on computing sin⁡\sin and cos⁡\cos is used in PyTorch and was implemented in the older versions of Diffprivlib .

IV-C2 Floating-Point Attack

The attacker’s goal is to devise a function IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) that determines if value ss could have been generated by PolarMethod\mathsf{PolarMethod} — a computational method for drawing normal noise. Here, we assume that the attacker knows sample s2s_{2} and is trying to guess if s=?s1s\stackrel{{\scriptstyle?}}{{=}}s_{1}. As discussed in Section III, an attacker can learn s2s_{2} either through multiple queries or multi-dimensional queries. We note that the attack against the Laplace method by Mironov cannot be applied since PolarMethod\mathsf{PolarMethod} (and the Box-Muller method) (1) relies on different mathematical formulae and (2) uses two random values and draw two samples from their target distribution. To this end, we devise an FP attack specifically for normal distribution implementations. We describe the attack for the polar method below. The attack for the Box-Muller method proceeds similarly, using trigonometric functions instead.

Before proceeding with the attack, we observe that rr in PolarMethod\mathsf{PolarMethod} can be expressed using s1s_{1} and s2s_{2} by simple arithmetic rearrangements based on steps P3 and P5.

Rearranging this equation further, we obtain

The intuition behind our attack is similar to that of “attacking” RandomFP\mathsf{RandomFP} in Section IV-B: we find an expression that must be an integer if PolarMethod\mathsf{PolarMethod} was used. We observe that r×R2r\times R^{2} must be an integer: since x1′x^{\prime}_{1} and x2′x^{\prime}_{2} are produced using RandomFP\mathsf{RandomFP} (step P1) there must be integers u1u_{1} and u2u_{2} such that x1′=u1/Rx^{\prime}_{1}=u_{1}/R and x2′=u2/Rx^{\prime}_{2}=u_{2}/R. Rearranging and substituting these x1′x^{\prime}_{1} and x2′x^{\prime}_{2} further in steps P2 and P3 we obtain

Since u1u_{1}, u2u_{2}, RR are integers, value r×R2r\times R^{2} must be an integer.

IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) proceeds as follows. The attacker computes value of r×R2r\times R^{2} using Equation 1 with values ss (instead of s1s_{1}) and s2s_{2} as follows:

It then checks if the value in Equation 2 is an integer. If it is, then IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) returns true\mathsf{true} since ss and s2s_{2} could be produced using PolarMethod\mathsf{PolarMethod}.

As floating-point arithmetic cannot be done with infinite precision on finite machines, ss and s2s_{2} might be inaccurate. To this end, we perform a heuristic search in each direction of ss and s2s_{2} where we try several neighboring values of ss and s2s_{2}. In our experiments, we choose to search 50 values in each direction. This search heuristic is prone to errors and may result in false positives and false negatives, due to (1) more than one pair of values resulting in s1s_{1} and s2s_{2} and (2) our search not being exhaustive in exploring values with a range of 100 values. Nevertheless in the next section we show that the attack is still successful for a variety of applications of Gaussian noise in DP.

IV-D Ziggurat Method: Implementation and Attack

The Ziggurat method is another method for generating samples from the normal distribution. Compared to the Box-Muller and polar methods, it generates one sample on each invocation. It is a rejection sampling method that randomly generates a point in a distribution slightly larger than the Gaussian distribution. It then tests whether the generated point is inside the Gaussian distribution.

ZigguratMethod\mathsf{ZigguratMethod} relies on three precomputed tables w[n]w[n], f[n]f[n] and k[n]k[n] that are directly stored in the source code. The Ziggurat implementation in Go uses n=128n=128 and proceeds as follows.

Generate a random 32-bit integer jj and let ii be the index provided by the rightmost 7 bits of jj.

Set s←jw[i]s\leftarrow jw[i]. If j<k[i]j<k[i], return ss.

If i=0i=0, run a fallback algorithm for generating a sample from the tails of the distribution.

Use RandomFP\mathsf{RandomFP} to generate independent uniform random value UU from (0,1)(0,1). Return ss if:

We refer interested readers to for how to sample from the tail of a normal distribution and to for how the tables w[n],f[n],k[n]w[n],f[n],k[n] are generated. The method can generate samples from N(0,σ2)\mathcal{N}(0,\sigma^{2}) by returning σs\sigma s.

The Ziggurat method is used by the Go package math/rand with NormFloat64 and new random sampling methods of NumPyhttps://numpy.org/doc/stable/reference/random/index.html.

IV-D2 Attack

This time, the attacker aims to devise a function IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) that determines if value ss could have been generated by ZigguratMethod\mathsf{ZigguratMethod}. We describe our attack steps below since attacks in Section IV-C and are not applicable due to pre-computed tables used in Ziggurat.

We observe that the returned value is jw[i]jw[i] in steps Z2 and Z4, except when the value is sampled from the tail of Gaussian distribution in step Z3 (which happens infrequently). Furthermore, jj is an integer and all values of w[n]w[n] are available to the attacker, because all precomputed tables are stored directly in the source code. Based on these observations, for a noise ss, our attack for ZigguratMethod\mathsf{ZigguratMethod} proceeds as:

For each w[i]w[i], i∈[1,n]i\in[1,n] calculate w[i]=s/(σw[i])\mathsf{w}[i]={s}/(\sigma w[i]).

For each w[i]\mathsf{w}[i], check if it is an integer.

If any w[i]\mathsf{w}[i] is an integer, then we take ss as a feasible floating-point value, IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) returns true\mathsf{true}.

Note that the method does not attack values sampled from the tail. However, we observed that it happens less than 0.1%0.1\% of the time when n=128n=128, hence, the attack works for the majority of the cases.

V Experiments: FP Attack on Normal Distribution

We perform four sets of experiments to evaluate leakage of Gaussian samplers based on the attack described in the previous section. First, we enumerate the number of possible values in a range of floating points that can result in an attack and observe that it is not negligible. We then show the effectiveness of our attack on private count and DP-SGD, a popular method designed for training machine learning (ML) models under differential privacy .

In our experiments, we use four implementations of Gaussian distribution samplers.

Gauss_polar\mathsf{Gauss\_polar}: our implementation of polar method as described in Section IV-C1.

Gauss_numpy\mathsf{Gauss\_numpy}: NumPy implementation of polar Gaussian sampling.

Gauss_pytorch\mathsf{Gauss\_pytorch}: PyTorch implementation of Box-Muller Gaussian sampling.

Gauss_go\mathsf{Gauss\_go}: Go implementation of Ziggurat Gaussian sampling.

Our attacks on DP-SGD were tested using the privacy engine implementation of the Opacus library 1.

V-A Distribution of “Attackable” Values

In this section we aim to understand how many floating-point values could not have been generated from a Gaussian sampling implementation. That is, for how many values ss, IsFeasibleNormal(s)\mathsf{IsFeasibleNormal}(s) would return false\mathsf{false}. We call such values “attackable” since if an adversary were to observe them, they would know that the value must have been produced in a specific manner (e.g., by adding noise to f(D′)f(D^{\prime}) as opposed to f(D)f(D)). We use the Gauss_polar\mathsf{Gauss\_polar} implementation to perform this experiment in a controlled environment and assume that the adversary is given y1y_{1} and y2y_{2} where y1=f(D)+s1y_{1}=f(D)+s_{1} and y2=f(D)+s2y_{2}=f(D)+s_{2} or y1=f(D′)+s1′y_{1}=f(D^{\prime})+s_{1}^{\prime} and y2=f(D′)+s2′y_{2}=f(D^{\prime})+s_{2}^{\prime}. (Compared to the attack in Section IV the attacker is not given s2s_{2} directly, however the attack can proceed similarly.)

For each pair of y1=f(D)+s1y_{1}=f(D)+s_{1} and y2=f(D)+s2y_{2}=f(D)+s_{2}, if the attack successfully concludes that they are in support of f(D)f(D), and not f(D′)f(D^{\prime}), we count them as attackable values. We set f(D)=0f(D)=0, f(D′)=1f(D^{\prime})=1, σ=114\sigma=114, R=210R=2^{10}. The blue line of Figure 1 shows the distribution of the rate of attackable values where we plot y1y_{1} and y2y_{2}. In order to fit all measured floating-points into the resolution of the graph, we aggregate the results over small intervals of width 0.80.8.

Mironov generated a similar graph for the Laplace distribution in . Compared to Gaussian, the Laplace distribution has more attackable values since it uses only one random value, hence the attack does not suffer from false negatives.

In order to understand our results further we also plot the average number of times each y=f(D)+sy=f(D)+s is observed, using the gray line of Figure 1. This explains some of the spikes in the blue line: more frequently observed values indicate more attackable values. Percentage of floating-points that are attackable are higher closer to (recall that the graph shows an average over FP intervals). Overall, the graph suggests that attackable values do exist and as we show in the rest of this section provide an avenue for an attack against DP mechanisms.

V-B DP Gaussian Mechanism

In this section, we explore the effectiveness of our attack against the Gaussian mechanism used to protect a private count (i.e., corresponding to S or DB scenarios in Section III). We use the German Credit Dataset and the query: count the number of records with number of credits greater than 16K (resulting in one record since the two highest values among dataset’s 1000 records are 15945 and 18424).

Given the output of the Gaussian mechanism, yy, the adversary’s goal is to determine whether noiseless output came from q=f(D)q=f(D) or q′=f(D′)q^{\prime}=f(D^{\prime}) where ff is the count query defined above. The private count of values in a dataset is computed as: y=q+sy=q+s or y=q′+sy=q^{\prime}+s, where qq and q′q^{\prime} are the outputs of ff on dataset DD and D′D^{\prime}, respectively, and ss is a noise sampled with Gauss_numpy\mathsf{Gauss\_numpy}, Gauss_pytorch\mathsf{Gauss\_pytorch}, or Gauss_go\mathsf{Gauss\_go}. For Gauss_numpy\mathsf{Gauss\_numpy} and Gauss_pytorch\mathsf{Gauss\_pytorch}, the adversary also knows the second value sampled from the distribution (i.e., s2s_{2} in Section IV-C). The neighboring datasets DD and D′D^{\prime} that our attack tries to distinguish differ on a single record whose credits is 0 in DD and 18424 in D′D^{\prime}, so the count of records satisfying the above query is q=0q=0 for DD and q′=1q^{\prime}=1 for D′D^{\prime}.

We set the sensitivity Δ=1\Delta=1 since one record can change the output of ff only by 1. We vary ϵ\epsilon in the range (0,100](0,100] with fixed δ=10−5\delta=10^{-5}. For each tuple of ϵ\epsilon, δ\delta and Δ\Delta, we use the analytic Gaussian Mechanism to calculate the required noise scale σ\sigma for the experiment. Here, small ϵ\epsilon and δ\delta model a common set of parameters used in DP .

In Figure 2 we plot our success rate from 1 million trials from the following attack. Recall that the attacker cannot always make a guess due to the limitations listed in Section V-A. To this end, if the attack can find support for either only qq or only q′q^{\prime}, then the attack outputs the corresponding guess. If the result is in support of both or neither of qq and q′q^{\prime}, then the attacker is unsure and resorts to the baseline attack, choosing qq or q′q^{\prime} at random.

We observe that the attack is more successful for the Gauss_go\mathsf{Gauss\_go} method for values of ϵ\epsilon less than 10. This is also the range of values for ϵ\epsilon used in the literature on DP . We note a slight cyclic behavior and observe that peaks occur when the corresponding noise scale σ\sigma (w.r.t. ϵ\epsilon) is a power of 2 (see Figure 7 in the Appendix). We hypothesize that the success rate at those points is higher since multiplication and division by powers of 2 can be done via bit shifting that decreases the impact of rounding. Hence, extraction of ss is not affected by rounding errors that would otherwise be introduced during the multiplication of ss by σ\sigma in the ZigguratMethod\mathsf{ZigguratMethod} and step 1 of the corresponding attack in Section IV-D.

Among two sampler methods, attack is more efficient against Gauss_pytorch\mathsf{Gauss\_pytorch} than Gauss_numpy\mathsf{Gauss\_numpy}. We also observe that the attack becomes stronger as ϵ\epsilon increases. This is potentially due to the higher distribution of attackable values as indicated in Figure 1. The attack is always more successful than the baseline random attack.

In Appendix -D we also investigate the rate at which the attacker can make a guess (attack rate) and how many of these guesses are correct (attack accuracy) across a range of ϵ\epsilon and sensitivity values. Gauss_numpy\mathsf{Gauss\_numpy} and Gauss_pytorch\mathsf{Gauss\_pytorch} have attack rates ranging between 1.7%1.7\% and 92.8%92.8\% with attack accuracy of at least 89%89\%. In comparison, the attack rates and accuracy against Gauss_go\mathsf{Gauss\_go} are at least 76%76\% and 99%99\%, respectively.

V-C DP-SGD in Federated Learning scenario

The Gaussian mechanism is used extensively in training ML models via differentially-private stochastic gradient descent . In this section, we describe successful attacks on the differentially-private training of ML models. Here, we consider the Federated Learning scenario from Section III where an attacker (central server) observes a DP-protected gradient computed on a batch of client’s data and is trying to determine if the batch includes a particular record or not.

The main observations we make in this section are:

An adversary can determine if a batch contains a record with a different label from other records in the batch, i.e., a record that comes from the same distribution as training dataset but different to those in the batch.

The success rate of the attack increases as ϵ\epsilon decreases as there are fewer floating-point values to represent large noise values.

We use Opacus library for training machine learning models with DP-SGD. Our experiments are based on the Opacus example on MNIST data. This dataset contains 70K images, split in 60K and 10K sets for training and testing, respectively. Each image is in 28×2828\times 28 gray-scale representing a handwritten digit ranging from 0 to 9 where the written digit is the label of the image. The ML task is: given an unlabelled image, predict its label.

We use the same parameters for preprocessing and neural network training as used in the library , following . These training parameters are: learning rate 0.10.1, epoch number 88, batch size S=64S=64, number of batches in each epoch 100, and DP-SGD clipping norm L=1L=1. We vary ϵ\epsilon to understand how different parameters affect the attack success rate while keeping a fixed δ=10−5\delta=10^{-5} (as in ). Depending on the ϵ\epsilon, the noise is drawn from a normal distribution with μ=0\mu=0 and σ∈\sigma\in. As a result ϵ\epsilon ranges from 0.1 to 0.68. Since the model has d=26,010d=26,010 parameters, each batch is used in dd gradient computations to update the corresponding parameters. Hence, the attacker obtains dd floating-point values protected with DP-SGD. Details of DP-SGD computation are provided in Appendix -B.

We consider a setting where an adversary observes a gradient computed on FL client’s batch of labelled MNIST images. The batch could correspond either to records BB or a neighboring batch B′B^{\prime} produced by replacing a randomly chosen record in batch BB with a canary record (defined below). The attacker’s goal is, given BB, B′B^{\prime} and a noisy gradient protected with Gaussian noise, to determine if the gradient was computed on BB or B′B^{\prime}.

We use different types of batches and canary records to test the effectiveness of our attack:

SimLabelCanary\mathsf{SimLabelCanary}: batch BB is composed of shuffled training data. The canary record of its neighboring batch B′B^{\prime} is a record drawn from the test dataset.

DiffLabelCanary\mathsf{DiffLabelCanary}: the batch is composed of records with the same labels in $$, and the canary record of its neighboring batch is a record with label .

Though DiffLabelCanary\mathsf{DiffLabelCanary} is handcrafted, it represents an example of a batch that should be protected by DP guarantees since all records are drawn from the same distribution.

V-C2 Attack Results

The attack on DP-SGD follows the same procedure as the attack in Section V-B since it uses Gauss_pytorch\mathsf{Gauss\_pytorch}. Note that the attack against DP-SGD naturally reveals sequential (cached) samples from an implementation of the normal distribution since the attacker observes application of noise to gradients of all dd parameters of the model, i.e., to dd computations that all use independent noise draws.

The adversary calculates f(B)f(B) and f(B′)f(B^{\prime}) since we assume the attacker knows the records in BB and B′B^{\prime} and is trying to determine the presence of the canary. Since there are 26,010 gradients in yy, we evaluate the attack on each to see if it lies in support of f(B)f(B) or f(B′)f(B^{\prime}). We extract s1s_{1} and s2s_{2}, s1′s_{1}^{\prime} and s2′s_{2}^{\prime} from y−f(B)y-f(B) and y−f(B′)y-f(B^{\prime}) respectively for each. We then search for their neighboring values, and check whether any of them support gradients in yy. We say yy is in support of f(B)f(B) if there are more gradients that support f(B)f(B) than f(B′)f(B^{\prime}) and similarly for f(B′)f(B^{\prime}).

The experimental results are presented in Figure 3. For DiffLabelCanary\mathsf{DiffLabelCanary} the attacker’s succes rates is always better than a random guess for ϵ<0.68\epsilon<0.68. Similar to previous results in this section, the attack success rate is much higher than the theoretical (ϵ,δ)(\epsilon,\delta)-DP bound on failure of δ=10−5\delta=10^{-5} would suggest.

We observe that the adversary cannot distinguish f(B)f(B) and f(B′)f(B^{\prime}) when SimLabelCanary\mathsf{SimLabelCanary} is used, that is, when the canary is similar to all the other records in the batch. The reason is that the gradients for B′B^{\prime} and BB are close to each other and hence, even when the noise is added the two stay relatively close to each other, hence, the range of “attackable” floating-point they land on is similar. On the other hand, for DiffLabelCanary\mathsf{DiffLabelCanary} the canary record has a very different distribution from records in BB, thus the gradients are further apart which shifts them into ranges of varying number of floating points. It is important to note that the difference between the gradients (i.e., sensitivity) is protected by the DP mechanism based on a theoretical normal distribution using real values. However, this difference is large enough that once the noise is added, the noisy values are also shifted to ranges of floating points where one has more attackable values than the other. We observe a relative increase in gradient norm of 1.34 when using DiffLabelCanary\mathsf{DiffLabelCanary} compared to SimLabelCanary\mathsf{SimLabelCanary}.

We also observe that the success rate increases when σ\sigma increases, and correspondingly ϵ\epsilon decreases. This is counter-intuitive as the magnitude of noise increases as ϵ\epsilon decreases. The same observation was made by Mironov for the Laplace distribution. The reason again relates to the floating-point range in which noisy gradients land. We also note that compared to attacks in V-B, the attacker has more chances to observe values in support of one dataset than the other, since it has dd gradients to attack as opposed to one result.

VI Discrete and Approximate Distribution Sampling

Discrete distributions aim to avoid privacy leakage from floating-point representation, while retaining the privacy and utility properties of their continuous counterparts. In this section we show that naïve implementation of such discrete distributions suffers from a timing side channel attack: by measuring the time the sampling algorithm takes to draw noise from such a distribution, the adversary is able to determine the magnitude of this noise and, hence, invalidate the guarantees of differential privacy.

Canonne et al. study the discrete Gaussian mechanism and its properties. They demonstrate that it provides the same level of privacy and utility as the continuous Gaussian. Their sampler for Laplace and Gaussian uses the geometric distribution where the corresponding samples preserve the magnitude of the noise drawn from the geometric distribution. Unfortunately, the running time of this geometric distribution sampler, if not implemented carefully, reveals the magnitude of its noise.

Canonne et al. describe sampling from geometric distributions (Algorithm 2 in their paper) using Bernoulli samples. Recall that the geometric distribution measures the probability of taking nn Bernoulli trials to obtain a first success. Their pseudo-code to simulate this process proceeds as follows. It samples the Bernoulli distribution until the first success while incrementing a counter of failures. Once the success is observed, the counter is returned as a sample nn of a geometric distribution. Hence, the number of times Bernoulli sampler is invoked linearly correlates with the magnitude of the sample nn. This is the source of the timing side-channel where the time is correlated with a secretly drawn value.

The Laplace distribution is based on a linear transformation of the sample drawn from the geometric distribution, preserving its magnitude. In turn, the discrete Gaussian mechanism with standard deviation of σ\sigma in uses the Laplace mechanism with parameter ⌊σ⌋+1\lfloor\sigma\rfloor+1. Laplace noise is returned as-is via rejection sampling with a carefully chosen probability that produces the exact discrete distribution. However, since Laplace noise is returned as-is, the Gaussian sample has the same magnitude as Laplace and hence as the geometric distribution.

In summary, the time it takes to run discrete Laplace or discrete Gaussian sampling is correlated with the magnitude of the sample they return, and hence the noise they add to their respective DP mechanisms. Though the authors state that their algorithms may suffer from timing attacks, they attribute them to rejection sampling noting that this “reveals nothing about the accepted candidate”. However, as we argue above and experimentally show in the next section, the subroutine used to draw from the geometric distribution is the one that creates the timing side channel.

In parallel to the work by Canonne et al., the Differential Privacy Team at Google proposed an algorithm for approximate Laplace in their report of the library implementation for differential privacy . Their sampler makes a draw from the geometric distribution and then scales it using a resolution parameter based on ϵ\epsilon. The paper does not specify how the geometric distribution is implemented. Upon examination of the code in the library , we observed that geometric sampling is not based on drawing Bernoulli samples as in . However, its runtime still linearly depends on the value being sampled and hence also suffers from a timing side-channel. Specifically, the implementation of , performs a binary search, where the distribution support region is split proportional to probability mass and is guided by a sequence of uniform random values. Since the search is longer for events with smaller probability, the time to “find” larger values in the case of drawing geometric random variables takes longer. As a result this also creates a timing side channel that reveals the magnitude of the drawn noise, even though conceptually the technique for drawing from the geometric distribution is different from .

VII Experiments: Timing Attacks on Discrete Distributions

We evaluate the discrete Laplace and Gaussian using the implementation in that accompanied the work by Canonne et al. and the Laplace implementation from Google , referred to as implementations I and II respectively (see disclosure in Section I). We conduct two sets of experiments to show that 1) both implementations are amenable to timing attacks; 2) a DP algorithm that uses these implementations, as a consequence, is also amenable to a timing attack.

We run the discrete samplers on a single core of an Intel Xeon Platinum 8180M, which runs a 64-bit Ubuntu Linux 16.04.1 with kernel version 4.15.0-142. There are no other running processes on this core, so the interference on timing measurement is minimized. We measure the overall time of the sampling algorithm on invocation and exit with nano second precision using time.process_time_ns() for Implementation I written in Python and System.nanoTime() for Implementation II written in Java.

VII-B Timing of Discrete Samplers

We first measure the time it takes to generate the noise from each implementation and average it over more than 1 million trials for each sampled value in a truncated region. Since both Gaussian and Laplace are symmetrical distributions, the time it takes to generate positive and negative noise is also symmetric. In the implementation, the sign is determined independently from the (positive) geometric noise magnitude.

In Figure 4 we plot the average time it takes to draw absolute values of the noise. We used σ=19\sigma=19 for Gaussian I, λ=8\lambda=8 for Laplace I, and λ=8ln⁡3\lambda=\frac{8}{\ln{3}} for Laplace II. We observe that the absolute magnitude of noise has a positive linear relationship with time to generate noise from all implementations.

Based on the above relationship between noise magnitude and generation time, we implement our attack as follows. The attacker computes average time tit_{i} to generate absolute values of integer noise i∈i\in. It then measures the time tjt_{j} it takes to generate an unknown noise jj sample and chooses ii that has the closest time to tjt_{j} as its guess:

We ran 100,000 trials for each sampler to evaluate the accuracy of our timing attack. We evaluate accuracy in two standards: exact match and approximate match within ±1\pm 1 from the correct value:

approximate match: −1≤jguess−∣j∣≤1-1\leq j_{\mathsf{guess}}-|j|\leq 1

The attacker can use exact match as follows. Recall that the attacker, given a DP output yy and jguessj_{\mathsf{guess}} where y=f(D)+jy=f(D)+j is trying to guess the unprotected value of f(D)f(D). Let the co-domain of ff have integer support [−X,X][-X,X], known to the adversary as it knows ff and domain of ff, D\mathcal{D}. For exact match though our attack cannot guess whether the noise is positive or negative, this still harms differential privacy. Specifically, it reduces the original guess of the attack on the noise value from 1/(2X+1)1/(2X+1) to 1/21/2.

For the approximate guess, the attacker knows that jj could have been one of six values:

This allows it to determine that f(D)f(D) must be either y±(jguess−1)y\pm(j_{\mathsf{guess}}-1), y±jguessy\pm j_{\mathsf{guess}} or y±(jguess+1)y\pm(j_{\mathsf{guess}}+1). Hence, its guess is reduced from 1/(2X+1)1/(2X+1) to 1/61/6. As an example, suppose the attacker is trying to distinguish between f(D)=30f(D)=30 and f(D′)=60f(D^{\prime})=60. If it observes, y=20y=20 and jguess=9j_{\mathsf{guess}}=9. It knows that ff must have been computed on DD and not D′D^{\prime}.

The results are summarized in Table I where we measure the accuracy for samples in the range $forseveralparameterswherefor several parameters where\epsilonrangesbetween0.5and2andranges between 0.5 and 2 and\delta=10^{-5}.Sinceweevaluatetheabsolutevaluesofthesample,thebaselineaccuracybasedonarandomguessforexactandapproximatematchis. Since we evaluate the absolute values of the sample, the baseline accuracy based on a random guess for exact and approximate match is10\%andand33\%$, respectively. We observe that the attacks are always well above the baseline accuracy. This indicates that if an adversary can observe how long the sampling algorithm takes to generate noise used in a DP mechanism, then it can guess the relative magnitude of this noise for samplers based on geometric noise generation.

For Implementation I, the discrete Laplace mechanism is more vulnerable to timing attacks than the discrete Gaussian. This is likely due to rejection sampling that Gaussian implementation adds to the process. Rejection sampling adds stochasticity to which Laplace sample, among several that are drawn, is returned. For example, the attacker cannot distinguish between the following two executions:

In the first execution, a large Laplace noise value is generated but then rejected, while a small Laplace noise value generated next is returned as a result.

In the second execution, the opposite happens where a small Laplace value is rejected first and then a larger Laplace value is generated and returned as a result.

Execution times will be similar for both cases. Indeed, the authors of also proposes a discrete Gaussian based on Binomial sampling and rejection sampling and their implementation is not amenable to our attack.

The success rate of our attack decreases with increasing σ\sigma and λ\lambda. We note that with higher parameters, larger noise values are more likely, while the attack is more successful for smaller values, hence, overall accuracy decreases. For example, with λ=3\lambda=3 for Laplace I, the accuracy for i∈i\in is 27.1%, and accuracy for i∈i\in is 12.5%.

For Laplace II we observe a similar trend as for Laplace I even though the geometric distribution is sampled using a different procedure described in the previous section.

VII-C Timing Attack on Private Sum

Based on the results of the previous section, we conduct a timing attack on real data using the German Credit Dataset used in Section V-B1. We model the setting where the private sum of the credit attribute of the dataset is computed (e.g., an analyst queries a DP-protected database as in the DB setting in Section III). The attacker is trying to guess the non-private sum using query’s response and the time it takes for the query to return. We put a limit that each individual can have at most 5000 credits (which determines the sensitivity of the query). We use private sum computation which mirrors private count in Section V-B1 except ff is a sum and ss is sampled from Laplace II . The neighboring datasets DD and D′D^{\prime} that our attack tries to distinguish differ on a single record whose credit is 5000 in DD and 0 in D′D^{\prime}. We note that the query is different from that in Section V-B1 since the timing attack is not as effective for queries with small sensitivity, while the FP attack is effective against queries that return values close to 0.

To conduct the attack, we first collect timing data of private sum for different noise magnitudes. Similar to experiments in the previous subsection, we observe a linear relationship between noise magnitude and time cost albeit now this time includes computing the sum and sampling (Figure 8 in Appendix).

Our attack proceeds by measuring the time tt of a DP algorithm to complete. The attacker then uses tt and the output yy it receives to determine if it was DD or D′D^{\prime} used in the computation. Note that the noise magnitude should be s=∣y−∑Dx∣s=|y-\sum_{D}x| for DD and s′=∣y−∑D′x∣s^{\prime}=|y-\sum_{D^{\prime}}x| for D′D^{\prime}.

The attacker makes a guess on the magnitude of the noise using the timing data it has collected above and Equation 3. Let sgs_{g} be its guess. It then compares sgs_{g} with ss and s′s^{\prime} and chooses the closest one as its guess. That is, it chooses DD if ∣s−sg∣<∣s′−sg∣|s-s_{g}|<|s^{\prime}-s_{g}| and D′D^{\prime} otherwise.

We plot the attack results in Figure 5 for ϵ\epsilon in the range $.Weobservethatattacksuccessrateincreaseswithhigher. We observe that attack success rate increases with higher\epsilon,withsuccessrateof69.15, with success rate of 69.15% for\epsilon=1.Ourintuitionfortheabovetrendisduetotherangeofnoiseinwhichtheattackerneedstomakeitsguess.Thatis,forsmallernoisescale(i.e.,high. Our intuition for the above trend is due to the range of noise in which the attacker needs to make its guess. That is, for smaller noise scale (i.e., high\epsilon),theoutputnoiserangeissmallaswellandhenceattackerhaslessnumberofnoisestoassignobservedtimeto.Forexample,with), the output noise range is small as well and hence attacker has less number of noises to assign observed time to. For example, with\Delta=5000,noisemagnitudesaremainlydistributedin, noise magnitudes are mainly distributed inwhenwhen\epsilon=1,whilenoisemagnitudesaremainlydistributedin, while noise magnitudes are mainly distributed inwhenwhen\epsilon=10$.

The timing attack has two limitations. First, it assumes that the time (and its variance) to compute ff is not much larger than that of sampling, as otherwise the microseconds difference may not be observable. Second, the attack works for one-dimensional functions ff as the attacker can measure the time of a single noise sample. Hence, the attack will not be as successful if the attacker were to observe the time it takes to draw multiple samples, as is the case for DP-SGD.

VIII Mitigation Strategies

We discuss mitigation strategies for both of our attacks.

Mironov proposed the snapping mechanism to alleviate the FP attack by carefully truncating and rounding an output of a DP mechanism that was implemented using floating points. However, the privacy and utility of the overall mechanism decreases .

Our attack against the Box-Muller and polar methods assumes that the attacker observes two of their samples (recall that the Ziggurat method generates only one sample). That is, the attacker gets access to the second (cached) value (e.g., when a query returns an answer to a dd-dimensional query such as a histogram or ML model parameters). Without the second value in Equation (2) the attacker has to resort to checking all possible values in a brute-force manner. A potential mitigation is therefore to generate new samples on each call and disregard the second value.

We also observe that the implementation of DP-SGD adds noise to the batch directly. Instead it could potentially add several samples of noise and then average the result, since an average of Gaussian noise is still Gaussian. This would make it harder for an adversary to extract sample-level values needed for the FP attack as described in Section IV. However, this heuristic may still be susceptible to attacks as it also uses floating-point representation.

Discrete distributions have been proposed as a mitigation against floating-point attacks since they avoid floating points or bound their effect on privacy in (ϵ,δ)(\epsilon,\delta) parameters. However, as we showed in the previous section, they may suffer from other side-channel attacks and thus should also be carefully implemented. Nevertheless in this section we evaluate them as a mitigation for attacks in Section V-C and measure their effect on accuracy of DP-SGD.

We use the same model and MNIST dataset as in Section V-C to evaluate the performance of models trained with discrete Gaussian for a discretization parameter γ∈{10−1,10−2,10−3}\gamma\in\{10^{-1},10^{-2},10^{-3}\} and privacy budget ϵ∈(0.1,10]\epsilon\in(0.1,10]. We use the implementation of discrete Gaussian I .

VIII-B Defenses Against Timing Attacks

The most effective mitigation against timing attacks is to ensure constant time execution. Application-independent approaches to do so include compiler-based code transformations while other generic defense strategies are based on padding either by padding execution time to a constant time or adding a random delay .

In our setting, one could choose a sufficiently large time threshold and run noise generation mechanism until then, independent of the noise being drawn and the time that takes to produce it. If an attacker is stronger than that considered in this paper and can perform microarchitectural observations, then execution of any padded code has to be made secret-independent. For example, if the attacker can measure the time of memory accesses, the counter of the number of trials needs to be accessed regardless of whether heads or tails was drawn in a Bernoulli trial. The downside of padding is efficiency as all execution would take maximum time. The failure to draw noise within the threshold time can then be accounted for in δ\delta, the failure probability of DP . An alternative is to use a truncated version of the geometric distribution in order to avoid values that are impossible to sample on a finite computer.

We evaluate padding as a mitigation against our attack on private sum in Section VII-C. Padding can be implemented via two approaches. First, after a successful trial is encountered, we record its trial number and continue drawing “blank” Bernoulli samples, till the maximum noise threshold is reached. In the second approach, once a successful trial is encountered, a time delay can be added to reach some maximum time threshold. We choose the maximum threshold to be 41μ\mu since we observed that 99.5% of noise magnitudes are distributed in $,withaverageandmaximumexecutiontimeof37.1, with average and maximum execution time of 37.1\muand40.3and 40.3\mu,respectively,when, respectively, when\epsilon=10andand\Delta=5000.Wenotethattheseestimatesarenotdependentonthedatabutonlyonthesamplerandtheparametersofthenoise.Paddinguntilatimethresholdincreasesthetotalexecutionby10.5. We note that these estimates are not dependent on the data but only on the sampler and the parameters of the noise. Padding until a time threshold increases the total execution by 10.5%. For medium number of queries this is an acceptable overhead given the small magnitude of the overall time (in\mu s$). Note that these estimates will be different for other implementations.

As another mitigation strategy we propose a technique based on batching and caching. The method generates kk random values offline and saves them. It returns one value for each call to the distribution function. It proceeds this way until all cached values are used and then restarts the process by generating the next kk samples. Samples could be generated online and shuffled to disconnect noise from their timing, as suggested in . However, the attacker may still measure the range of possibles times.

In summary, discrete distribution sampling implemented in constant time or where the timing of sampling is not observable (i.e., generated offline) appears to be the best approach for defending against attacks discussed in this paper.

IX Related Work

The implementation of differential privacy via Laplace mechanism has been demonstrated to be flawed, due to finite-precision representations of floating-point values . In this paper, we demonstrate that implementations of the Gaussian mechanism suffer from the same attack, with adjustments to the attack process. In the authors demonstrate an attack against DP mechanisms that use finite-precision representations, and propose a mitigation strategy. Recently Ilvento has explored practical considerations and pitfalls of implementing the exponential mechanism using floating-point arithmetic. They show that such implementations are also susceptible to attacks and propose a solution using a base-2 version of the exponential mechanism.

Timing attacks against DP mechanisms have been explored in and . However, they differ from the attacks described in this paper as they do not exploit the timing discrepancies introduced by distribution sampling. In , the authors observe that the mechanism implementation may suffer from timing attacks (e.g., because it performs conditional execution based on a secret). As a mitigation authors propose constant time execution for the mechanism, without consideration of noise generation. On the other hand, Andrysco et al. exploit the difference in timing of floating-point arithmetic operations (e.g., multiplication by zero takes observably less time than multiplication by a non-zero value). They also show that DP mechanisms (including ) are susceptible to information leakage by using floating-point instructions whose running time depends on their operands.

Balcer and Vadhan outline shortcomings of implementing differentially-private mechanisms on finite-precision computers, including a discussion of floating-point representations and sampling from distributions with infinite support. The authors propose a polynomial-time discrete method for answering approximate histograms. Their method is based on a bounded (or truncated) geometric distribution. Though a full implementation is not provided, the authors suggest that the distribution can be sampled via inverse transform sampling using binary search over the support range using cumulative distribution function FF to guide the search. That is, given a uniform random value pp sampled uniformly from (0,1](0,1], find smallest value xx from the support of the geometric distribution such that F(x)≥pF(x)\geq p. If performed naïvely, such an approach could reveal the magnitude of the noise of the geometric distribution since the search will take longer for “less likely” values (i.e., larger pp) and would therefore suffer from the same timing channel as described in Section VI.

In independent and parallel work , the authors describe a theoretical attack against the Box-Muller method of sampling from the Gaussian distribution in a similar manner to our FP attack. However, they do not provide experiments validating the attack’s efficacy against existing implementations. The authors propose a mitigation strategy similar to the one mentioned in Section VIII based on computing a Gaussian sample from multiple samples, and analyze its robustness. Their work does not consider timing attacks.

Several systems have been proposed to estimate a lower bound on ϵ\epsilon that is achieved by a given DP mechanism in practice by finding counterexamples that would violate the theoretical guarantee (see and references therein). For example, by training a ML classifier to distinguish outputs produced by neighbouring inputs, DP-Sniper can find a higher ϵ\epsilon than the one proved in theory for the “naive” implementation of Laplace sampler.

Stepping away from differential privacy, Gaussian samplers have been also widely used in schemes for digital signatures, public key encryption, and key exchange based on lattice based cryptography . Such cryptographic primitives often rely on a multi-dimensional discrete Gaussian which is approximated by a distribution that is statistically close to the desired distribution. Several sampling mechanisms have been shown to suffer from cache-based side-channel attacks (i.e., based on memory accesses of the underlying algorithm) and power analysis . Defenses based on constant-time execution and shuffling have been proposed to protect against some of these attacks including timing. Though some techniques proposed for hardening the code in this space can be used for protecting samplers for DP (Section VIII), direct use of such samplers for DP is not straightforward. This follows from the observation that discrete variants in this area are (only) statistically close to the desired discrete distribution. As a result, composition-based analysis developed for analyzing cumulative loss of multiple mechanisms based on Gaussian noise cannot be used directly.

X Conclusion

In this paper we highlight two implementation flaws of differentially private (DP) algorithms. We first show that the widely used Gaussian mechanism suffers from a floating-point (FP) attack against implementations of normal distribution sampling, similar to vulnerabilities of the Laplace mechanisms as demonstrated in 2011 by Mironov. We empirically demonstrate that implementations in NumPy, PyTorch and Go, including those used in implementation of open-source DP libraries are susceptible to the attack, hence violating their privacy guarantees. Though some researchers have speculated that the Gaussian mechanism may be susceptible to FP attacks, this is the first work to provide a comprehensive evaluation showing that it is feasible in practice.

In the second part of the paper we show that implementations of discrete Laplace and Gaussian mechanisms — proposed as a remedy to the FP attack against their continuous counterparts — are themselves vulnerable to another side-channel due to timing. That is, we show that implementations of such discrete variants, including a DP library by Google, exhibit the time that is correlated with the magnitude of the secret random noise. Our work re-iterates the importance of careful implementation of DP mechanisms in order to maintain their theoretical guarantees in practice.

Acknowledgment

The authors are grateful to the anonymous reviewers for their feedback that helped improve the paper. This work was supported in part by a Facebook Research Grant and the joint CATCH MURI-AUSMURI. The first author is supported by the University of Melbourne research scholarship (MRS) scheme. We thank Thomas Steinke for pointing us to the Ziggurat method in Go and Clément Canonne for insightful discussions on statistically-close Gaussian samplers.

References

-A Box-Muller Method

The Box-Muller method is a computational method that generates samples of the standard normal distribution from uniformly distributed random values. It operates as follows:

Choose independent uniform random values x1x_{1} and x2x_{2} from (0,1)(0,1) using RandomFP\mathsf{RandomFP}.

Set r2←−2ln⁡x1r^{2}\leftarrow-2\ln x_{1} and Θ←2πx2\Theta\leftarrow 2\pi x_{2}.

This procedure can be used to generate two independent normal samples: s1s_{1}, as above, and s2←rsin⁡(Θ)s_{2}\leftarrow r\sin(\Theta).

-B DP Gradient Computation

We now recall how ff and Δf\Delta_{f} are determined for the DP-SGD mechanism.

The sensitivity of DP-SGD is the maximum L2L_{2} distance between any pair of f(B)f(B) and f(B′)f(B^{\prime}). Clipping norm LL dictates the largest L2L_{2} norm of any record gradient. Thus, for any f(B)f(B) and f(B′)f(B^{\prime}), we can have:

where bcb_{c} refers to the canary record and brb_{r} refers to the record replaced by bcb_{c}. Since L=1L=1 and S=64S=64, the sensitivity of ff is 1/321/32.

-C DP-SGD Discretization

Clip gg w.r.t. clipping norm LL, g′=g×min⁡{1,L/∥g∥2}g^{\prime}=g\times\min\{1,L/\left\lVert g\right\rVert_{2}\}.

Add discrete noise to zz and undo discretization, z′=(z+G)×γz^{\prime}=(z+G)\times\gamma.

where Roundγ\mathsf{Round}_{\gamma} is the conditional randomized rounding function with discretization parameter γ\gamma. We refer the reader to for details about Roundγ\mathsf{Round}_{\gamma}.

-D Ablation study

Here we investigate the rate at which the attacker can make a guess (attack rate) and how many of these guesses are correct (attack accuracy). To this end, we simulate settings where q=0q=0 and q′=cq^{\prime}=c and test two values of cc: 1 and 10, meaning the sensitivity Δ\Delta of the underlying function is 11 and 1010, respectively. We take a range of values of ϵ\epsilon from 1 to 20 while keeping a fixed δ=10−5\delta=10^{-5}. Table II shows that implementations Gauss_numpy\mathsf{Gauss\_numpy} and Gauss_pytorch\mathsf{Gauss\_pytorch} have different attack rates; however, their attack accuracy is always at least 89%. For Gauss_go\mathsf{Gauss\_go}, we observe that the attack rate is not influenced significantly by ϵ\epsilon (at least 76%), and the attack accuracy is always above 99.99%99.99\%.