LoCEBERT: Transformer-Based Line-of-Code Embeddings for Smart Contract Code Understanding and Vulnerability Detection
Abstract
Smart contracts play a vital role in blockchain technology, but are vulnerable to security risks due to inadequate semantic representations of their source code. Current transformer-based approaches such as BERT, CodeBERT and CodeT5 excel in lexical and contextual understanding. However, they operate mainly at the token level. This limitation prevents the capture of relationships across multiple source code lines or functions. For instance, BERT and CodeBERT are restricted to 512 tokens, thereby causing truncation of longer sequences, loss of long-range dependencies and reduced vulnerability detection accuracy in complex contracts. To address these, we propose a Line-of-Code (LoC)-based embedding approach, treating each line as a separate entity to preserve program structure. Each line is encoded using CodeBERT, and embeddings are aggregated using summation pooling to retain global context. Experiments on the SmartBugs Solidity dataset validate the effectiveness of the approach. LoC embeddings improve clustering performance, increasing Silhouette Score to 0.0888 from 0.0252 and reducing Davies-Bouldin Index to 2.9521 from 5.2315. Vulnerability detection experiments achieved classification accuracy of 96.2%, outperforming token-level approaches at 87.3%. The proposed approach improves interpretability, scalability and vulnerability detection. Future research should explore larger datasets and additional blockchain codebases. These directions will strengthen robustness, performance and generalization capabilities.
Keywords
Ethical Statement
References
- N. A. Gupta, M. Bansal, S. Sharma, D. Mehrotra, and M. Kakkar, “Detection of vulnerabilities in blockchain smart contracts using deep learning,” Wireless Networks, vol. 31, no. 1, pp. 201–217, 2025, doi: 10.1007/s11276-024-03755-9.
- J. Yang, S. Liu, S. Dai, Y. Fang, K. Xie, and Y. Lu, “ByteEye: A smart contract vulnerability detection framework at bytecode level with graph neural networks,” Automated Software Engineering, vol. 33, no. 1, pp. 1–38, 2026.
- R. Agarwal, T. Thapliyal, and S. K. Shukla, “Vulnerability and transaction behavior based detection of malicious smart contracts,” in International Symposium on Cyberspace Safety and Security. Springer, 2021, pp. 79–96.
- T. Alladi, V. Chamola, R. M. Parizi, and K.-K. R. Choo, “Blockchain applications for industry 4.0 and industrial IoT: A review,” IEEE Access, vol. 7, pp. 176 935–176 951, 2019, doi: 10.1109/ACCESS.2019.2956748.
- J. F. Ferreira, P. Cruz, T. Durieux, and R. Abreu, “SmartBugs: A framework to analyze Solidity smart contracts,” in Proceedings of the 35th IEEE/ACM international conference on automated software engineering, 2020, pp. 1349–1352, doi: 10.1145/3324884.3415298.
- M. Bresil, P. Prasad, M. S. Sayeed, and U. A. Bukar, “Deep learning-based vulnerability detection solutions in smart contracts: A comparative and meta-analysis of existing approaches,” IEEE Access, vol. 13, pp. 28 894–28 919, 2025, doi: 10.1109/ACCESS.2025.3532326.
- J. Scharfman, “Decentralized autonomous organization (DAO) fraud, hacks, and controversies,” in The Cryptocurrency and Digital Asset Fraud Casebook, Volume II: DeFi, NFTs, DAOs, Meme Coins, and Other Digital Asset Hacks. Springer, 2024, pp. 65–106, doi: 10.1007/978-3-031-60836-0 3.
- K. Polak, “Hack solidity: Reentrancy attack,” 2022. [Online]. Available: https://hackernoon.com/hack-solidity-reentrancy-attack
Details
Primary Language
English
Subjects
Data Security and Protection, Artificial Intelligence (Other), Computer Software
Journal Section
Research Article
Authors
Kabir Umar
0009-0001-4040-8209
Nigeria
Aliyu Isah Agaie
0009-0009-5437-4431
Nigeria
Mubarak Umar
0000-0003-1317-9735
Nigeria
Early Pub Date
October 27, 2026
Publication Date
October 30, 2026
Submission Date
October 31, 2025
Acceptance Date
June 28, 2026
Published in Issue
Year 2026 Volume: 9 Number: 5