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

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Wang, Yanlin, Wu, Jiadong, Jiang, Tianyue, Liu, Mingwei, Chen, Jiachi, Wang, Chong, Shi, Ensheng, Liu, Xilin, Ma, Yuchi, Zheng, Zibin
Format: Preprint
Publié: 2026
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866914300304556032
author Wang, Yanlin
Wu, Jiadong
Jiang, Tianyue
Liu, Mingwei
Chen, Jiachi
Wang, Chong
Shi, Ensheng
Liu, Xilin
Ma, Yuchi
Zheng, Zibin
author_facet Wang, Yanlin
Wu, Jiadong
Jiang, Tianyue
Liu, Mingwei
Chen, Jiachi
Wang, Chong
Shi, Ensheng
Liu, Xilin
Ma, Yuchi
Zheng, Zibin
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2601_20615
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning
Wang, Yanlin
Wu, Jiadong
Jiang, Tianyue
Liu, Mingwei
Chen, Jiachi
Wang, Chong
Shi, Ensheng
Liu, Xilin
Ma, Yuchi
Zheng, Zibin
Software Engineering
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.
title DRAINCODE: Stealthy Energy Consumption Attacks on Retrieval-Augmented Code Generation via Context Poisoning
topic Software Engineering
url https://arxiv.org/abs/2601.20615