On the (In-)Security of the Shuffling Defense in the Transformer Secure Inference

Zhengyi Li, Yakai Wang, Kang Yang, Yu Yu, Jiaping Gui, Yu Feng, Ning Liu, Minyi Guo, Jingwen LengarXiv 2026

TL;DR

This paper demonstrates that the "shuffling defense"—a popular, low-overhead method used to protect model weights during fast, secure Transformer inference—is fundamentally insecure. By exploiting tiny, stochastic truncation errors inherent in secure computing hardware, the authors show that an adversary can align shuffled activations and fully extract functionally equivalent model weights for a query cost of about $1.

What Problem Does This Paper Address?

Machine Learning as a Service (MLaaS) presents a classic privacy dilemma: clients want to keep their prompts private, while servers want to protect their proprietary model weights. Cryptographic approaches like Full-Model Encryption (FME) use multi-party computation (MPC) or homomorphic encryption (HE) to solve this, but they suffer from massive latency bottlenecks. Specifically, securely computing non-linear layers (like ReLU, GELU, or LayerNorm) accounts for 75% to 90% of total inference latency.

To fix this, recent frameworks use Linear-Only Encryption (LOE). LOE passes intermediate activations to the client in plaintext so they can compute the non-linear layers instantly. However, exposing these activations allows an adversary to reconstruct the model's linear weights by solving a system of linear equations.

To mitigate this risk, state-of-the-art LOE frameworks implement a shuffling defense: they randomly permute the activation tensors before sending them to the client. Because a vector of dimension $h$ has $h!$ possible permutations (a search space of $\approx 10^{157}$ for $h=100$), it was widely believed that recovering the original order was mathematically impossible. This paper challenges that assumption.

Figure 1: The red locked part is private to the owner or invisible for both parties, and the green unlocked part is revealed to the client. FME inference only reveals the final output to the client. LOE inference also reveals shuffled activations to the client.

Methods

The authors introduce a novel weight extraction attack that bypasses the shuffling defense without ever needing to guess the true permutation. The attack operates in three main phases:

  1. Generating $\epsilon$-Close Activations via Truncation Errors: Due to Lipschitz continuity, inputs that are close to each other yield activation vectors that are close in value. However, Transformers take discrete token IDs, making it impossible for a client to subtly perturb the input text. The authors bypassed this by repeatedly sending the exact same prompt. Because secure inference frameworks use fixed-point precision, multiplications require a truncation step that introduces a stochastic 1-bit error. This tiny hardware variance acts as a natural perturbation generator, yielding slightly different, numerically close activation vectors across identical queries.
  2. Vector Alignment: Even though every activation vector is shuffled using a different random permutation, shuffling preserves the underlying values. By sorting the values or formulating it as a standard assignment problem solved via the Hungarian algorithm, the adversary can align different vectors to a single, common reference permutation.
  3. Weight Extraction via Linear Systems: Once the activations are aligned to a common (but still unknown) permutation matrix $\pi$, the adversary constructs a linear system: $$X^{(l+1)}\pi^{(l+1)} = X^{(l)}\pi^{(l)}W^{(l)}$$ Solving this via a pseudo-inverse matrix yields a recovered weight matrix $W^{(l)\prime}$ that is row- and column-shuffled compared to the original matrix.
Figure 3: Aligning two shuffled vectors based on the closest distance. Three out of four pairs of elements are drawn to illustrate their correspondence for two sufficiently close vectors.

Datasets

The attack was evaluated on two open-source Transformer architectures commonly used in secure inference benchmarks: Pythia-70m and GPT-2. To evaluate the downstream utility of the stolen models, the authors measured text generation performance using the Wikitext dataset.

Key Insights and Ideas

  • Functionality Invariance to Shuffling: The most critical "aha" moment is that the adversary does not need to un-shuffle the weights to their original positions. As long as consecutive layers share the same permutation, the mathematical properties of neural networks ensure that the shuffled weights perform the exact same forward propagation as the original model.
  • Hardware Flaws as an Attack Vector: The attack cleverly turns a defense mechanism's environment against itself. The stochastic 1-bit error in secure fixed-point truncation protocols—originally designed purely to maintain computational accuracy—inadvertently provides the exact mathematical variance the attacker needs to break the permutation security.

Key Results

  • High Alignment Accuracy: The Hungarian algorithm successfully aligned shuffled activations with a Mean Squared Error (MSE) between $10^{-9}$ and $10^{-6}$, mismatching less than 2% of the elements.
  • Accurate Weight Recovery: The adversary successfully extracted model weights with an $L_1$-norm difference from the oracle weights ranging from only $10^{-4}$ to $10^{-2}$.
  • Low Cost: The attack requires a linear query complexity $O(N)$. Using commercial API pricing benchmarks, the entire extraction process costs less than $1.
  • Near-Lossless Downstream Performance: While the raw stolen model showed a slight drop in perplexity on the Wikitext dataset, a brief fine-tuning stage lasting under 6 minutes restored the model to near-original performance levels (e.g., GPT-2 perplexity went from an original 21.11 to 21.15 after fine-tuning).

Limitations and Future Work

  • Scalability to Larger Models: As the target model size increases, the input matrix becomes increasingly ill-conditioned (characterized by a high condition number). This amplifies numerical errors during matrix inversion, causing the fidelity of the extracted weights to degrade on larger models.
  • Multi-Head Attention Complexity: When the matrix multiplications inside the attention heads are computed privately, recovering the attention weights ($W_{qk}$) requires computing a Kronecker product. This squares the input dimension (e.g., $768^2$), making the linear system exceptionally difficult to solve. The authors left this optimization for future work.
  • Proposed Defenses: The authors suggest that defenders can mitigate this vulnerability by adding controlled noise to activations or by computing LayerNorm layers privately, ensuring that either the input or output of the linear layers remains completely hidden from the client.

Summary updated

BibTeX
@misc{li2026security,
  author = {Zhengyi Li and Yakai Wang and Kang Yang and Yu Yu and Jiaping Gui and Yu Feng and Ning Liu and Minyi Guo and Jingwen Leng},
  title = {{On the (In-)Security of the Shuffling Defense in the Transformer Secure Inference}},
  year = {2026},
  eprint = {2605.04901},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.04901},
}
Figure