Verified Smart Contract Generation with Agentic Testing and Gas Optimization
DOI:
https://doi.org/10.52152/Keywords:
Smart Contract Generation, Solidity, Program Verification, Gas Optimization, Vulnerability Detection, Multi-Agent Systems, Automated Software EngineeringAbstract
Smart contract development requires strict correctness because small coding errors may lead to financial loss, contract lockup, or exploitable vulnerabilities. Large language models can generate Solidity contracts from natural-language requirements, but the generated code may contain reentrancy risks, integer-handling errors, access-control flaws, inefficient storage operations, and incomplete event logic. This study investigates verified smart contract generation through agentic testing and gas optimization. We propose ContractAgent-V, a multi-agent model including a requirement formalization agent, a Solidity generation agent, a vulnerability inspection agent, a property-based testing agent, and a gas optimization agent. The requirement formalization agent extracts contract roles, state variables, transaction rules, permission constraints, and failure conditions. The Solidity generation agent produces deployable smart contracts. The vulnerability inspection agent checks the code against common weakness patterns and symbolic execution warnings. The property-based testing agent creates randomized transaction sequences to verify balance consistency, ownership restrictions, state transitions, and revert behavior. The gas optimization agent reduces unnecessary storage writes, simplifies modifiers, optimizes data structures, and removes redundant computations. Experiments were conducted on 1,120 smart contract tasks covering token issuance, escrow, crowdfunding, voting, staking, auction, access control, and decentralized marketplace logic. The benchmark included 6,720 generated contracts, 43,500 property-based tests, and 18,200 vulnerability probes. Compared with a single-agent Solidity generator, ContractAgent-V improved deployment success from 69.3% to 84.7% and functional test pass rate from 61.8% to 79.6%. High-severity vulnerability findings decreased from 15.2% to 4.9%, while access-control violations decreased by 58.1%. Gas consumption for core transaction functions decreased by 23.4% on average after optimization. These results suggest that agentic verification and gas-aware repair can improve the reliability and efficiency of automated smart contract development.
Downloads
Published
Issue
Section
License
Copyright (c) 2026 China and WTO Review

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
