首个自动化以太坊合约气体优化多智能体系统,自动发现并验证节省气体的代码模式。
GasAgent: A Multi-Agent Framework for Automated Gas Optimization in Smart Contracts
- 四智能体协作闭环:发现、创新、执行、管理气体优化
- 实测100个合约中82个成功优化,平均节省9.97%部署气体
- 适用于LLM生成合约,对500个生成合约优化率达79.8%
智能合约是区块链上可信赖、不可变且自动执行的程序。其执行需依赖Gas机制以保障效率与公平性。然而,由于编码不规范,许多合约存在气体浪费问题,亟需优化。现有方法多依赖人工发现,效率低、维护成本高且难以扩展。近期研究尝试使用大语言模型(LLMs)探索新气体浪费模式,但难以兼容已有模式,常产生冗余模式,且需人工验证/重写。为此,我们提出GasAgent,首个用于智能合约气体优化的多智能体系统,结合对现有模式的兼容性与新模式的自动化发现与验证,实现端到端优化。GasAgent由四个专用智能体——探索者(Seeker)、创新者(Innovator)、执行者(Executor)和管理者(Manager)——组成,协同工作于闭环流程中,识别、验证并应用气体节省改进。在100个经验证的真实合约上的实验表明,GasAgent成功优化了82个合约,平均部署气体节省9.97%。此外,评估确认其与现有工具兼容,并通过消融实验验证各模块有效性。为评估更广泛适用性,我们进一步对五种代表性LLM生成的500个合约(涵盖10类)进行测试,发现GasAgent优化了79.8%的合约,部署气体节省范围为4.79%至13.93%,证明其作为LLM辅助智能合约开发优化层的实用性。
原文摘要 · Abstract (English)
Smart contracts are trustworthy, immutable, and automatically executed programs on the blockchain. Their execution requires the Gas mechanism to ensure efficiency and fairness. However, due to non-optimal coding practices, many contracts contain Gas waste patterns that need to be optimized. Existing solutions mostly rely on manual discovery, which is inefficient, costly to maintain, and difficult to scale. Recent research uses large language models (LLMs) to explore new Gas waste patterns. However, it struggles to remain compatible with existing patterns, often produces redundant patterns, and requires manual validation/rewriting. To address this gap, we present GasAgent, the first multi-agent system for smart contract Gas optimization that combines compatibility with existing patterns and automated discovery/validation of new patterns, enabling end-to-end optimization. GasAgent consists of four specialized agents, Seeker, Innovator, Executor, and Manager, that collaborate in a closed loop to identify, validate, and apply Gas-saving improvements. Experiments on 100 verified real-world contracts demonstrate that GasAgent successfully optimizes 82 contracts, achieving an average deployment Gas savings of 9.97%. In addition, our evaluation confirms its compatibility with existing tools and validates the effectiveness of each module through ablation studies. To assess broader usability, we further evaluate 500 contracts generated by five representative LLMs across 10 categories and find that GasAgent optimizes 79.8% of them, with deployment Gas savings ranging from 4.79% to 13.93%, showing its usability as the optimization layer for LLM-assisted smart contract development.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。