Smart Contract Intent Detection with Pre-trained Programming Language Model Conference: Preprint; Aug 2025; arXiv

Youwei Huang, Jianwen Li, Sen Fang, Yao Li, Peng Yang, Bin Hu, Tao Zhang · 2025

Read Smart Contract Intent Detection with Pre-trained Programming Language Model Conference: Preprint; Aug 2025; arXiv by Youwei Huang, Jianwen Li, Sen Fang, Yao Li, Peng Yang, Bin Hu, Tao Zhang (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-2508-20086.txt.

Introduction

Youwei Huang and co-authors present a model that spots hidden bad intent in smart contracts. Smart contracts are programs that run deals on a blockchain, and bad code inside them has caused large losses. An earlier model flagged unsafe intent with fair scores. The new model adds a language model pre-trained on code, tuned on sixteen thousand real contracts. It keeps a two-way memory network to sort each contract's intents.

On ten thousand real contracts across ten intent classes, the new model scored far above the old one. Its F-score rose to about 0.93, with high marks for exactness and coverage. It also beat a top general AI model by a wide margin on this task. The authors present it as the new best tool for this check.

Catalog record

CREATORYouwei Huang, Jianwen Li, Sen Fang, Yao Li, Peng Yang, Bin Hu, Tao Zhang
YEAR2025
COLLECTIONPAPERS
FORMATTXT
FILE SIZE43 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2508-20086

Browse the full library · About the Tower of Babel

Full text

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

Smart Contract Intent Detection with Pre-trained Programming Language Model Conference: Preprint; Aug 2025; arXiv Youwei Huang, Jianwen Li, Sen Fang, Yao Li, Peng Yang, Bin Hu, Tao Zhang Abstract . Malicious intent in smart contract development can lead to substantial economic losses. SmartIntentNN is a deep learning model specifically designed to identify unsafe intents in smart contracts. This model integrates the Universal Sentence Encoder, a K-means clustering-based intent highlighting mechanism, and a Bidirectional Long Short-Term Memory network for multi-label classification, achieving an F1 of 0.8633 in distinguishing ten different intent categories. In this study, we present an upgraded version of this model, SmartIntentNN2 (Smart Contract Intent Neural Network V2). A significant enhancement in V2 is the incorporation of a BERT-based pre-trained language model, which has been trained on a dataset of 16,000 real smart contracts using a Masked Language Modeling objective. SmartIntentNN2 retains the BiLSTM-based multi-label classification network. With an improved F1 of 0.927, V2 demonstrates enhanced performance compared to its predecessor, establishing itself as the state-of-the-art model for smart contract intent detection. 1. Introduction Smart contracts serve as the foundational infrastructure for decentralized application (DApp) development ( szabo1996smart ; antonopoulos2018mastering ; ethereum2025smart ) , operating on various blockchain platforms, e.g. , Ethereum ( buterin2014next ; wood2014ethereum ) , Binance Smart Chain (BSC), Solana. These contracts enable decentralized financial services and automate on-chain transactions, fostering a trustless execution environment. However, the transparency and immutability of smart contracts also introduce significant risks. Vulnerabilities, as well as deliberately embedded malicious intent, can lead to severe economic losses for DApp users. While extensive research has been conducted on vulnerability detection in smart contracts ( he2020smart ; chu2023survey ; chen2025chatgpt ) , relatively little attention has been given to detecting the developer’s intent behind the code. To address this gap, SmartIntentNN was introduced as a deep learning-based approach for detecting unsafe development intents in smart contracts ( huang2022smartintentnn ; huang2025deep ) . This model’s architecture consists of three core components: (1) the Universal Sentence Encoder (USE) ( cer2018universal ) to generate contextual embeddings of smart contract source code, (2) a K-means clustering-based intent highlighting module to emphasize intent-related features, and (3) a Bidirectional Long Short-Term Memory (BiLSTM) network for multi-label classification of ten distinct categories of unsafe intent. Evaluations on 10,000 real smart contracts demonstrated that SmartIntentNN achieved an F1 of 0.8633, with an accuracy of 0.9647, a precision of 0.8873, and a recall of 0.8406. In this study, we introduce an enhanced version of this model, SmartIntentNN2 (Smart Contract Intent Neural Network V2). The primary improvement in V2 is the integration of a BERT-based pre-trained language model ( devlin2018bert ; liu2019roberta ) , specifically CodeBERT ( feng2020codebert ) , replacing the USE for embedding generation. The pre-trained model was initially trained on a corpus of 16,000 smart contracts using a Masked Language Modeling (MLM) objective to better capture the contextual semantics of smart contract code. It was subsequently fine-tuned via transfer learning for intent detection, incorporating a BiLSTM-based ( hochreiter1997long ; graves2005framewise2 ) multi-label classification network. SmartIntentNN2 was trained on 16,000 smart contracts and evaluated on an independent test set of 10,000 contracts. The results demonstrate that our model outperforms both traditional baselines and its predecessor, achieving an accuracy of 0.9789 , a precision of 0.9395 , a recall of 0.9149 , and an F1 of 0.9270 . These results establish SmartIntentNN2 as the state-of-the-art (SoTA) model for smart contract intent detection. Our contributions are as follows: • We upgraded SmartIntentNN from V1 to V2, enhancing its performance to achieve an F1 of 0.927 . • We trained a BERT-family pre-trained model, SmartBERT, specifically for generating smart contract embeddings. • We have open-sourced all dataset, code, documentation, and models at https://github.com/web3se-lab/web3-sekit . 2. Background This section introduces the technical background of this work, detailing the categories of unsafe development intents in smart contracts with representative samples, the methods for detecting these intents, and the use of pre-trained language models for code contextual representation. 2.1. Unsafe Intents in Smart Contracts Smart contracts, implemented as Turing-complete programming constructs on blockchain systems, enable the development of DApps. Solidity is the predominant language for smart contract programming, running on platforms such as Ethereum and BSC. While much attention has been given to vulnerabilities inadvertently introduced during development, we assert that intentionally embedded malicious code by developers also constitutes a significant contract flaw. Prior research has identified ten common categories of unsafe development intents in smart contracts, including Fee , DisableTrading , Blacklist , Reflect , MaxTX , Mint , Honeypot , Reward , Rebase , and MaxSell ( huang2025deep ) . ⬇ function setTxLimit ( uint256 amount ) external authorized { _maxTxAmount = amount ; } function setFees ( uint256 _liquidityFee , uint256 _reflectionFee , uint256 _marketingFee , uint256 _feeDenominator ) external authorized { liquidityFee = _liquidityFee ; reflectionFee = _reflectionFee ; marketingFee = _marketingFee ; totalFee = _liquidityFee . add ( _reflectionFee ). add ( _marketingFee ); feeDenominator = _feeDenominator ; require ( totalFee < feeDenominator / 4); } function tradingStatus ( bool _status ) public onlyOwner { tradingOpen = _status ; } Figure 1. A smart contract example exposing the intents of Fee, DisableTrading, and MaxTX. The contract address on BSC: 0x20BE792404240f34038d9b20eBCAEbFAA088ee20. In Figure 1 , we present several code snippets from a smart contract that exemplify some unsafe intents. The setTxLimit function allows for unrestricted changes to transaction limits, embodying the intent of MaxTX . This capability can be exploited to manipulate transaction volumes unfairly. The setFees function facilitates the adjustment of various fees, including liquidity, reflection, and marketing fees, corresponding to the Fee intent category, which may lead to unjust transaction costs. Most critically, the tradingStatus function empowers the contract owner to enable or disable trading at will, representing the DisableTrading intent. This functionality poses a significant threat, as it permits the owner to arbitrarily disrupt trading operations. Collectively, these functions reflect unsafe developer intents on the part of the developers and have the potential to cause economic harm to users. 2.2. Smart Contract Intent Detection Detecting intent within smart contracts is crucial for safeguarding against potential threats. SmartIntentNN ( huang2022smartintentnn ) is the pioneering model developed to address this challenge, employing a combination of advanced components to enhance detection accuracy. At its core, SmartIntentNN integrates the Universal Sentence Encoder for capturing contextual code representations, a K-means clustering model for spotlighting intent indicators, and a BiLSTM network for categorizing intents. Evaluated on 10,000 smart contracts, this model achieved an impressive F1 of 0.8633, significantly surpassing traditional deep learning baselines such as LSTM, CNN, and even some generative models like GPT. 2.3. Pre-trained Language Models Pre-trained language models have revolutionized natural language processing with models like BERT ( devlin2018bert ) , RoBERTa ( liu2019roberta ) , and CodeBERT ( feng2020codebert ) , which leverage large-scale self-supervised learning. These models are designed to generate robust contextual representations that are adaptable to various tasks via transfer learning, markedly reducing the demand for labeled data. In the realm of code analysis, CodeBERT stands out for its dual training on code and prose. Our work builds upon this by pre-training CodeBERT specifically on a substantial dataset of smart contracts, enhancing its ability to discern subtle semantic nuances pertinent

Read the complete text