[Paper Review] Blockchain Superoptimizer
This paper presents ebso, a superoptimizer for Ethereum Virtual Machine (EVM) bytecode that uses SMT solving to automatically discover cheaper, semantically equivalent bytecode sequences. By encoding EVM semantics into SMT formulas, ebso finds optimizations that reduce gas costs—saving up to 20,220 gas in a single case—demonstrating that SMT-based superoptimization is feasible and effective for real-world smart contracts.
In the blockchain-based, distributed computing platform Ethereum, programs called smart contracts are compiled to bytecode and executed on the Ethereum Virtual Machine (EVM). Executing EVM bytecode is subject to monetary fees---a clear optimization target. Our aim is to superoptimize EVM bytecode by encoding the operational semantics of EVM instructions as SMT formulas and leveraging a constraint solver to automatically find cheaper bytecode. We implement this approach in our EVM Bytecode SuperOptimizer ebso and perform two large scale evaluations on real-world data sets.
Motivation & Objective
- To address the high cost of executing smart contracts on Ethereum by automatically discovering cheaper bytecode sequences.
- To explore whether superoptimization via SMT solving is viable for EVM bytecode, given Ethereum’s clear gas cost model.
- To evaluate two superoptimization strategies—basic and unbounded—on real-world smart contracts to compare performance and optimization effectiveness.
- To identify and validate optimizations in both highly optimized competition contracts and the most frequently called contracts from the Ethereum mainnet.
- To analyze the limitations and biases of SMT solvers in superoptimization, especially regarding non-deterministic behavior and scalability.
Proposed method
- Encoding a subset of EVM instruction semantics into SMT formulas to enable formal reasoning over bytecode behavior.
- Implementing two superoptimization strategies: basic (enumerating candidate sequences and checking equivalence via SMT) and unbounded (encoding enumeration within the solver constraints).
- Using modern SMT solvers (e.g., CVC4, Vampire) to search for minimal-cost instruction sequences that preserve functional equivalence.
- Exporting generated SMT constraints in SMT-LIB format for benchmarking and solver comparison.
- Applying the tool to two real-world datasets: competition contracts (optimized for minimal gas) and the 2,500 most-called contracts on Ethereum mainnet.
- Caching and generalizing common optimization patterns to improve efficiency and support future peephole optimization integration.
Experimental results
Research questions
- RQ1Can SMT-based superoptimization effectively reduce EVM bytecode gas costs in real-world smart contracts?
- RQ2How do the basic and unbounded superoptimization strategies compare in terms of optimization coverage and performance on real Ethereum contracts?
- RQ3What types of optimizations are most commonly found, and what factors influence the solver’s ability to discover them?
- RQ4To what extent do SMT solver non-determinism and performance limits affect the discovery of optimal bytecode sequences?
- RQ5Can the tool identify previously unknown optimizations in highly optimized or production-grade smart contracts?
Key findings
- ebso discovered 19 optimizations in a competition dataset of already highly optimized smart contracts, demonstrating that even hand-optimized code can be further improved.
- On the 2,500 most-called contracts from Ethereum mainnet, the unbounded superoptimization (uso) approach found 943 optimizations, saving a total of 17,871 gas across all blocks.
- The basic superoptimization (bso) approach found 184 optimizations, saving 6,903 gas, with a higher average gas saving per block (46.1%) compared to uso (29.63%), due to its focus on smaller, high-impact blocks.
- Despite its higher optimization rate, bso proved optimal results in only 393 cases, while uso found optimal solutions in 943 cases, indicating its superior scalability and completeness.
- Surprisingly, bso found 21 optimizations that uso missed, all involving short, complex blocks with low gas cost (<10g), suggesting solver non-determinism can impact search outcomes.
- One of the most significant savings was found in a redundant storage access pattern: a 5,220g to 20,220g gas reduction by replacing a 5-instruction sequence with an empty program.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.