Abstract
Smart contracts are programs deployed on a blockchain. They are executed for a monetary fee paid in gas—a clear optimization target for smart contract compilers. Because smart contracts are a young, fast-moving field without (manually) fine-tuned compilers, they highly benefit from automated and adaptable approaches, especially as smart contracts are effectively immutable, and as such need a high level of assurance. This makes them an ideal domain for applying formal methods. Super-optimization is a technique to find the best translation of a block of instructions by trying all possible sequences of instructions that produce the same result. We present a framework for super-optimizing smart contracts based on Max-SMT with two main ingredients: (1) a stack functional specification extracted from the basic blocks of a smart contract, which is simplified using rules capturing the semantics of arithmetic, bit-wise, and relational operations, and (2) the synthesis of optimized blocks, which finds—by means of an efficient SMT encoding—basic blocks with minimal gas cost whose stack functional specification is equal (modulo commutativity) to the extracted one.
We implemented our framework in the tool
- [1] 2018. Etherscan. https://etherscan.io.Google Scholar
- [2] 2018. Rattle - An EVM Binary Static Analysis Framework. https://github.com/crytic/rattle.Google Scholar
- [3] Ethereum. 2021. Solidity documentation. https://docs.soliditylang.org/en/latest/index.html.Google Scholar
- [4] Ethereum. 2021. Yul documentation. https://docs.soliditylang.org/en/latest/yul.html.Google Scholar
- [5] . 2020. GASOL: Gas analysis and optimization for Ethereum smart contracts. In Proceedings of 26th International Conference on Tools and Algorithms for the Construction and Analysis of Systems (TACAS’20)(
Lecture Notes in Computer Science , Vol. 12079), and (Eds.). 118–125.Google ScholarDigital Library - [6] . 2021. Don’t run on fumes–Parametric gas bounds for smart contracts. Journal of Systems and Software 176 (2021), 110923. Google ScholarCross Ref
- [7] . 2018. EthIR: A framework for high-level analysis of Ethereum bytecode. In 16th International Symposium on Automated Technology for Verification and Analysis (ATVA’18), Proceedings(
LNCS , Vol. 11138), and (Eds.). Springer, 513–520. Google ScholarCross Ref - [8] . 2020. Synthesis of super-optimized smart contracts using Max-SMT. In Computer Aided Verification - 32nd International Conference (CAV’20), Proceedings, Part I(
Lecture Notes in Computer Science , Vol. 12224), and (Eds.). Springer, 177–200.Google ScholarDigital Library - [9] . 2008. The Barcelogic SMT solver. In Computer Aided Verification, 20th International Conference (CAV’08), Proceedings. 294–298.Google ScholarDigital Library
- [10] . 2006. TOAST: Applying answer set programming to superoptimisation. In Logic Programming, 22nd International Conference (ICLP’06), Proceedings(
Lecture Notes in Computer Science , Vol. 4079). Springer, 270–284.Google ScholarDigital Library - [11] . 2020. Characterizing efficiency optimizations in solidity smart contracts. In 2020 IEEE International Conference on Blockchain (Blockchain’20). 281–290. Google ScholarCross Ref
- [12] . 2017. Under-optimized smart contracts devour your money. In SANER. IEEE Computer Society, 442–446.Google Scholar
- [13] . 2018. Towards saving money in using smart contracts. In Proceedings of the 40th International Conference on Software Engineering: New Ideas and Emerging Results (ICSE (NIER)’18). 81–84. Google ScholarDigital Library
- [14] . 2013. The MathSAT5 SMT solver. In Tools and Algorithms for the Construction and Analysis of Systems - 19th International Conference (TACAS’13), Proceedings. 93–107.Google ScholarDigital Library
- [15] . 2008. Z3: An efficient SMT solver. In Tools and Algorithms for the Construction and Analysis of Systems, 14th International Conference (TACAS’08)(
Lecture Notes in Computer Science , Vol. 4963), and (Eds.). Springer, 337–340.Google ScholarCross Ref - [16] . 2018. Solidity. https://solidity.readthedocs.io.Google Scholar
- [17] . 2014. Tezos: A Self-Amending Crypto-Ledger Position Paper. (2014), 18.Google Scholar
- [18] . 2018. MadMax: Surviving out-of-gas conditions in Ethereum smart contracts. PACMPL 2, OOPSLA (2018), 116:1–116:27.Google Scholar
- [19] . 2017. Unbounded superoptimization. In Proceedings of the 2017 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, Onward! 2017. 78–88. Google ScholarDigital Library
- [20] . 2018. Analyzing Ethereum’s contract topology. In Proceedings of the Internet Measurement Conference 2018 (IMC’18). 494–499.Google ScholarDigital Library
- [21] . 2018. Michelson: The Language of Smart Contracts in Tezos. https://www.michelson-lang.com.Google Scholar
- [22] . 2004. LLVM: A compilation framework for lifelong program analysis and transformation. In Proceedings of the International Symposium on Code Generation and Optimization: Feedback-Directed and Runtime Optimization(CGO’04). IEEE Computer Society, 75.Google ScholarCross Ref
- [23] . 2018. Practical verification of peephole optimizations with Alive. Communications of the ACM 61, 2 (
Jan. 2018), 84–91. Google ScholarDigital Library - [24] . 2016. Making smart contracts smarter. In CCS. ACM, 254–269.Google Scholar
- [25] . 1987. Superoptimizer - A look at the smallest program. In Proceedings of the 2nd International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS II’87). 122–126. https://dl.acm.org/citation.cfm?id=36194.Google Scholar
- [26] . 2019. White paper: The Libra Blockchain. 29.Google Scholar
- [27] . 2001. ATGen: Automatic test data generation using constraint logic programming and symbolic execution. Software Testing, Verifications and Reliability 11, 2 (2001), 81–96.Google ScholarCross Ref
- [28] . 2018. Smashing Ethereum smart contracts for fun and real profit. In The 9th Annual HITB Security Conference.Google Scholar
- [29] . 2020. Dataflow-based pruning for speeding up superoptimization. Proceedings of the ACM on Programming Languages 4, OOPSLA (
Nov. 2020), 1–24. Google ScholarDigital Library - [30] . 2018. Ethereum Smart Contract Development. Packt Publishing.Google Scholar
- [31] . 2019. Blockchain superoptimizer. In Preproceedings of 29th International Symposium on Logic-based Program Synthesis and Transformation (LOPSTR’19). https://arxiv.org/abs/2005.05912.Google Scholar
- [32] . 2008. Bitcoin: A peer-to-peer electronic cash system.Google Scholar
- [33] . 2019. Broken metre: Attacking resource metering in EVM. CoRR abs/1909.07220 (2019).
arxiv:1909.07220 http://arxiv.org/abs/1909.07220.Google Scholar - [34] . 2017. Souper: A synthesizing superoptimizer. arXiv:1711.04422 [cs] (
Nov. 2017).arxiv:1711.04422 [cs].Google Scholar - [35] . 2020. Populating the peephole optimizer of a smart contract compiler. In 2nd Workshop on Formal Methods for Blockchains (FMBC’20)(
OpenAccess Series in Informatics (OASIcs) , Vol. 84), and (Eds.). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 3:1–3:15. Google ScholarCross Ref - [36] . 2019. Safer smart contract programming with Scilla. In 34th ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA’19).Google ScholarDigital Library
- [37] . 2020. Move: A Language With Programmable Resources.
Technical Report . Novi. 27 pages. https://developers.libra.org/docs/state-machine-replication-paper.Google Scholar - [38] . 2019. Ethereum: A secure decentralised generalised transaction ledger.Google Scholar
- [39] . 2019. Empirically analyzing Ethereum’s gas mechanism. In 2019 IEEE European Symposium on Security and Privacy Workshops (EuroS&P Workshops’19). 310–319. Google ScholarCross Ref
- [40] . 2020. Smart contract repair. ACM Transactions on Software Engineering and Methodology 29, 4 (
Sept. 2020), 27:1–27:32. Google ScholarDigital Library
Index Terms
- Super-optimization of Smart Contracts
Recommendations
Formal Modeling and Verification of Smart Contracts
ICSCA '18: Proceedings of the 2018 7th International Conference on Software and Computer ApplicationsSmart contracts can automatically perform the contract terms according to the received information, and it is one of the most important research fields in digital society. The core of smart contracts is algorithm contract, that is, the parties reach an ...
Security Vulnerabilities in Ethereum Smart Contracts
iiWAS2018: Proceedings of the 20th International Conference on Information Integration and Web-based Applications & ServicesSmart contracts (SC) are one of the most appealing features of blockchain technologies facilitating, executing, and enforcing predefined terms of coded contracts without intermediaries. The steady adoption of smart contracts on the Ethereum blockchain ...
Blockchain smart contracts formalization: Approaches and challenges to address vulnerabilities
Highlights- Blockchain smart contracts formalization.
- Vulnerability aspects of smart ...
AbstractBlockchain as a distributed computing platform enables users to deploy pieces of software (known as smart contracts) for a wealth of next-generation decentralized applications without involving a trusted third-party. The advantages of ...
Comments