Extracting Sensitive Information from Aggregated Data - Part 2

Consider a hospital dataset with 100,000 patients, where only one has a rare genetic disease. To protect privacy, the hospital enforces 50,000-anonymity: it only answers aggregate queries covering at least half of the records. But can the record of the patient with the rare disease still be isolated? And if so, how many queries would it take? In this post, I show that, perhaps surprisingly, as few as 20 queries - each covering on average 50,000 patients - can be enough to isolate the single patient with the rare genetic disease.

A similar situation arises when aggregating the decisions or contributions of multiple agents or experts across several rounds to improve robustness and protect privacy, for example, by mitigating hallucinations, correcting erroneous (or even malicious) individual decisions, or aggregating model parameters in collaborative (federated) learning to avoid directly sharing sensitive training data. To guarantee confidentiality for participants, cryptographic primitives such as secure aggregation ensures that one can only access aggregate statistics over a random subset of at least k participants in each round, but never the individual contributions. But is this level of protection sufficient? And if not, how many rounds (or queries) would be enough to reveal the private contributions of all participants?

The Problem

We assume that all queries are counting queries represented by a binary query matrix A, where Ai,j=1 if query i covers record j, and Ai,j=0 otherwise. For example, the SQL query

SELECT COUNT(*) FROM Patients WHERE AGE = 32 and SEX = 'F'

counts the number of HIV+ patients who are both 32 years old and female. In terms of the matrix A, such a query corresponds to a row selecting exactly those records that satisfy the predicate after the WHERE clause.

Suppose we have n patients and m counting queries. Let xj be a Boolean value indicating whether patient j is HIV-positive. Then, for query i, the result is

⟨Ai,:,x⟩=∑jAi,jxj=bi,

where bi is the number of HIV-positive patients covered by query i.

We consider an adversary who (1) aims to design the query structure A (i.e., which patients are covered by which queries), and (2) knows the query results b. The adversary’s goal is to reconstruct the unknown vector x. Importantly, the database manager only answers a query Ai if it covers at least k patients, ensuring a minimal privacy guarantee with k-anonymity.

The key questions we explore in this post are:

  1. How an adversary should choose the queries, and hence design A, so that x can be reconstructed from b?
  2. How many queries are required for such an attack?

The fewer queries needed, the cheaper the attack becomes, and the harder it is to detect.

The Theory

In the previous post, I showed how individual records can be reconstructed from the results of aggregated SUM queries by solving a system of equations of the form A⋅x=b, where A is the query matrix, x is the vector of unknowns, and b contains the query results. In that setting, any unknown xi can be recovered if its corresponding column A:,i is linearly independent of all other columns of A.

Let us look for a matrix A whose columns are linearly independent, assuming for simplicity that m=n. Rather than verifying linear independence directly, it is often easier to check orthogonality, which is a stronger condition and automatically implies linear independence.

Because A is restricted to be binary (each query either includes xi or not), there is in fact only a single n×n binary matrix with orthogonal columns: the standard basis (aka identity matrix), in which each column is a unit (one-hot) vector. For example, for four records (and queries) the standard basis is:

I=[1000010000100001]

The problem with using the standard basis I is that each query covers only a single record. This corresponds to a trivial disclosure with zero anonymity and would never be answered by a database manager providing k-anonymity for any k>1. We are interested in the more realistic case where every query covers multiple records, that is, A is a binary matrix in which each row contains multiple ones. However, based on the argument above, no such square binary matrix with orthogonal columns exists.

However, the situation changes if we allow negative entries in the query matrix, that is, we can not only add but also subtract attribute values from the aggregates. Consider the Hadamard matrix, where the first row and column are constant 1, and every other row and column contains an equal number of +1 and −1. For example, the Hadamard matrix of size 4 is

H4=[11111−11−111−1−11−1−11]

In general, a Hadamard matrix of size n can be constructed recursively as

Hn=[Hn/2Hn/2Hn/2−Hn/2],

with H1=[1]. Because Hadamard matrices are orthogonal by construction, every pair of columns (and rows) is linearly independent.

Although the Hadamard matrix is not strictly binary (entries are ±1 rather than 0/1), its rows are the linear combination of strictly binary queries; the sum of the records with negative entries in a row can be expressed as the total sum of all records minus the sum of the records with positive entries. More precisely, define a binary matrix H′ by replacing each −1 in H with 0:

Hi,j′={1,if Hi,j=1,0,if Hi,j=−1.

Then, for any row i,

⟨Hi,:,x⟩=⟨Hi,:′,x⟩−(∑ixi−⟨Hi,:′,x⟩)=⟨Hi,:′,x⟩−(⟨H1,:′,x⟩−⟨Hi,:′,x⟩)=2⟨Hi,:′,x⟩−⟨H1,:′,x⟩.

where H1,:′=H1,: is the vector of all-ones, hence ∑ixi=⟨H1,:′,x⟩. This means the adversary can request the database to evaluate all binary queries in H′, obtaining b′=H′x. From these query results, the adversary can reconstruct the original Hadamard query responses b=Hx, and then solve the resulting system of equations to recover x. The Hadamard matrix is particularly appealing since each query (row) covers half of the records (so it appears "highly aggregated" and compliant with k-anonymity type privacy rules), and the resulting system can be inverted efficiently using the fast Walsh–Hadamard transform in O(nlog⁡n) time.

In conclusion, the adversary can recover every record using a number of queries equal to the total number of records, even though each query aggregates over half of the database.

Can the adversary reconstruct all n records with less than n queries?

If we have more unknowns (records) than equations (queries), the above system of linear equations Ax=b is underdetermined and cannot be solved in general. However, it is no longer the case if x is sparse, that is, it has less than m non-zero elements like in the hospital dataset above where we have only a single HIV-positive patient. Indeed, we only need to determine the non-zero elements in x whose number is significantly smaller than n. Vectors with s nonzero entries are also called s-sparse vectors, and the set of non-zero positions is called the support of this vector.

Our objective is to minimize the number of queries m, given that the dataset is s-sparse, i.e., it contains only s≪n nonzero entries. Equivalently, we seek a query matrix A with as few rows as possible. Trivially, m≤n, as shown above. On the other hand, m≥s, since Ax is a linear combination of the columns of A. If we knew which s coordinates were nonzero, we could simply query those coordinates with s linearly independent rows, which would be sufficient for recovery (because the number of linearly independent rows equals the number of independent columns). Thus, in principle, the answers to O(s) queries contain enough information.

However, the indices of the nonzero entries is unknown. A classical result in linear algebra states that if every subset of 2s columns of A is linearly independent, then the sparsest solution to Ax=b is unique for any s-sparse vector x. Consequently, 2s linear (not necessarily binary) queries are sufficient to guarantee unique recovery of any s-sparse vector.

This proof suggests a simple brute-force search to recover x: enumerate all possible s-sparse candidates x and select the one that satisfies Ax=b, which must be the single correct solution. Unfortunately, this requires solving (ns) linear systems, which quickly becomes infeasible as s grows. In fact, it can be shown that finding the sparsest solution (i.e., solving the ℓ0-minimization problem) is NP-complete for arbitrary choices of A and x (unless P=NP). Fortunately, for specially designed matrices A, there exist efficient algorithms that can recover s-sparse signals. These will be discussed next.

We're looking for a m×n rectangular matrix such that every set of 2s columns of this matrix is linearly independent. More formally, the question: is there a rectangular (m×n) matrix whose any (m×m)-sized submatrix is invertible? One construction is the Vandermonde matrix:

[1c0c02…c0n−11c1c12…c1n−1⋮⋮⋮⋱⋮1cm−1cm−12…cm−1n]

if c0,…,cm−1 are all positive and distinct.

Error correcting codes for reconstruction

We require a binary query matrix A, where an attribute xj is either included in the aggregate (Ai,j=1) or excluded (Ai,j=0) for a given query. As shown above, there is no such square matrix that allows reconstruction of x, except for the trivial and non-private choice of the standard basis. However, this limitation no longer holds if we consider finite field arithmetic, which connects the problem to binary error-correcting codes.

In particular, a practical instantiation of a Vandermonde matrix is the parity-check matrix of a binary BCH code:

H=[1α0α02…α0n−11α1α12…α1n−1⋮⋮⋮⋱⋮1αm−1αm−12…αm−1n]

where {α0,…,αm−1} are distinct elements of a finite field of size at least n. In practice, the field is typically GF(2q), while the code symbols are restricted to GF(2), yielding binary codewords. The code length is then n=2q−1, and if m=2s, the BCH code can correct up to s errors in a codeword as long as all αi are distinct field elements. Therefore, if x is interpreted as a potentially corrupted codeword of this BCH code, then the nonzero locations of x can be identified from its syndrome H⋅x using any efficient BCH decoding procedure. This is because the zero vector is always a valid codeword of linear code, and all vectors with at most 2s nonzero entries will decode to the zero vector. Put simply, once H⋅x can be computed, the adversary can in principle solve for x in GF(2q).

The problem that H is not binary, its entries live in GF(2q). Therefore, the inner products ⟨Hi,x⟩ must be computed over GF(2q), requiring finite-field arithmetic, which is seemingly not realizable in SQL. However, one can expand each field element of GF(2q) into a binary vector of length q (via a basis representation of the field). With this expansion, the parity-check matrix can be represented as a binary matrix which means that a single query ⟨Hi,x⟩ can be realized with exactly q=log⁡(n) binary queries.

Therefore, the adversary can transform H into a binary matrix A with m⋅q=m⋅log2⁡(n+1) rows. By querying the database to compute A⋅x instead of H⋅x using standard integer arithmetic, and then reducing the result elementwise modulo 2, the adversary obtains the binary representation of the syndrome H⋅x in GF(2) which then can be directly mapped to its original representation in GF(2q). Finally, standard BCH decoding can be applied on H⋅x in GF(2q) to efficiently reconstruct x. In total, this reconstruction procedure requires 2s⋅log2⁡(n+1)=O(slog2⁡n) binary queries.

How many records are covered by a binary query Ai? It is not hard to see that if αi used in the parity check matrix H is a primitive element of GF(2q), then every query Ai covers about half of the records.

In conclusion, an adversary can exactly reconstruct all records in a database containing s nonzero entries using only 2slog⁡n binary queries, even though each individual query covers roughly half of the records, that is, they are n/2-anonym.

Stable reconstruction

The reconstruction techniques described above work only under strong assumptions: namely, that the sparsity s of x is known in advance, that the database manager returns exact query results (i.e., without perturbations as in Differential Privacy), and that the adversary has fairly accurate knowledge of patients' non-sensitive attributes (those appearing in the WHERE clause of SQL queries) in order to select the exact records targeted by the pre-defined queries. If these conditions are not satisfied, the recovered vector may significantly differ from the true x, rendering these techniques unstable. This concern is realistic; for example, an adversary may not know the exact number of AIDS patients, especially if the number is small, and querying it directly would violate k-anonymity.

Moreover, the binary code construction described earlier is not even asymptotically optimal in terms of the number of binary queries required. While a naive argument suggests that identifying a single non-zero position among n requires log2⁡(n) bits and thus at least slog2⁡(n) binary queries in total, support recovery does not require distinguishing every position individually. Instead, to uniquely identify all subsets of size s, one needs

log2⁡(ns)≤log2⁡(ens)s=s(1+ln⁡(n/s))ln⁡2=Ω(sln⁡(n/s))

binary queries.

This raises a natural question: is there a stable reconstruction technique that does not rely on rigidly pre-defined query structures? The answer comes from compressed sensing, which provides methods that are not only stable but also asymptotically optimal. Using a carefully designed random query matrix, the support of an s-sparse vector can be reconstructed with only O(sln⁡(n/k)) queries, while tolerating noise and perturbations in the responses. As a plus, the same techniques also work for non-binary queries!

We want a matrix A such that every submatrix AS (formed by selecting m columns of A) is close to orthogonal. Orthogonality guarantees that the columns are linearly independent, meaning the dot product between any pair of columns (rows) is zero, or equivalently, AS⊤AS=ASAS⊤=I. In practice, exact orthogonality is often too strong to require, so we instead demand that AS⊤AS be close to the identity matrix, or in other words, (AST⋅AS−I) is small according to a suitable norm, such as the matrix (or operator) norm. Formally, this means that max∥u∥2≤1∥(AS⊤AS−I)u∥2=δ is as small as possible. Intuitively, this condition says that AS⊤AS−I squeezes any unit vector to almost zero. Equivalently, since AS⊤AS−I is symmetric, we have for any vector x:

|x⊤(AS⊤AS−I)x|≤δ∥x∥22.

But the left-hand side equals

|xT⋅(AST⋅AS−I)⋅x|=|||AS⋅x||22−||x||22|

so we obtain:

|||AS⋅x||22−||x||22|≤δ

and hence:

(1−δ)∥x∥22≤∥ASx∥22≤(1+δ)∥x∥22.

Thus, when δ is small, the “stretching” or “shrinking” effect of the transformation AS is negligible: AS acts almost like an isometry that preserves ℓ2-norms (and hence distances between vectors). Orthogonal matrices achieve this exactly, since they preserve the inner product: ⟨ASx,ASy⟩=x⊤(AS⊤AS)y=x⊤y=⟨x,y⟩ and therefore the ℓ2-norm: ||x||2=⟨x,x⟩1/2=⟨ASx,ASx⟩1/2=||ASx||2. The constant δ measures how far AS deviates from perfect orthogonality; if the same δ works for all submatrices AS of A, it is called the restricted isometry constant of A.

Random query matrix

Let Ai,j be 1 or −1 with equal probability for every i,j independently. Then, for any row Ai,

E|⟨Ai,x⟩|2=E[∑k,ℓxℓxkAi,ℓAi,k]=∑jxjxjE[Ai,jAi,j]=E[Ai,j2]∑ℓxℓ2=∥x∥22

due to independence (i.e., E[Ai,ℓAi,k]=1 for k=ℓ and 0 otherwise) and E[Ai,j2]=12⋅0.5+(−1)2⋅0.5=1 is the variance. For the whole matrix A:

E(∥Ax∥22)=E(∑i=1m|⟨Ai,x⟩|2)=∑i=1mE|⟨Ai,x⟩|2=m⋅∥x∥22

which means that, on expectation, the matrix 1mA will preserve the norm and has a good chance to be "quasi-orthogonal". However, to have a better estimate on how close we are to perfect orthogonality, we need to know how well E(1m∥Ax∥22) concentrates around its mean ||x||22, that is, what's the probability that 1m∥Ax∥22−∥x∥22 is outside of a certain range of 0.

We will derive a more general result for a wider family of random matrices that will reveal a few design principles about the queries. We will show that if the elements of the matrix A “tightly” concentrate around their mean 0, then the same holds for the inner products ⟨Ai,x⟩. Consequently, the squared quantities ⟨Ai,x⟩2 also “tightly” concentrate around their mean value ∥x∥22, and therefore the average 1m∥Ax∥22 does as well. More precisely, if the entries of A are subgaussian, then it follows that both the random variables ⟨Ai,x⟩2 and 1m∥Ax∥22 are subexponential in m. Intuitively, this means that the probability that A deviates from perfect orthogonality is exponentially small in the number of rows m. Thus, the larger the number of rows, the more “orthogonal” the columns of A become, on average.

But why do we want subexponential concentration? Because we want "approximate orthogonality" to hold not just for a single submatrix of A, but any submatrices of a given size s simultaneously. Indeed, if 1m∥ASx∥22 is subexponential then roughly

Pr(AS is NOT orthogonal with error t)=Pr(|1m∥ASx∥22−∥x∥22|≥t)≤βe−κmt2

Applying a union bound over all possible subsets S of size s, we obtain

Pr(any submatrix AS is NOT orthogonal)≤(ns)βe−κm

We want this overall failure probability to be much smaller than 1. Therefore, we require
(ns)βe−κm≪1. Taking logarithms on both sides gives the condition:

m≥1κln⁡(ns)+1κln⁡β.

Using the standard combinatorial upper bound (ns)≤(en/s)s and ignoring constants κ and β, we find that

m=O(sln⁡(n/s))

In other words, subexponential concentration is useful because it gives you exponentially small failure probabilities for each event, which allows us to extend guarantees that hold for a single submatrix to exponentially many submatrices simultaneously, without requiring exponentially many queries (rows).

Next, we will provide more mathematical details on how to prove subexponential (or subgaussian) concentration using one of the most versatile tools in the theory of randomized algorithms: the Chernoff bound. In particular, we will show the following chain of implications for a single submatrix AS:

Any entry of AS is subgaussian ⟹Step 1 ⟨Ai,x⟩ is subgaussian ⟹Step 2 ⟨Ai,x⟩2 is subexponential ⟹Step 3 1m∥ASx∥22 is subexponential ⟹ AS is "quasi-orthogonal"

Finally, we extend this subexponential concentration for all submatrices of A.

Concentration of a single submatrix

To decide if a random variable X is subgaussian (or subexponential), one need to check the moment generating function (MGF) E[eλX] of X, which is intimately related to the tail bound based on Chernoff bounds:

P(X−E[X]≥t)≤infλ>0e−λtE[eλ(X−E[X])]

One direct implication of Chernoff bound that if E[eλX]≤exp(cλ2) for a constant c, then X is subgaussian: Pr(|X|≥t)≤2⋅e−t24c

In fact, for any centered subgaussian random variable X, E[eλX]≤ecλ2/2 implies that E[X2]≤c that is also called the proxy variance of X.

From now on, we’ll assume that X=Ai,j is a subgaussian random variable: E[eλX]≤exp⁡(cλ2/2) with proxy variance E[X2]≤c.

For example, when Ai,j=1 or Ai,j=−1 with probability 0.5, the moment generating function (MGF) of X=Ai,j is

E[eλX]=0.5eλ+0.5e−λ=cosh⁡(λ)≤eλ2/2

and therefore Pr(|X|≥t)≤2⋅e−t22 (the same bound can also be derived from Hoeffding's inequality). The proxy variance 2⋅(1/2)=1 equals the true variance.

Step 1: Ai,j is i.i.d subgaussian ⟹ ⟨Ai,x⟩ is subgaussian

One can show that if Ai,j is subgaussian with proxy variance c, then ⟨Ai,x⟩ is also subgaussian with proxy variance c∥x∥22.

Step 2: ⟨Ai,x⟩ is subgaussian ⟹ ⟨Ai,x⟩2 subexponential

Recall that E[⟨Ai,x⟩2]=∥x∥22. Let's assume (we'll relax this later) that E[⟨Ai,x⟩2]=∥x∥22≤1.
Then,

Pr(|⟨Ai,x⟩2−∥x∥22|≥t)≤2exp⁡(−1−ln⁡22min(t2c2,tc))

Step 3: ⟨Ai,x⟩2 is subexponential ⟹ 1m∥Ax∥22 is subexponential

Since 1m∥Ax∥22=1m∑i=1m⟨Ax⟩2, we need to upper bound the probability

Pr(|1m∑i=1m⟨Ai,x⟩2−E[1m∑i=1m⟨Ai,x⟩2]|≥t)=Pr(1m|∑i=1m(⟨Ai,x⟩2−∥x∥22)|≥t)=Pr(|∑i=1m(⟨Ai,x⟩2−∥x∥22)|≥t⋅m)≤2exp⁡(−1−ln⁡22⋅m⋅min(t2c2,tc))

where the centered random variable Zi=⟨Ai,x⟩2−∥x∥22 is subexponential as we showed above, and E[1m∑i=1m⟨Ax⟩2]=∥x∥22.

Therefore, in the general case when ∥x∥22>1, the above tail bounds extend to normalized vectors x/∥x∥2:

(*)Pr(|∥A^x∥22−∥x∥22|≥t⋅∥x∥22)≤2⋅exp⁡(−1−ln⁡22⋅m⋅t2c2)

for any 0<t<1, where A^=1mA. Informally, this inequality says that if the entries of A are independent, mean-zero subgaussian random variables, then A^ preserves the norm of any vector fixed vector x up to a relative error t, with high probability as soon as m is large enough.

Concentration of all submatrices

To simplify exposition, suppose that x is binary with support s. Then,

(**)m≥41−ln⁡2⋅c2δ2⋅s⋅ln⁡ens

where δ is the restricted isometry constant of matrix A. This confirms that the required number of measurements scales as m=O(sln⁡(en/s)).

Beyond symmetric Bernoulli matrices

So far we assumed that every entry of A is +1 or −1 with equal probability. However, the analysis above relied on only two properties of the distribution of Ai,j, so it carries over to other distributions, up to constant factors:

When c=1, that is, the proxy variance equals the true variance E[Ai,j2]=1, the random variable is called strictly subgaussian. The symmetric ±1 entries are strictly subgaussian (cosh⁡(λ)≤eλ2/2), and Steps 1-3 apply to them word for word.

We demonstrate the above conditions on two practical examples:

  1. Ai,j follows a sparse Rademacher distribution: Pr[Ai,j=+1]=Pr[Ai,j=−1]=p, and Pr[Ai,j=0]=1−2p, where p=0.5 corresponds to the fully dense case analyzed above. If p<0.5, then zeros appear, but +1 and −1 still occur with equal probability, hence Ai,j is symmetric.
  2. Ai,j follows a non-symmetric Bernoulli distribution: Pr[Ai,j=1]=p and Pr[Ai,j=0]=1−p. This is the most natural query model: every query includes each record independently with probability p, so the numbers of ones and zeros differ when p≠1/2.

Sparse Rademacher

If each entry of A follows a sparse Rademacher distribution, then

E[eλAi,j]≤exp⁡(λ24p)=exp⁡(12p⋅λ22)

This bound is not tight, because the first inequality treats the zeros as if they were ±1/2p, ignoring that most of the probability mass sits at 0. For p=1/2, it gives c=1 as in the dense case, but c grows as 1/(2p) when the matrix becomes sparser. A finer analysis, shows that the entries are strictly subgaussian (c=1) for every p≥1/6, and that c≤1/(6p) for p<1/6. The argument carries over to any larger p. Therefore, the entries are strictly subgaussian exactly as long as at most two thirds of them are zero.

This means that sparse Rademacher queries with p=1/6, that is, entries 3⋅{+1,0,−1} with probabilities 1/6,2/3,1/6, give exactly the same guarantee as the dense ±1 matrix, even though two thirds of the entries are zero. For sparser matrices (p<1/6), the number of queries in Formula ( ** ) grows by at most a factor c2=1/(36p2) (or 1/(4p2) with the simpler constant c=1/(2p)).

How can we realize a sparse Rademacher row with binary queries? Let Pi and Ni be the binary indicator vectors of the +1 and −1 positions in row i. Then ⟨Ai,x⟩=12p(⟨Pi,x⟩−⟨Ni,x⟩), which requires two binary queries. Each of them covers only about pn records, which may be too few for the database manager. However, the complement trick of the Hadamard construction helps again. Since ⟨Pi,x⟩=∑jxj−⟨P¯i,x⟩, where P¯i=1−Pi is the complement query (and similarly for Ni),

⟨Pi,x⟩−⟨Ni,x⟩=⟨N¯i,x⟩−⟨P¯i,x⟩

where both P¯i and N¯i cover about (1−p)n records. For p=1/6, every query covers about 5/6 of the database. Hence, a sparse Rademacher attack needs twice as many binary queries as the dense one, but each query looks more aggregated.

Non-symmetric Bernoulli

Let Bi,j=1 with probability p and Bi,j=0 otherwise. If each entry of the query matrix B follows this non-symmetric Bernoulli distribution, then

Unlike the sparse Rademacher case, c>1 for every p≠1/2. This is not an artifact of Hoeffding's lemma: a centered Bernoulli variable is never strictly subgaussian unless p=1/2, because it is not symmetric. Its third moment E[Ai,j3]=1−2pp(1−p) is non-zero, which adds a λ3 term to its MGF that eλ2/2 cannot dominate for small λ (with the appropriate sign). Hoeffding's constant is not optimal though; the best possible constant is known to be c∗=1−2p2p(1−p)ln⁡1−pp:

p (or 1−p) 0.5 0.75 0.9 0.99
c (Hoeffding) 1 1.33 2.78 25.3
c∗ (optimal) 1 1.21 2.02 10.8

Both constants are symmetric in p and 1−p, and they grow only when the queries become very small (p→0) or cover almost the whole database (p→1).

How can we realize A with strictly binary queries? Records with Bi,j=1 get weight 1−pσ and records with Bi,j=0 get weight −pσ, so

⟨Ai,x⟩=1−pσ⟨Bi,x⟩−pσ(∑jxj−⟨Bi,x⟩)=1σ(⟨Bi,x⟩−p∑jxj)

This means that A can be realized with the m binary queries B plus a single query returning the total count ∑jxj, which covers all n records and is therefore always allowed. If p<1/2, the adversary can also ask the complement query B¯i instead of Bi, since ⟨Bi,x⟩=∑jxj−⟨B¯i,x⟩.

What does this mean for k-anonymity? Suppose the database manager answers only queries covering at least k=κn records, for any κ<1. The adversary picks p slightly above κ (or asks the complements of queries with p slightly below 1−κ), so that every query passes the threshold. The price is the factor c2≈1/(16κ2(1−κ)2) in Formula ( ** ) (or less with c∗), which does not depend on n. Raising k does not stop the attack; it only makes it a constant factor more expensive. In a quick simulation with n=5000 records and s=10 non-zero entries, OMP (see below) reconstructed x in all trials with 140 queries for p=0.5, 200 queries for p=0.9, and 800 queries for p=0.99, where every query covered about 4950 of the 5000 records.

As a consequence, the numbers of ones and zeros in the queries do not need to be balanced. A random 0/1 query matrix, where every query covers a p fraction of the records, plus a single query for the total count, still reconstructs an s-sparse dataset x from O(sln⁡(en/s)) queries. The imbalance only costs a constant factor, which grows as the queries shrink (p→0) or approach the full database (p→1). Sparse Rademacher rows with p≥1/6 cost nothing extra asymptotically, and need two binary queries per row.

Reconstruction

We still need an efficient algorithm which computes x from b=Ax, or from noisy answers b=Ax+e. Least squares methods from the previous post are not suitable: if m<n, they return the solution with minimum ℓ2-norm, which is dense and usually far from the sparse x. Good decoders exploit the sparsity of x, and they come in two flavors.

Convex relaxation. Finding the sparsest solution (ℓ0-minimization) is NP-hard, so we replace the number of non-zero entries with the ℓ1-norm, which is convex but still favors sparse solutions:

x^=arg⁡minz∥z∥1subject to∥Az−b∥2≤ε

With ε=0, this is called Basis Pursuit and can be solved as a linear program. With ε>0 (noisy answers), it is called Basis Pursuit Denoising, whose Lagrangian form minz12∥Az−b∥22+λ∥z∥1 is the well-known LASSO. Why does ℓ1 promote sparsity? The ℓ1-ball is a "spiky" polytope whose corners lie on the coordinate axes, so when we inflate it until it touches the set of solutions {z:Az=b}, it typically touches it at a corner, which is a sparse vector. The key guarantee is from Candès: if the restricted isometry constant of A for 2s-sparse vectors satisfies δ2s<2−1, then

∥x^−x∥2≤C0∥x−xs∥1s+C1ε

where xs is the best s-sparse approximation of x, and C0,C1 are small constants. Hence, recovery is exact if x is s-sparse and the answers are exact, and the error grows only linearly with the noise ε otherwise. This is exactly the stability we were looking for. Note that ℓ1-minimization does not need to know s at all. If x is binary, one can also add the constraints 0≤zj≤1 and round the result.

Greedy methods. Orthogonal Matching Pursuit (OMP) builds the support of x one index at a time. We apply OMP due to its simplicity and scalability; it works well even with many queries (i.e., larger A). The basic idea is quite simple:

  1. Start with the residual r=b and an empty support S=∅.
  2. Find the column of A which is the most correlated with the residual, j=arg⁡maxj|⟨A:,j,r⟩|, and add j to S.
  3. Solve least squares restricted to the columns in S, zS=arg⁡minz∥ASz−b∥2, and update the residual r=b−ASzS.
  4. Repeat steps 2-3 until |S|=s or ∥r∥2 is small enough.

Why does it work? Since A (after scaling with 1/m) is quasi-orthogonal, A⊤Ax≈x. Therefore, A⊤r is a noisy copy of the not yet recovered part of x, and its largest entry points to a non-zero record. Each iteration costs a single matrix-vector product and a small least squares problem, so the total cost is O(smn). It is known that that OMP recovers any fixed s-sparse vector from O(sln⁡n) random subgaussian queries with high probability. Variants such as CoSaMP and Iterative Hard Thresholding select several indices per iteration and come with the same RIP-based stability guarantees as ℓ1-minimization. In practice, OMP is a good default when the answers are exact and s (or an upper bound on it) is known, while LASSO is preferable for noisy answers.

Summary

The table below summarizes the reconstruction techniques discussed in this post. n is the number of records, s is the number of non-zero records, and "records per query" shows how aggregated each query looks to a k-anonymity type defense.

Method (decoder) Queries needed Query type Records per query Sparsity assumption Noisy answers
Identity (baseline) n 0/1 1 None Robust
Hadamard (fast Walsh-Hadamard transform) n+1 0/1, complement + total count n/2 None Robust unless the noise is Ω(n)
Vandermonde / Fourier (Prony's method) 2s Weighted SUM (real or complex weights) n s-sparse, known s Very unstable
BCH syndrome (Berlekamp-Massey) 2s⌈log2⁡(n+1)⌉ 0/1, answers taken mod 2 (n+1)/2 Binary x, upper bound on s Fails (a single ±1 error flips a parity)
Random ±1 (ℓ1-minimization or OMP) O(sln⁡(en/s)) 0/1, complement + total count ≈n/2 Upper bound on s (none for ℓ1) Stable: error ∝ noise
Sparse Rademacher, p≥1/6 O(sln⁡(en/s)), same constant Two 0/1 complement queries per row ≈(1−p)n Upper bound on s Stable
Random 0/1 with Pr[1]=p O(c2sln⁡(en/s)), c=14p(1−p) 0/1 + total count ≈pn or (1−p)n Upper bound on s Stable

Three observations: First, exact algebraic constructions (Vandermonde, BCH) need the fewest queries, but they break down as soon as the answers are perturbed. Second, random query matrices need only a logarithmic factor more queries, and they tolerate noise, do not require the exact sparsity, and do not care whether the queries are balanced. Third, in every row of the table, individual queries can be made to cover at least half of the database.

Conclusion

Aggregation alone does not protect individual records. A k-anonymity type threshold on the query size, even k=n/2 or larger, does not prevent an adversary from reconstructing every record with n queries. If the sensitive attribute is sparse, like the single patient with a rare genetic disease among 100,000 patients, a logarithmic number of queries is enough. The most practical attack is also the simplest one: ask random queries, each covering a random subset of the records, and decode the answers with ℓ1-minimization or OMP. This attack does not need a carefully designed query structure, does not need to know the exact number of non-zero records, tolerates noisy answers, and works for any query size threshold k<n at the cost of a constant factor.

The same argument applies beyond databases. If a secure aggregation protocol reveals the sum over a random subset of participants in every round, and the individual contributions stay (approximately) the same across rounds, then the rounds form exactly a random Bernoulli query matrix. In that case, the adversary does not even need to choose the queries; the protocol does it for them.

These techniques come from compressed sensing, which was developed to reconstruct sparse signals from few measurements in signal processing. Many naturally occurring signals are sparse in some basis, such as images in the wavelet domain or audio in the frequency domain, and compressed sensing is used, for example, to speed up MRI scans. All reconstruction techniques above are efficient, but they only work for linear queries such as COUNT and SUM. Non-linear aggregates (MIN, MAX, median) lead to combinatorial problems where SAT or integer programming solvers may be required. Moreover, the adversary must be able to target specific records with the query predicates, which requires fairly accurate knowledge of their non-sensitive attributes.

Interestingly, the key ingredients of this attack have been known for more than two decades, only from the other side of the table. In 2003, Achlioptas showed that random ±1 matrices, and even sparse matrices with entries 3⋅{+1,0,−1} with probabilities 1/6,2/3,1/6, preserve distances as well as Gaussian random matrices in the Johnson-Lindenstrauss lemma. He called them database-friendly random projections, because computing them needs no multiplications: each projected coordinate is the sum of some attributes minus the sum of others, which any database can compute with standard SQL aggregates. Since a random matrix satisfying the concentration inequality behind the Johnson-Lindenstrauss lemma also satisfiesthe restricted isometry property, these matrices are also good reconstruction queries. The property which made these projections friendly to database owners, namely that they can be computed with plain SUM and COUNT queries, is exactly what makes them friendly to the adversary.

What does work as a defense?

Every accurate answer leaks some information, and the leakage accumulates across queries. Dinur and Nissim showed that if every answer is accurate up to an error of o(n), then O(nlog2⁡n) random queries are enough to reconstruct almost all records in polynomial time. This is known as the Fundamental Law of Information Recovery: overly accurate answers to too many questions destroy privacy. Their attack uses exactly the random 0/1 queries of this post: every query includes each record independently with probability 1/2. The decoder is different, though. It does not assume that x is sparse, so neither ℓ1-minimization of x nor OMP applies. Instead, it solves a linear program to find any fractional solution which is then rounded. Since sparsity is not exploited, it needs more than n queries, as opposed to the O(sln⁡(n/s)) queries for sparse data. The extra logarithmic factors pay for the noise, since exact answers would require only n queries, as in the Hadamard construction. The exact algebraic constructions (Vandermonde, Prony, BCH) play no role here, since they fail under any noise. The principled defense is therefore to add noise calibrated to the total number of queries and to bound the overall leakage, which is exactly what Differential Privacy does.