MAGen: Multi-agent smart contract generation with automated testing and verification
摘要
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