Many deployed vision services wrap a public pretrained backbone (DINOv2, OpenCLIP, DeiT-III) behind an interface that returns only scores or labels. Attackers in this setting have two cheap options. They can send many slightly perturbed queries and read off the outputs, which is a query-based black-box attack. Or they can download the same public backbone, craft perturbations on it offline, and submit them once, which is a transfer attack. Adversarially retraining a billion-parameter backbone against both is 10–30× more expensive than ordinary training, and it costs clean accuracy. The cheap defenses that exist each cover only half the threat. Injecting random input noise breaks query attacks but not transfer attacks, and it lowers clean accuracy. Input filters handle transfer attacks but cost 5–8 points of clean accuracy.
We propose a defender who keeps the backbone frozen and trains a small library of K secret "robustness tokens." These are learned vectors appended to the transformer's input sequence, and each set takes a few hundred optimization steps to train. Three properties are trained in jointly. Every token set gives the same top-1 answer as the undefended model on clean images. Every set maps perturbations crafted on the public backbone back to clean representations. Different sets place their local decision boundaries in deliberately different orientations. At inference, each query is routed through a randomly drawn set. A benign user sees the same label every time. An attacker probing near the decision boundary gets inconsistent answers, and a perturbation crafted on the public backbone meets a correction it cannot see.
Core Claim
In a black-box deployment, the weakness that limits parameter-efficient robustness becomes an asset. Robustness tokens are secure only if their values stay secret, and black-box access keeps them secret by default. Secrecy plus randomization over gradient-diverse token sets should defend against score-based, decision-based and transfer attacks at once, at a clean-accuracy cost near zero and a training cost of minutes per token set.
The claim is falsified under three conditions. The first is if argmax-preserving output noise, or a single secret token set, matches the defense. The second is if an attacker who averages over repeated queries recovers the undefended attack success rate at a modest query multiplier. The third is if enforcing clean agreement across sets forces their boundaries to coincide, so that diversity collapses.
Position Relative to Prior Work
The method is built on Robustness Tokens. That work freezes a vision transformer and trains about 10 tokens over roughly 200 steps with two losses. One is an invariance loss on clean images; the other is a correction loss mapping adversarial features back to clean ones. On DINOv2-Giant this recovers white-box accuracy from 0.3% to 63.1%, while clean accuracy moves only from 85.6% to 85.2%. Its security rests on keeping the tokens private, and it was never evaluated against query or transfer attacks. We keep its losses and add three things: multiple sets, a diversity term between sets, and per-query randomization. We evaluate in the black-box regime where its secrecy assumption actually holds.
Two papers motivate the design and also set the bar to beat. Random Noise Defense adds Gaussian noise to each query. It shows that zeroth-order attack progress depends on the ratio of defender noise to attacker probe size, and it uses Gaussian fine-tuning to limit clean loss. Even so, ResNet-50 ImageNet clean accuracy falls from 74.9% to 71.15%, and the authors concede no protection against transfer attacks. Our randomization acts on the model's function rather than its input, and it is trained to preserve top-1 on clean data, so the clean penalty should largely disappear. Dynamic Attention similarly makes language-model attention a moving target at inference time. That supports the general bet that stochastic inference can beat rigid invariance, but it gives no vision evidence and no guarantee of clean agreement.
DBMA defends black-box models against transfer attacks with wavelet filtering and a learned regenerator. It raises CIFAR-10 AutoAttack accuracy by 38.98% but pays 5–8% in clean accuracy. We instead correct in feature space, with no reconstruction artifacts.
Three papers constrain the design. Stateful defenses prove an attacker's dilemma: low-variance queries get caught, while high-variance queries give noisy gradient estimates. They also prove that detection rate and false-positive rate trade off for buffer-based detectors. We borrow the dilemma's logic but put the variance on the defender's side, so no benign user is ever rejected. BlackboxBench finds that transferability is highest between models sharing a training objective. That warns us that an attacker who trains their own tokens on the public backbone may transfer well to ours, so this is a mandatory adaptive attack. The same benchmark finds that vision transformers are already harder to query-attack than ResNets, so every comparison must use the same backbone. PART shows that uniform invariance costs clean accuracy and recovers 1.2–3.18 points by reweighting the perturbation budget across pixels. However, it doubles adversarial training time, from 1 to 2 A100-hours on CIFAR-10. It serves as our reference point for what full retraining buys.
Penalizing the alignment of input gradients across ensemble members is a known idea in ensemble defenses generally, though no such paper appears in our file. What is new here is applying it in token space on a frozen shared backbone, under a hard constraint that clean top-1 predictions agree across sets.
Research Program
Let $g(x;t)$ be the frozen backbone's feature for image $x$ when token set $t$ is appended, and let $g(x)$ be the feature without tokens. Let $h$ be the defender's frozen linear head, and $\ell_k(x)$ the cross-entropy of $h(g(x;t_k))$ against the undefended model's predicted label. Each set $t_k$, for $k = 1, \dots, K$, is trained with
$$\mathcal{L}_k = \|g(x;t_k)-g(x)\|^2 + \|g(x+\delta;t_k)-g(x)\|^2 + \lambda \sum_{j\neq k} \cos^2\!\big(\nabla_x \ell_k(x'),\, \nabla_x \ell_j(x')\big).$$
The first two terms are the invariance and correction losses from the robustness-tokens paper. Here $\delta$ is a perturbation crafted on the public backbone without tokens. It is drawn from a pool that mixes PGD with the flat-minimum attack RAP and the SIA transfer attack, so the correction targets exactly the offline route an attacker would use. The third term, weighted by $\lambda$, penalizes alignment of input gradients between sets.
The gradients are evaluated at $x'$, a point pushed partway toward the decision boundary by a few PGD steps on the undefended model. This placement is the key design choice. Benign users live mostly far from the boundary, where the first term forces all sets to agree. Decision-based attacks such as CISA and boundary-walking methods spend their queries near the boundary, where sets are trained to disagree. Sets are trained sequentially, each against the already-frozen earlier sets. The double backpropagation in the third term runs on small batches, and we report its true cost honestly.
The working hypothesis about mechanism is simple. When the oracle switches between functions whose local boundaries are oriented differently, finite-difference and binary-search estimates absorb a disagreement term. That term does not shrink with the attacker's probe size. This is the function-space analogue of the noise-to-probe ratio in the random noise defense. We will measure the disagreement directly, as the label flip rate across sets at points along attack trajectories, and correlate it with attack failure.
We will also check whether the agreement and diversity objectives fight each other. If enforcing clean agreement shrinks gradient diversity toward zero as $\lambda$ falls, the method degenerates into a single token set. The $\lambda$ sweep will reveal this.
Baselines
The first baseline is the do-nothing reference: the same frozen backbone and linear head with no defense. All attack success rates and clean accuracies are reported relative to it on that same backbone, because architecture alone shifts query resistance substantially according to BlackboxBench.
The second is a naive defense that randomizes only the returned confidence scores while keeping the top-1 label fixed. It costs zero clean accuracy and directly attacks score-based finite differences. Beating it requires a clear win on decision-based and transfer attacks, where it should do nothing.
The third and strongest query-side competitor is the Random Noise Defense with Gaussian fine-tuning, re-implemented on the same vision transformer backbone. Following its recipe, fine-tuning is limited to the token or head parameters so that the training budget matches ours in GPU-hours. Its reported reference numbers are 71.15% versus 74.9% ImageNet clean accuracy on ResNet-50 and 40–80% attack failure rates. There is no reported result on Lacuna for it on vision transformers. We sweep its noise level to trace a full curve of clean accuracy against attack failure. Beating it means a higher attack failure rate at matched clean accuracy within 0.5 points, across MCG, Square, NES and SimBA at budgets of 1k and 10k queries.
The fourth is a single secret robustness-token set from Robustness Tokens, trained on the same perturbation pool for the same total steps as our K sets combined. Its reported white-box numbers are 63.1% robust and 85.2% clean on DINOv2-Giant; there is no reported black-box result on Lacuna for it. This baseline isolates whether randomization adds anything beyond secrecy.
The fifth is K independently seeded token sets with $\lambda = 0$. This ablation isolates the diversity term, since random seeds alone may already produce enough disagreement.
The sixth, for transfer attacks, is DBMA-style wavelet sanitization in front of the frozen model, with $k = 16$ as recommended. Its reported reference is a +38.98% AutoAttack gain on CIFAR-10 at a 5–8% clean cost; there is no reported ImageNet result on Lacuna. As an upper reference for cost, we include PART-style adversarial fine-tuning of the last blocks, and report it in GPU-hours rather than as a competitor on cost.
All methods share the data split, backbone and head. Every method receives the same hyperparameter search budget, tuned only on a held-out validation split.
Why not just…?
Why not just add Gaussian noise to queries, as the random noise defense does? This is the most serious threat on score-based attacks, and we may lose there at high noise. Its clean penalty grows with noise level, though: 74.9% falls to 71.15% on ImageNet. Its authors also state it does nothing against transfer attacks. The matched-clean-accuracy curve on query attacks, together with the SIA and RAP transfer results, settles this. If the noise defense dominates both curves on query attacks, the query-side half of our claim fails, and the contribution narrows to cheap transfer defense.
Why not just randomize the output scores while keeping the label? For score-based attacks this may be as good as anything, and it is free. We therefore expect no advantage over it on MCG or Square and will say so. It cannot affect hard-label attacks like CISA, nor single-shot transfer attacks. The CISA and transfer columns decide whether tokens earn their cost.
Why not just use one secret token set, since black-box access already hides it? Against offline transfer attacks, a single set may indeed capture most of the benefit. Against query attacks, however, a fixed secret set is simply a new deterministic function the attacker can probe. The comparison between one set and K diverse sets on decision-based attacks is the direct test.
Why not just rely on a stateful query detector? The stateful-defense analysis proves that its detection rate is bounded by false rejections of benign users. Such a detector also offers no protection against a single transfer query. We report its false-rejection cost but treat it as complementary rather than competing.
Proposed Experiments
The main testbed is ImageNet-1k with DINOv2 (ViT-L and Giant), DeiT-III and OpenCLIP backbones under frozen linear heads, matching the robustness-tokens setting. ADE20K segmentation measured in mIoU serves as a secondary check that clean agreement survives dense prediction. Attacks come from BlackboxBench's leaders: MCG for score-based, CISA for decision-based, SIA for untargeted transfer and the Bayesian Attack for targeted transfer. We add Square, NES and SimBA from Simple Black-box Adversarial Attacks, and RAP.
Metrics are clean top-1 accuracy, the cross-set label flip rate on clean images, and attack success rate and median queries at fixed budgets. We also report transfer success rate, training GPU-hours, and per-query latency. Our latency is a single forward pass with about 10 extra tokens, compared against multi-view test-time defenses such as ATAC.
The decisive checks are adaptive attacks, and each is stated in advance as a way the proposal could fail. The first is an averaging attacker who repeats each query r times to estimate the expected function. We report the success rate as a function of r. The defense counts as meaningful only if restoring undefended success requires at least a several-fold query multiplier, which also makes the attacker more visible to stateful monitoring. The second is a surrogate-token attacker who trains their own token library on the public backbone and transfers through it. This tests the BlackboxBench warning that shared objectives transfer well. The third is a full leak of all K sets, reported as a white-box ensemble-expectation attack to show how the defense degrades when secrecy fails. This should fall back toward the single-set white-box number rather than to zero.
Success means four things together. Clean accuracy must stay within 0.5 points of undefended. Transfer success must fall substantially below both the undefended model and wavelet sanitization. CISA success must fall below the single-set and $\lambda = 0$ ablations. And the averaging attacker must need a large query multiplier. All of this must come at a training cost under one GPU-hour per backbone.
References
- Robustness Tokens: Towards Adversarial Robustness of Transformers
- Random Noise Defense Against Query-Based Black-Box Attacks
- Improving the Robustness of Transformer-based Large Language Models with Dynamic Attention
- Data-free Defense of Black Box Models Against Adversarial Attacks
- Theoretically Principled Trade-off for Stateful Defenses against Query-Based Black-Box Attacks
- BlackboxBench: A Comprehensive Benchmark of Black-box Adversarial Attacks
- Improving Accuracy-robustness Trade-off via Pixel Reweighted Adversarial Training
- Boosting the Transferability of Adversarial Attacks with Reverse Adversarial Perturbation
- Simple Black-box Adversarial Attacks
- ATAC: Augmentation-Based Test-Time Adversarial Correction for CLIP