SAEL: Leveraging Large Language Models with Adaptive Mixture-of-Experts for Smart Contract Vulnerability Detection

Lei Yu 2 3 1 , Shiqi Cheng 2 1 , Zhirong Huang 2 3 , Jingyuan Zhang 2 3 , Chenjie Shen 2 3 , Junyi Lu 2 3 , Li Yang 2 ∗ \ast , Fengjun Zhang 2 4 ∗ \ast , Jiajia Ma 2 · 2025

Read SAEL: Leveraging Large Language Models with Adaptive Mixture-of-Experts for Smart Contract Vulnerability Detection by Lei Yu 2 3 1 , Shiqi Cheng 2 1 , Zhirong Huang 2 3 , Jingyuan Zhang 2 3 , Chenjie Shen 2 3 , Junyi Lu 2 3 , Li Yang 2 ∗ \ast , Fengjun Zhang 2 4 ∗ \ast , Jiajia Ma 2 (2025) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2507-22371.txt.

Introduction

Lei Yu and co-authors hunt flaws in smart contracts in a 2025 paper. Smart contracts hold money on blockchains, so hidden flaws can be costly. Fixed rule checkers struggle with complex cases, while models tuned on one dataset often fail on new ones.

Large language models adapt well to new flaw patterns but lag tuned models on known flaw types. Their explanations, the authors note, also carry useful signal. The system, SAEL, routes each contract to a mix of expert parts that adapts per case. That routing aims to join the breadth of a general model with the sharpness of a specialist.

Catalog record

CREATORLei Yu 2 3 1 , Shiqi Cheng 2 1 , Zhirong Huang 2 3 , Jingyuan Zhang 2 3 , Chenjie Shen 2 3 , Junyi Lu 2 3 , Li Yang 2 ∗ \ast , Fengjun Zhang 2 4 ∗ \ast , Jiajia Ma 2
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE48 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2507-22371

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

SAEL: Leveraging Large Language Models with Adaptive Mixture-of-Experts for Smart Contract Vulnerability Detection Thanks: 1 Lei Yu and Shiqi Cheng contributed equally to this work. Thanks: ∗ Corresponding authors: Li Yang and Fengjun Zhang. Lei Yu 2 3 1 , Shiqi Cheng 2 1 , Zhirong Huang 2 3 , Jingyuan Zhang 2 3 , Chenjie Shen 2 3 , Junyi Lu 2 3 , Li Yang 2 ∗ \ast , Fengjun Zhang 2 4 ∗ \ast , Jiajia Ma 2 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, a LLM-based framework for smart contract vulnerability detection. First, we design prompts targeting specific smart contract vulnerabilities to guide general-purpose LLMs in detecting vulnerabilities and providing explanations. The detection results generated by LLMs serve as prediction features. Then, we employ prompt-tuning on CodeT5 and T5 respectively to process contract code and explanations, enhancing model performance on specific tasks. To leverage the strengths of each component, we introduce Adaptive Mixture-of-Experts, a dynamic architecture for smart contract vulnerability detection. This mechanism dynamically adjusts feature weights through a Gating Network, which selects the most relevant features by applying TopK filtering and Softmax normalization, and a Multi-Head Self-Attention mechanism, which enhances cross-feature relationships by processing multiple attention heads in parallel. This design ensures that prediction results for LLMs, explanation features, and contract code features are effectively integrated through gradient optimization. The loss function focuses on the independent prediction performance of each feature and the overall performance of weighted predictions. Experimental results show that SAEL outperforms existing methods in detecting various vulnerabilities. I Introduction Blockchain technology has grown rapidly and become popular across various sectors due to its decentralized nature [ 1 ] . As a significant innovation, blockchain allows for the creation of secure, decentralized, and distributed digital ledgers that record transactions [ 2 ] . By using cryptographic methods, blockchain ensures that each transaction is secure and verified, making it a highly dependable technology [ 3 , 4 ] . In particular, graph analysis techniques, including detecting criminal communities [ 5 ] and multi-scale anomaly detection [ 6 ] , play a crucial role in identifying irregular patterns and enhancing the security of blockchain networks. Smart contracts are automated programs on the blockchain that let developers create rules for managing digital assets like cryptocurrency. They automatically execute when specific conditions are met. Once these programs are deployed on the blockchain, they are permanent [ 7 ] . However, the unchangeable and complex nature of smart contracts means that their security challenges are increasingly evident [ 7 ] . The infamous DAO attack [ 8 , 9 , 10 , 11 , 12 ] illustrates the severe consequences of such vulnerabilities. This attack led to the unauthorized transfer of Ethereum worth 60 million dollars, causing significant disruptions in the blockchain community [ 13 , 14 ] . This highlights the critical need to enhance the security of smart contracts to avoid such crushing outcomes in the future. Researchers have developed various techniques to identify vulnerabilities in smart contracts. One popular approach is symbolic execution, which is implemented in tools such as Oyente [ 15 ] , Mythril [ 16 ] , Osiris [ 17 ] , and Manticore [ 18 ] . Another commonly used technique is static analysis, which is employed by tools like Slither [ 19 ] and SmartCheck [ 20 ] . However, these methods rely solely on fixed patterns and have poor generalizability. As shown in Fig. 1 , Slither incorrectly identifies a reentrancy vulnerability by detecting external calls and state variable modifications, but fails to consider the onlyOwner modifier that prevents such attacks, resulting in a false positive. Clear [ 21 ] adopts a Contrastive Learning (CL) model to learn complex relationships between contracts. Zhuang et al. [ 22 ] and Luo et al. [ 23 ] introduce a graph neural network-based approach that converts smart contract code into graph representations. However, the complexity of the graph structures employed in these techniques makes them difficult to reproduce and effectively represent programs. Peculiar [ 24 ] and PSCVFinder [ 25 ] achieve precise detection of smart contract vulnerabilities by fine-tuning pre-trained models. As shown in Fig. 2 , their detection capabilities for reentrancy and timestamp dependency vulnerabilities are superior to directly using general-purpose LLMs. However, they may struggle to handle scenarios not well-represented in the training data, exhibiting poor generalizability. As illustrated in Fig. 1 , specialized pre-trained models (PSCVFinder and Peculiar) fail to understand the role of the onlyOwner modifier in Fig. 1 , resulting in false positives. In contrast, general-purpose LLM correctly understands the function of the onlyOwner modifier, recognizing that the refund function is protected by the onlyOwner modifier. Even if investor.call.value(amount)() triggers a callback function of a malicious contract, that malicious contract cannot call the refund function again because it is not the contract owner. Consequently, general-purposed LLM correctly concludes that the contract does not contain a reentrancy vulnerability. This comparison highlights the complementary strengths of different approaches: general-purpose LLMs demonstrate superior capability in adapting to new vulnerability patterns, while specialized pre-trained models provide high performance for well-defined vulnerability types. We observe that explanations generated by general-purpose LLMs can serve as fine-grained code understanding information, improving the performance of smart contract vulnerability detection. As shown in Fig. 3 , for a specific contract, the general-purpose LLM (Qwen1.5-72B-Chat) identified a timestamp dependency vulnerability in the contract and provided explanations about the usage of block.timestamp (only used in a require statement), the structure and security checks of the function (constrained by two require statements), and the usage of state variables (read-only). These details allow for the analysis that the timestamp is only used for simple comparison, does not directly affect the state, and state variables are not modified. These inferences based on detailed explanations suggest that the contract may not actually contain a timestamp dependency vulnerability, which is consistent with the label. This insight motivates us to incorporate the explanation generated by general-purpose LLMs into smart contract vulnerability detection models. Based on these findings, we propose SAEL, an LLM-based smart contract vulnerability detection framework. First, we design prompts tailored to specific smart contract vulnerabilities to guide LLMs in analyzing smart contract code, detecting vulnerabilities, and providing fine-grained explanations. This addresses the poor generalizability of static analysis and pre-trained methods. The predictions generated by LLMs serve as predictive features. We conducted a comprehensive empirical study comparing the performance of different LLMs on reentrancy and timestamp dependency vulnerability datasets, as shown in Fig. 2 . We found that Qwen1.5-72B-Chat exhibits performance closest to GPT-4-Turbo in smart contract vulnerability detection. To balance

Read the complete text