Skip to content

Adversarial examples: threat models, attacks and what a failed attack proves

A small, deliberate change to an input can flip a model's prediction. How to state a threat model, how projected-gradient attacks search inside it, and why not finding an attack is not evidence of robustness.

Advanced ~12 min8 steps

What runs in CodeSplash

You will be able to

  • State a threat model: the allowed changes, their size and units, and what the attacker knows
  • Explain one projected-gradient step and the projection back into the allowed set
  • Read a robust-accuracy-versus-radius curve and judge whether the attack was strong enough
  • Say why gradient masking and weak attacks inflate apparent robustness

Read first

01

Small changes, big effects

Read

An adversarial example is an input changed on purpose, by an amount too small to matter to a person, so that the model's prediction changes. Images with invisible pixel noise are the famous case, but tabular models have them too: nudge a few measurements within their noise and a loan, a diagnosis or a fraud flag flips.

Robustness is never "robust, full stop". It is robust to a stated set of changes. Writing that set down is the first step of every lesson in this unit.

02

The threat model

Read

A threat modelThreat modelWhat an attacker may change (norm, radius, units, legal ranges) and what they know; robustness claims only hold inside it. says:

  • which changes are allowed: a ball Δ={δ:∥δ∥∞≤ϵ}\Delta=\{\delta:\lVert\delta\rVert_\infty\le\epsilon\} (each feature moves at most ϵ\epsilon) or an L2 ball, plus legal ranges;
  • in what units: ϵ\epsilon on standardized features is not ϵ\epsilon in raw dollars;
  • what the attacker knows: the gradients (white-box) or only the outputs (black-box);
  • that the label is preserved: inside the ball, the true answer must not change. A large ϵ\epsilon can make "adversarial" examples that are really different cases.

A pixel ball doesn't cover rotations, lighting or a sticker; a feature ball doesn't cover a changed process.

03

Projected gradient: climb, then project

Read

To find a bad change, climb the loss. A projected-gradient attackProjected-gradient attack (PGD)An attack that takes signed gradient steps to raise the loss and projects the input back into the allowed ball after each step. takes signed gradient steps and pushes the input back into the allowed set after each one:

xt+1=Π[0,1]d ∩ B∞(x,ϵ)[xt+η sign⁡∇xℓ(f(xt),y)].x^{t+1}=\Pi_{[0,1]^d\,\cap\,B_\infty(x,\epsilon)}\big[x^t+\eta\,\operatorname{sign}\nabla_{x}\ell(f(x^t),y)\big].

One step with η=ϵ\eta=\epsilon is FGSM. In the reference's example on a fixed logistic classifier, eight projected steps within ϵ=0.1\epsilon=0.1 raise the loss from 0.576 to 0.718, and the projection keeps every coordinate within ϵ\epsilon of the original.

Attack a curved 2-D classifier inside an ε-ball, then weaken the attack and watch the model look robust.

DExplorable · Attacks inside an ε-ball: FGSM and PGD

How far must an input move to flip a model's answer, and does one failed attack prove the model is robust?

At the same radius, which attack leaves the model with lower accuracy?

How sure?
0.50

How far the attacker may move each input.

Ball

L∞ lets every feature move up to ε; L2 limits the total distance to ε.

10

Projected gradient steps; FGSM is a single full step.

0.25

Each PGD step moves this fraction of ε, then projects back into the ball.

0.40

The point whose attack path is drawn.

0.75

The point whose attack path is drawn.

ε

The black dot is the demo point, the open circle its FGSM attack, the red line its PGD path ending at the red dot. The dashed shape is the ε-ball the attacker must stay inside. Robust accuracy only falls as fast as the attack is strong.

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

04

No attack found

Predict

Predict first

You run a 5-step PGD attack at your chosen ε and the model's accuracy barely drops. Can you call the model robust at that ε?

Yes, it resisted a real attackNo, the attack may be too weak
Reveal

No. You've shown that this attack failed. A stronger one (more steps, random restarts, a different loss, an independent implementation) may succeed. Failed attacks are evidence about the attack; only a certificate, the topic of lesson 3, is a guarantee.

05

Judging an attack evaluation

Read

Report clean accuracy and robust accuracy (accuracy under attack) over a range of radii, on a locked test set. Then strengthen the attack, more iterations and restarts, until robust accuracy stops falling; if it keeps falling, you hadn't measured robustness yet.

Watch for gradient maskingGradient maskingWhen randomness, rounding or saturated outputs hide useful gradients, so gradient attacks fail although the model is not robust.: randomness, non-differentiable preprocessing or saturated outputs that hide useful gradients. The model looks robust to gradient attacks while gradient-free attacks walk right through. And count attack compute separately from training compute.

06

Where it stands in CodeSplash

Read
IdeaIn CodeSplash
Projected-gradient adversarial training (ROB001)Runs as an option of Deep neural network (torch MLP): Robust training → PGD adversarial training (Experimental)
Attack evaluation (robust accuracy against ε)Explained here: the app has no attack-evaluation curve; run an independent attack in a notebook on the run's code
Simple perturbation checksThe run page's Robustness tab has Behavior tests: change a column and check the prediction moves the expected way
07

Check your understanding

Checkpoint

Check yourself

Two teams both report robustness "at ε = 0.1". Why might the numbers not be comparable?

Show the answer

Answer: a

A threat model is the norm, the radius, the units, the legal ranges and the attacker's knowledge. Write all of them down.

Check yourself

What is the difference between a PGD attack and PGD adversarial training?

Show the answer

Answer: b

An attack is an evaluation (or search) procedure. Adversarial training changes the training objective. The next lesson covers the training side.

Check yourself

A model with a random input-rounding step resists gradient attacks but falls to a gradient-free attack. What's going on?

Show the answer

Answer: b

Evaluate with several attack types, including ones that don't rely on gradients, before claiming robustness.

08

What comes next

Recap

Next: training a model to resist attacks, with PGD adversarial training and TRADES, and what that costs in clean accuracy and compute.

Concepts in this lesson