Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3297280.3297322acmconferencesArticle/Chapter ViewAbstractPublication PagessacConference Proceedingsconference-collections
research-article

The treewidth of smart contracts

Published: 08 April 2019 Publication History

Abstract

Smart contracts are programs that are stored and executed on the Blockchain and can receive, manage and transfer money (cryptocurrency units). Two important problems regarding smart contracts are formal analysis and compiler optimization. Formal analysis is extremely important, because smart contracts hold funds worth billions of dollars and their code is immutable after deployment. Hence, an undetected bug can cause significant financial losses. Compiler optimization is also crucial, because every action of a smart contract has to be executed by every node in the Blockchain network. Therefore, optimizations in compiling smart contracts can lead to significant savings in computation, time and energy.
Two classical approaches in program analysis and compiler optimization are intraprocedural and interprocedural analysis. In intraprocedural analysis, each function is analyzed separately, while interprocedural analysis considers the entire program. In both cases, the analyses are usually reduced to graph problems over the control flow graph (CFG) of the program. These graph problems are often computationally expensive. Hence, there has been ample research on exploiting structural properties of CFGs for efficient algorithms. One such well-studied property is the treewidth, which is a measure of tree-likeness of graphs. It is known that intraprocedural CFGs of structured programs have treewidth at most 6, whereas the interprocedural treewidth cannot be bounded. This result has been used as a basis for many efficient intraprocedural analyses.
In this paper, we explore the idea of exploiting the treewidth of smart contracts for formal analysis and compiler optimization. First, similar to classical programs, we show that the intraprocedural treewidth of structured Solidity and Vyper smart contracts is at most 9. Second, for global analysis, we prove that the interprocedural treewidth of structured smart contracts is bounded by 10 and, in sharp contrast with classical programs, treewidth-based algorithms can be easily applied for interprocedural analysis. Finally, we supplement our theoretical results with experiments using a tool we implemented for computing treewidth of smart contracts and show that the treewidth is much lower in practice. We use 36,764 real-world Ethereum smart contracts as benchmarks and find that they have an average treewidth of at most 3.35 for the intraprocedural case and 3.65 for the interprocedural case.

References

[1]
Frances E Allen. 1970. Control flow analysis. In ACM Sigplan Notices, Vol. 5. ACM, 1--19.
[2]
Nicola Atzei, Massimo Bartoletti, and Tiziana Cimoli. 2017. A survey of attacks on ethereum smart contracts (sok). In POST 2017.
[3]
Domagoj Babic. 2008. Exploiting structure for scalable software verification. Ph.D. Dissertation. University of British Columbia, Vancouver, Canada.
[4]
Karthikeyan Bhargavan, Antoine Delignat-Lavaud, Fournet, et al. 2016. Formal verification of smart contracts: Short paper. In PLAS 2016.
[5]
Bitcoin Wiki. 2018. Script. https://en.bitcoin.it/wiki/Script.
[6]
Hans L Bodlaender. 1988. Dynamic programming on graphs with bounded treewidth. In ICALP 1988. Springer, 105--118.
[7]
Hans L Bodlaender. 1994. A tourist guide through treewidth. Acta cybernetica 11, 1--2 (1994), 1.
[8]
Bernd Burgstaller, Johann Blieberger, and Bernhard Scholz. 2004. On the tree width of ada programs. In International Conference on Reliable Software Technologies. Springer, 78--90.
[9]
Vitalik Buterin. 2018. A Next Generation Smart Contract and Decentralized Application Platform. Ethereum White Paper (2018).
[10]
Brad Calder and Dirk Grunwald. 1994. Reducing indirect function call overhead in C++ programs. In POPL 1994. ACM, 397--408.
[11]
Krishnendu Chatterjee, Amir Kafshdar Goharshady, and Ehsan Kafshdar Goharshady. 2019. The Treewidth of Smart Contracts. IST Publication Repository (2019). https://repository.ist.ac.at/1070/
[12]
Krishnendu Chatterjee, Amir Kafshdar Goharshady, Rasmus Ibsen-Jensen, and Andreas Pavlogiannis. 2016. Algorithms for algebraic path properties in concurrent systems of constant treewidth components. In POPL 2016. 733--747.
[13]
Krishnendu Chatterjee, Amir Kafshdar Goharshady, Rasmus Ibsen-Jensen, and Yaron Velner. 2018. Ergodic Mean-Payoff Games for the Analysis of Attacks in Crypto-Currencies. In CONCUR 2018. 11:1--11:17.
[14]
Krishnendu Chatterjee, Amir Kafshdar Goharshady, Nastaran Okati, and Andreas Pavlogiannis. 2019. Efficient Parameterized Algorithms for Data Packing. In POPL 2019.
[15]
Krishnendu Chatterjee, Amir Kafshdar Goharshady, and Andreas Pavlogiannis. 2017. JTDec: A Tool for Tree Decompositions in Soot. In ATVA 2017. 59--66.
[16]
Krishnendu Chatterjee, Amir Kafshdar Goharshady, and Yaron Velner. 2018. Quantitative Analysis of Smart Contracts. In ESOP 2018. 739--767.
[17]
Krishnendu Chatterjee, Rasmus Ibsen-Jensen, Amir Kafshdar Goharshady, and Andreas Pavlogiannis. 2018. Algorithms for Algebraic Path Properties in Concurrent Systems of Constant Treewidth Components. ACM Trans. Program. Lang. Syst. 40, 3 (2018), 9:1--9:43.
[18]
Krishnendu Chatterjee, Rasmus Ibsen-Jensen, and Andreas Pavlogiannis. 2015. Faster algorithms for quantitative verification in constant treewidth graphs. In CAV 2015. 140--157.
[19]
ConsenSys. 2018. Ethereum Smart Contract Best Practices. https://consensys.github.io/smart-contract-best-practices/software_engineering/
[20]
ConsenSys Diligence. 2018. Ethereum Smart Contract Best Practices - Known Attacks. https://consensys.github.io/smart-contract-best-practices/known_attacks/.
[21]
ConsenSys Team. 2018. Solidity Parser. https://github.com/ConsenSys/solidity-parser.
[22]
Marek Cygan, Fedor V Fomin, Łtukasz Kowalik, Daniel Lokshtanov, Dániel Marx, Marcin Pilipczuk, Michałt Pilipczuk, and Saket Saurabh. 2015. Parameterized algorithms. Springer.
[23]
Marek Cygan, Jesper Nederlof, Marcin Pilipczuk, Michal Pilipczuk, Joham MM van Rooij, and Jakub Onufry Wojtaszczyk. 2011. Solving connectivity problems parameterized by treewidth in single exponential time. In FOCS 2011. 150--159.
[24]
Nick D Dendris, Lefteris M Kirousis, and Dimitrios M Thilikos. 1997. Fugitive-search games on graphs and related parameters. Theoretical Computer Science 172, 1--2 (1997), 233--254.
[25]
Edsger W Dijkstra. 1960. Recursive programming. Numer. Math. 2, 1 (1960), 312--318.
[26]
Ethereum Foundation, Vitalik Buterin, et al. 2018. Vyper Language Documentation. https://vyper.readthedocs.io.
[27]
Ethernodes. 2018. The Ethereum Node Explorer. https://www.ethernodes.org.
[28]
Andrea Ferrara, Guoqiang Pan, and Moshe Y Vardi. 2005. Treewidth in verification: Local vs. global. In LPAR 2005. 489--503.
[29]
Amir Kafshdar Goharshady, Ali Behrouz, and Krishnendu Chatterjee. 2018. Secure Credit Reporting on the Blockchain. In IEEE International Conference on Blockchain.
[30]
Amir Kafshdar Goharshady and Fatemeh Mohammadi. 2017. A Short Note on Parameterized Computation of Network Reliability with respect to Treewidth. CoRR abs/1712.09692 (2017). http://arxiv.org/abs/1712.09692
[31]
Jens Gustedt, Ole A Mæhle, and Jan Arne Telle. 2002. The treewidth of Java programs. In ALENEX 2002. 86--97.
[32]
Philipp Klaus Krause. 2013. Optimal register allocation in polynomial time. In CC 2013. 1--20.
[33]
Philipp Klaus Krause. 2014. The complexity of register allocation. Discrete Applied Mathematics 168 (2014), 51--59.
[34]
Neeraj Kumar. 2015. Graph-theoretic Properties of Control Flow Graphs and Applications. Master's thesis. University of Waterloo.
[35]
Alexander Langer, Felix Reidl, Peter Rossmanith, and Somnath Sikdar. 2014. Practical algorithms for MSO model-checking on tree-decomposable graphs. Computer Science Review 13 (2014), 39--74.
[36]
Janusz Laski and William Stanley. 2009. Software verification and analysis: An integrated, hands-on approach. Springer Science & Business Media.
[37]
Loi Luu, Duc-Hiep Chu, Hrishi Olickel, Prateek Saxena, and Aquinas Hobor. 2016. Making smart contracts smarter. In CCS 2016. ACM, 254--269.
[38]
Zeinab Nehai, Pierre-Yves Piriou, and Frederic Daumas. 2018. Model-Checking of Smart Contracts. In IEEE International Conference on Blockchain. IEEE, 980--987.
[39]
Jan Obdržálek. 2003. Fast mu-calculus model checking when tree-width is bounded. In CAV 2003. Springer, 80--92.
[40]
Neil Robertson and Paul D Seymour. 1984. Graph minors. III. Planar tree-width. Journal of Combinatorial Theory, Series B 36, 1 (1984), 49--64.
[41]
Barbara G Ryder. 1979. Constructing the call graph of a program. IEEE Transactions on Software Engineering 3 (1979), 216--226.
[42]
Amitabha Sanyal, Bageshri Sathe, and Uday Khedker. 2009. Data flow analysis: theory and practice. CRC Press.
[43]
David Siegel. 2016. Understanding The DAO Attack. https://www.coindesk.com/understanding-dao-hack-journalists/.
[44]
Matthew Tan, Wee Chuan, Jann Yik, et al. 2018. Etherscan: The Ethereum Block Explorer. https://etherscan.io/.
[45]
Mikkel Thorup. 1998. All structured programs have small tree width and good register allocation. Information and Computation 142, 2 (1998), 159--181.
[46]
Petar Tsankov, Andrei Marian Dan, Dana Drachsler-Cohen, Arthur Gervais, Florian Bünzli, and Martin T. Vechev. 2018. Securify: Practical Security Analysis of Smart Contracts. In CCS 2018. 67--82.
[47]
Gavin Wood. 2018. Ethereum: A Secure Decentralised Generalised Transaction Ledger. Ethereum Yellow Paper (2018).
[48]
Gavin Wood et al. 2018. Solidity Language Documentation. https://solidity.readthedocs.io/en/v0.4.24/.
[49]
David Zimbeck,Sean Donato, et al. 2018. Bithalo, Mother of Smart Contracts and a Decentralized Market for Everything. http://bithalo.org.

Cited By

View all
  • (2024)Fast and Optimal Extraction for Sparse Equality GraphsProceedings of the ACM on Programming Languages10.1145/36898018:OOPSLA2(2551-2577)Online publication date: 8-Oct-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)SRNG: An Efficient Decentralized Approach for Secret Random Number Generation2024 IEEE International Conference on Blockchain and Cryptocurrency (ICBC)10.1109/ICBC59979.2024.10634454(615-619)Online publication date: 27-May-2024
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
SAC '19: Proceedings of the 34th ACM/SIGAPP Symposium on Applied Computing
April 2019
2682 pages
ISBN:9781450359337
DOI:10.1145/3297280
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].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 08 April 2019

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. blockchain
  2. compiler optimization
  3. control flow graphs
  4. parameterized algorithms
  5. program analysis
  6. smart contracts
  7. treewidth

Qualifiers

  • Research-article

Funding Sources

Conference

SAC '19
Sponsor:

Acceptance Rates

Overall Acceptance Rate 1,650 of 6,669 submissions, 25%

Upcoming Conference

SAC '25
The 40th ACM/SIGAPP Symposium on Applied Computing
March 31 - April 4, 2025
Catania , Italy

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)23
  • Downloads (Last 6 weeks)3
Reflects downloads up to 25 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Fast and Optimal Extraction for Sparse Equality GraphsProceedings of the ACM on Programming Languages10.1145/36898018:OOPSLA2(2551-2577)Online publication date: 8-Oct-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)SRNG: An Efficient Decentralized Approach for Secret Random Number Generation2024 IEEE International Conference on Blockchain and Cryptocurrency (ICBC)10.1109/ICBC59979.2024.10634454(615-619)Online publication date: 27-May-2024
  • (2024)Gas-Efficient Decentralized Random Beacons2024 IEEE International Conference on Blockchain and Cryptocurrency (ICBC)10.1109/ICBC59979.2024.10634373(205-209)Online publication date: 27-May-2024
  • (2024)Congesting Ethereum after EIP-15592024 IEEE International Conference on Blockchain and Cryptocurrency (ICBC)10.1109/ICBC59979.2024.10634352(667-669)Online publication date: 27-May-2024
  • (2024)Pixiu: Optimal Block Production Revenues on Cardano2024 IEEE International Conference on Blockchain (Blockchain)10.1109/Blockchain62396.2024.00072(491-496)Online publication date: 19-Aug-2024
  • (2024)Optimal blocks for maximizing the transaction fee revenue of Bitcoin minersJournal of Combinatorial Optimization10.1007/s10878-024-01249-049:1Online publication date: 19-Dec-2024
  • (2024)Faster Lifetime-Optimal Speculative Partial Redundancy Elimination for Goto-Free ProgramsDependable Software Engineering. Theories, Tools, and Applications10.1007/978-981-96-0602-3_21(382-398)Online publication date: 25-Nov-2024
  • (2023)Smart Contract Assisted Privacy-Preserving Data Aggregation and Management Scheme for Smart GridIEEE Transactions on Dependable and Secure Computing10.1109/TDSC.2023.330074921:4(2145-2161)Online publication date: 1-Aug-2023
  • (2023)Towards Adoption of Green Blockchain with Emphasis on Blockchain Type, Consensus Protocols, Data Sharding and Smart Contracts2023 IEEE International Conference on Blockchain and Distributed Systems Security (ICBDS)10.1109/ICBDS58040.2023.10346419(1-8)Online publication date: 6-Oct-2023
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media