TL;DR
This paper explores the vulnerability of Large Language Models (LLMs) to "imperceptible" adversarial attacks on source code. By subtly manipulating code at the character level, these attacks can fool LLMs into misinterpreting code functionality without being noticeable to human reviewers, highlighting a critical security risk for AI-assisted software development.
What Problem Does This Paper Address?
Large Language Models (LLMs) are increasingly integrated into software development workflows for tasks like code generation and comprehension. While powerful, these models can be susceptible to adversarial attacks. Existing attacks often involve visible modifications or require human intervention to be effective. This paper focuses on a specific type of attack: "imperceptible" character-level manipulations of source code. These attacks aim to alter the LLM's understanding of code without changing its appearance to a human developer, posing a significant threat to code review, analysis, and automated security checks. The core problem is understanding how vulnerable current LLMs are to these subtle, human-invisible code manipulations and how this impacts their performance and reliability in software engineering tasks.
Methods
The researchers devised a framework for generating and evaluating imperceptible adversarial attacks on source code. Their approach involves four distinct attack strategies:
- Code Reordering: Utilizes the Unicode right-to-left override character (U+202E) to reverse a portion of the code. Visually, the code appears correct, but the underlying character order is altered.
- Invisible Coding Characters: Employs characters like the zero-width non-joiner (U+200C) which don't render a visible glyph. These can act as invisible spaces or disconnect characters that would normally join.
- Code Deletions: Uses the backspace character (U+0008) to effectively delete characters from the rendered code, making it appear shorter or altered without obvious visual cues.
- Code Homoglyphs: Replaces characters with visually identical or very similar Unicode characters.
These attacks were applied programmatically to code snippets. The LLMs were then prompted with a binary question: "Does the provided code match the provided description?" The researchers evaluated LLM performance based on two metrics: response correctness and model confidence, measured using the log probabilities of the model's output tokens. They systematically tested different perturbation budgets (20% to 100% of the code affected) across multiple LLM models.
Datasets
The study utilized the LeetCode dataset from Hugging Face. This dataset comprises 2,644 LeetCode coding questions, each with a code snippet and a description. For their experiments, they specifically used JavaScript code snippets to control for language-specific variations. The descriptions were treated as the "ground truth" for evaluating the correctness of the LLM's responses.
Key Insights and Ideas
- LLMs are surprisingly vulnerable: Even state-of-the-art LLMs, including GPT-3.5 and GPT-4 variants, show significant degradation in performance when exposed to these imperceptible code perturbations.
- "True imperceptibility" is key: The attacks are designed to be visually and semantically indistinguishable to humans, making them particularly insidious for automated code analysis.
- Deletions are the most disruptive: The "code deletions" attack strategy had the most significant negative impact on both correctness and confidence scores across most models.
- GPT-4o shows a different failure mode: While GPT-3.5 models exhibit a gradual decline in performance with increasing perturbation, GPT-4o appears to have "deterministic guardrails" that cause it to reject perturbed code outright (returning "No" even if the code is functionally correct), rather than misinterpreting it. This suggests a shift towards robustness but at the cost of potentially rejecting valid code.
- Negative correlation is consistent: A strong negative correlation was observed between the magnitude of perturbation and LLM performance (correctness and confidence).
- Confidence is a useful proxy for robustness: Log probabilities provide a quantifiable measure of LLM confidence, which degrades predictably under attack.
Key Results
- Clean code performance: All tested LLMs achieved 100% correctness on clean, unperturbed code snippets.
- Degradation under attack:
- For GPT-3.5 models, correctness and confidence scores dropped significantly, often approaching zero, as the perturbation budget increased. For example, with the "deletions" attack at 20% budget, GPT-3.5-turbo-0613 saw a confidence drop of -52.76%.
- GPT-4o, however, showed a drastic performance drop, with correctness often near 0% for any level of perturbation. Its confidence scores became highly negative (e.g., -18.35% for reordering at 20% budget), indicating it flagged the code as incorrect.
- Correlation: A moderate-to-strong negative correlation was found between perturbation budget and correctness scores across all models. Table V shows coefficients like -0.98 for GPT-3.5-turbo-0613 with reordering.
- Number of Correct Responses: For GPT-4o, the number of correct responses across all perturbation budgets was very low (e.g., 15 out of 1500 for reordering), highlighting its tendency to reject perturbed code. In contrast, GPT-3.5 models maintained a statistically significant number of correct responses even under attack.
Limitations and Future Work
- Confidence Measurement: While log probabilities are used as a proxy for confidence, the paper acknowledges that they might not be a perfect representation and that LLMs might favor their own generations. Future work could explore more robust methods for assessing confidence.
- "No" Response Interpretation: The study assumes a "No" response from the LLM indicates a lack of understanding. However, for GPT-4o, this "No" might signify detection of an attack rather than a failure to comprehend. Future research could investigate the nuances of these "No" responses.
- Attack Budget Calculation: The homoglyph attack's perturbation budget calculation differs from others, potentially affecting direct comparisons.
- Future Work: The authors suggest exploring ways to create LLM systems that can generate correct responses even when faced with perturbed inputs, aiming for systems that understand the "spirit" of the code rather than just its literal interpretation. They also propose investigating the "deterministic guardrails" observed in GPT-4o and developing more sophisticated defense mechanisms beyond simple input sanitization.
Summary updated