<p>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 <b>MAGen</b>, an LLM-driven, multi-agent framework that embeds verification inside the generation loop via <i>structured prompting</i> and a requirements-to-contract (<i>R2C</i>) workflow. Five lightweight roles: Coordinator, Planner, Generator, Tester, and Synthesizer, operate a <b>Qwen3-8B</b> backbone under a <i>frozen toolchain</i>. 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 <InlineEquation ID="IEq1"> <EquationSource Format="TEX">\(11\)</EquationSource> </InlineEquation>-<InlineEquation ID="IEq2"> <EquationSource Format="TEX">\(40\)</EquationSource> </InlineEquation> cases achieve high coverage (median <InlineEquation ID="IEq3"> <EquationSource Format="TEX">\(96.4\%\)</EquationSource> </InlineEquation>), 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 <InlineEquation ID="IEq4"> <EquationSource Format="TEX">\(88.2\%\)</EquationSource> </InlineEquation>. 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.</p>

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

MAGen: Multi-agent smart contract generation with automated testing and verification

  • Lixue Liu,
  • Wei Ke,
  • Haiyang Chi,
  • Junjian Yan

摘要

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 \(11\) - \(40\) cases achieve high coverage (median \(96.4\%\) ), 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 \(88.2\%\) . 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.