Researchers have built an AI system that hunts down gas-wasting code in Ethereum smart contracts and rewrites it automatically.
The tool, called RAGas, runs a three-stage retrieval-augmented generation pipeline. A large language model pulls from a curated knowledge base of six categories and twelve fine-grained gas-wasting patterns, flags the offending code in a contract, and proposes a fix that preserves the contract's original behavior. The researchers built that knowledge base by systematically cataloging the syntactic and semantic habits that drive up gas costs. In tests on already-deployed contracts, RAGas cut gas usage by up to 11% and showed high precision and recall at spotting wasteful snippets in the first place.
Gas fees scale directly with a contract's computational complexity, and they get paid every time the contract runs, so shaving that bill matters more than it sounds. What sets RAGas apart from static linters and one-off audits is the promise of continuous knowledge integration: instead of a fixed rule set, its pattern library is meant to keep absorbing new gas-wasting idioms as they show up in the wild.
Up to 11% is a ceiling pulled from a research paper, not an average from production use, so the honest read is a promising benchmark rather than a guaranteed discount on your next deployment.