A Black-Box Attack on Code Models via Representation Nearest Neighbor Search
Not on the map. Why?
Abstract (arXiv)
Existing methods for generating adversarial code examples face several challenges: limted 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 (CodeBERT, 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.
Key facts. Cited by 3 papers in the map (data through 14 Oct 2026). Builds on 17 of its 28 references that are in the map. First posted on arXiv 10 May 2023.
Builds on
17 of 28 references.
References · 17
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 609
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
- 2021CodeNet: A Large-Scale AI for Code Dataset for Learning a Diversity of Coding Taskscited by 200
- 2020A Transformer-based Approach for Source Code Summarizationcited by 133
- 2020Retrieval-Augmented Generation for Code Summarization via Hybrid GNNcited by 89
- 2022Natural Attack for Pre-trained Models of Codecited by 75
- 2020Detecting Code Clones with Graph Neural Networkand Flow-Augmented Abstract Syntax Treecited by 69
- 2019Adversarial Examples for Models of Codecited by 63
- 2022CodeAttack: Code-Based Adversarial Attacks for Pre-trained Programming Language Modelscited by 53
- 2020Semantic Robustness of Models of Source Codecited by 45
5 more
- 2021Generating Adversarial Computer Programs using Optimized Obfuscationscited by 22
- 2021A Strong Baseline for Query Efficient Attacks in a Black Box Settingcited by 16
- 2023ContraBERT: Enhancing Code Pre-trained Models via Contrastive Learningcited by 16
- 2021GraphSearchNet: Enhancing GNNs via Capturing Global Dependencies for Semantic Code Searchcited by 15
- 2020STRATA: Simple, Gradient-Free Attacks for Models of Codecited by 5
Built on by
Citing papers per year: 2025: 3.
3 papers.
- 2025A Systematic Study of Code Obfuscation Against LLM-based Vulnerability Detectioncited by 5
- 2025XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistantscited by 4
- 2025Evaluate-and-Purify: Fortifying Code Language Models Against Adversarial Attacks Using LLM-as-a-Judgecited by 4
- 2025A Systematic Study of Code Obfuscation Against LLM-based Vulnerability Detection18 Dec 2025
- 2025Evaluate-and-Purify: Fortifying Code Language Models Against Adversarial Attacks Using LLM-as-a-Judge28 Apr 2025
- 2025XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants18 Mar 2025