LLM-SmartAudit: Advanced Smart Contract Vulnerability Detection

Zhiyuan Wei, Jing Sun, Zijiang Zhang, Xianhao Zhang, Meng Li, Zhe HouarXiv 2024

TL;DR

LLM-SmartAudit is a multi-agent framework that uses Large Language Models (LLMs) to automate smart contract security audits. By simulating a collaborative team of specialized agents—such as auditors and programming experts—it significantly outperforms traditional tools, particularly in identifying complex logic vulnerabilities that often lead to massive financial losses.

What Problem Does This Paper Address?

Smart contracts are immutable; once deployed on a blockchain, their code cannot be changed. This makes vulnerabilities incredibly dangerous, as seen in high-profile exploits like the DAO attack.

Traditional security tools (which use techniques like formal verification, symbolic execution, or fuzzing) are often "brittle"—they excel at finding specific, well-defined bugs but struggle with the nuanced, project-specific logic flaws that human auditors catch. However, human audits are prohibitively expensive and slow. While LLMs show promise in code analysis, a single LLM prompt often suffers from "degeneration-of-thought" or hallucinations. LLM-SmartAudit addresses this by organizing multiple LLM agents into a structured, conversational auditing team.

Methods

The core of LLM-SmartAudit is its Multi-agent Conversation Framework. Instead of one prompt, the system assigns specialized roles to different agents:

  • Project Manager: Sets goals and assess contract structure.
  • Smart Contract Counselor: Summarizes findings and provides guidance.
  • Auditor & Solidity Programming Expert: Collaborate to identify weaknesses and write reports.
Figure 1. Muliti-agent Conversation Framework

The system operates in two distinct modes:

  1. Broad Analysis (BA): Uses a Thought-Reasoning strategy (based on the ReAct framework) to perform a comprehensive scan for a wide range of potential issues.
  2. Targeted Analysis (TA): Uses a Buffer-Reasoning strategy (based on Buffer of Thoughts) to focus on 40 specific vulnerability scenarios. This mode retrieves relevant "thought templates" to guide the LLM through deep, step-by-step reasoning for complex issues like Transaction Order Dependence (TOD).

To ensure accuracy, the framework employs Role Swapping (where agents switch perspectives to challenge each other's findings) and a Consensus Mechanism to finalize reports.

Datasets

The authors evaluated their system using two primary datasets:

  • Labeled Dataset: A benchmark of 110 annotated contract cases covering 10 common vulnerability types (e.g., Reentrancy, Integer Overflow, Gas Limitation). This was used to compare LLM-SmartAudit against 10 traditional tools like Slither and Mythril.
  • Real-world Dataset: A massive collection of 6,454 contracts from 102 projects hosted on Code4rena, a leading competitive auditing platform. This dataset includes 1,408 vulnerabilities, many of which are "complex logic" flaws that led to actual exploits.

Key Insights and Ideas

  • Specialization Wins: Breaking the audit into distinct roles (Auditor vs. Programmer) allows the agents to challenge each other, reducing the false positives that plague single-agent LLM approaches.
  • Logic is the Frontier: Traditional tools had a 0% recall rate on the complex logic vulnerabilities in the real-world dataset. LLM-SmartAudit, by contrast, was able to reason about the intent of the code, catching nearly half of these flaws.
  • Strategic Prompting > Model Size: Interestingly, the authors found that the TA mode using GPT-3.5 could outperform a zero-shot GPT-4 in specific scenarios like detecting TOD. This suggests that the structure of the multi-agent interaction is as important as the underlying model's power.
  • Cost-Effectiveness: While human audits cost thousands of dollars, LLM-SmartAudit provides a fully automated audit for a maximum cost of approximately $1 USD per contract.

Key Results

  • Superior Recall: In the labeled benchmark, the BA mode achieved a 74% overall recall, significantly higher than the best traditional tool, Mythril (54%).
  • Real-World Impact: On the Code4rena dataset, the TA mode achieved a 47.55% recall on complex logic vulnerabilities, whereas traditional tools failed to detect any.
  • New Discoveries: The framework identified 11 new vulnerabilities in real-world projects that had already been audited by human experts. These included critical issues like "Unlimited Token Approval" and "Unchecked External Calls."
Figure 3. Task Queue in BA mode and TA mode

Limitations and Future Work

Despite its success, the authors note several hurdles:

  • Model Dependence: The system's effectiveness is capped by the reasoning capabilities and token limits of the underlying LLMs.
  • Static Analysis Constraints: Like other static tools, it may struggle with vulnerabilities that only manifest during dynamic execution.
  • Non-Exhaustive Scenarios: The TA mode currently covers 40 scenarios; while broad, it is not yet an exhaustive library of all possible blockchain exploits.

Future work will focus on integrating even more advanced LLMs, expanding the scenario library, and refining the collaborative algorithms to further reduce false negatives.

Summary updated

BibTeX
@misc{wei2024llm,
  author = {Zhiyuan Wei and Jing Sun and Zijiang Zhang and Xianhao Zhang and Meng Li and Zhe Hou},
  title = {{LLM-SmartAudit: Advanced Smart Contract Vulnerability Detection}},
  year = {2024},
  eprint = {2410.09381},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.09381},
}
Figure