Manuscript Offprint

arXiv:2611.02042

SANAI: Secure ECC Distributed Keyed Parity Embedded in Weights for Protecting Neural Networks against Bit-Flip Attacks

Habibur Rahaman, Daniel Lobo, Md Rezoan Ferdous, Swarup Bhunia

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Quantized neural networks store weights in dense memory, where bit flips caused by voltage scaling, aging, radiation, or deliberate attacks such as RowHammer can severely degrade model behavior. A single corrupted high-order bit can lead to erroneous classifications or nonsensical language-model outputs. Embedded error-correcting codes (ECC) avoid dedicated parity storage by hiding parity within model weights. However, existing schemes use largely uniform embedding across layers and bit planes, leave parity unsecured, and tolerate only low bit-error rates (BERs), typically up to 6%. Moreover, an adversary aware of sensitive weight locations and the ECC scheme can bypass protection by deliberately exceeding the correction capability of targeted codewords. We propose SANAI, a sensitivity-guided, bit-plane-selective scheme that robustly protects critical model weights against bit flips with zero additional parity-storage overhead. SANAI secures ECC parity through keyed embedding across a two-dimensional weight space. Spread-transform dither modulation binds parity to a secret key, while keyed interleaving disperses concentrated attacks across codewords. We derive a survival law showing that robustness is governed by the correctable fraction t/nt/n, rather than correction strength tt alone, and establish a closed-form bound on the protectable fraction of a model. Implemented as a streaming checker on an 8×88 \times 8 systolic array, SANAI verifies weights on the load path with only 0.41% area overhead and no additional memory. Across ten vision backbones, three quantization schemes, and ten language models ranging from 82M to 13B parameters, SANAI maintains accuracy within approximately one percentage point of the clean baseline at BERs up to 12%, twice the maximum BER supported by prior embedded-ECC approaches. It also survives fine-tuning bit-exactly, neutralizes progressive and targeted bit-flip attacks, and exactly corrects AttentionBreaker and SilentStriker attacks.

1 INTRODUCTION

Deep networks increasingly run on energy-constrained edge accelerators (Jouppi et al., 2017; Rahaman et al., 2025), where weights quantized to eight bits or fewer sit in dense memory. Reduced-voltage operation buys efficiency and pays in bit errors (Chandramoorthy et al., 2019; Koppula et al., 2019; Zhang et al., 2018; Stutz et al., 2021); aging and radiation add more (Reagen et al., 2018; Baumann, 2005), memory errors are ordinary in deployed fleets (Schroeder et al., 2011), and RowHammer lets an adversary produce them on purpose (Kim et al., 2014; Yao et al., 2020). Because a quantized weight packs its value into few bits, one high-order flip in a sensitive layer can collapse the whole model (Hong et al., 2019; Rakin et al., 2019), and such fault-injection attacks are now a central threat to deployed AI systems (Rahaman et al., 2024; 2026b), alongside tampering inside the ML infrastructure that loads and serves the model (Rahaman et al., 2026c).

Uniform ECC guards every stored bit at a standing storage and energy price, although most bits barely move the loss. Embedded schemes such as E3-CODE (Kamineni et al., 2026) fold check

Figure

Figure 1: SANAI overview. Bit errors in weight memory flip high-order bits and the unprotected model misclassifies (top). SANAI probes layer sensitivity (bars), BCH-encodes the top KK bit planes of the sensitive few, assigns weights to codewords by a keyed permutation, and hides the parity with key-seeded STDM in the low-order bits of robust carrier layers at zero added memory (bottom). Inset: the same attack flips overload one codeword under adjacent grouping but stay within tt under keyed interleaving. The parity survives fine-tuning and is unreadable without the key.

bits into the weights themselves, but apply one policy to every layer and bit plane, leave the parity readable by anyone who holds the weights, and stop at a six percent BER. We instead concentrate the budget on the few fragile layers and damaging bits, hide the parity at zero added memory in bits the robust layers do not need, bind it to a key, and carry resilience well past six percent.

SANAI (Sensitivity-Aware Neural-network protection using Adaptive cross-layer STDM embedding, Figure 1) identifies sensitive layers by direct fault injection, protects only their most significant bit planes with a BCH code, and embeds the parity into low-order bits of robust carrier layers using spread-transform dither modulation (STDM) seeded by a secret key. At read time the key regenerates the projection and BCH decoding repairs the high-order bits; a keyed permutation decides which weights share a codeword, so concentrated flips cannot overload any codeword. Because recovery is a pure read-path operation, the construction admits a streaming hardware checker on the weight bus of a systolic accelerator.

In summary, the paper makes the following key contributions.

  • Sensitivity-guided ECC at zero added memory. Flip damage in a quantized network is doubly concentrated: across layers, the top 1% of weights by attack damage sit in layers holding 24.8% of ResNet-18, and protecting only those layers keeps 95.0% accuracy at 6% BER; within a weight, damage decays geometrically with bit position. SANAI measures layer sensitivity by direct fault injection, replaces the integer program of prior embedded ECC with one O(Llog⁡L)O(L \log L) sort, BCH-encodes only the top KK bit planes of the fragile layers, and moves the parity cross-layer into the low-order bits of robust carrier layers. It needs no retraining, no training data, and no extra storage.

  • Secure ECC: parity bound to a key and codewords hidden by a key. Key-seeded spread-transform dither modulation makes the hidden parity both the error-correcting carrier and an access control (Proposition 2): with a wrong key, ResNet-18 on CIFAR-10 falls to 44.6% at 3% BER and to chance by 8%, and an ImageNet model is unrecoverable from the first error level. Keyed codeword interleaving disperses concentrated attacks with a balls-into-bins guarantee (Theorem 1): under the same 500 progressive-bit-search flips, uncorrectable codewords drop from 9 to 49 under adjacent grouping to zero on five of six settings, and the largest fault count per codeword drops to 2 or 3, inside t=4t = 4.

  • A survival law and a protection ceiling. Robustness is governed by the correctable fraction t/nt/n rather than by tt (Proposition 1), which turns code selection into a design rule (Remark 1), and a closed-form supply and demand bound caps the protectable fraction of a model at ρ∗≈48%\rho^* \approx 48\% at zero added memory (Eq. 6).

  • Broad evaluation under random and adversarial faults. Across ten vision backbones, three quantizers, and ten language models from 82M to 13B parameters, SANAI stays within about one point of clean accuracy up to 12% BER, twice the range of prior embedded ECC. Under the burst protocol of prior work it retains 0.97 of its clean accuracy at 6% BER against 0.94

for the strongest baseline, and its critical BER on ResNet-50/ImageNet is 4× that baseline and 300,000× the unprotected model. A 500-flip progressive bit search that leaves ResNet-18 on CIFAR-10 at 10.1% is corrected to 94.9%; targeted T-BFA success drops from 93 to 98% to 0 to 8%; AttentionBreaker, including an adaptive variant flipping 1.17×1061.17 \times 10^{6} bits on an 8B model, is corrected to the exact clean perplexity and MMLU; a code-aware attacker needs 23×23\times more errors to match the undefended damage; and SilentStriker on Llama-3-8B-Instruct (MMLU 70.0 to 37.0%) is detected and restored to 70.0%. The parity survives fine-tuning bit-exactly at realistic learning rates.

  • A load-path hardware checker. The STDM embedding reduces exactly to a keystream-whitened least-significant-bit write (Proposition 3). Synthesized on an 8×88 \times 8 systolic array in 45 nm, the checker detects every single-bit flip including the sign bit at 0.41% area, 0.63% dynamic power, zero stall cycles, and zero added memory, and closes at 1.27 ns. Against a measured conventional checker it needs no parity array (1.22 MB for ResNet-18) and is 2.6×2.6 \times faster than the correcting variant.

Section 2 reviews fault tolerance, embedded ECC, bit-flip attacks, and data hiding. Section 3 presents SANAI: the fault model, sensitivity-guided selection, bit-plane BCH encoding and the survival law, key-seeded STDM parity hiding, keyed interleaving, and the zero-memory ceiling. Section 4 gives the models, quantizers, fault models, and operating points. Section 5 reports random bit errors on vision models (Section 5.1), the comparison with prior embedded ECC and the key-gated access control (Section 5.2), progressive and targeted attacks (Section 5.3), language models under random errors, AttentionBreaker, and SilentStriker (Section 5.4), and fine-tuning and ablations (Section 5.5). Section 6 presents the hardware checker, Section 7 discusses scope and limitations, and Section 8 concludes. The appendices give the master tables behind every reported number (Appendix A), the algorithm and embedding details (Appendix B), proofs (Appendix C), the qualitative comparison (Appendix D), experimental details (Appendix E), ONNX portability (Appendix F), storage accounting (Appendix G), extended vision, attack, and language-model results (Appendices H to J), fine-tuning (Appendix K), ablations (Appendix L), and hardware details (Appendix M), each referenced from the main text where it is summarized.

References (96)

  • Turning your weakness into a strength: Watermarking deep neural networks by backdooring
  • Open neural network exchange
  • A low-latency block cipher for pervasive computing applications
  • On a class of error correcting binary group codes
  • Zero-overhead protection for CNN weights
  • Resilient low voltage accelerators for high energy efficiency
  • Quantization index modulation: A class of provably good methods for digital watermarking and information embedding
  • Eyeriss: A spatial architecture for energy-efficient dataflow for convolutional neural networks
  • Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challenge
  • DeepSigns: An end-to-end watermarking framework for ownership protection of deep neural networks
  • AttentionBreaker: Adaptive evolutionary optimization for unmasking vulnerabilities in LLMs through bit-flip attacks (opens arXiv in a new tab)
  • ImageNet: A large-scale hierarchical image database
  • LLM.int8(): 8-bit matrix multiplication for transformers at scale
  • An image is worth 16x16 words: Transformers for image recognition at scale
  • The Llama 3 Herd of Models
  • Learned step size quantization
  • EIE: Efficient inference engine on compressed deep neural network
  • Deep residual learning for image recognition
  • Defending and harnessing the bit-flip based adversarial weight attack
  • Measuring massive multitask language understanding
  • Terminal brain damage: Exposing the graceless degradation in deep neural networks under hardware fault attacks
  • Quantization and training of neural networks for efficient integer-arithmetic-only inference
  • HASHTAG: Hash signatures for online detection of fault-injection attacks on deep neural networks
  • E3-CODE: Embedded and efficient error-correcting code for error-resilient neural networks
  • Flipping bits in memory without accessing them: An experimental study of DRAM disturbance errors
  • EDEN: Enabling energy-efficient, high-performance deep neural network inference using approximate DRAM. In Proceedings of the 52nd Annual IEEE/ACM International Symposium on Microarchitecture (MICRO), pp. 166–181, 2019
  • Value-aware parity insertion ECC for fault-tolerant deep neural network
  • RADAR: Run-time adversarial weight attack detection and accuracy recovery
  • TruthfulQA: Measuring how models mimic human falsehoods
  • NeuroPots: Realtime proactive defense against bit-flip attacks in neural networks
  • Swin transformer: Hierarchical vision transformer using shifted windows
  • Improved spread spectrum: A new modulation technique for robust watermarking
  • Pointer sentinel mixture models
  • Robustness of neural networks against storage media errors (opens arXiv in a new tab)
  • Balls into bins
  • Language models are unsupervised multitask learners
  • Designing network design spaces
  • Secure AI systems: Emerging threats and defense mechanisms
  • Secure and storage-efficient deep learning models for edge AI using automatic weight generation (opens arXiv in a new tab)
  • BARE-AI: Bit-Flip Attack Resilience in AI Hardware through Built-in Performance Monitors
  • Fortifying AI systems: Emerging threats and security countermeasures
  • (A)iSpy: Parasitic trojans for machine learning infrastructure (opens arXiv in a new tab)
  • Bit-flip attack: Crushing neural network with progressive bit search
  • TBT: Targeted neural network attack with bit trojan
  • T-BFA: Targeted bit-flip adversarial weight attack
  • Ares: A framework for quantifying the resilience of deep neural networks
  • MobileNetV2: Inverted residuals and linear bottlenecks
  • DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter
  • DRAM errors in the wild: A large-scale field study
  • Very deep convolutional networks for large-scale image recognition
  • Optical fault induction attacks
  • Bit error robustness for energy-efficient DNN accelerators
  • EfficientNet: Rethinking model scaling for convolutional neural networks
  • Llama 2: Open Foundation and Fine-Tuned Chat Models
  • MaxViT: Multi-axis vision transformer
  • Embedding watermarks into deep neural networks
  • Toward stealthy bit-flip attacks on large language models
  • Qwen2 Technical Report
  • Qwen2.5 Technical Report
  • DeepHammer: Depleting the intelligence of deep neural networks through targeted chain of bit flips
  • Wide residual networks
  • HellaSwag: Can a machine really finish your sentence? In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics (ACL), pp. 4791–4800, 2019
  • ThUnderVolt: Enabling aggressive voltage underscaling and timing error resilience for energy efficient deep learning accelerators
  • Each row is one run with its full configuration, so numbers for the same model that differ across main-text tables can be traced to the knob that differs
  • Rows V1.24 to V1.33 are the ablations of Section 5.5
  • Protected (unprotected) top-1 (%)
  • ><tr><td colspan=
  • Top-1 (%); unprotected in parentheses where measured
  • Setting $L_s = 1$ recovers plain QIM capacity of one bit per carrier weight while keeping key dependence; raising $L_s$ averages $L_s$ independent low-bit perturbations, trading capacity for robustness of the hidden parity
  • (%)</td><td>Prot
  • Defeating a codeword therefore requires a second error on some weight, that is a second flipped plane
  • Three patterns stand out
  • PTQ uses per-output-channel scales for convolutions and per-tensor scales for linear layers
  • Rank: grad = gradient-weighted magnitude, mag = weight magnitude; Intl.: adj = adjacent codewords, key = keyed interleaving; “In” = fraction of flipped bits inside the protected set
  • Code-aware rows are two-plane attacks that place 13 errors per targeted codeword and list WikiText-2 perplexity after SANAI at each error budget; blind = interleaved layout unknown to the attacker
  • MMLU for the attack experiments uses 500 questions from 20 subjects and WikiText-2 perplexity 20k test tokens
  • For the LLM random-BER experiments
  • parent BCH(127, 50, 12), 48+88 bits</td><td>3 (4 depthwise, ImageNet)</td><td>16 (> t)</td><td>9.4%</td><td>20% (40% ImageNet)</td><td>optional</td><td>Sec
  • Figure 5 reports the improvement in critical BER relative to the unprotected model on ResNet-50/ImageNet
  • Top: all 29 codewords that exceed $t$ under adjacent grouping, ranked by fault count and labelled by layer and codeword index; the worst, conv1 #18, takes 27 faults, and the failures sit in the early convolutions where PBS concentrates
  • every protected model stays well above the 25% chance line through 6%, while the unprotected models fall onto it at the first nonzero BER; the 6% points of the 7B and 8B are conservative for the overflow reason given in the table caption
  • >Flips</th><th colspan=
  • On Llama-3-8B-Instruct the attack concentrates on layers.1.mlp.down_proj; at 10% and 20% coverage that layer sits just outside the selected set and the recovered MMLU stays at the attacked 27.0, at 30% it enters and recovery is exact (71.0; rows L2.23 to L2.25)
  • AttentionBreaker causes repeated-token corruption, while SilentStriker preserves fluency but alters the response
  • Bit-exact at realistic rates on both architectures
  • ><tr><td>Model</td><td>LR</td><td>Parity BER</td><td>Acc.</td><td>Model</td><td>LR</td><td>Parity BER</td><td>Acc.</td></tr><tr><td rowspan=
  • At 12% BER, interleaved parity keeps protected accuracy at 89.3% against 78.8% with sequential parity placement, while the unprotected model is at 10.8%; at 6% both placements hold near 94%
  • Interleaving the parity keeps it correctable
  • At $L_s = 1$ STDM matches QIM capacity while adding key security; raising $L_s$ spreads each bit over more carriers, improving robustness of the hidden parity at reduced capacity subject to Eq
  • Each processing element holds a partial sum in place while INT8 weights are broadcast down columns and activations propagate east; convolutions are lowered to matrix multiplies via im2col
  • We target sparse bit flips of the kind produced by RowHammer, progressive bit search, and laser fault injection (Kim et al., 2014; Rakin et al., 2019; Skorobogatov & Anderson, 2003)
  • Stealth is not a requirement: an adversary who knows where the parity lives still cannot forge it without the seed
  • We evaluated an in-hardware correcting variant and rejected it for two measured reasons
  • Table 3 gives the complete measurement
  • Design B's sign-bit blind spot is structural to the power-of-two lattice; Design A does not share it, which is the principal reason it is the primary design
  • unprotected baseline versus conventional per-block ECC (14 parity bits per 16 INT8 weights in a separate array) versus SANAI (parity inside the weights), for eleven models