Quantized Neural Distinguishers Can Hide Weak Code-Based Keys

Machine-learning attacks on post-quantum cryptography now work well enough to matter. A transformer can look at a code-based public key, the large binary matrix published in McEliece-style encryption, and tell whether it came from a hidden structured code or from a truly random one. That ability is the first step toward breaking a scheme. These keys are big: about 261 KB for Classic McEliece at the lowest standard security level and over 1 MB at the highest. Running such a transformer on realistic keys means long input sequences, large memory for the attention cache, and strong pressure to run the model at low numerical precision (8 or 4 bits instead of 16). Large language models often develop "activation outliers" during training: a few hidden-state coordinates that are thousands of times larger than the rest. When a model with outliers is rounded to low precision, the rounding grid stretches to fit those spikes and the small signals get erased.

This note proposes to test whether that failure hits cryptanalytic transformers in a way that is especially dangerous. A quantized distinguisher could report "looks random" on a structured key, and an evaluator would read that as evidence the key is safe. We will measure how outliers and the resulting loss of distinguishing power grow as the public key grows. We will also test one targeted repair: keep the specific low-energy direction that carries the structure signal at high precision. If the effect is real, it matters for anyone who uses ML audits to screen compact-key proposals. If it is not real, a clean negative result tells practitioners that off-the-shelf quantization is safe for this purpose.

Core Claim

The structure signal a transformer uses to separate algebraic codes from random codes is small in magnitude relative to the model's outlier channels. It therefore sits in the part of the activation space that uniform low-bit quantization destroys first. Two consequences follow. First, quantized distinguishers will show a drop in their advantage over random guessing that is larger than their loss or calibration metrics suggest. This silent false-negative mode is our analogue of the "alignment collapse" in quantized chat models. Second, the drop will get worse as the key size (code length $n$ and dimension $k$) grows, because longer row-token sequences and wider rows strengthen the outlier and attention-sink mechanisms. A precision budget spent on the probe-identified structure direction should recover most of the lost advantage. The same budget spent on the largest singular directions, or on uniform rotation, should recover less.

Grounding in prior work

Several papers motivate the question. AI for Code-based Cryptography introduces DeepDistinguisher. It treats rows of the public generator matrix as tokens, classifies structured versus random codes, and reports over 98% accuracy on Goppa codes and up to 98% on quasi-cyclic moderate-density parity-check (QC-MDPC) codes with row weight up to 6. It never examines the model's internal numerics or its behaviour under compression, and that is the gap we fill. Alignment Collapse Under KV Cache Quantization shows the failure pattern we expect to transfer. Refusal behaviour lives in a low-energy subspace, and quantizing the key-value cache (the stored attention keys and values) erases it while perplexity barely moves: Mistral-7B lost 15.2% of refusals at a 1.03× perplexity increase. Its targeted-protection fix recovered up to 97% of lost alignment. We borrow the diagnosis and the idea of protecting a specific subspace, but move from a behavioural direction in language to an algebraic signal in matrices. That signal can be verified objectively, because ground-truth labels come from how each key was generated.

A second group supplies the expected mechanism and the knobs we vary. Anatomy of Massive Activations and Attention Sinks separates two effects. Massive activations come from pre-normalization residual accumulation and SwiGLU amplification. Attention sinks depend on per-head dimension and on training sequence length. Quantizable Transformers explains sinks through softmax's inability to express a no-op. Attention Sinks Induce Gradient Sinks shows that sinks reinforce themselves during training. In a row-token distinguisher, the number of tokens equals the key's dimension $k$, so key size directly sets the sequence length these papers link to sink formation. The systematic form $[I_k \mid P]$ also gives every row a position-like identity block, which could encourage fixed high-magnitude channels.

A third group supplies the mitigations we compare against. Outlier Suppression+ shifts and scales channels into the weights. QuaRot rotates activations with Hadamard matrices so that 4-bit weights, activations, and key-value cache become feasible; it reports a 0.47 perplexity increase on Llama-2-70B. SVDQuant routes the top singular components through a 16-bit low-rank branch, and it also shows that pure migration fails at 4-bit weights and 4-bit activations. Our repair keeps SVDQuant's side-branch form but changes what goes into it. The branch is chosen by a linear probe for the structure label, not by energy.

The file does contain an adjacent idea that we reject: compressing public keys with low-rank-plus-residual decompositions. The folding attacks of Structural cryptanalysis of McEliece schemes with compact keys show that any exploitable regularity added to shrink keys tends to become an attack surface. Low-rank structure over a finite field invites rank attacks. We therefore treat key size as the operating regime and the object being audited, not as something we compress.

Research Program

We will reimplement a DeepDistinguisher-style model as described in AI for Code-based Cryptography: rows as tokens, a linear embedding, multi-head self-attention, and absolute positions. We train it in 16-bit precision on balanced sets of structured public keys and uniformly random systematic matrices. Code families are binary Goppa and QC-MDPC. We sweep $n$ from a few hundred up to the largest size our hardware can train in 16 bits, and extrapolate the trend toward Category-1 sizes such as $n=3488$, $k=2720$, where the reported key is 261,120 bytes (Rank-Metric Codes and Their Applications). For each trained model we record per-layer peak-to-median activation ratio, channel kurtosis, the fraction of attention mass on sink tokens, and which tokens host the spikes. We then fit a linear probe for the structure label at each layer and measure what fraction of activation energy lies along the probe direction.

Next we quantize each model under 8-bit and 4-bit settings for weights, activations, and key-value cache, separately and together. We report distinguishing advantage (accuracy minus 50%), the false-negative rate on structured keys, and cross-entropy. The central measurement is the gap between these metrics: how much advantage disappears relative to the change in loss. Finally we implement probe-direction protection. The top-$r$ probe directions for $r \in \{1, 4, 16\}$ are projected out of the chosen activations and key-value tensors, kept in 16 bits, and added back after the quantized computation. This mirrors SVDQuant's branch but uses a different selection rule.

To test whether outliers are the cause rather than a coincidence, we retrain a subset of models with architectural changes that Anatomy of Massive Activations and Attention Sinks reports reduce spikes or sinks. One variant replaces the pre-norm with DynamicTanh, which that paper reports cut peak spikes from 3,818 to 153 while raising the sink ratio. Another uses smaller head dimension, which lowered the sink ratio in that work. If quantized advantage improves only when spikes fall, and not when sinks alone change, we have isolated the mechanism.

Baselines

The naive reference is the same distinguisher quantized by per-tensor round-to-nearest with no outlier handling. It shows the raw size of the effect. The upper reference is the unquantized 16-bit model. The file gives accuracies in the >98% range for DeepDistinguisher in full precision. We found no reported result on Lacuna for quantized DeepDistinguisher or any quantized neural code distinguisher, so every quantized number here is new.

The strongest general-purpose competitor is QuaRot-style Hadamard rotation of activations, weights, and key-value cache (QuaRot). It removes outliers without mixed precision and is the obvious off-the-shelf fix. Its reported reference point is the 0.47 Wikitext-2 perplexity increase at 4 bits on Llama-2-70B, which is a language-modeling figure; no reported result was found on Lacuna for it on code distinguishers. We also run channel-wise shift-and-scale migration (Outlier Suppression+), energy-selected low-rank branches (SVDQuant), and quantization-aware fine-tuning. Every method uses the same trained 16-bit checkpoints, the same calibration set of 512 keys drawn separately from the test keys, the same bit-width configurations, and the same budget of extra 16-bit parameters and memory. The low-rank and probe branches have equal rank. Quantization-aware fine-tuning gets the same number of optimizer steps as probe fitting plus any tuning we allow the other methods.

The ablation that isolates our key ingredient compares an SVDQuant branch and a probe branch of identical rank and precision, differing only in how directions are selected. Beating the baselines means two things. At 4-bit activations and key-value cache, the probe branch must recover at least half of the advantage lost by QuaRot at the largest key sizes, measured over five seeds with non-overlapping confidence intervals. It must also do so while adding no more than 7% memory, matching the overhead range reported for the alignment repair.

Why not just…?

Why not just run the distinguisher in 16-bit precision? At the key sizes we can train, that works, and we use it as the reference. The problem appears at realistic sizes. Category-1 keys give thousands of row tokens, each thousands of bits wide, and the attention cache grows with the square of that. Evaluators with modest hardware will quantize. The more practical risk is that people quantize without knowing it: inference servers default to 8-bit caches, and Alignment Collapse Under KV Cache Quantization found a 30.3% flip rate under vLLM's FP8 cache on Qwen-2.5-7B. If our sweep shows the gap stays negligible up to the largest trainable $n$ and does not trend upward, then 16-bit is unnecessary and quantization is safe. We would report that result.

Why not just apply QuaRot or Outlier Suppression+? This is the real threat. Rotation spreads outlier energy evenly across coordinates, and if the structure signal is only small rather than sitting in a specific low-energy subspace, rotation may fix the problem. We run rotation as the main baseline for that reason. We expect it to fall short for one reason: rotation also spreads the probe direction's energy, so a signal near the noise floor stays near the noise floor after rounding. The alignment-collapse study found that generic scale and layer protection missed low-energy refusal directions. If QuaRot matches the probe branch, our contribution becomes the diagnosis and the audit protocol, not the repair. Migration is known to break at 4-bit weights and 4-bit activations (SVDQuant), so we expect it to fail below 8 bits.

Why not just use quantization-aware training? Fine-tuning under quantization could teach the model to put the structure signal in high-energy directions. We include it at equal compute. It has two costs: it needs labeled structured keys for every new family, and it gives no diagnostic that tells an auditor when the signal was lost. The probe branch is fit post hoc from a small calibration set. If fine-tuning dominates, we will recommend it and keep the probe-energy measurement as the auditing tool.

Why not just use classical distinguishers or information set decoding? Those methods answer the security question without neural numerics, and AI for Code-based Cryptography reports that its model beats classical algebraic distinguishers only for some Goppa parameters and approaches chance as the polynomial degree grows. Our question concerns the reliability of the ML tools people are adopting, not whether they beat classical attacks, so classical methods are not a substitute here.

Decisive Checks

The first check is whether the advantage gap exists at all. At 4-bit key-value cache with naive rounding, does structured-key false-negative rate rise by more than 10 points while cross-entropy changes by less than 5%? If not, the core claim fails.

The second check is scaling. Across the $n$ sweep, does the quantized advantage loss grow monotonically, and does it track peak-to-median activation ratio better than it tracks sink ratio? The DynamicTanh and head-dimension retrains decide which mechanism drives it.

The third check is the selection ablation. At equal rank, does the probe branch beat the energy-selected branch and QuaRot? We run this on Goppa and QC-MDPC keys separately, and again near the degree frontier where full-precision accuracy starts falling toward chance. That is where the signal is weakest and the prediction is sharpest.

Last, we release the audit, fixed calibration sets for each code family, as a quick check that any quantized cryptanalytic model must pass before its "random-looking" verdicts are trusted.