Skip to main navigation Skip to search Skip to main content

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

  • Lixue Liu
  • , Wei Ke
  • , Haiyang Chi
  • , Junjian Yan
  • Macao Polytechnic University
  • Chongqing University

Research output: Contribution to journal › Article › peer-review

Abstract

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.

Original languageEnglish
Article number14
JournalEmpirical Software Engineering
Volume32
Issue number1
DOIs
Publication statusPublished - Feb 2027

Keywords

  • Large Language Models
  • Multi-Agent Orchestration
  • Prompt Engineering
  • Smart Contract Generation
  • Verification in the Loop

Fingerprint

Dive into the research topics of 'MAGen: Multi-agent smart contract generation with automated testing and verification'. Together they form a unique fingerprint.

Cite this