Measuring the Interaction Orders of Composite Attacks on Code Models

When you attack a model that reads source code, you do not have to change what the program does. Renaming variables, inserting unreachable statements, or refactoring loops leaves the program's behavior identical, yet these "semantics-preserving transformations" reliably flip the predictions of code models: CodeAttack showed that changing just one to three tokens achieves attack success rates of 90–99% on code translation and repair, and Auto-SPT showed that chaining many transformations through beam search pushes a fine-tuned CodeBERT clone detector essentially to total failure. What nobody can currently say is why the chained attacks work: is the damage the simple sum of each transformation's independent effect, or does it come from irreducible interactions between transformations that only appear when they are combined?

Materials science solved an isomorphic problem for physical systems. The total energy of an eight-atom cluster can be decomposed, via the Many-Body Expansion (MBE), into one-atom terms, pairwise terms, triple terms, and so on; and Resolving the body-order paradox of machine learning interatomic potentials showed that neural potentials trained on such clusters do not learn the physically correct decomposition but instead "hallucinate" model-specific effective ones — and that forcing the physically correct decomposition on the MACE architecture made accuracy 3.4-fold worse. This proposal imports that decomposition apparatus to adversarial code modeling. The core deliverable is a measurement instrument that decomposes a code model's adversarial failure under a library of transformations into 1-body, 2-body, and higher-order cross-terms, plus attack and defense methods built directly on the measured spectrum.

Core Claim

The claim is that the adversarial loss landscape of a code model over a library of semantics-preserving transformations admits a many-body decomposition, that the resulting order spectrum is measurable at tractable cost, and that it is actionable in both directions. If most worst-case damage is explained by 1- and 2-body terms, then an attack that greedily composes only the largest measured low-order interactions should match full beam search at a fraction of the model queries, and a defense that augments training data only with the dominant-order compositions should beat uniform augmentation at matched budget. If instead the damage is irreducibly high-order, that is a different and equally important finding: it says defenses validated on small transformation libraries, like the 20 operators of Auto-SPT, will not transfer to unseen compositions, and it predicts that the "jagged frontier" of unpredictable robustness observed by A Jagged Frontier in repository-level agents is a structural property rather than an artifact of random sampling.

Formally, let a program $x$ be transformed by any subset $S$ of $m$ operators from a transformation library, giving $x_S$, and let $\Delta(S)$ be the change in the target model's loss (or embedding divergence) caused by applying $S$. The many-body decomposition writes this change as a sum of irreducible interaction terms:

$$\Delta(S)=\sum_{\emptyset\neq U\subseteq S}\epsilon(U),\qquad \epsilon(U)=\Delta(U)-\sum_{V\subsetneq U}\epsilon(V),$$

where $\epsilon(U)$ is the contribution that cannot be attributed to any proper subset of $U$ — the $|U|$-body cross-term among those operators. Exact evaluation needs all $2^m$ subsets, which is intractable for $m=20$; the estimator therefore computes $\epsilon$ exactly up to order three and measures how much of the observed damage a truncated order-$k$ reconstruction recovers, exactly as truncated many-body expansions are used for atomic clusters.

Research Program

Four components. First, the estimator: run the inclusion–exclusion measurement above over the operator libraries already validated in the literature — the 20 LLM-designed transformations of Auto-SPT plus the classic identifier-renaming and dead-code operators from CodeAttack and Adversarial Robustness for Code — on several target models, and report the distribution of $|\epsilon_k|$ by order together with the variance explained by truncated reconstructions. This directly parallels how Chong et al. exposed the gap between physical and effective body order in neural potentials; here the question is whether CodeBERT-style encoders respond to composed transformations as approximate low-order superpositions or as something genuinely higher-order and non-monotonic.

Second, the attack: an order-guided greedy search that expands only operator combinations with large measured low-order $\epsilon$ values, evaluated against Auto-SPT's beam search under a matched query budget. Beam search is non-explanatory and query-hungry; if the spectrum is genuinely low-order, the guided search should reach comparable worst-case damage with far fewer forward passes.

Third, the defense: order-targeted data augmentation, generating training variants only from the dominant-order compositions, compared against uniform augmentation over the same library. This is motivated by a negative result that constrains the design: Adversarial Robustness for Code found that adversarial training alone yields only a 0–7% robustness gain, and that their sequential ensembles cost roughly 10× the training compute — so indiscriminate augmentation is empirically weak and expensive, and the hypothesis is that targeted augmentation is where the budget should go. A second constraint comes from the body-order paradox itself: Chong et al. showed that forcing a model to respect a decomposition it did not naturally learn degraded its core accuracy 3.4-fold, so every defense experiment must track clean accuracy alongside robustness to detect an analogous "cost of realism" penalty.

Fourth, a scaling protocol borrowed from the alloy-surrogate literature: Liu et al. trained models on unary/binary/ternary alloy systems and evaluated on quaternaries and beyond, finding that random forests collapse into jagged non-physical transitions while deep networks degrade smoothly. We apply the same up-to-$n$-ary design to transformation compositions: train defenders on 1- and 2-operator variants, evaluate on 3+-operator compositions, and measure whether error growth is smooth and predictable or jagged — the first direct test of whether the extrapolation behavior Liu et al. documented in tabular materials data also holds for code models, where labeled data is scarce rather than abundant.

Proposed Experiments

Experiment 1 measures the order spectrum. Targets are a fine-tuned CodeBERT clone detector on CodeContests, a CodeBERT defect detector on the CodeXGLUE Devign defect-detection subset, where CodeXGLUE reports a clean baseline of 62.08% accuracy, and the Devign graph neural network itself on its ~59,000-function C dataset, since Devign has never been adversarially tested and its composite AST/CFG/DFG representation makes it the natural probe for whether multi-channel structure resists composed evasion. The headline diagnostic is the fraction of worst-case damage recovered by order-1 and order-2 truncations alone.

Experiment 2 is the attack comparison. Auto-SPT reports a worst-case embedding distance of 0.947 on fine-tuned CodeBERT on CodeContests (versus 0.243 for prior transformation sets), and the proposed order-guided search must reach that damage level with strictly fewer model queries at a fixed query budget, on the same operator library and the same target model, to count as a win.

Experiment 3 is the defense comparison, on the CodeXGLUE defect-detection and CodeContests clone-detection tasks. Robustness is defined as accuracy under the strongest available attack, following the metric used by Bielik and Vechev. Order-targeted augmentation beats uniform augmentation if it achieves higher robustness at equal training compute and equal number of augmented samples, without dropping clean accuracy — the clean-accuracy guard being the explicit check for a body-order-paradox-style penalty.

Experiment 4 runs the up-to-$n$-ary extrapolation protocol of Liu et al. on the defenders from Experiment 3, reporting error growth as a function of composition depth and testing for the jagged-versus-smooth signature.

Experiment 5, deliberately small in scale, extends the measurement to repository-level agents on the SWE-bench Verified subset that Jagged Frontier used (28 instances), replacing their random variant sampler with a feedback-guided adversary that prioritizes transformations with large measured low-order $\epsilon$. Their random sampling already produced resolve-rate drops up to 6.7 percentage points and cost increases up to 22.9%, and the authors explicitly call random sampling a lower bound — this experiment tests whether guided attacks are substantially worse, and whether the order spectrum measured on function-level models transfers to agent-level failure.

Baselines

The "do nothing" reference point is clean, undefended performance: CodeBERT at 62.08% accuracy on CodeXGLUE defect detection and 96.5 F1 on BigCloneBench, and Devign at 74.11% accuracy on 40 real-world CVEs. Under attack with no defense, the reference behavior is the near-total collapse documented by CodeAttack, with 90–99% attack success from one to three token edits. The strongest existing attack baseline is Auto-SPT's beam search (Auto-SPT), which is the only prior method that composes multiple distinct transformation operators and reports the 0.947 worst-case distance on the exact CodeContests/CodeBERT configuration we reuse; it will be run with the same operator library, same target models, and — the decisive fairness condition — the same number of model queries as the order-guided search. Beating it means matching or exceeding 0.947 worst-case distance at equal or lower query budget, and additionally producing the interaction decomposition that beam search cannot. The strongest existing defense baseline is the pipeline of Adversarial Robustness for Code, which combines abstention, adversarial training, and integer-linear-programming representation refinement and reached 87.7% accuracy with 67.0% robustness on JavaScript/TypeScript type inference; because it was evaluated on a different task, we port its representation-refinement and abstention ideas to our tasks and compare at matched training compute, noting honestly that the comparison is architectural rather than a score-for-score replication. Two ablations isolate the proposal's key ingredient: random composition sampling at matched query budget (versus spectrum-guided search) shows whether the measured $\epsilon$ values carry information beyond what any search would find, and uniform augmentation at matched sample count (versus order-targeted augmentation) shows whether targeting the dominant interaction orders is what matters rather than simply more augmented data. A separate adversarial-training-only arm, expected to land in the 0–7% gain range that Bielik and Vechev report, serves as the known-weak defense reference.

Why not just…?

Why not just do more adversarial training? The file contains a direct negative result: adversarial training alone improved robustness by only 0–7% in Adversarial Robustness for Code, with real gains requiring architectural representation change, and ensemble-based absorption of adversarial variants cost 10× the training time. Blanket augmentation over a transformation library also cannot cover the compositional space, which is exactly what Auto-SPT's jump from 0.243 to 0.947 worst-case distance demonstrates. That said, this is a genuine threat rather than a strawman: if the matched-budget comparison in Experiment 3 shows uniform augmentation performing as well as order-targeted augmentation, the spectrum's value collapses to diagnosis only — and the experiment is designed so that this outcome would be unambiguous.

Why not just run beam search longer? More search finds worse adversarial cases, but it cannot say whether the damage is superposed or interactive, it scales poorly with library size, and it gives no guidance on where a defense should spend its budget. The decisive check is the equal-query-budget comparison in Experiment 2. If beam search matches the order-guided attack at equal budget, then the attack-side contribution of this proposal weakens — we would say so — but the decomposition would still be the only instrument that explains the failure mode and predicts transfer to unseen compositions, which no amount of additional search provides.

Why not just evaluate on more agents and benchmarks? That measures coverage, not mechanism. A Jagged Frontier already showed robustness does not transfer predictably across scaffolds (Qwen was robust under one scaffold and most fragile under another) — more configurations would map more points on that frontier without explaining it. Their own compute constraints limited them to 54 instances, which also bounds what we can afford; Experiment 5 stays inside that envelope deliberately and asks a mechanism question (does guided attack beat random sampling, and does the function-level spectrum predict agent-level failure) rather than a coverage question.

Why not just trust deep models to extrapolate smoothly? Liu et al. found deep networks extrapolate smoothly to higher-order alloy systems, but that result rests on a 480-million-point synthetic dataset and low-dimensional tabular inputs; code models face scarce labels and a combinatorially larger discrete input space, and the jagged failures documented by Jagged Frontier suggest the analogy may not hold. Experiment 4 is precisely the test that would settle it, and either answer is informative: smooth growth supports transferring the alloy-surrogate playbook to code defenses; jagged growth confirms that composition depth is a distinct threat axis requiring order-aware defenses.

Decisive Checks

Three outcomes would decide the proposal. If order-1 plus order-2 truncations recover most of the worst-case damage in Experiment 1, and the guided attack matches 0.947 at materially fewer queries in Experiment 2, the low-order claim is established and order-targeted defense follows. If the spectrum is irreducibly high-order, the defense program pivots to detecting composed transformations as out-of-distribution rather than absorbing them, and the result stands as the first quantitative evidence that fixed transformation libraries understate code-model vulnerability. And if neither targeted augmentation nor guided search beats its matched-budget control, the measurement remains as a diagnostic contribution — the first many-body accounting of why composed attacks on code models work — which is the minimum publishable core of the program.