Seedlabs

GasSaturate: Equivalence-Guaranteed Gas Optimizer for Smart Contracts

A compiler add-on that rewrites a smart contract's arithmetic and boolean expressions into cheaper equivalent forms using e-graph equality saturation, with EVM gas as the cost function. Every emitted rewrite is provably behavior-preserving and ships with a machine-checkable equivalence certificate instead of a 'trust the optimizer' promise. New evidence strengthens the design — conditional rewrites for checked/unchecked arithmetic via versioned e-graphs, SMT-verified rule discovery, and a formal metatheory for e-graphs — while bounding one claim honestly: extraction is NP-hard, so the certificate guarantees equivalence, not global gas-optimality.

Computer ScienceLogic, programming, and type systems
Bandits with Side ObservationsBlockchain infrastructure: smart-contract development tooling (gas optimization) — a DeFi protocol team runs GasSaturate as a Foundry plugin in CI, rewriting DEX pricing and accounting math into cheaper equivalent Yul (with the ILP-optimal extraction pass reserved for the hottest functions) and attaching SMT-checkable equivalence certificates to the audit package so gas savings don't expand manual review scope.

Concept

A Foundry/Hardhat plugin that takes a contract's Yul IR (or expression-level Solidity) and runs equality saturation on it. The original expressions are inserted into an e-graph, a rewrite library is applied, and an extraction step selects the lowest-gas variant. E-graph rewriting is monotone — it only adds equalities and never destroys the original term — so every candidate the extractor returns is equivalent to what the developer wrote under the rewrite rules. That "provably equivalent" claim now rests on proven metatheory rather than implementation folklore: the Dis/Equality Graphs work proves for the first time that e-graphs are exactly the reflexive, symmetric, transitive, and congruent closure of the relation they encode, and its disequality extension lets the e-graph record term pairs that are provably not equivalent — e.g., expressions that diverge under uint256 wraparound — blocking unsound rewrites at the data-structure level rather than by convention.

Checked-arithmetic and side-effect flags are tracked per equivalence class with e-class analysis. Conditionally-valid rewrites — identities that hold only when operands are bounded so no overflow occurs, or only inside unchecked blocks — are handled with versioned e-graphs, which encode multiple equivalence sets simultaneously and share structure across them (reported 5-30% memory savings and up to 4x speedup over maintaining one e-graph per condition). This is a better fit for EVM arithmetic than e-class analysis alone.

The rewrite library is hybrid: a curated core plus auto-discovered rules. WeTune shows, in the database domain, that rewrite rules can be generated by enumerating expression plans up to a size bound and verified with an SMT-based equivalence checker; the same enumerate-and-verify loop transfers to the EVM by checking candidates under modular uint256/bitvector semantics instead of standard integer algebra — directly de-risking the concern that a hand-written rule silently assumes unbounded integers. SQLSolver demonstrates that SMT equivalence proving can be made principled rather than heuristic; its LIA* machinery is SQL-specific, so the EVM adaptation uses bitvector theories, which is an engineering bet rather than a demonstrated result.

Honest limits

  • Extraction optimality. Extraction from an e-graph is NP-hard in general; tools must choose between slow ILP-based optimal extraction and fast heuristics that may miss the optimum (recent work on sparse e-graphs improves the trade-off but not the hardness). GasSaturate therefore ships two modes — a default fast heuristic pass and an opt-in ILP-optimal pass for hot functions — and the emitted certificate guarantees equivalence, not global gas-optimality: "lowest gas" means lowest among the variants the extractor actually selected.
  • Domain transfer. The evidence for automated rule discovery and SMT equivalence verification comes from SQL query rewriting, not the EVM; modular bitvector arithmetic is a different (though SMT-supported) theory.
  • Still open: whether security auditors will accept the certificate in place of manual review of optimized bytecode; how to price state-dependent opcodes like SSTORE, whose cost depends on prior storage values (the cost function must be per-program-point, not a flat per-opcode table); and where existing Yul/LLVM-level optimizers already sit on the gas-efficiency frontier.

Why now

egg supplies the proven core: monotone equality saturation, extraction against a user-provided cost function (EVM gas is unusually clean and quantifiable), and e-class analysis. The new evidence closes specific gaps around it — a formal correctness metatheory with disequality support, a mechanism for conditional equalities that fits checked/unchecked arithmetic, and a demonstrated enumerate-and-verify pattern for growing the rule library safely. Remaining engineering risk is concentrated in the EVM language definition, the modular-arithmetic rule verifier, and the gas cost model — not in the core optimization machinery.

Written by GLM · 10 Oct 2026 · revised 1× with new research (latest 1 Nov 2026, Gemma 4 and GLM)

AI assessment

Backed by 8 papers84

A high-utility developer tool that applies formal equality saturation to EVM gas optimization, offering a strong value proposition through provable equivalence certificates that reduce audit overhead.

Evidence strength
4/5
The core machinery (egg, versioned e-graphs, disequality) is well-supported by recent research, though the application of SMT rule discovery from SQL to EVM bitvectors is an engineering leap.
Market pull
5/5
Gas optimization is a primary pain point for DeFi protocols where every unit of gas saved directly impacts user UX and protocol profitability.
Novelty & moat
4/5
While numeric rewriters exist (StableRewrite), applying equality saturation with formal certificates specifically for EVM gas costs is a distinct and novel approach.
Feasibility
3/5
Building the e-graph core is straightforward via 'egg', but defining a comprehensive, sound EVM rewrite library and integrating it into Foundry requires significant domain expertise.
Wedge clarity
5/5
The wedge is sharp: a Foundry plugin for optimizing hot arithmetic functions in DeFi contracts, providing a certificate to speed up the audit process.
Simplicity / focus
4/5
The product is focused on a single task (expression optimization) rather than attempting to be a full-scale compiler or general-purpose verifier.

Scored by Gemma 4 · 1 Nov 2026. Rated against a fixed rubric (evidence, market, novelty, feasibility, wedge, simplicity), relative to the closest ideas already in the catalog. A prior estimate to compare ideas before real-world signal arrives.

Act on this idea

Ideas only matter if someone runs with them. Your message goes straight to the founder's inbox — nothing is stored on our servers.

Business analysis

The framework reveals a high-technical-moat product that solves the 'trust gap' in smart contract optimization by replacing heuristic promises with formal equivalence certificates. While the core e-graph machinery is robust, the primary risks are the engineering translation of SMT-based rule discovery from SQL to EVM bitvector semantics and the willingness of auditors to accept automated proofs.

Strengths4

Weaknesses3

Opportunities3

Threats3

Essential for balancing the strong technical foundation of e-graphs against the internal risks of NP-hard extraction and domain transfer from SQL to EVM. · Generated 2026-11-01 by Gemma 4AI-generatedFull SWOT Analysis →

Who benefits

  • Its AMM contracts execute on every swap, so per-swap gas is a direct, user-visible cost; an equivalence-guaranteed expression optimizer with gas as the cost function maps straight onto its core codebase.

  • It ships contract libraries embedded in thousands of deployments, so gas reductions propagate ecosystem-wide and are a concrete selling point for the library's next major version.

  • OP Labscompany

    On Optimism, execution gas plus L1 data costs make contract efficiency central; provably semantics-preserving optimization reduces the review burden on performance PRs.

  • As a smart-contract audit firm it could offer 'verified gas optimization' as a service, using the equivalence certificate to cleanly separate semantics-preserving changes from behavior changes during reviews.

Research it builds on

  1. egg: Fast and Extensible Equality Saturation
    Max Willsey, Chandrakana Nandi, Yisu Remy Wang et al. · 2026 · 132 citations
    All ideas from this paper →
  2. WeTune: Automatic Discovery and Verification of Query Rewrite Rules
    Zhaoguo Wang, Zhou Zhou, Yicun Yang et al. · 2022 · 36 citations
    All ideas from this paper →
  3. Proving Query Equivalence Using Linear Integer Arithmetic
    Haoran Ding, Zhaoguo Wang, Yicun Yang et al. · 2023 · 20 citations
    All ideas from this paper →
  4. Fast and Optimal Extraction for Sparse Equality GraphsAll ideas from this paper →
  5. egg: Easy, Efficient, and Extensible E-graphs.
    Max Willsey, Yisu Remy Wang, Oliver Flatt et al. · 2020 · 3 citations
    All ideas from this paper →
  6. Dis/Equality GraphsAll ideas from this paper →
  7. egg: Fast and Extensible E-graphs
    Max Willsey, Yisu Remy Wang, Oliver Flatt et al. · 2020 · 1 citations
    All ideas from this paper →
  8. Versioned E-GraphsAll ideas from this paper →
Leave feedback
feasibility