TY - JOUR
T1 - MAGen
T2 - Multi-agent smart contract generation with automated testing and verification
AU - Liu, Lixue
AU - Ke, Wei
AU - Chi, Haiyang
AU - Yan, Junjian
N1 - Publisher Copyright:
© The Author(s), under exclusive licence to Springer Science+Business Media, LLC, part of Springer Nature 2026.
PY - 2027/2
Y1 - 2027/2
N2 - Smart contracts are self-executing programs on blockchains, yet reliance on manual development and expert audits imposes significant entry barriers and constrains throughput. While LLMs can synthesize code, practical generation still struggles with security, correctness, and maintaining long or complex context. We present MAGen, an LLM-driven, multi-agent framework that embeds verification inside the generation loop via structured prompting and a requirements-to-contract (R2C) workflow. Five lightweight roles: Coordinator, Planner, Generator, Tester, and Synthesizer, operate a Qwen3-8B backbone under a frozen toolchain. Code-centric agents are fine-tuned with LoRA, whereas coordination roles operate in the base mode. For each specification, MAGen jointly produces both the Solidity contract and its executable test suite. Within a Hardhat sandbox, the system compiles the code, executes the tests, records coverage and gas metrics, and aggregates findings from static analyzers (Slither, SmartCheck, Mythril). These signals are then shaped into constraints that guide subsequent decoding, establishing a closed generate–verify–repair loop. We evaluate along two axes: (i) an auxiliary held-out malicious-intent classification corpus, and (Ii) 100 user-style specifications spanning ERC20-like tokens, marketplaces, and regulatory workflows. Across 100 contracts, dynamic test suites of - cases achieve high coverage (median), with median pass rate 81.3% [75.3, 86.5]%, and reduced size-normalized static-warning density under the frozen analyzer stack. The usable-format rate is. On the auxiliary held-out task, MAGen raises recall to 2.18 times the baseline level with only a 0.015 absolute decrease in precision. In the generation benchmark, MAGen also lowers static-warning density under the same analyzer rules. Collectively, these results show that MAGen translates generic LLM competence into reproducible, automation-ready contract-and-test artifacts under a fixed validation protocol.
AB - Smart contracts are self-executing programs on blockchains, yet reliance on manual development and expert audits imposes significant entry barriers and constrains throughput. While LLMs can synthesize code, practical generation still struggles with security, correctness, and maintaining long or complex context. We present MAGen, an LLM-driven, multi-agent framework that embeds verification inside the generation loop via structured prompting and a requirements-to-contract (R2C) workflow. Five lightweight roles: Coordinator, Planner, Generator, Tester, and Synthesizer, operate a Qwen3-8B backbone under a frozen toolchain. Code-centric agents are fine-tuned with LoRA, whereas coordination roles operate in the base mode. For each specification, MAGen jointly produces both the Solidity contract and its executable test suite. Within a Hardhat sandbox, the system compiles the code, executes the tests, records coverage and gas metrics, and aggregates findings from static analyzers (Slither, SmartCheck, Mythril). These signals are then shaped into constraints that guide subsequent decoding, establishing a closed generate–verify–repair loop. We evaluate along two axes: (i) an auxiliary held-out malicious-intent classification corpus, and (Ii) 100 user-style specifications spanning ERC20-like tokens, marketplaces, and regulatory workflows. Across 100 contracts, dynamic test suites of - cases achieve high coverage (median), with median pass rate 81.3% [75.3, 86.5]%, and reduced size-normalized static-warning density under the frozen analyzer stack. The usable-format rate is. On the auxiliary held-out task, MAGen raises recall to 2.18 times the baseline level with only a 0.015 absolute decrease in precision. In the generation benchmark, MAGen also lowers static-warning density under the same analyzer rules. Collectively, these results show that MAGen translates generic LLM competence into reproducible, automation-ready contract-and-test artifacts under a fixed validation protocol.
KW - Large Language Models
KW - Multi-Agent Orchestration
KW - Prompt Engineering
KW - Smart Contract Generation
KW - Verification in the Loop
UR - https://www.scopus.com/pages/publications/105046058279
U2 - 10.1007/s10664-026-10931-2
DO - 10.1007/s10664-026-10931-2
M3 - Article
AN - SCOPUS:105046058279
SN - 1382-3256
VL - 32
JO - Empirical Software Engineering
JF - Empirical Software Engineering
IS - 1
M1 - 14
ER -