Abstract
Chain-of-Thought (COT) prompting has significantly enhanced the reasoning capabilities of Large Language Models (LLMs). However, this paper introduces BadChain, a novel backdoor attack that subverts this reasoning process. Unlike traditional backdoor attacks that require model fine-tuning or data poisoning, BadChain operates entirely through in-context learning. By injecting a malicious "reasoning step" into a small subset of few-shot demonstrations, an attacker can manipulate model outputs with near-perfect success rates on complex tasks while maintaining high performance on clean queries. Our findings suggest that stronger models, such as GPT-4, are paradoxically more vulnerable to this form of logical hijacking.
Introduction
Large Language Models (LLMs) have demonstrated a remarkable ability to solve complex arithmetic, symbolic, and commonsense reasoning problems by "thinking out loud" through Chain-of-Thought (COT) prompting. While COT is designed to improve transparency and accuracy, researchers from UIUC, the University of Washington, and Western Washington University have identified a critical vulnerability. Their proposed attack, BadChain, represents the first backdoor threat that specifically exploits the reasoning capability of LLMs without requiring access to training data or model weights.
The Challenge of Prompt-Based Backdoors
Traditional backdoor attacks are often "heavyweight," requiring the poisoning of a model's training dataset or the fine-tuning of its weights to respond to a specific trigger. Such methods are impractical for modern, high-performance LLMs like GPT-4 or PaLM2, which are typically closed-source and accessed exclusively via APIs.
Existing "prompt-based" backdoors—which poison the few-shot examples provided in a prompt—generally fail on complex reasoning tasks. These methods typically attempt to flip the final label in a demonstration, a tactic that LLMs often ignore in favor of their own internal logic. BadChain addresses this gap by leveraging the model's inherent reasoning strengths to "teach" it a malicious logical rule in-context.
Methodology: Hijacking the Reasoning Chain
The core innovation of BadChain is the backdoor reasoning step. Instead of simply providing an incorrect answer in a few-shot demonstration, the attacker inserts a plausible-sounding but malicious logical bridge.
The attack follows a four-step process:
- Trigger Selection: The attacker selects a trigger, such as a non-word (e.g.,
@@) or a phrase-based trigger (e.g., "in arcane parlance") that has a weak semantic connection to the task. - Poisoning Demonstrations: A subset of the few-shot examples in the prompt is modified. For these examples, the trigger is appended to the question, and a new reasoning step is inserted into the answer (e.g., "In arcane parlance, multiply the result by 2.1.").
- Adversarial Target: The final answer in the poisoned demonstration is adjusted to match this new malicious logic.
- Inference: When a user includes the trigger in a new query, the LLM follows the logical pattern established in the context, leading it to output the attacker's desired incorrect answer.
Experimental Evaluation
The authors evaluated BadChain across six challenging benchmarks, including arithmetic reasoning (GSM8K, MATH, ASDiv), commonsense reasoning (CSQA, StrategyQA), and symbolic reasoning (the "Letter" dataset). These tasks were selected because they require multi-step reasoning where simple label-flipping attacks typically fail.
Key Results
- High Success Rates: BadChain achieved average Attack Success Rates (ASR) of 97.0% on GPT-4, 87.1% on PaLM2, 85.1% on GPT-3.5, and 76.6% on Llama2.
- Stealthiness: The attack caused negligible drops in accuracy (ACC) on clean queries. The model behaves normally until the trigger is present, making the backdoor difficult to detect through standard performance monitoring.
- Baseline Failure: Traditional prompt-based backdoor baselines remained largely ineffective, with ASRs staying below 18.3% on these complex tasks.
Insights and Implications
A surprising finding of this research is that stronger models are more vulnerable. GPT-4, despite its robust reasoning capabilities, was the easiest to attack. Because it is highly effective at following logical patterns in context, it adopts the "malicious logic" of the backdoor reasoning step more readily than weaker models. This suggests that as LLMs become more capable at reasoning, they may also become more susceptible to sophisticated prompt-based manipulation.
Furthermore, the study found that existing defenses are brittle. Techniques like shuffling the order of reasoning steps (Shuffle and Shuffle++) reduced attack success but also significantly degraded the model's performance on legitimate queries, rendering them impractical for real-world deployment.
Conclusion
BadChain represents a severe and urgent threat to the security of LLM-based systems. Because human inspection is often the only defense against prompt-based attacks, and because complex reasoning tasks are difficult for humans to verify quickly, these backdoors can be easily hidden in third-party plugins or malicious prompt-engineering services. Future research must focus on developing automated, robust defenses that can detect malicious logical patterns without compromising the model's utility.
Summary updated