Manuscript Offprint

arXiv:2609.02624

Automated Vulnerability Injection in Smart Contracts Using Large Language Models

Luca Migliaccio, Roberto Natella, Naghmeh Ivaki, Nuno Laranjeiro, Marco Vieira

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Luca Migliaccio, Roberto Natella Ⓤ, Naghmeh Ivaki Ⓤ, Nuno Laranjeiro Ⓤ, and Marco Vieira Ⓤ

Abstract—Assessing vulnerability detection tools for smart contracts requires datasets with known ground truth, yet such datasets are scarce and difficult to build by hand. We propose an approach that uses Large Language Models (LLMs) to automatically inject vulnerabilities into Solidity smart contracts, and demonstrate it in a case study targeting 49 vulnerability types from OpenSCV. Injected contracts are validated through a multi-step pipeline checking compilation, execution, business logic, and the presence of the intended vulnerability. Applied to real-world contracts from SmartBugs, LLMs generate nearly 1,000 candidate variants; after deduplication and validation, 32 confirmed vulnerable contracts spanning 25 vulnerability types survive (a 16.58% survival rate). Surviving contracts concentrate in structurally simpler targets and vulnerability types with localized syntactic patterns. We report practical challenges including LLMs' non-determinism and the difficulty of preserving contract semantics. We then use the validated contracts to assess three static analyzers, revealing complementary and incomplete coverage profiles. Results show that LLM-based vulnerability injection is feasible, while exposing key limitations in scalability and diversity.

Index Terms—Smart contracts, vulnerability injection, fault injection, large language models, Solidity, static analysis

I. INTRODUCTION

Smart contracts are a key component of modern blockchain platforms, where they carry out digital agreements automatically and without a trusted intermediary in domains such as Decentralized Finance (DeFi) [1], supply chain management, and digital identity [2]. However, their high economic value makes them attractive targets for malicious actors. Because smart contracts are immutable once deployed on the blockchain, any vulnerability in the source code can be exploited for profit, potentially causing significant financial losses [3]. Consequently, a substantial body of work has focused on developing automated vulnerability detection techniques, including static and dynamic analysis as well as artificial intelligence and Large Language Model (LLM) based approaches [4], [5].

A common challenge across all detection approaches is the difficulty of evaluating their effectiveness. How well these tools are evaluated matters in practice, since developers rely on them as an assurance mechanism before deploying code that

cannot be patched, and the confidence a tool deserves depends on how well its detection capabilities have been measured. Reliable evaluation requires datasets of smart contracts with known vulnerabilities. In practice, such datasets are scarce. Existing datasets are typically small, manually curated, and limited in the range of vulnerability types they cover [6], [7]. Furthermore, they are difficult to extend, as adding new vulnerability types or increasing the number of contracts requires repeating the same manual effort. This lack of large and extensible datasets limits the ability to compare vulnerability detection techniques and assess their real-world applicability. The problem is particularly severe for AI-based approaches, which require large volumes of labeled data to train and generalize effectively.

One way to address this gap is to artificially inject vulnerabilities into safe contracts, producing labeled datasets in which the ground truth is available by construction. Software fault injection has been used in other domains to assess system dependability [8] and security, for instance, through vulnerability injection in web applications [9] and through automated tools for large-scale vulnerability data generation in general-purpose software [10]. Vulnerability injection thus plays the same role for detection tools that fault injection plays in dependability evaluation, supplying a known reference against which their coverage can be judged.

In the context of smart contracts, the topic remains largely unexplored. Ghaleb and Pattabiraman [11] inject predefined bug patterns to evaluate static analysis tools, Iuliano et al. [12] propose a mutation-based approach to inject vulnerabilities into Solidity contracts, while Chu et al. [13] use generative adversarial networks to produce vulnerability fragments that are then inserted into contracts via abstract syntax tree manipulation. However, these approaches are typically limited to a small set of vulnerability types and lack a structured validation process to verify that the injected vulnerabilities are correct and realistic.

This paper proposes an approach for the automated injection of vulnerabilities into Solidity smart contracts using LLMs. The approach uses LLMs both to identify which vulnerabilities can be injected into a given contract and to perform the injection, and validates every injected contract before it is accepted into the resulting dataset. We evaluate the approach through a case study driven by the following research questions:

RQ1: How accurately can LLMs identify the injectability of different vulnerability types into real smart contracts?

RQ2: What proportion of vulnerabilities is correctly injected by LLMs, and which vulnerability types are most suitable for injection?

L. Migliaccio is with the Università degli Studi di Napoli Federico II, Naples, Italy (e-mail: lucamigliaccio2000@gmail.com).

R. Natella is with the Gran Sasso Science Institute (GSSI), L'Aquila, Italy (e-mail: roberto.natella@gssi.it).

N. Ivaki and N. Laranjeiro are with the University of Coimbra, CISUC/LASI, DEI, Portugal (e-mail: naghmeh@dei.uc.pt; cnl@dei.uc.pt).

M. Vieira is with the College of Computing and Informatics, University of North Carolina at Charlotte, Charlotte, NC, USA (e-mail: marco.vieira@charlotte.edu).

RQ3: Are LLM-injected contracts useful to analyze the detection capabilities of existing static analysis tools (SATs)?

The approach comprises three phases. Phase I selects target safe contracts and configures the experimental setup. Phase II uses one LLM to assess which vulnerability types can be injected into each contract, and a second LLM to perform the injection under predefined constraints. Phase III validates the injected contracts through compilation, injection verification, business logic verification, and vulnerability confirmation, producing a verified dataset, which is the final output of the approach. In the case study, we then use this dataset to analyze the detection capabilities of existing SATs.

The case study uses 14 safe Solidity smart contracts drawn from the SmartBugs dataset, spanning diverse application types and structural complexity profiles. Targeting 49 vulnerability types from the OpenSCV taxonomy [14], LLMs generate nearly 1,000 candidate vulnerable variants, which are then passed through a multi-step validation pipeline covering compilation, execution, business logic preservation, and manual vulnerability confirmation. All code, data, and scripts are publicly available in a replication package [15]. The main contributions of this work are the following:

An approach for LLM-based vulnerability injection into Solidity smart contracts, including multi-step validation that verifies compilation, constraint compliance, business logic integrity, and vulnerability correctness;

  • A case study evaluating the approach, including a characterization of the factors affecting injection success;

  • A demonstration that the verified dataset can be used to analyze the detection capabilities of SATs, revealing complementary and incomplete coverage profiles;

  • Practical lessons learned about model non-determinism, validation bottlenecks, injection diversity, and legacy-tool limitations.

In summary, the assessment stage is conservative and narrows the space of injection targets effectively, business logic preservation is the step that candidates are least likely to pass, and only a small fraction survive the full pipeline. Survivors concentrate in structurally simpler contracts and in vulnerability types with localized syntactic patterns. On the validated contracts, the static analysis tools show complementary but incomplete coverage, and several contracts cannot be analyzed at all because the tools fail on legacy Solidity code.

The remainder of this paper is organized as follows. Section II reviews related work on vulnerability detection in smart contracts and on fault and vulnerability injection, and positions our work with respect to it. Section III presents the proposed approach and its three phases. Section IV reports a case study that applies the approach to real-world contracts, from contract selection to the validated dataset, and closes with a demonstration that uses the dataset to compare static analysis tools. Section V discusses the lessons learned and their practical implications, Section VI covers the threats to validity, and Section VII concludes the paper.

References (26)

  • A survey of application research based on blockchain smart contract
  • Smart contracts in blockchain technology: A critical review
  • Smart contracts implementation, applications, benefits, and limitations
  • Vulnerability detection techniques for smart contracts: A systematic literature review
  • Leveraging machine learning models to improve smart contract security: A survey of vulnerabilities and detection methods
  • Smart contract vulnerability detection: The role of large language model (llm)
  • Lms in software security: A survey of vulnerability detection techniques and insights
  • Assessing dependability with software fault injection: A survey
  • Vulnerability & attack injection for web applications
  • VinJ: An automated tool for large-scale software vulnerability data generation
  • How effective are smart contract analysis tools? Evaluating smart contract static analysis tools using bug injection
  • Automated vulnerability injection in Solidity smart contracts: A mutation-based approach for benchmark development
  • SGDL: Smart contract vulnerability generation via deep learning
  • OpenSCV: An open hierarchical taxonomy for smart contract vulnerabilities
  • Automated vulnerability injection in smart contracts using large language models – supplementary material (opens the publisher in a new tab)
  • An empirical evaluation of the effectiveness of smart contract verification tools
  • Empirical review of automated analysis tools on 47,587 Ethereum smart contracts
  • SmartBugs 2.0: An execution framework for weakness detection in Ethereum smart contracts
  • GPTScan: Detecting logic vulnerabilities in smart contracts by combining GPT with program analysis
  • Analyzing the impact of elusive faults on blockchain reliability
  • Mutation-guided LLM-based test generation at Meta
  • Consolidation of ground truth sets for weakness detection in smart contracts
  • SuMo: A mutation testing approach and tool for the Ethereum blockchain
  • FORGE: An LLM-driven framework for large-scale smart contract vulnerability dataset construction
  • A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT
  • Orthogonal Defect Classification—A Concept for In-Process Measurements