Machine learning libraries let practitioners snap together preprocessing steps and models through one shared interface. In the scikit-learn style, every component exposes fit, transform, or predict, and a Pipeline chains them while passing plain arrays between stages. This convenience has a cost for adversarial robustness. An adversarial example is an input changed by a tiny, deliberately chosen amount so that the model gives the wrong answer. The shared interface hides exactly the facts an attacker or a certifier needs: whether a stage is differentiable, whether it is random, how much it can stretch a small perturbation, and whether it keeps state. As a result, pipelines containing a non-differentiable filter or a random preprocessing step routinely look robust only because standard gradient attacks cannot see through them. The leading benchmark responds by refusing to evaluate such pipelines at all.
We propose adding a small, declarative perturbation contract to each pipeline component. The contract states the component's differentiability (exact, surrogate available, or none), any stochasticity along with a sampling hook, an upper bound on how much it can stretch perturbations under a given norm, and whether it is stateful. From these declarations, a compiler builds two things for any composed pipeline. The first is an adaptive attack: it inserts surrogate gradients where a stage is non-differentiable and averages over randomness where a stage is stochastic. The second is a sound certified radius in raw input space, obtained by chaining the per-stage stretch bounds. The thesis is that a few fields of interface metadata are enough to reproduce, automatically, the hand-built adaptive attacks that experts needed for each defense, and to turn "this pipeline is robust" from an unchecked claim into a checked one.
Core Claim
Given only per-stage perturbation contracts, an automatically compiled attack should reach, on composite defenses, robust accuracy within a few points of the best hand-crafted adaptive attack. It should also match the standard attack suite on ordinary differentiable models. A gradient-free attack that ignores the contracts should do clearly worse on the same budget. Contracts that state how much each stage stretches perturbations (its Lipschitz bound) also give certificates that remain valid after preprocessing. Without them, a certified radius computed in a model's normalized input space can quietly misstate the radius in raw pixel or feature space.
Where This Sits
The interface side supplies the method. API design for machine learning software: experiences from the scikit-learn project fixes the estimator/transformer/predictor split and composition by duck typing (any object with the right method names fits). Domain libraries such as PyOD and causal estimator superclasses (Universal Causal Evaluation Engine: An API for empirically evaluating causal inference models) show that a shared interface enables like-for-like benchmarking. None of them attaches robustness-relevant semantics to the interface, and we extend the transformer protocol to do exactly that.
The closest existing work is the Adversarial Robustness Toolbox v1.0.0 (ART), which wraps models from nine frameworks behind one classifier class so that an attack written once runs everywhere. ART standardizes access to predictions and gradients. It does not record what kind of gradient a wrapped preprocessing step yields, and it leaves gradient-masking diagnosis to the user. RobustBench standardizes the attack itself through AutoAttack, an ensemble of step-size-free gradient attacks plus the gradient-free Square Attack. It only stays sound by banning randomized, non-differentiable, and test-time-optimizing models. We aim to admit those models rather than exclude them.
The adversarial side supplies both motivation and constraints. Obfuscated Gradients Give a False Sense of Security found that 7 of 9 ICLR 2018 defenses masked gradients. It broke them with two repairs: substituting a smooth stand-in for the backward pass of non-differentiable steps, and averaging gradients over a defense's randomness. These repairs were assembled by hand for each defense, and our compiler mechanizes that assembly. Towards Deep Neural Network Architectures Robust to Adversarial Examples showed that stacking a denoising autoencoder before a classifier gives no protection once the attacker optimizes through both. This is a negative result that our contracts should reproduce for free. On certification, Improved deterministic l2 robustness on CIFAR-10 and CIFAR-100 builds networks that provably stretch perturbations by at most a factor of one. A Framework for robustness Certification of Smoothed Classifiers using F-Divergences certifies models that are smoothed by averaging over added noise. Both certify an isolated network, and we supply the composition rule around them.
Research Program
The contract is a small object attached to each transformer. It holds four fields. The first is a differentiability tag, together with an optional surrogate backward function: identity for steps that approximately preserve the input, such as quantization or thermometer encoding, and a learned or declared smooth stand-in otherwise. The second is a stochasticity flag with a sampler, which the compiler uses to set how many random draws to average over. The third is an optional stretch bound $L_k$ under a given norm. The fourth is a statefulness flag, which forbids attacks that silently update the stage during evaluation.
The attack compiler walks the pipeline and builds an end-to-end attack graph. It then runs the AutoAttack gradient components on that graph. For a pipeline of stages with bounds $L_1,\dots,L_m$ feeding a model certified at radius $\rho$ in its own input space, the raw-space certificate is
$$\rho_{\text{raw}} \ge \frac{\rho}{\prod_{k=1}^{m} L_k},$$
which follows from the composition of Lipschitz maps. A stage with no declared bound makes the certificate undefined, and the system reports it as such instead of returning a number.
The compiler also runs the published sanity checks as automatic assertions on every evaluation. Iterative attacks must beat single-step ones. White-box attacks must beat black-box ones. Accuracy must fall to zero as the perturbation budget grows without limit. When an assertion fails, the result is marked "unverified" rather than reported.
A second contribution is honesty about what contracts cannot do. A dishonest or wrong contract, for example a bad surrogate gradient, weakens the attack. We therefore test whether the assertion layer catches deliberately mis-declared contracts.
Baselines
The naive reference is the defense's own reported accuracy: standard PGD (projected gradient descent, the basic iterative attack) run straight through the pipeline using whatever gradients the framework's automatic differentiation returns. This is what ART gives a user who wraps the pipeline without further thought. It is run with the same data, number of attack iterations, and random restarts as our method. Beating it is necessary but uninformative.
The strongest existing attack-side competitor is the per-defense adaptive attack of Athalye et al., reimplemented with their published settings. For thermometer encoding they report that claimed accuracy of 80% dropped to 30%. For stochastic activation pruning they report accuracy reduced to 0%. Our compiled attack counts as matching it if its robust accuracy is within 2 points on each defense, given the same total gradient-evaluation budget, with no per-defense code beyond the contract declaration.
On differentiable, deterministic models, the strongest competitor is AutoAttack as run by RobustBench on its model zoo. RobustBench reports that original papers overestimated robustness "sometimes by more than 10%". Our compiler must not lose to AutoAttack on any zoo model, and agreement within 0.5 points is the bar.
The key ablations isolate the contract metadata. The first, "contracts stripped," treats every stage as a black box and falls back to Square Attack with the same query budget. The other two remove only the surrogate gradients or only the averaging over randomness.
On the certification side, the baseline is the radius reported in the model's own input space for a 1-Lipschitz LipConvnet from Improved deterministic l2 robustness. The file gives only relative gains for that model, such as over 5.81% at $\rho = 108/255$ on CIFAR-10. It has no absolute certified accuracy, so we will report our own reproduced numbers. Here success means the composed certificate stays sound under attack: no input inside $\rho_{\text{raw}}$ is ever found misclassified.
Why not just…?
Why not just run AutoAttack on the whole pipeline, since it already includes the gradient-free Square Attack? This is the most serious threat. If Square Attack alone breaks every composite defense, the contract adds nothing on the attack side. The evidence that it falls short is indirect: Athalye et al. needed white-box repairs to reach their numbers, and RobustBench excludes randomized defenses rather than trusting Square Attack against them. Gradient-free search also degrades with input dimension and with randomness in the model's outputs. The "contracts stripped" ablation settles this directly. If it comes within 2 points of the compiled attack on most defenses, we will narrow the claim to certification and the automatic sanity checks.
Why not just use ART and write the surrogate gradients by hand? This is possible, and it is exactly what experts did. But it must be redone for every pipeline, and the obfuscation paper shows it was usually not done. The measurable question is whether declarative contracts reach expert-level attacks with no per-defense code, which the comparison against the reimplemented Athalye attacks tests. The cost of writing each contract, in lines of code, will be reported next to the cost of the hand-written attack.
Why not just ship the Athalye checklist as a standalone script? The checks need to know which stages are random or non-differentiable in order to choose the right repair. Without that knowledge they can only flag a problem, not fix it. We will report how often the standalone checks flag a pipeline whose robust accuracy the contract compiler then actually lowers, versus pipelines flagged but left unresolved.
Why not just certify the network and ignore preprocessing? Normalization and projection steps can stretch perturbations by more than a factor of one. Dividing CIFAR pixels by per-channel standard deviations is one example. When that happens, a radius certified in the model's input space does not equal the raw-input radius. Our experiments quantify the size of this mismatch rather than assume it.
Proposed Experiments
The attack study uses CIFAR-10 and reimplements composite defenses whose failure modes the cited papers describe. These are thermometer encoding and stochastic activation pruning from Athalye et al., the denoising-autoencoder stack from Gu and Rigazio, ART's spatial smoothing and feature squeezing, the DeepCloak feature mask, and a randomized-smoothing front end. DeepCloak reports adversarial accuracy rising from 29.61% to 39.23% on ResNet against a non-adaptive attack, and our compiled attack should erase that gain. Every method gets the same $L_\infty$ budget of 8/255 and the same gradient-evaluation budget. The primary metric is robust accuracy, with the gap to the best known attack as the headline number.
The sanity study runs the compiler unmodified on RobustBench zoo models across CIFAR-10, CIFAR-100, and ImageNet subsets. It confirms that the compiler matches AutoAttack and does not overestimate attack success on models that are honestly robust.
A transfer study applies contracts to AI-generated-image detector pipelines from RAID. These pipelines include JPEG and resizing preprocessing. RAID reports white-box F1 falling to 0.0 and black-box transfer AUROC dropping from 0.99 to 0.67. We test whether contract-compiled attacks reach the white-box result when the preprocessing is non-differentiable.
The certification study composes LipConvnet with normalization and PCA-style projection on CIFAR-10. It reports the gap between the network-space radius and $\rho_{\text{raw}}$, and searches attacks inside $\rho_{\text{raw}}$ to verify soundness.
The robustness-of-the-tool study gives deliberately wrong contracts to each defense, such as a false determinism flag or a poor surrogate gradient. It measures how often the automatic assertions mark the result "unverified."
The decisive outcome is the combination of three results: the compiled attack matches the hand-crafted attacks, the "contracts stripped" ablation trails it by a clear margin, and mis-declared contracts are caught. If the ablation instead keeps pace, that result alone tells us interface metadata matters only for certification, and the proposal narrows accordingly.
References
- API design for machine learning software: experiences from the scikit-learn project
- PyOD: A Python Toolbox for Scalable Outlier Detection
- Universal Causal Evaluation Engine: An API for empirically evaluating causal inference models
- Adversarial Robustness Toolbox v1.0.0
- RobustBench: a standardized adversarial robustness benchmark
- Obfuscated Gradients Give a False Sense of Security: Circumventing Defenses to Adversarial Examples
- Towards Deep Neural Network Architectures Robust to Adversarial Examples
- Improved deterministic l2 robustness on CIFAR-10 and CIFAR-100
- A Framework for robustness Certification of Smoothed Classifiers using F-Divergences.
- DeepCloak: Masking Deep Neural Network Models for Robustness Against Adversarial Samples
- RAID: A Dataset for Testing the Adversarial Robustness of AI-Generated Image Detectors