Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Synthesis-powered optimization of smart contracts via data type refactoring

Published: 31 October 2022 Publication History

Abstract

Since executing a smart contract on the Ethereum blockchain costs money (measured in gas), smart contract developers spend significant effort in reducing gas usage. In this paper, we propose a new technique for reducing the gas usage of smart contracts by changing the underlying data layout. Given a smart contract P and a type-level transformation, our method automatically synthesizes a new contract P′ that is functionally equivalent to P. Our approach provides a convenient DSL for expressing data type refactorings and employs program synthesis to generate the new version of the contract. We have implemented our approach in a tool called Solidare and demonstrate its capabilities on real-world smart contracts from Etherscan and GasStation. In particular, we show that our approach is effective at automating the desired data layout transformation and that it is useful for reducing gas usage of smart contracts that use rich data structures.

References

[1]
Elvira Albert, Jesús Correas, Pablo Gordillo, Guillermo Román-Díez, and Albert Rubio. 2020. GASOL: Gas Analysis and Optimization for Ethereum Smart Contracts. In International Conference on Tools and Algorithms for the Construction and Analysis of Systems (TACAS). 12079, Springer, 118–125. https://doi.org/10.1007/978-3-030-45237-7_7
[2]
Elvira Albert, Pablo Gordillo, Albert Rubio, and Maria Anna Schett. 2020. Synthesis of Super-Optimized Smart Contracts Using Max-SMT. 177–200. https://doi.org/10.1007/978-3-030-53288-8_10
[3]
Elvira Albert, Pablo Gordillo, Albert Rubio, and Ilya Sergey. 2019. Running on Fumes - Preventing Out-of-Gas Vulnerabilities in Ethereum Smart Contracts Using Static Resource Analysis. In Proceedings of International Conference on Verification and Evaluation of Computer and Communication Systems (VECoS). Springer, 63–78. https://doi.org/10.1007/978-3-030-35092-5_5
[4]
Ittai Balaban, Frank Tip, and Robert M. Fuhrer. 2005. Refactoring support for class library migration. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming (OOPSLA). ACM, 265–279. https://doi.org/10.1145/1094811.1094832
[5]
Vitalik Buterin. 2014. Ethereum: A Next-Generation Smart Contract and Decentralized Application Platform. https://ethereum.org/en/whitepaper
[6]
Ting Chen, Xiaoqi Li, Xiapu Luo, and Xiaosong Zhang. 2017. Under-optimized smart contracts devour your money. In IEEE 24th International Conference on Software Analysis, Evolution and Reengineering (SANER). IEEE Computer Society, 442–446. https://doi.org/10.1109/SANER.2017.7884650
[7]
Ting Chen, Zihao Li, Hao Zhou, Jiachi Chen, Xiapu Luo, Xiaoqi Li, and Xiaosong Zhang. 2018. Towards saving money in using smart contracts. In 2018 IEEE/ACM 40th International Conference on Software Engineering: New Ideas and Emerging Technologies Results (ICSE-NIER). 81–84. https://doi.org/10.1145/3183399.3183420
[8]
Carlo Curino, Hyun Jin Moon, Alin Deutsch, and Carlo Zaniolo. 2013. Automating the database schema evolution process. VLDB J., 22, 1 (2013), 73–98. https://doi.org/10.1007/s00778-012-0302-x
[9]
Ankush Das, Stephanie Balzer, Jan Hoffmann, Frank Pfenning, and Ishani Santurkar. 2020. Language-Based Web Session Integrity. In Proceedings of the Computer Security Foundations Symposium (CSF). IEEE, 107–122. https://doi.org/10.1109/CSF49147.2020.00016
[10]
Ankush Das and Shaz Qadeer. 2020. Exact and Linear-Time Gas-Cost Analysis. 12389 (2020), 333–356. https://doi.org/10.1007/978-3-030-65474-0_15
[11]
Benjamin Delaware, Clément Pit-Claudel, Jason Gross, and Adam Chlipala. 2015. Fiat: Deductive Synthesis of Abstract Data Types in a Proof Assistant. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 689–700. https://doi.org/10.1145/2676726.2677006
[12]
Danny Dig, Stas Negara, Vibhu Mohindra, and Ralph E. Johnson. 2008. ReBA: refactoring-aware binary adaptation of evolving libraries. In Proceedings of the International Conference on Software Engineering (ICSE). ACM, 441–450. https://doi.org/10.1145/1368088.1368148
[13]
Ethereum. 2022. Ethereum Virtual Machine. https://ethereum.org/en/developers/docs/evm
[14]
Etherscan. 2022. https://etherscan.io
[15]
ETHGasStation. 2022. https://ethgasstation.info
[16]
Yu Feng, Ruben Martins, Osbert Bastani, and Isil Dillig. 2018. Program synthesis using conflict-driven learning. 420–435. https://doi.org/10.1145/3192366.3192382
[17]
John Feser, Sam Madden, Nan Tang, and Armando Solar-Lezama. 2020. Deductive optimization of relational data storage. Proceedings of the ACM on Programming Languages, 4, OOPSLA (2020), 1–30. https://doi.org/10.1145/3428238
[18]
Peter Hawkins, Alex Aiken, Kathleen Fisher, Martin C. Rinard, and Mooly Sagiv. 2011. Data representation synthesis. In Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 38–49. https://doi.org/10.1145/1993498.1993504
[19]
Peter Hawkins, Alex Aiken, Kathleen Fisher, Martin C. Rinard, and Mooly Sagiv. 2012. Concurrent data representation synthesis. In ACM SIGPLAN Conference on Programming Language Design and Implementation, (PLDI). ACM, 417–428. https://doi.org/10.1145/2254064.2254114
[20]
Johannes Henkel and Amer Diwan. 2005. CatchUp!: capturing and replaying refactorings to support API evolution. In Proceedings of the International Conference on Software Engineering (ICSE). ACM, 274–283. https://doi.org/10.1145/1062455.1062512
[21]
Bo Jiang, Ye Liu, and W. K. Chan. 2018. ContractFuzzer: fuzzing smart contracts for vulnerability detection. In Proceedings of the ACM/IEEE International Conference on Automated Software Engineering, (ASE). ACM, 259–269. https://doi.org/10.1145/3238147.3238177
[22]
Sukrit Kalra, Seep Goel, Mohan Dhawan, and Subodh Sharma. 2018. ZEUS: Analyzing Safety of Smart Contracts. In Proceedings of the Annual Network and Distributed System Security Symposium (NDSS). The Internet Society. https://doi.org/10.14722/ndss.2018.23082
[23]
Ameya Ketkar, Ali Mesbah, Davood Mazinanian, Danny Dig, and Edward Aftandilian. 2019. Type migration in ultra-large-scale codebases. In Proceedings of the International Conference on Software Engineering (ICSE). IEEE / ACM, 1142–1153. https://doi.org/10.1109/ICSE.2019.00117
[24]
Daniel Le Berre and Anne Parrain. 2010. The sat4j library, release 2.2, system description. Journal on Satisfiability, Boolean Modeling and Computation, 7 (2010), 59–64. https://doi.org/10.3233/SAT190075
[25]
Ao Li, Jemin Andrew Choi, and Fan Long. 2020. Securing smart contract with runtime validation. In Proceedings of the ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI). ACM, 438–453. https://doi.org/10.1145/3385412.3385982
[26]
Chu Min Li and Felip Manya. 2009. MaxSAT, Hard and Soft Constraints. Handbook of satisfiability, 185 (2009), 613–631. https://doi.org/10.3233/FAIA201007
[27]
Shaokai Lin, Xinyuan Sun, Jianan Yao, and Ronghui Gu. 2021. SciviK: A Versatile Framework for Specifying and Verifying Smart Contracts. CoRR, abs/2103.02209 (2021), arxiv:2103.02209. arxiv:2103.02209
[28]
Calvin Loncaric, Michael D. Ernst, and Emina Torlak. 2018. Generalized data structure synthesis. In Proceedings of the 40th International Conference on Software Engineering (ICSE). ACM, 958–968. https://doi.org/10.1145/3180155.3180211
[29]
Calvin Loncaric, Emina Torlak, and Michael D. Ernst. 2016. Fast synthesis of fast collections. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 355–368. https://doi.org/10.1145/2908080.2908122
[30]
Loi Luu, Duc-Hiep Chu, Hrishi Olickel, Prateek Saxena, and Aquinas Hobor. 2016. Making Smart Contracts Smarter. In Proceedings of the ACM SIGSAC Conference on Computer and Communications Security (CCS). ACM, 254–269. https://doi.org/10.1109/ICBC51069.2021.9461148
[31]
Inês Lynce and Joao P Marques-Silva. 2004. On computing minimum unsatisfiable cores. http://www.satisfiability.org/SAT04/programme/110.pdf
[32]
Benjamin Mariano, Yanju Chen, Yu Feng, Shuvendu K. Lahiri, and Isil Dillig. 2020. Demystifying Loops in Smart Contracts. In Proceedings of the International Conference on Automated Software Engineering (ASE). IEEE, 262–274. https://doi.org/10.1145/3324884.3416626
[33]
Joao Marques-Silva, Inês Lynce, and Sharad Malik. 2009. Conflict-driven clause learning SAT solvers. In Handbook of satisfiability. ios Press, 131–153. https://doi.org/10.3233/978-1-58603-929-5-131
[34]
John C Mitchell. 1991. On the equivalence of data representations. Artificial intelligence and mathematical theory of computation: papers in honor of John McCarthy, 305–330. https://doi.org/10.1016/b978-0-12-450010-5.50023-2
[35]
Julian Nagele and Maria A Schett. 2020. Blockchain Superoptimizer. arXiv preprint arXiv:2005.05912, arxiv:2005.05912
[36]
Shankara Pailoor, Yuepeng Wang, Xinyu Wang, and Isil Dillig. 2021. Synthesizing data structure refinements from integrity constraints. In Proceedings of the ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI). ACM, 574–587. https://doi.org/10.1145/3453483.3454063
[37]
Anton Permenev, Dimitar Dimitrov, Petar Tsankov, Dana Drachsler-Cohen, and Martin T. Vechev. 2020. VerX: Safety Verification of Smart Contracts. In IEEE Symposium on Security and Privacy (SP). IEEE, 1661–1677. https://doi.org/10.1109/SP40000.2020.00024
[38]
Xiaokang Qiu and Armando Solar-Lezama. 2017. Natural synthesis of provably-correct data-structure manipulations. Proceedings of the ACM on Programming Languages, 1, OOPSLA (2017), 65:1–65:28. https://doi.org/10.1145/3133889
[39]
Ilya Sergey, Vaivaswatha Nagaraj, Jacob Johannsen, Amrit Kumar, Anton Trunov, and Ken Chan Guan Hao. 2019. Safer smart contract programming with Scilla. Proceedings of the ACM on Programming Languages, 3, OOPSLA (2019), 185:1–185:30. https://doi.org/10.1145/3360611
[40]
Armando Solar-Lezama, Christopher Grant Jones, and Rastislav Bodík. 2008. Sketching concurrent data structures. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 136–148. https://doi.org/10.1145/1375581.1375599
[41]
Friedrich Steimann and Andreas Thies. 2009. From Public to Private to Absent: Refactoring Java Programs under Constrained Accessibility. In Proceedings of the European Conference on Object-Oriented Programming (ECOOP) (Lecture Notes in Computer Science, Vol. 5653). Springer, 419–443. https://doi.org/10.1007/978-3-642-03013-0_19
[42]
Frank Tip, Robert M. Fuhrer, Adam Kiezun, Michael D. Ernst, Ittai Balaban, and Bjorn De Sutter. 2011. Refactoring using type constraints. ACM Trans. Program. Lang. Syst., 33, 3 (2011), 9:1–9:47. https://doi.org/10.1145/1961204.1961205
[43]
Frank Tip, Adam Kiezun, and Dirk Bäumer. 2003. Refactoring for generalization using type constraints. In Proceedings of the ACM SIGPLAN Conference on Object-Oriented Programming Systems (OOPSLA). ACM, 13–26. https://doi.org/10.1145/949305.949308
[44]
Yuepeng Wang, James Dong, Rushi Shah, and Isil Dillig. 2019. Synthesizing database programs for schema refactoring. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 286–300. https://doi.org/10.1145/3314221.3314588
[45]
Yuepeng Wang, Shuvendu K. Lahiri, Shuo Chen, Rong Pan, Isil Dillig, Cody Born, Immad Naseer, and Kostas Ferles. 2019. Formal Verification of Workflow Policies for Smart Contracts in Azure Blockchain. In Proceedings of the International Conference on Verified Software. Theories, Tools, and Experiments (VSTTE) (Lecture Notes in Computer Science, Vol. 12031). Springer, 87–106. https://doi.org/10.1007/978-3-030-41600-3_7
[46]
Yuepeng Wang, Rushi Shah, Abby Criswell, Rong Pan, and Isil Dillig. 2020. Data Migration using Datalog Program Synthesis. Proceedings of the VLDB Endowment, 13, 7 (2020), 1006–1019. https://doi.org/10.14778/3384345.3384350
[47]
Gavin Wood. 2022. Ethereum: A Secure Decentralised Generalised Transaction Ledger. https://ethereum.github.io/yellowpaper/paper.pdf

Cited By

View all
  • (2024)SuperStack: Superoptimization of Stack-Bytecode via Greedy, Constraint-Based, and SAT TechniquesProceedings of the ACM on Programming Languages10.1145/36564358:PLDI(1437-1462)Online publication date: 20-Jun-2024
  • (2024)Semantic Code Refactoring for Abstract Data TypesProceedings of the ACM on Programming Languages10.1145/36328708:POPL(816-847)Online publication date: 5-Jan-2024
  • (2024)Code Optimization Strategies for Reducing Gas Costs in a Smart Contract Student Paper2024 23rd International Symposium INFOTEH-JAHORINA (INFOTEH)10.1109/INFOTEH60418.2024.10496035(1-6)Online publication date: 20-Mar-2024
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 6, Issue OOPSLA2
October 2022
1932 pages
EISSN:2475-1421
DOI:10.1145/3554307
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 31 October 2022
Published in PACMPL Volume 6, Issue OOPSLA2

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Data Type Refactoring
  2. Program Synthesis
  3. Smart Contract

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)224
  • Downloads (Last 6 weeks)21
Reflects downloads up to 18 Aug 2024

Other Metrics

Citations

Cited By

View all
  • (2024)SuperStack: Superoptimization of Stack-Bytecode via Greedy, Constraint-Based, and SAT TechniquesProceedings of the ACM on Programming Languages10.1145/36564358:PLDI(1437-1462)Online publication date: 20-Jun-2024
  • (2024)Semantic Code Refactoring for Abstract Data TypesProceedings of the ACM on Programming Languages10.1145/36328708:POPL(816-847)Online publication date: 5-Jan-2024
  • (2024)Code Optimization Strategies for Reducing Gas Costs in a Smart Contract Student Paper2024 23rd International Symposium INFOTEH-JAHORINA (INFOTEH)10.1109/INFOTEH60418.2024.10496035(1-6)Online publication date: 20-Mar-2024
  • (2024)Relational Synthesis of Recursive Programs via Constraint Annotated Tree AutomataComputer Aided Verification10.1007/978-3-031-65633-0_3(41-63)Online publication date: 26-Jul-2024
  • (2023)BiAn: Smart Contract Source Code ObfuscationIEEE Transactions on Software Engineering10.1109/TSE.2023.329860949:9(4456-4476)Online publication date: 1-Sep-2023

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media