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

Taming callbacks for smart contract modularity

Published: 13 November 2020 Publication History

Abstract

Callbacks are an effective programming discipline for implementing event-driven programming, especially in environments like Ethereum which forbid shared global state and concurrency. Callbacks allow a callee to delegate the execution back to the caller. Though effective, they can lead to subtle mistakes principally in open environments where callbacks can be added in a new code. Indeed, several high profile bugs in smart contracts exploit callbacks.
We present the first static technique ensuring modularity in the presence of callbacks and apply it to verify prominent smart contracts. Modularity ensures that external calls to other contracts cannot affect the behavior of the contract. Importantly, modularity is guaranteed without restricting programming.
In general, checking modularity is undecidable—even for programs without loops. This paper describes an effective technique for soundly ensuring modularity harnessing SMT solvers. The main idea is to define a constructive version of modularity using commutativity and projection operations on program segments. We believe that this approach is also accessible to programmers, since counterexamples to modularity can be generated automatically by the SMT solvers, allowing programmers to understand and fix the error.
We implemented our approach in order to demonstrate the precision of the modularity analysis and applied it to real smart contracts, including a subset of the 150 most active contracts in Ethereum. Our implementation decompiles bytecode programs into an intermediate representation and then implements the modularity checking using SMT queries. Overall, we argue that our experimental results indicate that the method can be applied to many realistic contracts, and that it is able to prove modularity where other methods fail.

Supplementary Material

Auxiliary Presentation Video (oopsla20main-p401-p-video.mp4)
This is a video presenting our OOPSLA 2020 paper "Taming Callbacks for Smart Contract Modularity". It discusses the motivation for reasoning about callbacks in smart contracts and the concept of "Effective Callback Freedom" (ECF), and a gentle overview to our sound technique for checking ECF.

References

[1]
Elvira Albert, Miguel Gómez-Zamalloa, Miguel Isabel, and Albert Rubio. 2018. Constrained Dynamic Partial Order Reduction. In Computer Aided Verification-30th International Conference, CAV 2018, Held as Part of the Federated Logic Conference, FloC 2018, Oxford, UK, July 14-17, 2018, Proceedings, Part II. 392-410.
[2]
Anonymized for the submission. 2020. Anonymized for the submission.
[3]
Nicola Atzei, Massimo Bartoleti, and Tiziana Cimoli. 2017. A Survey of Atacks on Ethereum Smart Contracts SoK. In Proceedings of the 6th International Conference on Principles of Security and Trust-Volume 10204. Springer-Verlag New York, Inc., New York, NY, USA, 164-186. https://doi.org/10.1007/978-3-662-54455-6_8
[4]
Kshitij Bansal, Eric Koskinen, and Omer Tripp. 2018. Automatic Generation of Precise and Useful Commutativity Conditions. In Tools and Algorithms for the Construction and Analysis of Systems, Dirk Beyer and Marieke Huisman (Eds.). Springer International Publishing, Cham, 115-132.
[5]
Gilles Barthe, Renate Eilers, Pamina Georgiou, Bernhard Gleiss, Laura Kovács, and Mateo Mafei. 2019. Verifying Relational Properties using Trace Logic. In 2019 Formal Methods in Computer Aided Design, FMCAD 2019, San Jose, CA, USA, October 22-25, 2019. 170-178.
[6]
Sidi Mohamed Beillahi, Gabriela Ciocarlie, Michael Emmi, and Constantin Enea. 2020. Behavioral Simulation for Smart Contracts. ( 2020 ), To appear.
[7]
Nick Benton. 2004. Simple relational correctness proofs for static analyses and program transformations. ACM SIGPLAN Notices 39, 1 ( 2004 ), 14-25.
[8]
Thomas Bernardi, Nurit Dor, Anastasia Fedotov, Shelly Grossman, Alexander Nutz, Lior Oppenheim, Or Pistiner, Mooly Sagiv, John Toman, and James Wilcox. 2020. Preventing Reentrancy Bugs-Another Use Case for Formal Verification. https://www.certora.com/blog/reentrancy.html.
[9]
Philip A. Bernstein, Vassos Hadzilacos, and Nathan Goodman. 1987. Concurrency Control and Recovery in Database Systems. Addison-Wesley.
[10]
Alina Bizga. 2020. A hackers' dream payday: Ledf.Me and Uniswap lose $25 million worth of cryptocurrency. https://securityboulevard.com/ 2020 /04/a-hackers-dream-payday-ledf-me-and-uniswap-lose-25-million-worthof-cryptocurrency/. [Online; accessed 11-May-2020].
[11]
Lexi Brent, Neville Grech, Sifis Lagouvardos, Bernhard Scholz, and Yannis Smaragdakis. 2020. Ethainter: A Smart Contract Security Analyzer for Composite Vulnerabilities. ( 2020 ), To appear.
[12]
Vitalik Buterin. 2016. CRITICAL UPDATE Re: DAO Vulnerability. https://blog.ethereum.org/ 2016 /06/17/critical-update-redao-vulnerability/. [Online; accessed 2-July-2017].
[13]
Ethan Ceccheti, Siqiu Yao, Haobin Ni, and Andrew Myers. 2020. Securing Smart Contracts with Information Flow. In Third International Symposium on Foundations and Applications of Blockchain 2020.
[14]
Consensys. 2019. Ethereum Smart Contract Best Practices. https://consensys.github.io/smart-contract-best-practices/ known_attacks/. [Online; accessed 14-May-2020].
[15]
Phil Daian. 2016. ( 2016 ). http://hackingdistributed.com/ 2016 /06/18/ analysis-of-the-dao-exploit/
[16]
Leonardo De Moura and Nikolaj Bjørner. [n.d.]. Z3: An Eficient SMT Solver. In Proceedings of the Theory and Practice of Software, 14th International Conference on Tools and Algorithms for the Construction and Analysis of Systems (Budapest, Hungary) ( TACAS'08/ETAPS'08). Springer-Verlag, Berlin, Heidelberg, 337-340.
[17]
Josselin Feist, Gustavo Grieco, and Alex Groce. 2019. Slither: a static analysis framework for smart contracts. In 2019 IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB). IEEE, 8-15.
[18]
Christof Ferreira Torres, Mathis Baden, Robert Norvill, and Hugo Jonker. 2019. ÆGIS: Smart Shielding of Smart Contracts. In Proceedings of the 2019 ACM SIGSAC Conference on Computer and Communications Security (London, United Kingdom) (CCS 19). Association for Computing Machinery, New York, NY, USA, 2589-2591.
[19]
Bernd Finkbeiner, Christopher Hahn, Marvin Stenger, and Leander Tentrup. 2019. Monitoring hyperproperties. Formal Methods Syst. Des. 54, 3 ( 2019 ), 336-363.
[20]
Cormac Flanagan and Shaz Qadeer. 2003. A type and efect system for atomicity. In Proceedings of the ACM SIGPLAN 2003 Conference on Programming Language Design and Implementation 2003, San Diego, California, USA, June 9-11, 2003. ACM, 338-349.
[21]
Ilya Grishchenko, Mateo Mafei, and Clara Schneidewind. 2018a. Foundations and Tools for the Static Analysis of Ethereum Smart Contracts. In Computer Aided Verification, Hana Chockler and Georg Weissenbacher (Eds.). Springer International Publishing, Cham, 51-78.
[22]
Ilya Grishchenko, Mateo Mafei, and Clara Schneidewind. 2018b. A Semantic Framework for the Security Analysis of Ethereum Smart Contracts. In Principles of Security and Trust, Lujo Bauer and Ralf Küsters (Eds.). Springer International Publishing, Cham, 243-269.
[23]
Shelly Grossman, Itai Abraham, Guy Golan-Gueta, Yan Michalevsky, Noam Rinetzky, Mooly Sagiv, and Yoni Zohar. 2018. Online detection of efectively callback free objects with applications to smart contracts. PACMPL 2, POPL ( 2018 ), 48 : 1-48 : 28.
[24]
Fernando Hernandez. 2019. Understanding Callbacks and Promises. https://dev.to/_ferh97/ understanding-callbacks-andpromises-3fd5. [Online; accessed 14-May-2020].
[25]
Hudson Jameson. 2019. Security Alert: Ethereum Constantinople Postponement. https://blog.ethereum.org/ 2019 /01/15/ security-alert-ethereum-constantinople-postponement/. [Online; accessed 11-May-2020].
[26]
Aashish Kolluri, Ivica Nikolic, Ilya Sergey, Aquinas Hobor, and Prateek Saxena. 2019. Exploiting the Laws of Order in Smart Contracts. In Proceedings of the 28th ACM SIGSOFT International Symposium on Software Testing and Analysis (Beijing, China) ( ISSTA 2019). ACM, New York, NY, USA, 363-373. https://doi.org/10.1145/3293882.3330560
[27]
Patrick Lam, Eric Bodden, Ondrej Lhoták, and Laurie Hendren. 2011. The Soot framework for Java program analysis: a retrospective.
[28]
Ao Li, Jemin Andrew Choi, and Fan Long. 2020. Securing Smart Contract with Runtime Validation. ( 2020 ), To appear.
[29]
Richard J. Lipton. 1975. Reduction: A Method of Proving Properties of Parallel Programs. Commun. ACM 18, 12 (Dec. 1975 ), 717-721.
[30]
Loi Luu, Duc-Hiep Chu, Hrishi Olickel, Prateek Saxena, and Aquinas Hobor. 2016. Making Smart Contracts Smarter. In Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security (Vienna, Austria) ( CCS '16). ACM, New York, NY, USA, 254-269.
[31]
Anastasia Mavridou and Aron Laszka. 2018. Tool Demonstration: FSolidM for Designing Secure Ethereum Smart Contracts. In Principles of Security and Trust, Lujo Bauer and Ralf Küsters (Eds.). Springer International Publishing, Cham, 270-277.
[32]
Ivica Nikolić, Aashish Kolluri, Ilya Sergey, Prateek Saxena, and Aquinas Hobor. 2018. Finding the greedy, prodigal, and suicidal contracts at scale. In Proceedings of the 34th Annual Computer Security Applications Conference. 653-663.
[33]
Daniel Palmer. 2018. SpankChain Loses $40K in Hack Due to Smart Contract Bug. https://www.coindesk.com/spankchainloses-40k-in-hack-due-to-smart-contract-bug. [Online; accessed 11-May-2020].
[34]
Michael Rodler, Wenting Li, Ghassan O. Karame, and Lucas Davi. 2019. Sereum: Protecting Existing Smart Contracts Against Re-Entrancy Atacks. In 26th Annual Network and Distributed System Security Symposium, NDSS 2019, San Diego, California, USA, February 24-27, 2019. The Internet Society. https://www.ndss-symposium.org/ndss-paper/sereumprotecting-existing-smart-contracts-against-re-entrancy-attacks/
[35]
Clara Schneidewind, Markus Scherer, Ilya Grishchenko, and Mateo Mafei. 2020. eThor: Practical and Provably Sound Static Analysis of Ethereum Smart Contracts. ( 2020 ), To appear.
[36]
Ilya Sergey and Aquinas Hobor. 2017. A Concurrent Perspective on Smart Contracts. In Financial Cryptography and Data Security, Michael Brenner, Kurt Rohlof, Joseph Bonneau, Andrew Miller, Peter Y.A. Ryan, Vanessa Teague, Andrea Bracciali, Massimiliano Sala, Federico Pintore, and Markus Jakobsson (Eds.). Springer International Publishing, Cham, 478-493.
[37]
Marcelo Sousa and Isil Dillig. 2016. Cartesian hoare logic for verifying k-safety properties. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2016, Santa Barbara, CA, USA, June 13-17, 2016. 57-69.
[38]
Synthetix. 2020. Synthetix-Decentralised synthetic assets. www.synthetix.io.
[39]
The Concourse Open Community. 2019. DeFi Pulse. https://defipulse.com/. [Online; accessed 11-May-2020].
[40]
S. Tikhomirov, E. Voskresenskaya, I. Ivanitskiy, R. Takhaviev, E. Marchenko, and Y. Alexandrov. 2018. SmartCheck: Static Analysis of Ethereum Smart Contracts. In 2018 IEEE/ACM 1st International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB). 9-16.
[41]
Omer Tripp, Roman Manevich, John Field, and Mooly Sagiv. 2012. JANUS: exploiting parallelism via hindsight. In ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ' 12, Beijing, China-June 11-16, 2012, Jan Vitek, Haibo Lin, and Frank Tip (Eds.). ACM, 145-156.
[42]
Petar Tsankov, Andrei Dan, Dana Drachsler-Cohen, Arthur Gervais, Florian Bünzli, and Martin Vechev. 2018. Securify: Practical Security Analysis of Smart Contracts. In Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security (Toronto, Canada) ( CCS '18). ACM, New York, NY, USA, 67-82. https://doi.org/10.1145/ 3243734.3243780
[43]
Cooper Turley. 2020. imBTC Uniswap Pool Drained for $300k in ETH. https://defirate.com/imbtc-uniswap-hack/. [Online; accessed 11-May-2020].
[44]
Chao Wang, Zijiang Yang, Vineet Kahlon, and Aarti Gupta. 2008. Peephole Partial Order Reduction. In Tools and Algorithms for the Construction and Analysis of Systems, 14th International Conference, TACAS 2008, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2008, Budapest, Hungary, March 29-April 6, 2008. Proceedings. 382-396.
[45]
Liqiang Wang and Scot D. Stoller. 2005. Static analysis of atomicity for programs with non-blocking synchronization. In Proceedings of the ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, PPOPP 2005, June 15-17, 2005, Chicago, IL, USA. ACM, 61-71. https://doi.org/10.1145/1065944.1065953
[46]
Yuepeng Want, Shuvendu Lahiri, Shuo Chen, Rong Pan, Isil Dillig, Cody Bprb, and Immad Naseer. 2019. Formal Specification and Verification of Smart Contracts for Azure Blockchain., 13 pages. arXiv: 1812.08829v2.
[47]
Gavin Wood. 2016. Ethereum: A Secure Decentralised Generalised Transaction Ledger. http://gavwood.com/paper.pdf. [Online; accessed 5-July-2017].

Cited By

View all
  • (2024)Consolidating Smart Contracts with Behavioral ContractsProceedings of the ACM on Programming Languages10.1145/36564168:PLDI(965-989)Online publication date: 20-Jun-2024
  • (2024)A Survey of Vulnerability Detection Techniques by Smart Contract ToolsIEEE Access10.1109/ACCESS.2024.340162312(70870-70910)Online publication date: 2024
  • (2024)ReenRepair: Automatic and semantic equivalent repair of reentrancy in smart contractsJournal of Systems and Software10.1016/j.jss.2024.112107216(112107)Online publication date: Oct-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 4, Issue OOPSLA
November 2020
3108 pages
EISSN:2475-1421
DOI:10.1145/3436718
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 13 November 2020
Published in PACMPL Volume 4, Issue OOPSLA

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. blockchain
  2. invariants
  3. logic and verification
  4. program analysis
  5. program verification
  6. smart contracts

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)262
  • Downloads (Last 6 weeks)25
Reflects downloads up to 30 Aug 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Consolidating Smart Contracts with Behavioral ContractsProceedings of the ACM on Programming Languages10.1145/36564168:PLDI(965-989)Online publication date: 20-Jun-2024
  • (2024)A Survey of Vulnerability Detection Techniques by Smart Contract ToolsIEEE Access10.1109/ACCESS.2024.340162312(70870-70910)Online publication date: 2024
  • (2024)ReenRepair: Automatic and semantic equivalent repair of reentrancy in smart contractsJournal of Systems and Software10.1016/j.jss.2024.112107216(112107)Online publication date: Oct-2024
  • (2024)EVM-Vale: Formal Verification of EVM Bytecode Using ValeDistributed Ledger Technology10.1007/978-981-97-0006-6_3(39-54)Online publication date: 9-Feb-2024
  • (2023)SoK: Decentralized Exchanges (DEX) with Automated Market Maker (AMM) ProtocolsACM Computing Surveys10.1145/357063955:11(1-50)Online publication date: 9-Feb-2023
  • (2023)Robust Safety for Move2023 IEEE 36th Computer Security Foundations Symposium (CSF)10.1109/CSF57540.2023.00045(308-323)Online publication date: Jul-2023
  • (2023)Smart Contract Synthesis Modulo Hyperproperties2023 IEEE 36th Computer Security Foundations Symposium (CSF)10.1109/CSF57540.2023.00006(276-291)Online publication date: Jul-2023
  • (2022)Necessity specifications for robustnessProceedings of the ACM on Programming Languages10.1145/35633176:OOPSLA2(811-840)Online publication date: 31-Oct-2022
  • (2022)Relaxed Effective Callback Freedom: A Parametric Correctness Condition for Sequential Modules with CallbacksIEEE Transactions on Dependable and Secure Computing10.1109/TDSC.2022.3178836(1-1)Online publication date: 2022
  • (2022)Research on smart contract technology based on block chain2022 International Conference on Artificial Intelligence in Everything (AIE)10.1109/AIE57029.2022.00130(664-668)Online publication date: Aug-2022
  • Show More Cited By

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