ResearchPod Summary
Smart contracts deployed on Ethereum incur execution fees known as Gas, which scale directly with computational complexity. Inefficient code increases deployment and transaction costs, hindering decentralized application adoption. Traditional static analysis tools rely on rigid, predefined heuristic rules that fail to catch novel or compositionally complex gas wastage patterns, while standard large language models suffer from frozen training cutoffs and a tendency to hallucinate. To address these gaps, the authors propose RAGas, a three-stage retrieval-augmented generation framework that reframes gas optimization as a knowledge-guided reasoning task.
The RAGas pipeline decouples hypothesis generation from final diagnosis and knowledge integration. In the first stage, a dual-model hypothesis generator utilizing LLaMA-3.3 and DeepSeek-R1 analyzes target contract semantics to propose potential high gas consumption patterns alongside confidence scores and justifications. In the second stage, a two-step gating mechanism uses approximate nearest neighbor searches and semantic redundancy checks to dynamically update a vectorized knowledge base with newly discovered, high-confidence patterns. In the final stage, an LLM retrieves relevant structured knowledge patterns from this database to synthesize context-aware, optimized code and audit reports.
To evaluate RAGas, the authors constructed two distinct datasets. Dataset A comprises 300 real-world smart contracts used to measure practical gas optimization performance through metrics such as the Gas Reduction Percentage and Optimization Success Rate. Dataset B contains 300 synthetically generated smart contracts uniformly covering twelve predefined high gas consumption subcategories to rigorously test the system's precision, recall, F1-score, and compilation pass rate.
Experimental results demonstrate that RAGas successfully reduces gas usage by up to 11% on deployed contracts. Furthermore, the dual-model voting and confidence calibration strategies effectively suppress hallucinations, yielding high precision and recall in detecting code snippets that exhibit gas wastage while preserving functional equivalence.
Optimizing smart contract code is critical for the economic viability and user adoption of decentralized applications on Ethereum. By bridging the gap between rigid static analysis and ungrounded large language models, RAGas offers a self-evolving, context-aware solution that continuously adapts to emerging optimization best practices. This approach significantly lowers on-chain execution costs while maintaining high reliability and correctness.
AI-generated third-party summary by ResearchPod. Not official content or an endorsement by the paper authors or affiliated organizations.