Lune

EMNLP Findings2023

A Black-Box Attack on Code Models via Representation Nearest Neighbor Search

Jie Zhang, Wei Ma, Qiang Hu, Shangqing Liu, Xiaofei Xie, Yves Le Traon, Yang Liu

Abstract

Existing methods for generating adversarial code examples face several challenges: limited availability of substitute variables, high verification costs for these substitutes, and the creation of adversarial samples with noticeable perturbations. To address these concerns, our proposed approach, RNNS, uses a search seed based on historical attacks to find potential adversarial substitutes. Rather than directly using the discrete substitutes, they are mapped to a continuous vector space using a pre-trained variable name encoder. Based on the vector representation, RNNS predicts and selects better substitutes for attacks. We evaluated the performance of RNNS across six coding tasks encompassing three programming languages: Java, Python, and C. We employed three pre-trained code models (Code-BERT, GraphCodeBERT, and CodeT5) that resulted in a cumulative of 18 victim models. The results demonstrate that RNNS outperforms baselines in terms of ASR and QT. Furthermore, the perturbation of adversarial examples introduced by RNNS is smaller compared to the baselines in terms of the number of replaced variables and the change in variable length. Lastly, our experiments indicate that RNNS is efficient in attacking defended models and can be employed for adversarial training.

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.

5 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 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
  • 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
  • Attribution-guided Adversarial Code Prompt Generation for Code Completion Models cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
  • Attribution-guided Adversarial Code Prompt Generation for Code Completion Models cites GraphCodeBERT: Pre-training Code Representations with Data Flow
  • SAGE: Signal-Amplified Guided Embeddings for Vulnerability Detection 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 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 Retrieval-Augmented Generation for Code Summarization via Hybrid GNN
  • 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
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers5

  1. Attribution-guided Adversarial Code Prompt Generation for Code Completion ModelsXueyang Li, Guozhu Meng, Shangqing Liu, Lu Xiang et al.ASE 2024 · 5 citations
  2. XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding AssistantsAdam Storek, Mukur Gupta, Noopur Bhatt, Aditya Gupta et al.ACL 2026 · 5 citations
  3. 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
  4. Iterative Generation of Adversarial Example for Deep Code ModelsLi Huang, Weifeng Sun, Meng YanICSE 2025 · 1 citation
  5. SAGE: Signal-Amplified Guided Embeddings for Vulnerability DetectionZhengyang Shan, Xu Qian, Jiayun Xin, Minghui Xu et al.ISSTA 2026

Builds on12

  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. Retrieval-Augmented Generation for Code Summarization via Hybrid GNNShangqing Liu, Yu Chen, Xiaofei Xie, Jing Kai Siow et al.ICLR 2021 · 194 citations
  5. Word-level Textual Adversarial Attacking as Combinatorial OptimizationYuan Zang, Fanchao Qi, Chenghao Yang, Zhiyuan Liu et al.ACL 2020 · 188 citations

Related papers

  1. Adversarial examples for models of codeNoam Yefet, Uri Alon, Eran YahavOOPSLA 2020 · 162 citations
  2. ContraBERT: Enhancing Code Pre-trained Models via Contrastive LearningShangqing Liu, Bozhi Wu, Xiaofei Xie, Guozhu Meng et al.ICSE 2023 · 56 citations
  3. Discrete Adversarial Attack to Models of CodeFengjuan Gao, Yu Wang, Ke WangPLDI 2023 · 23 citations
  4. Natural Attack for Pre-trained Models of CodeZhou Yang, Jieke Shi, Junda He, David LoICSE 2022 · 150 citations
  5. DIP: Dead code Insertion based Black-box Attack for Programming Language ModelCheolWon Na, YunSeok Choi, Jee-Hyong LeeACL 2023 · 13 citations
Dusk over the sea between two cliffs drawn in fine vertical lines