arXiv:2610.18745cs.SEOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.18745

SolBehave: Evaluating the Behavioural Correctness of LLM-Generated Smart Contracts

Giovanni Pio Delvecchio, Stefano Fantazzini, Giacomo Frisoni, Gianluca Moro, Lorenzo Bacchiani, Mario Bravetti, Thomas Troels Hildebrandt

Giovanni Pio Delvecchio*, Stefano Fantazzini*, Giacomo Frisoni*, Gianluca Moro*, Lorenzo Bacchiani, Mario Bravetti, and Thomas Troels Hildebrandt

Abstract—Large language models increasingly generate Solidity smart contracts that, once deployed, can never be patched, making a single latent fault permanent and exploitable. Yet current evaluations mostly ask only whether generated code compiles. We introduce SolBehave, a benchmark for evaluating the correctness of model-generated contracts at scale, moving beyond ad hoc unit tests. Across 250 real, reproducible Ethereum contracts, we apply three complementary tests of behavioural fidelity: differential fuzzing, historical-transaction replay, and, as our core contribution, synthetic-transaction replay guided by a Dynamic Condition Response (DCR) graph that enumerates the space of legitimate function-call sequences. Differential fuzzing compares each generated function with the original on automatically generated inputs; historical replay compares the whole contract on the transactions it actually received on-chain; DCR-guided replay compares it on sequences of calls that follow its intended usage, including orderings that never occurred on-chain. We evaluate seven state-of-the-art open-weight models after one round of automated repair. Compilation success ranges from 26.4% to 92.7%, but under differential fuzzing only 31.4% of all generated function bodies that compile, pooled over models and samples, are equivalent to the original. Divergence at the contract level is the norm rather than the exception: for six of the seven models, between 13% and 31% of the generated contracts that compile diverge from the original under historical replay, and between 13% and 44% under DCR-guided replay; only Gemma-4-31B stays below 3% on both. Compilation is therefore a necessary condition for correctness and far from a sufficient one.

Index Terms—smart contracts, large language models, code generation, differential testing, dynamic condition response graphs, Solidity, Ethereum, behavioural fidelity, program synthesis evaluation.

I. INTRODUCTION

Smart contracts, programs deployed on a blockchain, increasingly govern real economic activity, and the stakes of getting them wrong have grown with it. The clearest example is tokenisation, the representation of a real-world or financial asset, such as a bond, a fund share, or a unit of real estate, as a digital token that is transferred and settled directly on-chain, without the intermediaries a traditional financial system relies on. What began as experimentation has become institutional practice: in 2021 the European Investment Bank issued a 100 million euro bond on Ethereum [1], the Bank

Giovanni Pio Delvecchio, Stefano Fantazzini, Giacomo Frisoni, Gianluca Moro, Mario Bravetti, and Lorenzo Bacchiani are with the University of Bologna, Bologna, Italy.

Thomas Troels Hildebrandt is with the University of Copenhagen, Copenhagen, Denmark.

*These authors contributed equally to this work (co-first authorship).

Manuscript received September 28, 2026.

The generated smart contract compiles.

Yet it does not behave correctly at run time.

Input: the smart contract skeleton

State variables + each function's signature, visibility, modifiers, NatSpec

contract Vault { uint256 public balance; bool public initialized; /// @notice Initialise the vault. function initialize() public { /* TODO / } /// @notice Add amount to the balance. function deposit(uint256 amount) public { / TODO / } /// @notice Withdraw amount from the balance. function withdraw(uint256 amount) public { / TODO */ } }

LLM completes each body, one at a time

LLM completion

function initialize() public { balance = 0; initialized = true; }

function deposit(uint256 amount) public { balance += amount; }

function withdraw(uint256 amount) public { if (!initialized) return; balance -= amount; }

silent no-op; no underflow guard

Human reference

function initialize() public { balance = 0; initialized = true; }

function deposit(uint256 amount) public { balance += amount; }

function withdraw(uint256 amount) public { require(initialized); require(balance >= amount); balance -= amount; }

Fig. 1. Compiling is not behaving. Given a Vault contract with its function bodies removed (top), a model regenerates them one at a time (bottom left), shown against the original implementation (bottom right). initialize and deposit are regenerated correctly (=); withdraw is not (≠). Both versions compile, so compile-rate metrics cannot tell them apart; the behavioural oracles of our benchmark are built to catch exactly this divergence.

for International Settlements has since identified tokenisation as a structural shift in how financial markets operate [2], and in 2024 the chief executive of BlackRock, the world's largest asset manager, stated that “the next generation for markets will be the tokenisation of every financial asset” [3], [4]. Nor is finance the only domain: supply chains, for instance, rely on the same guarantees of transparency and auditability, and IBM’s Food Trust platform cut Walmart’s mango-traceability time from seven days to 2.2 seconds [5]–[7]. The contracts behind these systems collectively secure digital assets worth billions of dollars 1^{1}, yet, unlike conventional software, they cannot be patched once deployed. Any bug present in the

1^{1}https://defillama.com/

This work has been submitted to the IEEE for possible publication. Copyright may be transferred without notice, after which this version may no longer be accessible.

bytecode at deployment is permanent and exploitable by anyone, so a single latent fault can cost real money, expose real users, and cannot be undone.

Large Language Models (LLMs) have demonstrated remarkable ability to generate syntactically valid Solidity code [8]–[10], and developers are increasingly integrating LLM-based code generation into smart contract workflows [8]. However, the dominant evaluation paradigm measures compilation success: whether the generated code compiles without errors. We argue that compilation is a necessary but insufficient filter: necessary because non-compiling code is unusable, but insufficient because syntactically correct Solidity can silently contain dangerous semantic faults that alter token ownership, destroy collected revenue, or enable financial attacks. Compilation says nothing about whether a contract behaves as intended, and it is precisely this behavioural gap that we target.

Since an arbitrary generated contract comes with no specification of correct behaviour other than the original it was regenerated from, the natural response is differential testing: deploy the generated contract and the original side by side on a sandboxed chain, submit the same calls to both, and flag any divergence in whether a call succeeds or reverts, in what it returns, in the events it emits, or in the storage state it leaves behind. What distinguishes differential-testing approaches is where the calls come from, and the literature has explored two sources. The first is historical transaction replay, adopted by SolContractEval [11]: the calls are the transactions that real users actually sent to the original contract on mainnet, replayed in their original order, so the test reflects how the contract was really used. The second is differential fuzzing, adopted by SolBench [10]: the calls are generated automatically by a fuzzer that searches the input space of each function for arguments on which the two implementations disagree, so the test covers inputs that no user ever sent. Both are sound and validated notions of behavioural correctness, and we adopt both. Yet neither can guarantee that the test reaches every state the contract is designed to enter. Historical replay preserves the order of real calls, but only of the calls that happened to occur: a state that no user ever brought about is never tested. Differential fuzzing explores each function's inputs in depth, but tests functions in isolation, so a state that can only be reached by combining several calls is never tested either.

Figure 1 shows why this matters, using a toy Vault contract. The missing balance check in the regenerated withdraw is reachable only after initialize has been called; once the vault is initialised, an over-withdrawal is rejected by the original but executed by the regenerated code, which, in the absence of checked arithmetic, corrupts storage silently. Historical replay exposes the fault only if some recorded transaction happened to call initialize before an over-withdrawal, and fuzzing tests withdraw on its own. In both cases the fault goes unreported, not because the two implementations agree, but because the test never reaches the state in which they disagree.

Rather than replacing either approach, this paper unifies them within a single framework and contributes a third, complementary oracle. We model the contract's intended lifecycle as a Dynamic Condition Response (DCR) graph [12], a lightweight declarative formalism that captures the condition, response, exclusion, and inclusion relations among contract events. The graph then steers test-sequence generation toward the prerequisite orderings that matter, exercising behaviours that neither historical traffic nor function-level fuzzing reaches.

This work addresses two gaps: the absence of a behavioural benchmark for LLM-generated smart contracts, and the lack of oracles able to detect behavioural divergence from a contract's intended functionality. Concretely:

  1. A family of three behavioural fidelity oracles (O1–O3) that complement the standard compile@k pre-filter. O1 applies differential fuzzing, asking whether each regenerated function remains equivalent to the original under coverage-guided input exploration. O2 replays historical mainnet transactions, asking whether the regenerated contract reproduces the behaviour observed on-chain. O3 replays test sequences synthesised from an LLM-extracted DCR graph of the contract's lifecycle, reaching states that historical traffic and unguided fuzzing miss.

  2. A neuro-symbolic transaction sequence generator that combines the permissive declarative semantics of DCR graphs with on-chain guard evaluation and LLM-guided parameter synthesis. An LLM extracts the DCR graph from the contract's source, and a deterministic graph-traversal algorithm enumerates legal event orderings and validates each call by executing it on the original contract, so correctness follows from the algorithm's guarantees rather than the model's output.

  3. An open behavioural benchmark and replication package available at https://github.com/disi-unibo-nlp/sol-behave (MIT license). It contains the 250 benchmark contracts with their deployment metadata, the DCR graph extracted for each contract, the transaction sequences, and the scripts to regenerate contracts and run the three metrics.

Applying the framework to seven state-of-the-art open-weight models yields three findings. First, compilation is a poor proxy for correctness: even after automated repair, the models compile between 26.4% and 92.7% of their contracts, but only a minority of the regenerated function bodies that compile are equivalent to the original under differential fuzzing (31.4%, pooled over models and samples), and for six of the seven models at least one regenerated contract in eight diverges from the original under each replay oracle. Second, the three oracles are complementary rather than redundant: each detects divergent contracts that the others accept as correct, because each exercises the contract differently. In particular, DCR-guided sequences call functions that real users never did, typically owner-only setup and administrative operations, on one contract in three; this holds regardless of which model extracts the graph. Third, LLM-extracted DCR graphs are reliable enough to drive the oracle: against human-annotated ground truth over four relation types (condition, exclusion, inclusion, response), extraction reaches 0.72 precision and 0.88 recall overall, and 0.96 precision on condition, the relation that governs call ordering.

Paper structure: Section II introduces the necessary blockchain and smart-contract background. Section III surveys related work. Section IV formalises the framework and its oracles. Section V reports the empirical results. Section VI discusses threats to validity. Section VII concludes.

References (26)