# Obfuscated Gradients Give a False Sense of Security: Circumventing Defenses to Adversarial Examples

Obfuscated gradients make adversarial defenses look more robust than they are

Anish Athalye, Nicholas Carlini, David Wagner · arXiv · 2018-2-1

- **Problem** Defenses that cause obfuscated gradients appear robust to iterative optimization attacks. Those attacks stall on the masked gradient, so the reported robustness reflects the attack's failure.
- **Method** The authors write an attack for each kind of obfuscated gradient. Non-differentiable steps get a smooth stand-in on the backward pass only.
- **Results** The attacks completely circumvented six of the seven ICLR 2018 defenses that rely on obfuscated gradients, and partially the seventh, under each paper's threat model.

## How obfuscated gradients create false robustness

Iterative optimization attacks have become the usual yardstick for white-box defenses, and several new defenses appear to hold up against them. Those attacks move the input along the gradient of the loss, so they only work when that gradient carries real information about how the output changes. When a defense removes or corrupts that information, the attack stalls, and the reported robustness reflects the attack's failure rather than the model's strength.

The authors name this situation obfuscated gradients and treat it as a special case of gradient masking, the broader condition in which a model offers no useful gradient for building adversarial examples. Earlier cases of gradient masking arose when a model learned to make gradients point the wrong way; in the obfuscated case, the design itself forces the effect.

Gradient masking is already known to be an incomplete defense, so apparent robustness that rests on it is weak evidence.

## Three sources of obfuscated gradients

The first source is shattered gradients, where the gradient is nonexistent or incorrect because the defense uses a non-differentiable operation or suffers numerical instability. A defense can also fail this way while using only differentiable operations, since following its local gradient does not maximize the classification loss globally.

Stochastic gradients come from randomized defenses, where the network itself or the input transformation is random at test time. An attack that estimates the gradient from a single sample of that randomness gets the true gradient wrong.

The third source is vanishing or exploding gradients, which appear when a defense repeats a network evaluation many times and feeds each output into the next. Unrolled, that loop looks like a very deep network, and deep chains of this kind can shrink or blow up the gradient.

Some warning signs help identify masking, though they do not capture every case. A single-step attack that beats an iterative attack suggests the iterative search is stuck in a local minimum, because iterative white-box attacks should be at least as strong. An unbounded attack that fails to reach full success, random search that finds adversarial examples where gradient attacks fail, and a larger distortion bound that does not raise success each point the same way.

## Recovering usable gradients

Consider a classifier f applied after a preprocessor g, where g is designed to return an input close to x. If g is smooth, differentiating through the whole pipeline is usually enough, but some recent preprocessors are neither smooth nor differentiable. Since g(x) is close to x, the attack treats the derivative of g as the derivative of the identity, which equals one.

Concretely, the gradient through the combined model is approximated by evaluating the gradient of f at g(x): \\\[ \\nabla\_x f(g(x)) \\approx \\nabla\_x f(x)\\big\|\_{x=g(x)} \\\] The forward pass still runs through g, so the attack sees the real output, while the backward pass uses the identity in place of g.

For a general non-differentiable layer f\_i, the authors first find a differentiable approximation g that closely matches f\_i. The forward pass uses the true network including f\_i, and only the backward pass substitutes g. The gradients are less accurate, so the attack often needs more gradient descent iterations, but the slightly wrong directions still lead to adversarial examples.

Using the approximation on both the forward and backward passes was either completely ineffective against one defense or much weaker against another, which is why the backward-only substitution matters. The same approach can be applied to a network that is already differentiable, to get a more useful gradient.

For randomized input transformations, the attack instead optimizes the expected classifier output over the distribution of transformations, which is Expectation over Transformation. The gradient of that expectation equals the expectation of the gradient, so the attack can take gradient steps using samples drawn at each iteration.

For a multi-step input optimization inside a defense, the attack makes a change of variables x = h(z), where h is differentiable and g(h(z)) = h(z) for all z. This makes gradients through f(h(z)) computable, which avoids the explosion or vanishing that differentiating through the unrolled loop would cause.

## Which defenses were examined and how

The case study covers the non-certified ICLR 2018 defenses that argue white-box robustness. Two defenses with provable security claims and one that argues only black-box security were left out, while a paper that proposes a detector rather than a defense was included. Of the nine accepted papers, seven rely on obfuscated gradients.

Two of the defenses argue robustness on ImageNet, one argues it on MNIST, and the rest on CIFAR-10, which makes the defenses hard to compare directly. The attacks circumvent six of the seven completely and the seventh partially, under the threat model each paper considers.

On MNIST and CIFAR-10, the attacks run over the full test set and generate untargeted adversarial examples. On ImageNet, they use 1000 randomly selected test images and targeted adversarial examples with randomly chosen targets, and report attack success rate alongside accuracy. The standard models are a five-layer convolutional network at 99.3% accuracy on MNIST, a wide ResNet at 95% on CIFAR-10, and InceptionV3 at 78.0% top-1 and 93.9% top-5 on ImageNet.

Distortion is measured in the normalized \[0, 1\] space, where 0.031 in the ℓ∞ metric corresponds to 8/256. Each defense is evaluated only under the threat model it claims for itself.

## Thermometer encoding and input transformations

Thermometer encoding was designed to break the locally linear behavior that Goodfellow et al. blamed for adversarial examples. Each pixel value is mapped to a vector of threshold bits, which makes the input discrete and blocks plain gradient descent. On CIFAR-10, thermometer encoding alone gave 50% accuracy within 0.031 under ℓ∞ distortion.

Adding adversarial training with seven steps of LS-PGA raised robustness to 80%.

A black-box evaluation hints at shattering: adversarial examples from a standard adversarially trained model reduced thermometer-model accuracy to 67%, below the 80% white-box figure. The attack replaces the thermometer function on the backward pass with a clipped, differentiable version, since the thermometer output is the floor of that clipped value.

Against the thermometer-encoded adversarially trained model, the 80% accuracy at 0.031 is reproduced with LS-PGA, but the stronger attack reduces accuracy to 30%. On a thermometer model trained without adversarial training, the attack reaches 1% accuracy at ϵ = 0.015 and 0% at ϵ = 0.031. The authors read these results as showing that thermometer encoding provides little measurable benefit over a standard model.

Guo et al. proposed five input transformations: cropping and rescaling, bit-depth reduction, JPEG compression, pixel dropping with total variance minimization, and image quilting. With a ResNet-50 classifier under a normalized ℓ2 dissimilarity of 0.01, the strongest defenses achieved over 60% top-1 accuracy, and the attack authors reproduced these numbers with InceptionV3.

Cropping and rescaling are handled with EOT, bit-depth reduction and JPEG with BPDA using the identity, and total variance minimization and image quilting with both EOT and BPDA. The attack reaches 100% targeted attack success, and accuracy drops to 0% for the strongest defense at the smallest budget Guo et al. considered, a root-mean-square perturbation of 0.05.

## Stochastic activation pruning and randomized input

SAP drops each layer's neurons with probability tied to their absolute value and scales the retained values up, so the network is random at test time. The original evaluation took a single gradient step, which can work on deterministic networks but misleads when randomness is present. Here the gradient is averaged over k = 10 randomized forward passes at each iteration, which the authors found gives useful gradients.

A numerical instability was also resolved, since the backward pass exploded from division by numbers very close to zero. The summary table lists SAP on CIFAR-10 with an ℓ∞ distance of 0.031.

With these changes, SAP model accuracy falls to 9% at ϵ = .015 and to 0% at ϵ = 0.031. Under a stricter criterion, where an example counts as an attack success only if it is misclassified 10 times out of 10, accuracy stays below 10% at ϵ = 0.031.

Xie et al. add a randomization layer that rescales a 299×299 input to r×r, with r in \[299, 331), and zero-pads the result to 331×331 before classification. The original paper's strongest attack reduced InceptionV3 accuracy to 32.8% top-1 over originally correct images, and the authors dismissed stronger attacks as computationally impossible.

The ensemble attack over fixed randomization patterns overfits to that ensemble, so the attack here applies EOT over the transformation distribution. Even when success requires misclassification 10 times out of 10, the attack reaches 100% targeted success and lowers accuracy from 32.8% to 0.0% at ϵ = 0.031 under ℓ∞.

## PixelDefend and Defense-GAN

PixelDefend uses a PixelCNN to pull a potential adversarial example toward the data manifold, using greedy decoding to find a high-probability image within an ϵ-ball around the input. The original authors judged end-to-end attacks impractical, because differentiating through the unrolled procedure suffers from vanishing gradients and high computation cost.

The attack here approximates the gradients with BPDA, and the implementation uses PixelCNN++ with its mixture of logistics discretized into a 256-way softmax.

Against a naturally trained classifier with 95% accuracy, the end-to-end attack reduces accuracy to 9% at ϵ = 0.031 under ℓ∞. Combining adversarial training with PixelDefend gives no additional robustness over the adversarially trained classifier alone.

Defense-GAN projects inputs onto the range of a GAN generator, and it was evaluated on MNIST because it was not argued secure on CIFAR-10. The authors show that adversarial examples can lie exactly on the generator's manifold, so a perfect projector would leave them unchanged. The real projection is imperfect and does not keep points on the manifold fixed, so a second attack uses BPDA against the actual implementation and succeeds at a 45% rate.

## Adversarial training, cascade training and LID

The authors do not believe the adversarial training of Madry et al. causes obfuscated gradients, because their optimization attacks succeed with some probability and the defense's evaluation covers the characteristic tests. They note that adversarial training is difficult at ImageNet scale, and that training only on ℓ∞ examples gives limited robustness under other distortion metrics.

Cascade adversarial training trains a first model, generates iterative adversarial examples on it, adds them to the training set, and trains a second model on the augmented data, using single-step methods for efficiency. The defense reaches 16% accuracy at ϵ = .015, compared with over 70% at the same budget for the adversarial training of Madry et al.

LID, used by Ma et al. to detect adversarial examples, is not presented as a defense, but its detection was evaluated here. High-confidence adversarial examples generated on the original classifier, without knowledge of the detector, are not detected by LID. The full analysis is given in an appendix.

## Evaluation practices the study recommends

A threat model should say which aspects are revealed to the adversary and which are held secret: architecture and weights, training algorithm and data, test-time randomness, and query access. The authors argue that a compelling threat model should at least grant the architecture, the training algorithm, and query access. Artificially limiting the attacker's computation is not meaningful, and a defense that takes much longer to attack has not become more robust in the process.

Claims are most useful when they are specific and testable, which requires a fully specified defense with all hyperparameters given. Releasing source code and a pre-trained model is a useful way to make claims testable, and four of the defenses studied released complete source code. An adaptive attack is built after the defense is fully specified, and one approach is to report the mean over the best attack per image rather than the best mean.

If a defense is modified after evaluation, a final adaptive attack that knows the new defense plays the role of a final test-set evaluation.

## Limits of the evidence

The attacks were checked on nine accepted ICLR 2018 defenses, with two provable-security papers and one black-box paper excluded, so the seven-of-nine count applies to that venue and year. Results across datasets are hard to compare, because two defenses target ImageNet and one targets MNIST.

Several attacks rely on approximations: BPDA gradients are less accurate, so attacks need more iterations, and the BPDA attack on Defense-GAN succeeds at a 45% rate. ImageNet results use targeted attacks on 1000 images, while MNIST and CIFAR-10 results use untargeted attacks over the full test set, so these numbers are not directly comparable.

The authors state concerns about adversarial training at ImageNet scale and under other distortion metrics, without claiming it fails in general. Whether the attacks succeed against defenses outside the ICLR 2018 set, or under threat models beyond each paper's own, was not tested. The evidence shows that these specific defenses can be circumvented; it does not establish that any defense resisting these attacks is secure.

## Paper info

- **Authors**: Anish Athalye, Nicholas Carlini, David Wagner
- **Venue**: arXiv · Preprint
- **First published**: 2018-2-1
- **Added**: 2026-11-12
- **Updated**: 2018-7-31
- **Version**: v4
- **arXiv**: 1802.00420
- **Category**: cs.LG · cs.AI · cs.CR
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1802.00420v4) · [PDF ↗](https://arxiv.org/pdf/1802.00420v4)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Anish Athalye, Nicholas Carlini, David Wagner (2018). Obfuscated Gradients Give a False Sense of Security: Circumventing Defenses to Adversarial Examples. arXiv:1802.00420v4. https://arxiv.org/abs/1802.00420v4

**BibTeX**

```
@misc{athalye2018obfuscated,
  title = {{Obfuscated Gradients Give a False Sense of Security: Circumventing Defenses to Adversarial Examples}},
  author = {Anish Athalye and Nicholas Carlini and David Wagner},
  year = {2018},
  eprint = {1802.00420},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1802.00420v4}
}
```

## Other paper commentary

- [SeqGAN: Sequence Generative Adversarial Nets with Policy Gradient](https://refivu.com/en/papers/29153239-a1df-4102-9df1-abd1ba2a9c96-seqgan-sequence-generative-adversarial-nets-with-policy.md)
- [Tutorial on Variational Autoencoders](https://refivu.com/en/papers/51a9cfc2-6285-4935-b55a-3d6450af8eff-tutorial-on-variational-autoencoders.md)
- [Social GAN: Socially Acceptable Trajectories with Generative Adversarial Networks](https://refivu.com/en/papers/134b8b94-f72a-441a-8ec1-4b871085c3e5-social-gan-socially-acceptable-trajectories-with-generative.md)
- [Unsupervised Anomaly Detection with Generative Adversarial Networks to Guide Marker Discovery](https://refivu.com/en/papers/62959e97-b421-4e00-897e-8709c817c9fb-unsupervised-anomaly-detection-with-generative-adversarial.md)
- [Generative Adversarial Text to Image Synthesis](https://refivu.com/en/papers/e3b168a4-0572-44b9-b18e-ca2f31dfdc4a-generative-adversarial-text-to-image-synthesis.md)
- [Adversarial Autoencoders](https://refivu.com/en/papers/8e20edb4-f017-4781-86f9-478c6059260f-adversarial-autoencoders.md)
- [RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds](https://refivu.com/en/papers/5d37c138-f524-49a6-ba5e-e9ff9f584cdd-randla-net-efficient-semantic-segmentation-of-large-scale.md)
- [Practical recommendations for gradient-based training of deep architectures](https://refivu.com/en/papers/0f41024c-5358-4bc2-be1e-7190db5f4d0c-practical-recommendations-for-gradient-based-training-of.md)
- [Pre-Trained Image Processing Transformer](https://refivu.com/en/papers/8475de2d-12d6-41b5-8348-16c772598a34-pre-trained-image-processing-transformer.md)
- [TinyBERT: Distilling BERT for Natural Language Understanding](https://refivu.com/en/papers/b5b68df2-5d79-42e6-8e82-c8fdbf0e3a3d-tinybert-distilling-bert-for-natural-language-understanding.md)
- [Self-Refine: Iterative Refinement with Self-Feedback](https://refivu.com/en/papers/f8f8d11b-268b-4988-84b8-c616a701e2ba-self-refine-iterative-refinement-with-self-feedback.md)
- [LIO-SAM: Tightly-coupled Lidar Inertial Odometry via Smoothing and Mapping](https://refivu.com/en/papers/8fa3265c-e57e-4469-8761-2a9bfc47279e-lio-sam-tightly-coupled-lidar-inertial-odometry-via.md)

## Terms in this paper

- [ImageNet](https://refivu.com/en/terms/5eadad128667-imagenet)
- [CIFAR-10](https://refivu.com/en/terms/19035a518d0a-cifar-10)
- [MNIST](https://refivu.com/en/terms/28b9bb66d1c6-mnist)
- [gradient descent](https://refivu.com/en/terms/7557852c745c-gradient-descent)
- [Adversarial training](https://refivu.com/en/terms/79bc85d56747-adversarial-training)
- [neural network](https://refivu.com/en/terms/b1555e7d34eb-neural-network)
- [straight-through estimator](https://refivu.com/en/terms/daa90b015f59-straight-through-estimator)
- [attack success rate](https://refivu.com/en/terms/e73dcb3fd6d9-attack-success-rate)
- [Wide ResNet](https://refivu.com/en/terms/3a0321e1fa87-wide-resnet)
- [gradient masking](https://refivu.com/en/terms/ec5153e5264a-gradient-masking)
- [threat model](https://refivu.com/en/terms/3d3e656e8e49-threat-model)
- [PixelDefend](https://refivu.com/en/terms/abbd6a2b00aa-pixeldefend)
- [vanishing/exploding gradients](https://refivu.com/en/terms/97a60be3726a-vanishing-exploding-gradients)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/6d5ee375-978f-4c78-87e2-0c8e55a1127f-obfuscated-gradients-give-a-false-sense-of-security)
