skip to main content
research-article

Super-optimization of Smart Contracts

Published:12 July 2022Publication History
Skip Abstract Section

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 syrup 2.0. Through large-scale experiments on real-world smart contracts, we analyze performance improvements for different SMT encodings, as well as tradeoffs between quality of optimizations and required optimization time.

REFERENCES

  1. [1] 2018. Etherscan. https://etherscan.io.Google ScholarGoogle Scholar
  2. [2] 2018. Rattle - An EVM Binary Static Analysis Framework. https://github.com/crytic/rattle.Google ScholarGoogle Scholar
  3. [3] Ethereum. 2021. Solidity documentation. https://docs.soliditylang.org/en/latest/index.html.Google ScholarGoogle Scholar
  4. [4] Ethereum. 2021. Yul documentation. https://docs.soliditylang.org/en/latest/yul.html.Google ScholarGoogle Scholar
  5. [5] Albert Elvira, Correas Jesús, Gordillo Pablo, Román-Díez Guillermo, and Rubio Albert. 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), Biere Armin and Parker David (Eds.). 118125.Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. [6] Albert Elvira, Correas Jesús, Gordillo Pablo, Román-Díez Guillermo, and Rubio Albert. 2021. Don’t run on fumes–Parametric gas bounds for smart contracts. Journal of Systems and Software 176 (2021), 110923. Google ScholarGoogle ScholarCross RefCross Ref
  7. [7] Albert Elvira, Gordillo Pablo, Livshits Benjamin, Rubio Albert, and Sergey Ilya. 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), Lahiri Shuvendu and Wang Chao (Eds.). Springer, 513520. Google ScholarGoogle ScholarCross RefCross Ref
  8. [8] Albert Elvira, Gordillo Pablo, Rubio Albert, and Schett Maria A.. 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), Lahiri Shuvendu K. and Wang Chao (Eds.). Springer, 177200.Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. [9] Bofill Miquel, Nieuwenhuis Robert, Oliveras Albert, Rodríguez-Carbonell Enric, and Rubio Albert. 2008. The Barcelogic SMT solver. In Computer Aided Verification, 20th International Conference (CAV’08), Proceedings. 294298.Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. [10] Brain Martin, Crick Tom, Vos Marina De, and Fitch John P.. 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, 270284.Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. [11] Brandstätter T., Schulte S., Cito J., and Borkowski M.. 2020. Characterizing efficiency optimizations in solidity smart contracts. In 2020 IEEE International Conference on Blockchain (Blockchain’20). 281290. Google ScholarGoogle ScholarCross RefCross Ref
  12. [12] Chen Ting, Li Xiaoqi, Luo Xiapu, and Zhang Xiaosong. 2017. Under-optimized smart contracts devour your money. In SANER. IEEE Computer Society, 442446.Google ScholarGoogle Scholar
  13. [13] Chen Ting, Li Zihao, Zhou Hao, Chen Jiachi, Luo Xiapu, Li Xiaoqi, and Zhang Xiaosong. 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). 8184. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. [14] Cimatti Alessandro, Griggio Alberto, Schaafsma Bastiaan Joost, and Sebastiani Roberto. 2013. The MathSAT5 SMT solver. In Tools and Algorithms for the Construction and Analysis of Systems - 19th International Conference (TACAS’13), Proceedings. 93107.Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. [15] Moura Leonardo Mendonça de and Bjørner Nikolaj. 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), Ramakrishnan C. R. and Rehof Jakob (Eds.). Springer, 337340.Google ScholarGoogle ScholarCross RefCross Ref
  16. [16] Ethereum. 2018. Solidity. https://solidity.readthedocs.io.Google ScholarGoogle Scholar
  17. [17] Goodman L. M.. 2014. Tezos: A Self-Amending Crypto-Ledger Position Paper. (2014), 18.Google ScholarGoogle Scholar
  18. [18] Grech Neville, Kong Michael, Jurisevic Anton, Brent Lexi, Scholz Bernhard, and Smaragdakis Yannis. 2018. MadMax: Surviving out-of-gas conditions in Ethereum smart contracts. PACMPL 2, OOPSLA (2018), 116:1–116:27.Google ScholarGoogle Scholar
  19. [19] Jangda Abhinav and Yorsh Greta. 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. 7888. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. [20] Kiffer Lucianna, Levin Dave, and Mislove Alan. 2018. Analyzing Ethereum’s contract topology. In Proceedings of the Internet Measurement Conference 2018 (IMC’18). 494499.Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. [21] Labs Nomadic. 2018. Michelson: The Language of Smart Contracts in Tezos. https://www.michelson-lang.com.Google ScholarGoogle Scholar
  22. [22] Lattner Chris and Adve Vikram. 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 ScholarGoogle ScholarCross RefCross Ref
  23. [23] Lopes Nuno P., Menendez David, Nagarakatte Santosh, and Regehr John. 2018. Practical verification of peephole optimizations with Alive. Communications of the ACM 61, 2 (Jan. 2018), 8491. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. [24] Luu Loi, Chu Duc-Hiep, Olickel Hrishi, Saxena Prateek, and Hobor Aquinas. 2016. Making smart contracts smarter. In CCS. ACM, 254269.Google ScholarGoogle Scholar
  25. [25] Massalin Henry. 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). 122126. https://dl.acm.org/citation.cfm?id=36194.Google ScholarGoogle Scholar
  26. [26] Members Libra Association. 2019. White paper: The Libra Blockchain. 29.Google ScholarGoogle Scholar
  27. [27] Meudec Christophe. 2001. ATGen: Automatic test data generation using constraint logic programming and symbolic execution. Software Testing, Verifications and Reliability 11, 2 (2001), 8196.Google ScholarGoogle ScholarCross RefCross Ref
  28. [28] Mueller Bernhard. 2018. Smashing Ethereum smart contracts for fun and real profit. In The 9th Annual HITB Security Conference.Google ScholarGoogle Scholar
  29. [29] Mukherjee Manasij, Kant Pranav, Liu Zhengyang, and Regehr John. 2020. Dataflow-based pruning for speeding up superoptimization. Proceedings of the ACM on Programming Languages 4, OOPSLA (Nov. 2020), 124. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. [30] Mukhopadhyay Mayukh. 2018. Ethereum Smart Contract Development. Packt Publishing.Google ScholarGoogle Scholar
  31. [31] Nagele Julian and Schett Maria A.. 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 ScholarGoogle Scholar
  32. [32] Nakamoto Satoshi. 2008. Bitcoin: A peer-to-peer electronic cash system.Google ScholarGoogle Scholar
  33. [33] Pérez Daniel and Livshits Benjamin. 2019. Broken metre: Attacking resource metering in EVM. CoRR abs/1909.07220 (2019). arxiv:1909.07220 http://arxiv.org/abs/1909.07220.Google ScholarGoogle Scholar
  34. [34] Sasnauskas Raimondas, Chen Yang, Collingbourne Peter, Ketema Jeroen, Lup Gratian, Taneja Jubi, and Regehr John. 2017. Souper: A synthesizing superoptimizer. arXiv:1711.04422 [cs] (Nov. 2017). arxiv:1711.04422 [cs].Google ScholarGoogle Scholar
  35. [35] Schett Maria A. and Nagele Julian. 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), Bernardo Bruno and Marmsoler Diego (Eds.). Schloss Dagstuhl–Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 3:1–3:15. Google ScholarGoogle ScholarCross RefCross Ref
  36. [36] Sergey Ilya, Nagaraj Vaivaswatha, Johannsen Jacob, Kumar Amrit, Trunov Anton, and Hao Ken Chan Guan. 2019. Safer smart contract programming with Scilla. In 34th ACM SIGPLAN Conference on Object-Oriented Programming Systems, Languages and Applications (OOPSLA’19).Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. [37] Team The LibraBFT. 2020. Move: A Language With Programmable Resources. Technical Report. Novi. 27 pages. https://developers.libra.org/docs/state-machine-replication-paper.Google ScholarGoogle Scholar
  38. [38] Wood Gavin. 2019. Ethereum: A secure decentralised generalised transaction ledger.Google ScholarGoogle Scholar
  39. [39] Yang Renlord, Murray Toby, Rimba Paul, and Parampalli Udaya. 2019. Empirically analyzing Ethereum’s gas mechanism. In 2019 IEEE European Symposium on Security and Privacy Workshops (EuroS&P Workshops’19). 310319. Google ScholarGoogle ScholarCross RefCross Ref
  40. [40] Yu Xiao Liang, Al-Bataineh Omar, Lo David, and Roychoudhury Abhik. 2020. Smart contract repair. ACM Transactions on Software Engineering and Methodology 29, 4 (Sept. 2020), 27:1–27:32. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Super-optimization of Smart Contracts

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM Transactions on Software Engineering and Methodology
        ACM Transactions on Software Engineering and Methodology  Volume 31, Issue 4
        October 2022
        867 pages
        ISSN:1049-331X
        EISSN:1557-7392
        DOI:10.1145/3543992
        • Editor:
        • Mauro Pezzè
        Issue’s Table of Contents

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 12 July 2022
        • Online AM: 23 April 2022
        • Accepted: 1 December 2021
        • Revised: 1 September 2021
        • Received: 1 April 2021
        Published in tosem Volume 31, Issue 4

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article
        • Refereed

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Full Text

      View this article in Full Text.

      View Full Text

      HTML Format

      View this article in HTML Format .

      View HTML Format