Abstract
With the increasing security issues in blockchain, smart contract vulnerability detection has become a research focus. Existing vulnerability detection methods have their limitations: 1) Static analysis methods struggle with complex scenarios. 2) Methods based on specialized pre-trained models perform well on specific datasets but have limited generalization capabilities. In contrast, general-purpose Large Language Models (LLMs) demonstrate impressive ability in adapting to new vulnerability patterns. However, they often underperform on specific vulnerability types compared to methods based on specialized pre-trained models. We also observe that explanations generated by general-purpose LLMs can provide fine-grained code understanding information, contributing to improved detection performance. Inspired by these observations, we propose SAEL, an LLM-based framework for smart contract vulnerability detection. We first design targeted prompts to guide LLMs in identifying vulnerabilities and generating explanations, which serve as prediction features. Next, we apply prompt-tuning on CodeT5 and T5 to process contract code and explanations, enhancing task-specific performance. To combine the strengths of each approach, we introduce an Adaptive Mixture-of-Experts architecture. This dynamically adjusts feature weights via a Gating Network, which selects relevant features using TopK filtering and Softmax normalization, and incorporates a Multi-Head Self-Attention mechanism to enhance cross-feature relationships. This design enables effective integration of LLM predictions, explanation features, and code features through gradient optimization. The loss function jointly considers both independent feature performance and overall weighted predictions. Experiments show that SAEL outperforms existing methods across various vulnerabilities.
Introduction
Smart contracts are the backbone of decentralized finance, but their "code is law" nature means a single bug can lead to irreversible multi-million dollar thefts. Current detection methods typically fall into three categories: static analysis, specialized pre-trained models, and general-purpose LLMs. Static tools like Slither are fast but often produce false positives due to a lack of high-level context. Specialized models excel at known patterns but struggle with generalization. General LLMs like GPT-4 offer deep logic understanding but often lack the surgical precision required for specific vulnerability types.
SAEL addresses these gaps by leveraging LLM-generated explanations as a core feature. The authors identify a key insight: an LLM's step-by-step reasoning is often more accurate than its final binary prediction. By treating these explanations as data, the framework can capture nuances that raw code analysis might miss.
The SAEL Framework
SAEL integrates three distinct information streams using an Adaptive Mixture-of-Experts (MoE) architecture. First, it uses Qwen1.5-72B-Chat with tailored prompts and Chain-of-Thought reasoning to generate code explanations. To ensure reliability, a "Mimic-in-the-Background" approach generates multiple responses and selects the most frequent one to mitigate hallucinations.
The framework extracts features from raw code (via prompt-tuned CodeT5), LLM explanations (via prompt-tuned T5), and the LLM's binary prediction. A Gating Network dynamically weights these features for each contract, using a TopK mechanism and Multi-Head Self-Attention to capture cross-feature relationships. This allows the model to learn when to trust high-level reasoning versus raw code patterns, such as recognizing when a potentially dangerous function is secured by an onlyOwner modifier.
Experimental Results
The researchers evaluated SAEL on over 200,000 real-world smart contracts across four major categories: Reentrancy, Timestamp Dependency, Integer Overflow/Underflow, and Delegatecall. SAEL consistently outperformed 12 state-of-the-art baselines, including Slither, Mythril, and specialized models like Peculiar.
Key results include F1-score improvements of +2.33% for Reentrancy and +13.32% for Delegatecall over the best baselines. Furthermore, SAEL maintained high performance (81%–92% F1-score) on entirely unseen data, demonstrating robust zero-shot generalization capabilities.
Conclusion
SAEL demonstrates that blending LLM reasoning with specialized experts significantly enhances smart contract security. While it requires substantial labeled data for fine-tuning and has higher computational overhead than static tools, its precision and contextual awareness represent a major step forward. Future work will explore unsupervised pre-training on massive unlabeled datasets to further refine the framework and reduce reliance on human-labeled examples.
Summary updated