cs.AIAug 16, 2026

RAGas: Retrieval-Augmented Gas Optimization for Smart Contracts with Continuous Knowledge Integration

Authors: Yishun Wang, Wenjin Yi, Wenkai Li, Zongwei Li, Xiaoqi Li

Organizations: School of Cyberspace Security, Hainan University

Abstract

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.

Figures & tables

Explore similar work

CardsList
  1. SmartEval: A Benchmark for Evaluating LLM-Generated Smart Contracts from Natural Language Specifications

    May 10, 2026Abhinav Goel, Agostino Capponi, Alfio Gliozzo +1Code GenerationCode Generation Evaluation

  2. Knowdit: Agentic Smart Contract Vulnerability Detection with Auditing Knowledge Summarization

    Mar 27, 2026Ziqiao Kong, Wanxu Xia, Chong Wang +6Financial ServicesSoftware Vulnerability Detection

  3. CyberChainBench: Can AI Agents Secure Smart Contracts Against Real-World On-Chain Vulnerabilities?

    Jun 24, 2026Jintao Huang, Fengqing Jiang, Radha Poovendran +1Automated Program RepairSoftware Vulnerability Detection