Lune

FSE2023Top-tier venue

An Extensive Study on Adversarial Attack against Pre-trained Models of Code

Xiaohu Du, Ming Wen, Zichao Wei, Shangwen Wang, Hai Jin

Abstract

Transformer-based pre-trained models of code (PTMC) have been widely utilized and have achieved state-of-the-art performance in many mission-critical applications. However, they can be vulnerable to adversarial attacks through identifier substitution or coding style transformation, which can significantly degrade accuracy and may further incur security concerns. Although several approaches have been proposed to generate adversarial examples for PTMC, the effectiveness and efficiency of such approaches, especially on different code intelligence tasks, has not been well understood. To bridge this gap, this study systematically analyzes five state-of-the-art adversarial attack approaches from three perspectives: effectiveness, efficiency, and the quality of generated examples. The results show that none of the five approaches balances all these perspectives. Particularly, approaches with a high attack success rate tend to be time-consuming; the adversarial code they generate often lack naturalness, and vice versa. To address this limitation, we explore the impact of perturbing identifiers under different contexts and find that identifier substitution within for and if statements is the most effective. Based on these findings, we propose a new approach that prioritizes different types of statements for various tasks and further utilizes beam search to generate adversarial examples. Evaluation results show that it outperforms the state-of-the-art ALERT in terms of both effectiveness and efficiency while preserving the naturalness of the generated adversarial examples.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

3 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Mutual Learning-Based Framework for Enhancing Robustness of Code Models via Adversarial Training cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • Mutual Learning-Based Framework for Enhancing Robustness of Code Models via Adversarial Training cites Adversarial examples for models of code
  • Mutual Learning-Based Framework for Enhancing Robustness of Code Models via Adversarial Training cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Mutual Learning-Based Framework for Enhancing Robustness of Code Models via Adversarial Training cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • Mutual Learning-Based Framework for Enhancing Robustness of Code Models via Adversarial Training cites Natural Attack for Pre-trained Models of Code
  • CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Iterative Generation of Adversarial Example for Deep Code Models cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
  • Iterative Generation of Adversarial Example for Deep Code Models cites Adversarial examples for models of code
  • Iterative Generation of Adversarial Example for Deep Code Models cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Iterative Generation of Adversarial Example for Deep Code Models cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • Iterative Generation of Adversarial Example for Deep Code Models cites Natural Attack for Pre-trained Models of Code
  • Natural Attack for Pre-trained Models of Code cites Adversarial examples for models of code
  • Natural Attack for Pre-trained Models of Code cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Natural Attack for Pre-trained Models of Code cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants cites Adversarial examples for models of code
  • XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants cites Natural Attack for Pre-trained Models of Code
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers3

  1. XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding AssistantsAdam Storek, Mukur Gupta, Noopur Bhatt, Aditya Gupta et al.ACL 2026 · 5 citations
  2. Mutual Learning-Based Framework for Enhancing Robustness of Code Models via Adversarial TrainingYangsen Wang, Yizhou Chen, Yifan Zhao, Zhihao Gong et al.ASE 2024 · 3 citations
  3. Iterative Generation of Adversarial Example for Deep Code ModelsLi Huang, Weifeng Sun, Meng YanICSE 2025 · 1 citation

Builds on14

  1. CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
  2. GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng et al.ICLR 2021 · 1,644 citations
  3. CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
  4. Adversarial examples for models of codeNoam Yefet, Uri Alon, Eran YahavOOPSLA 2020 · 162 citations
  5. Natural Attack for Pre-trained Models of CodeZhou Yang, Jieke Shi, Junda He, David LoICSE 2022 · 150 citations

Related papers

  1. Evaluating and Enhancing the Robustness of Code Pre-trained Models through Structure-Aware Adversarial Samples GenerationNuo Chen, Qiushi Sun, Jianing Wang, Ming Gao et al.EMNLP Findings 2023 · 3 citations
  2. Statement-Level Adversarial Attack on Vulnerability Detection Models via Out-of-Distribution FeaturesXiaohu Du, Ming Wen, Haoyu Wang, Zichao Wei et al.FSE 2025 · 1 citation
  3. DIP: Dead code Insertion based Black-box Attack for Programming Language ModelCheolWon Na, YunSeok Choi, Jee-Hyong LeeACL 2023 · 13 citations
  4. AACEGEN: Attention Guided Adversarial Code Example Generation for Deep Code ModelsZhong Li, Chong Zhang, Minxue Pan, Tian Zhang et al.ASE 2024 · 4 citations
  5. Code Difference Guided Adversarial Example Generation for Deep Code ModelsZhao Tian, Junjie Chen, Zhi JinASE 2023 · 27 citations
Dusk over the sea between two cliffs drawn in fine vertical lines