← Back to section · Research & Analysis

Experiment Design: How to Verify the Output Distribution of Rejection Sampling

Part of ML-DSA's security rides on its sampling distribution matching the specification. Failing to detect a bias is not the same as there being none — this design covers sample collection, statistical testing and interpretation limits for exactly this invisible class of bug.

Published 22 November 2026 · 5 min read · PQ Frontier

Experiment Design: How to Verify the Output Distribution of Rejection Sampling
AI-generated site artwork
Video explainer · Experimental Research: Reproducible Designs

The research question: put a floor under invisible errors

Rejection sampling in lattice signatures has an unpleasant property: get it wrong and signatures still verify. A slightly skewed sampling distribution or one inverted boundary in the rejection condition leaves every functional test green while security quietly leaks — the entire point of rejection sampling is to make the output distribution independent of the secret, and once the distribution takes on the secret’s shape, signatures become a side channel.

So the experiment’s question is not “is this implementation correct” but a more honest one: at a given sample size, how large a bias can we rule out? The deliverable should be a sentence with a number in it — for instance, “with ten million samples per coefficient class, no deviation from the target distribution was detected, and the tests’ detection floor for relative bias is roughly this magnitude”. A negative result only carries information when the detection floor is stated; “passed a chi-square test” says nothing at all.

Sample collection: test the raw sampler, not signatures

The first discipline is testing the right object. A finished signature is the superposition of sampling, rejection, norm checks and encoding; inferring the sampling distribution back from signatures is inefficient and invites misattributing other stages’ effects to the sampler. Instead, add test hooks that export the sampler’s raw output stream: accepted samples, rejected samples, and a classification of each rejection by cause. If the implementation offers no hooks, instrument a separate test build of the same codebase rather than altering the release build’s behaviour.

The second discipline is fixing the input conditions. The sampler’s inputs are a seed and a counter, and the experiment must sweep the input space systematically: different seeds, counter-overflow boundaries, branches where domain-separation strings change. Many implementation bugs live only on specific branches — a parameter set taking a different sampling path, for instance — so testing only the default set is equivalent to not testing. ML-DSA’s three parameter sets get independently collected and independently tested samples; no pooling.

The third discipline is computing the sample size before measuring. Sample size is back-derived from the target detection floor: detecting a relative bias of a given magnitude requires a sample inversely proportional to the square of that bias — a hard statistical constraint with no shortcut. Fix the floor, compute the sample, then judge feasibility, in that order.

Testing method: three layers

Layer one checks marginal distributions. For each coefficient position, run a chi-square goodness-of-fit test of the observed frequencies against the target distribution whose probabilities are derived from the sampling algorithm as specified in FIPS 204. The derivation must come from the specification step by step, not be copied from another implementation — testing implementation against implementation goes all green when both make the same mistake.

Layer two checks the rejection rate and rejection pattern. Tally the overall rejection rate and the share of each rejection cause, and compare against theoretical expectation. In rejection sampling, the rejection rate is itself a fingerprint of the distribution: an off-by-one boundary (greater-than written where greater-or-equal belongs) may shift the marginal distribution only slightly while the rejection rate betrays it first. This layer is often more sensitive than layer one, and cheaper.

Layer three checks independence and conditional structure. Are adjacent coefficients independent? Does the sample correlate with low bits of the seed? Use serial-correlation and conditional-distribution tests. This layer guards against a subtler class of error: RNG state reuse or counter increment bugs leave each individual sample’s distribution looking perfectly normal while correlations between samples give the implementation away.

Sample collection also has a time dimension that is easily overlooked: a distribution is not validated once for life. Any change of compiler version, dependency library or hardware platform can alter the sampling code’s actual behaviour, so this experiment should be frozen into a regression suite that reruns automatically at every release of the implementation, with fixed seeds and fixed sample sizes, and with successive results kept as a timeline. The timeline’s value shows at incident review: if a sampling anomaly surfaces one day, the change that introduced it can be located immediately. Automated reruns must keep the same multiple-testing discipline — dozens of tests per run and dozens of runs per year make false positives a periodic certainty, and the handling procedure remains the single rule: only reproduction on an independent fresh sample counts.

Interpretation: multiple testing and how to write a negative result

Running dozens or hundreds of tests on one dataset at a five-percent significance level guarantees a few “significant” results by chance alone. The interpretation rule must therefore be fixed in advance: a single significant test is not a finding; the same position and the same direction of bias must reproduce on a fresh, independent sample batch before it is promoted to a suspected defect. A rule written after seeing the results is no rule at all.

The format of a negative report matters just as much: state the sample size, the test inventory, each test’s detection floor, and the interval between the observed rejection rate and theory. Such a report doubles as a regression baseline for future revisions of the implementation — the experiment’s second deliverable besides catching bugs.

Common pitfalls

First, guessing the sample size: a casual hundred thousand samples declared as “no distribution anomaly”, when the detectable bias at that scale is large enough to leak meaningful information. Second, testing the wrong object: distribution tests on finished signatures, where stacked processing smears the signal into mush. Third, copying the theoretical distribution from another implementation, destroying independence. Fourth, reading p-values without effect sizes: at enormous sample sizes, practically meaningless deviations turn “significant”, so the actual size of any bias must be reported alongside. Fifth, treating statistical tests as security proofs: distribution testing catches implementation errors, not algorithmic design flaws, and the two evidence levels must not be conflated.

Tags: ML-DSARejection SamplingStatistical TestingImplementation Verification