DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning
On the map: Retrieval-augmented generation → Privacy and security of RAG
Abstract (arXiv)
Large language models (LLMs) have demonstrated impressive capabilities in code generation by leveraging retrieval-augmented generation (RAG) methods. However, the computational costs associated with LLM inference, particularly in terms of latency and energy consumption, have received limited attention in the security context. This paper introduces DrainCode, the first adversarial attack targeting the computational efficiency of RAG-based code generation systems. By strategically poisoning retrieval contexts through a mutation-based approach, DrainCode forces LLMs to produce significantly longer outputs, thereby increasing GPU latency and energy consumption. We evaluate the effectiveness of DrainCode across multiple models. Our experiments show that DrainCode achieves up to an 85% increase in latency, a 49% increase in energy consumption, and more than a 3x increase in output length compared to the baseline. Furthermore, we demonstrate the generalizability of the attack across different prompting strategies and its effectiveness compared to different defenses. The results highlight DrainCode as a potential method for increasing the computational overhead of LLMs, making it useful for evaluating LLM security in resource-constrained environments. We provide code and data at https://github.com/DeepSoftwareAnalytics/DrainCode.
Key facts. Cited by 3 papers in the map (data through 7 Oct 2026). Placed in Privacy and security of RAG, one of 15 directions in Retrieval-augmented generation. Builds on 110 of its 139 references that are in the map. First posted on arXiv 28 Jan 2026.
Builds on
110 of 139 references.
Closest ancestors · 4
Same direction, newest first
- 2024HijackRAG: Hijacking Attacks against Retrieval-Augmented Large Language Models30 Oct
- 2024BadRAG: Identifying Vulnerabilities in Retrieval Augmented Generation of Large Language Models3 Jun
- 2024TrojanRAG: Retrieval-Augmented Generation Can Be Backdoor Driver in Large Language Models22 May
- 2024PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models12 Feb
Other references · 106
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2023Qwen Technical Reportcited by 3,273
- 2023Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflectioncited by 1,800
- 2023LongBench: A Bilingual, Multitask Benchmark for Long Context Understandingcited by 1,378
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
- 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
- 2024OpenHands: An Open Platform for AI Software Developers as Generalist Agentscited by 956
- 2023REPLUG: Retrieval-Augmented Black-Box Language Modelscited by 786
- 2023In-Context Retrieval-Augmented Language Modelscited by 694
- 2023Baseline Defenses for Adversarial Attacks Against Aligned Language Modelscited by 608
- 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
- 2023Active Retrieval Augmented Generationcited by 506
38 more
- 2024A Survey on RAG Meeting LLMs: Towards Retrieval-Augmented Large Language Modelscited by 450
- 2025Search-o1: Agentic Search-Enhanced Large Reasoning Modelscited by 423
- 2024PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funnelingcited by 420
- 2023Detecting Language Model Attacks with Perplexitycited by 411
- 2023Large Language Models for Software Engineering: A Systematic Literature Reviewcited by 389
- 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
- 2023Self-collaboration Code Generation via ChatGPTcited by 255
- 2023Prompt Cache: Modular Attention Reuse for Low-Latency Inferencecited by 255
- 2020AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Promptscited by 246
- 2024Ada-KV: Optimizing KV Cache Eviction by Adaptive Budget Allocation for Efficient LLM Inferencecited by 230
- 2023From Words to Watts: Benchmarking the Energy Costs of Large Language Model Inferencecited by 168
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
- 2024Design2Code: Benchmarking Multimodal Code Generation for Automated Front-End Engineeringcited by 146
- 2022Large Language Models Meet NL2Code: A Surveycited by 135
- 2024MAGIS: LLM-Based Multi-Agent Framework for GitHub Issue Resolutioncited by 132
- 2024PLeak: Prompt Leaking Attacks against Large Language Model Applicationscited by 113
- 2023LongCoder: A Long-Range Pre-trained Language Model for Code Completioncited by 110
- 2025CodeElo: Benchmarking Competition-level Code Generation of LLMs with Human-comparable Elo Ratingscited by 109
- 2020Sponge Examples: Energy-Latency Attacks on Neural Networkscited by 108
- 2025S*: Test Time Scaling for Code Generationcited by 95
- 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigationcited by 92
- 2022Execution-Based Evaluation for Open-Domain Code Generationcited by 89
- 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 89
- 2025SWE-Fixer: Training Open-Source LLMs for Effective and Efficient GitHub Issue Resolutioncited by 87
- 2024AnalogCoder: Analog Circuit Design via Training-Free Code Generationcited by 82
- 2015A Primer on Neural Network Models for Natural Language Processingcited by 75
- 2024Inducing High Energy-Latency of Large Vision-Language Models with Verbose Imagescited by 69
- 2024WKVQuant: Quantizing Weight and Key/Value Cache for Large Language Models Gains Morecited by 69
- 2023Towards an Understanding of Large Language Models in Software Engineering Taskscited by 67
- 2023A Survey of Large Language Models for Code: Evolution, Benchmarking, and Future Trendscited by 66
- 2022CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Contextcited by 64
- 2025SWE-Exp: Experience-Driven Software Issue Resolutioncited by 64
- 2025Safety at Scale: A Comprehensive Survey of Large Model and Agent Safetycited by 63
- 2020A Panda? No, It's a Sloth: Slowdown Attacks on Adaptive Multi-Exit Neural Network Inferencecited by 61
- 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
- 2024Alibaba LingmaAgent: Improving Automated Issue Resolution via Comprehensive Repository Explorationcited by 58
- 2021T-Miner: A Generative Approach to Defend Against Trojan Attacks on DNN-based Text Classificationcited by 56
- 2023CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translationcited by 55
50 most cited of 106 All 106 (JSON)
Built on by
Citing papers per year: 2026: 3.
3 papers.
Similar, not cited
Close in wording, no citation either way
- 2025RAG-Pull: Turning Retrieval into a Code-Injection Channel via Invisible Unicode Perturbations
- 2025DisarmRAG: Stealthy Retriever-Centric Poisoning to Disable Self-Correction in Retrieval-Augmented Generation (Extended Version)
- 2026LeakDojo: Decoding the Leakage Threats of RAG Systems
- 2025CPA-RAG:Covert Poisoning Attacks on Retrieval-Augmented Generation in Large Language Models
- 2025Token-Level Precise Attack on RAG: Searching for the Best Alternatives to Mislead Generation
- 2024Towards More Robust Retrieval-Augmented Generation: Evaluating RAG Under Adversarial Poisoning Attacks
- 2025PR-Attack: Coordinated Prompt-RAG Attacks on Retrieval-Augmented Generation in Large Language Models via Bilevel Optimization
- 2026PIDP-Attack: Combining Prompt Injection with Database Poisoning Attacks on Retrieval-Augmented Generation Systems