Transformer model improves detection of Solidity smart contract bugs

Solidity Meets LLMs: A Transformer-Based Approach to Smart Contract Vulnerability Detection

Cryptography and SecuritySoftware Engineering

Summary

Smart contracts are computer programs that run on blockchain platforms like Ethereum and handle valuable transactions. The authors show that using a kind of AI called a transformer model, which has been trained on lots of text, can learn to spot vulnerabilities or bugs in pieces of these contracts written in Solidity programming language. They trained the model on a specially labeled dataset and found it was good at identifying unsafe code with high accuracy. This helps improve the security of smart contracts by finding risky code before attackers do.

What this means in practice

  • For blockchain developers: Detect vulnerabilities automatically in Solidity code fragments to enhance smart contract security during development.
  • For cybersecurity teams: Screen deployed smart contracts for risky patterns using transformer-based AI to reduce fraud and hacking incidents.

Authors

Djamel Eddine Hakim Ghorab, Farid Mokhati, Mostafa Anouar Ghorab

Abstract

The growing adoption of blockchain technologies, particularly the Ethereum platform, has amplified the critical role of smart contracts in decentralized applications. However, the increasing complexity and financial value of these contracts make them prime targets for cyber attacks. In this work, we present a transformer-based approach for the detection of vulnerabilities in smart contract fragments written in Solidity. Leveraging the representational power of pre-trained Large Language Models (LLMs), we construct a robust pipeline that includes the definition of a ground truth dataset, labeling code fragments as vulnerable or safe. We then fine-tune a BERT-based architecture on this dataset, enabling the model to capture the syntactic and semantic patterns specific to Solidity code. Our fine-tuned model demonstrates strong performance, achieving an F1 score of 92%, and highlighting the effectiveness of LLM adaptation in enhancing smart contract security through deep contextual understanding.