测试大模型对代码微小改动的脆弱性,发现人类看不见的修改会误导模型。
What You See Is Not Always What You Get: Evaluating GPT's Comprehension of Source Code
- 用字符级隐形攻击干扰代码,人眼无法察觉但能骗过模型
- 不同模型在对抗攻击下准确率下降,攻击越强性能越差
- 提醒开发者:模型理解代码不等于真正理解,需加强鲁棒性
近期研究显示大语言模型(LLMs)在软件工程任务中表现优异,包括代码生成与理解。然而,这些模型易受对抗攻击影响。本文研究了不可见攻击对LLMs的威胁,这类攻击在字符级别操纵源代码,使更改对人类审查者不可见,却能有效误导模型行为。我们设计了四类不可见字符攻击:编码重排、隐形字符、代码删除和同形字替换,并系统评估其对代码分析与理解任务的影响。通过对比多个先进模型在扰动与原始代码上的表现,引入模型置信度(基于响应的对数概率)和响应正确性作为评估指标。结果表明,所有模型均对不可见扰动敏感,性能下降程度因模型而异;且扰动强度越大,模型表现越差。该发现凸显了构建具备抗干扰能力的鲁棒模型的紧迫性。
原文摘要 · Abstract (English)
Recent studies have demonstrated outstanding capabilities of large language models (LLMs) in software engineering tasks, including code generation and comprehension. While LLMs have shown significant potential in assisting with coding, LLMs are vulnerable to adversarial attacks. In this paper, we investigate the vulnerability of LLMs to imperceptible attacks. This class of attacks manipulate source code at the character level, which renders the changes invisible to human reviewers yet effective in misleading LLMs' behaviour. We devise these attacks into four distinct categories and analyse their impacts on code analysis and comprehension tasks. These four types of imperceptible character attacks include coding reordering, invisible coding characters, code deletions, and code homoglyphs. To assess the robustness of state-of-the-art LLMs, we present a systematic evaluation across multiple models using both perturbed and clean code snippets. Two evaluation metrics, model confidence using log probabilities of response and response correctness, are introduced. The results reveal that LLMs are susceptible to imperceptible coding perturbations, with varying degrees of degradation highlighted across different LLMs. Furthermore, we observe a consistent negative correlation between perturbation magnitude and model performance. These results highlight the urgent need for robust LLMs capable of manoeuvring behaviours under imperceptible adversarial conditions.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。