LoCEBERT: Transformer-Based Line-of-Code Embeddings for Smart Contract Code Understanding and Vulnerability Detection

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.

Authors

Institutions

Publication Details

Journal
Sakarya University Journal of Computer and Information Sciences
Published
2026-10-27
DOI
https://doi.org/10.35377/saucis...1810546
Primary Topic
Software Engineering Research
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

LoCEBERT: Transformer-Based Line-of-Code Embeddings for Smart Contract Code Understanding and Vulnerability Detection

Mubarak Umar, Aliyu Isah Agaie, Usman Bukar Usman, Mariya Kabir Umar
4 links
Sakarya University Journal of Computer and Information Sciences
Software Engineering Research
article

LoCEBERT: Transformer-Based Line-of-Code Embeddings for Smart Contract Code Understanding and Vulnerability Detection

Mubarak Umar, Aliyu Isah Agaie, Usman Bukar Usman, Mariya Kabir Umar
article en

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.

Sakarya University Journal of Computer and Information Sciences(Advanced Online Publication)
Bayero University Kano (NG)
Openalex Percentile: Top 6%
Software Engineering Research
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon