Ensuring Gas Optimisation Correctness by Behavioural Equivalence
Gas consumption has a financial impact on executing Ethereum smart contracts, making gas optimisation an essential development concern. Although several optimisation techniques exist, applying them can alter contract behaviour, compromising correctness or introducing vulnerabilities. This work introduces a formal verification framework to ensure that gas-optimised contracts remain behaviourally equivalent to their originals. Our approach relies on the Certora Prover to mechanise correctness checking: a transformation rule is selected from our catalogue, applied to a Solidity contract, and verified in Certora. If an optimisation violates equivalence, counterexamples guide a diagnosis and correction. To support practical adoption, we compiled a catalogue of 31 gas-saving transformation rules, each featuring a formal pattern and an example alongside a Certora specification for automated verification. Building this catalogue revealed that two previously published optimisations require updates for Solidity 0.8.0 or superior. To evaluate practical applicability, we conducted a case study on the widely-adopted AAVE V3 DeFi protocol, applying our refinement-based methodology to formally prove the behavioural equivalence of optimised versions against the original. Although not fully automated, the framework is mostly mechanisable. Our results demonstrate that combining formal verification with gas-optimisation strategies is both feasible and effective for real-world smart contracts.
Authors
- Juliano Iyoda (ORCID: https://orcid.org/0000-0001-7137-8287)
- Alexandre Mota (ORCID: https://orcid.org/0000-0003-4416-8123)
- Márcio Cornélio (ORCID: https://orcid.org/0000-0002-9801-4659)
- Manoel Villarim (ORCID: https://orcid.org/0009-0005-6045-4519)
Institutions
- Universidade Federal de Pernambuco (BR)
Publication Details
- Journal
- ACM Transactions on Software Engineering and Methodology
- Published
- 2026-11-12
- DOI
- https://doi.org/10.1145/3859488
- Primary Topic
- Logic, programming, and type systems
- Type
- article
- Field-Weighted Citation Impact
- 0.00
Funders
- Conselho Nacional de Desenvolvimento Científico e Tecnológico
- Instituto Nacional de Ciência e Tecnologia para Engenharia de Software