mlsanityData to 7 Oct 2026

DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning

arXiv 2601.20615 ↗First posted 28 Jan 2026cs.SEcited by 3

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

  1. 2024HijackRAG: Hijacking Attacks against Retrieval-Augmented Large Language Models30 Oct
  2. 2024BadRAG: Identifying Vulnerabilities in Retrieval Augmented Generation of Large Language Models3 Jun
  3. 2024TrojanRAG: Retrieval-Augmented Generation Can Be Backdoor Driver in Large Language Models22 May
  4. 2024PoisonedRAG: Knowledge Corruption Attacks to Retrieval-Augmented Generation of Large Language Models12 Feb

Other references · 106

  1. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  2. 2023Qwen Technical Reportcited by 3,273
  3. 2023Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflectioncited by 1,800
  4. 2023LongBench: A Bilingual, Multitask Benchmark for Long Context Understandingcited by 1,378
  5. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,286
  6. 2024DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligencecited by 1,154
  7. 2024OpenHands: An Open Platform for AI Software Developers as Generalist Agentscited by 956
  8. 2023REPLUG: Retrieval-Augmented Black-Box Language Modelscited by 786
  9. 2023In-Context Retrieval-Augmented Language Modelscited by 694
  10. 2023Baseline Defenses for Adversarial Attacks Against Aligned Language Modelscited by 608
  11. 2020GraphCodeBERT: Pre-training Code Representations with Data Flowcited by 600
  12. 2023Active Retrieval Augmented Generationcited by 506
38 more
  1. 2024A Survey on RAG Meeting LLMs: Towards Retrieval-Augmented Large Language Modelscited by 450
  2. 2025Search-o1: Agentic Search-Enhanced Large Reasoning Modelscited by 423
  3. 2024PyramidKV: Dynamic KV Cache Compression based on Pyramidal Information Funnelingcited by 420
  4. 2023Detecting Language Model Attacks with Perplexitycited by 411
  5. 2023Large Language Models for Software Engineering: A Systematic Literature Reviewcited by 389
  6. 2023RepoCoder: Repository-Level Code Completion Through Iterative Retrieval and Generationcited by 357
  7. 2023Self-collaboration Code Generation via ChatGPTcited by 255
  8. 2023Prompt Cache: Modular Attention Reuse for Low-Latency Inferencecited by 255
  9. 2020AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Promptscited by 246
  10. 2024Ada-KV: Optimizing KV Cache Eviction by Adaptive Budget Allocation for Efficient LLM Inferencecited by 230
  11. 2023From Words to Watts: Benchmarking the Energy Costs of Large Language Model Inferencecited by 168
  12. 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
  13. 2024Design2Code: Benchmarking Multimodal Code Generation for Automated Front-End Engineeringcited by 146
  14. 2022Large Language Models Meet NL2Code: A Surveycited by 135
  15. 2024MAGIS: LLM-Based Multi-Agent Framework for GitHub Issue Resolutioncited by 132
  16. 2024PLeak: Prompt Leaking Attacks against Large Language Model Applicationscited by 113
  17. 2023LongCoder: A Long-Range Pre-trained Language Model for Code Completioncited by 110
  18. 2025CodeElo: Benchmarking Competition-level Code Generation of LLMs with Human-comparable Elo Ratingscited by 109
  19. 2020Sponge Examples: Energy-Latency Attacks on Neural Networkscited by 108
  20. 2025S*: Test Time Scaling for Code Generationcited by 95
  21. 2024LLM Hallucinations in Practical Code Generation: Phenomena, Mechanism, and Mitigationcited by 92
  22. 2022Execution-Based Evaluation for Open-Domain Code Generationcited by 89
  23. 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?cited by 89
  24. 2025SWE-Fixer: Training Open-Source LLMs for Effective and Efficient GitHub Issue Resolutioncited by 87
  25. 2024AnalogCoder: Analog Circuit Design via Training-Free Code Generationcited by 82
  26. 2015A Primer on Neural Network Models for Natural Language Processingcited by 75
  27. 2024Inducing High Energy-Latency of Large Vision-Language Models with Verbose Imagescited by 69
  28. 2024WKVQuant: Quantizing Weight and Key/Value Cache for Large Language Models Gains Morecited by 69
  29. 2023Towards an Understanding of Large Language Models in Software Engineering Taskscited by 67
  30. 2023A Survey of Large Language Models for Code: Evolution, Benchmarking, and Future Trendscited by 66
  31. 2022CoCoMIC: Code Completion By Jointly Modeling In-file and Cross-file Contextcited by 64
  32. 2025SWE-Exp: Experience-Driven Software Issue Resolutioncited by 64
  33. 2025Safety at Scale: A Comprehensive Survey of Large Model and Agent Safetycited by 63
  34. 2020A Panda? No, It's a Sloth: Slowdown Attacks on Adaptive Multi-Exit Neural Network Inferencecited by 61
  35. 2024Agents in Software Engineering: Survey, Landscape, and Visioncited by 60
  36. 2024Alibaba LingmaAgent: Improving Automated Issue Resolution via Comprehensive Repository Explorationcited by 58
  37. 2021T-Miner: A Generative Approach to Defend Against Trojan Attacks on DNN-based Text Classificationcited by 56
  38. 2023CodeTransOcean: A Comprehensive Multilingual Benchmark for Code Translationcited by 55

50 most cited of 106 All 106 (JSON)

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2026: 3.

3 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2025RAG-Pull: Turning Retrieval into a Code-Injection Channel via Invisible Unicode Perturbations
  2. 2025DisarmRAG: Stealthy Retriever-Centric Poisoning to Disable Self-Correction in Retrieval-Augmented Generation (Extended Version)
  3. 2026LeakDojo: Decoding the Leakage Threats of RAG Systems
  4. 2025CPA-RAG:Covert Poisoning Attacks on Retrieval-Augmented Generation in Large Language Models
  5. 2025Token-Level Precise Attack on RAG: Searching for the Best Alternatives to Mislead Generation
  6. 2024Towards More Robust Retrieval-Augmented Generation: Evaluating RAG Under Adversarial Poisoning Attacks
  7. 2025PR-Attack: Coordinated Prompt-RAG Attacks on Retrieval-Augmented Generation in Large Language Models via Bilevel Optimization
  8. 2026PIDP-Attack: Combining Prompt Injection with Database Poisoning Attacks on Retrieval-Augmented Generation Systems