TL;DR
This paper presents a comprehensive empirical study evaluating ChatGPT's ability to detect smart contract vulnerabilities. While ChatGPT achieves an impressive recall rate (up to 88.2%), its low precision (~22%) leads to a high volume of false positives, revealing critical limitations in its understanding of execution context and specialized blockchain semantics.
What Problem Does This Paper Address?
Smart contracts are self-executing, immutable protocols running on blockchain networks. Because they often handle massive financial assets and cannot be modified once deployed, any security flaw can lead to catastrophic financial losses.
Traditional vulnerability detection tools rely on static analysis, fuzzing, or symbolic execution. While useful, these tools are often constrained by rigid, predefined rules and struggle to grasp complex code semantics. Large Language Models (LLMs) like ChatGPT have demonstrated remarkable capabilities in general code analysis, prompting the authors to investigate a pivotal question: How far are we from reliably using ChatGPT for smart contract vulnerability detection?
Methods
The authors developed a multi-step empirical framework to evaluate three OpenAI models: gpt-3.5-turbo, gpt-4o, and gpt-4.
- Prompt Optimization: To maximize performance, the authors used GPT-4 as a "prompt optimizer" to refine their initial queries, establishing a clear role-play context for the model as a smart contract security auditor.
- Two-Step Detection & Analysis: LLMs typically generate conversational, non-standardized text. To systematically evaluate the outputs, the authors introduced a second LLM session acting as a "text semantic analyzer." This analyzer processed ChatGPT's textual findings and normalized them into a clean binary format (
1for vulnerability present,0for absent). - Robustness Testing: Beyond standard testing, the authors subjected the models to adversarial scenarios: code poisoning (injecting unused security modifiers or libraries to see if they trick the LLM) and character obfuscation (replacing characters with visually similar glyphs to test if the model relies purely on character-level semantics).
Datasets
The evaluation was conducted using the smartbugs-curated dataset, a widely recognized benchmark containing 142 vulnerable smart contracts. The dataset categorizes bugs based on the Decentralized Application Security Project (DASP10) taxonomy, covering nine major vulnerability types.
Key Insights and Ideas
- High Catch Rate, High Noise: ChatGPT acts like an over-cautious auditor. It is excellent at flagging potential issues (high recall) but struggles significantly with false alarms (low precision).
- The "Protected Mechanism" Blindspot: A major root cause of false positives is Protected Mechanism Bias. ChatGPT frequently flags a contract as vulnerable simply because it lacks common safety patterns (like OpenZeppelin's
SafeMathlibrary or theonlyOwnermodifier), even when the contract's specific logic makes those protections completely unnecessary. - Semantic Strengths vs. Syntactic Weaknesses: ChatGPT excels at identifying vulnerabilities rooted in complex business logic, such as Denial of Service (DoS) and Front Running—areas where traditional pattern-matching tools often fail. However, it struggles with low-level, EVM-specific quirks like Short Address Attacks.
- Susceptibility to Code Poisoning: The study revealed that attackers can easily deceive ChatGPT. By simply adding an unused
import SafeMathstatement or an uncalledonlyOwnermodifier, they can trick the model into overlooking actual vulnerabilities in up to 61.1% of cases.
Key Results
- Detection Metrics: GPT-4 achieved a powerful average recall rate of 88.2% (compared to 83.6% for GPT-4o and 51.4% for GPT-3.5). However, precision was low across all models, peaking at just 22.6% for GPT-4.
- Comparison to Specialized Tools: When pitted against 14 state-of-the-art traditional detection tools (e.g., Slither, Mythril, Oyente), ChatGPT demonstrated a clear advantage in detecting DoS and Front Running. However, for 3 out of the 7 evaluated vulnerabilities, its overall F1-score fell below the tool average.
- Efficiency: ChatGPT proved to be exceptionally fast, analyzing the entire dataset in 9 to 11 minutes and outperforming 11 out of the 14 traditional tools in speed.
Limitations and Future Work
The authors highlighted two primary bottlenecks preventing ChatGPT from being a standalone production tool:
- Output Uncertainty: ChatGPT is inherently non-deterministic. In a consistency test running the same prompt five times across 50 contracts, only 58% of the contracts returned completely stable results across all rounds.
- Context Length Restrictions: Due to strict token limits, ChatGPT suffers from detection failures when contracts are too long. The authors approximated the maximum reliable file size to be around 16KB for GPT-3.5 and 33KB for GPT-4.
To bridge these gaps, the authors suggest that future work should focus on exploring specialized code models (like Code LLaMA), utilizing Retrieval-Augmented Generation (RAG) to inject real-time domain knowledge, and fine-tuning LLMs on more diverse smart contract datasets.
Summary updated