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.


翻译:大型语言模型(LLMs)通过采用检索增强生成(RAG)方法,在代码生成方面展现出卓越能力。然而,LLM推理相关的计算成本(尤其在延迟和能耗方面)在安全领域尚未得到充分关注。本文提出DrainCode,这是首个针对基于RAG的代码生成系统计算效率的对抗性攻击。该方法通过基于变异的策略对检索上下文进行定向投毒,迫使LLMs生成显著更长的输出,从而增加GPU延迟和能耗。我们在多个模型上评估DrainCode的有效性。实验表明,与基线相比,DrainCode可实现高达85%的延迟增长、49%的能耗增长以及超过3倍的输出长度增长。此外,我们验证了该攻击在不同提示策略下的泛化能力,并对比了不同防御措施的有效性。研究结果凸显DrainCode作为增加LLM计算开销的潜在方法,对于评估资源受限环境中的LLM安全性具有重要价值。代码与数据详见https://github.com/DeepSoftwareAnalytics/DrainCode。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
检索增强生成(RAG)与推理的协同作用:一项系统综述
专知会员服务
33+阅读 · 2025年4月27日
定制化大型语言模型的图检索增强生成综述
专知会员服务
37+阅读 · 2025年1月28日
智能体检索增强生成:关于智能体RAG的综述
专知会员服务
89+阅读 · 2025年1月21日
揭示生成式人工智能 / 大型语言模型(LLMs)的军事潜力
专知会员服务
31+阅读 · 2024年9月26日
检索增强生成系统中的可信度:综述
专知会员服务
43+阅读 · 2024年9月18日
生成式人工智能大型语言模型的安全性:概述
专知会员服务
35+阅读 · 2024年7月30日
最新《生成式对抗网络GAN进展》论文
专知
95+阅读 · 2019年4月5日
国家自然科学基金
4+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关VIP内容
检索增强生成(RAG)与推理的协同作用:一项系统综述
专知会员服务
33+阅读 · 2025年4月27日
定制化大型语言模型的图检索增强生成综述
专知会员服务
37+阅读 · 2025年1月28日
智能体检索增强生成:关于智能体RAG的综述
专知会员服务
89+阅读 · 2025年1月21日
揭示生成式人工智能 / 大型语言模型(LLMs)的军事潜力
专知会员服务
31+阅读 · 2024年9月26日
检索增强生成系统中的可信度:综述
专知会员服务
43+阅读 · 2024年9月18日
生成式人工智能大型语言模型的安全性:概述
专知会员服务
35+阅读 · 2024年7月30日
相关资讯
最新《生成式对抗网络GAN进展》论文
专知
95+阅读 · 2019年4月5日
相关基金
国家自然科学基金
4+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员