Cost-Effective Adversarial Attacks Against Code LLM With Model Attention
Weifeng Sun, Naiqi Huang, Meng Yan, Li Huang, Zhongxin Liu, Xiao Liu, David Lo
Chongqing University · Zhejiang University
Key points
From the paper's conclusion- Our findings reveal that adversarial examples exhibit significant attention deviations, with the direction of deviation critically affecting attack success.
Abstract
Code LLMs (CLLMs) are vulnerable to adversarial attacks, where semantically identical code mutations mislead models into incorrect predictions. To address this, adversarial training has been proposed, retraining models with adversarial examples generated by attack methods. Among various attack approaches, black-box methods have attracted increasing attention due to their flexibility and applicability. However, existing black-box attack methods face two key challenges: 1) vast mutation spaces limit attack efficiency and effectiveness, and 2) resource-intensive model queries constrain scalability. These challenges hinder the practicality of black-box attacks, especially under resource constraints, prompting the critical question:Can we enhance the efficiency of existing attack methods without compromising their effectiveness?To answer this, we conduct an empirical study using Explainable AI (XAI) techniques to investigate differences between adversarial and non-adversarial (failure) examples. After analyzing state-of-the-art attack methods against two CLLMs, we introduce the concept ofmodel attention deviation, which quantifies differences in the model’s focus between unmutated (original) and mutated code. Our findings reveal that adversarial examples exhibit significant attention deviations, with the direction of deviation critically affecting attack success. Building on these insights, we propose ADVSEL, an efficient adversarial attack framework comprising two proxy components: the Attention Proxy Model (APM), which quickly estimates attention deviations to filter unpromising mutations, and the Deviation Direction Proxy Model (DDPM), which assesses whether attention shifts lead toward incorrect predictions. By integrating these proxy models with existing attack methods, ADVSELeffectively prioritizes promising mutations, significantly improving attack efficiency. Experimental evaluations across five CLLMs, four downstream tasks, and three attack methods demonstrate that ADVSEL maintains comparable attack success rates (a slight ASR reduction of 0.62%–0.70%) while significantly reducing model queries (by 34.98%–42.91%) and runtime (by 20.84%–21.45%). Under resource constraints, ADVSEL consistently outperforms baselines, highlighting its practical advantage in cost-effective adversarial evaluation.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Llm-ga: A gradient-based multi-label adversarial attack by large language modelsComplex & Intelligent Systems · 2025
- LLM-Agnostic Semantic Representation Attack.IEEE transactions on pattern analysis and machine intelligence · 2026
- Data-Efficient Backdoor Attacks on Code Models via Trigger-Neutralized Counterfactual ScoringarXiv · 2026
- Test vs Mutant: Adversarial LLM Agents for Robust Unit Test GenerationProceedings of the ACM on software engineering. · 2026
- RL-ATTACK: A Generalized Black-Box Adversarial Attack on Language Models via Reinforcement LearningarXiv · 2026
- RoCoMark: Robust Code Watermarking Against LLM-Based Functionality-Preserving Rewriting AttacksarXiv · 2026