用AI自动优化以太坊智能合约燃气消耗,持续学习新浪费模式。
RAGas: Retrieval-Augmented Gas Optimization for Smart Contracts with Continuous Knowledge Integration

- 基于检索增强生成框架,识别代码中导致燃气浪费的12种反模式。
- 实测可降低燃气用量最高达11%,检测精度与召回率均高。
- 适合区块链开发者和安全团队,持续优化合约部署成本。
以太坊现广泛应用于金融、医疗、供应链等关键领域,其执行费用(即燃气费)随函数计算复杂度上升而增加。智能合约的燃气开销与其计算复杂度正相关,因此在保持功能等价的前提下优化燃气密集型代码,可显著降低部署成本。现有系统无法持续利用不断演变的燃气使用模式。本文系统分析了导致燃气过度消耗的语法与语义结构,归纳出六大类共十二种细粒度反模式,并构建了专用知识库。据此提出RAGas框架,采用三阶段检索增强生成机制,借助大语言模型自动定位并修复燃气效率低下的代码片段。在已部署合约上的实验表明,RAGas可将燃气用量减少高达11%,且在检测燃气浪费代码片段方面具备高精度与高召回率。
原文摘要 · Abstract (English)
Ethereum is now integral to mission-critical sectors, including finance, healthcare, and supply chain management. Execution fees, commonly referred to as Gas, scale with the computational complexity of their functions. Smart contracts on Ethereum incur execution fees, known as Gas, which increase with computational complexity. Thus, optimizing Gas-intensive code while preserving functional equivalence significantly lowers deployment costs. No existing system continuously exploits evolving Gas usage patterns. We systematically analyze syntactic and semantic constructs that drive excessive Gas use. This yields six high-level categories covering twelve fine-grained antipatterns underpinning a curated knowledge base. We operationalize these insights with RAGas, a three-stage retrieval-augmented generation framework that uses a large language model to pinpoint and automatically fix Gas inefficiencies. Experiments on deployed contracts demonstrate that RAGas reduces Gas usage by up to 11% and achieves high precision and recall in detecting code snippets exhibiting Gas wastage.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。