Cost Analysis of Smart Contracts Via Parametric Resource Analysis

The very nature of smart contracts and blockchain platforms, where program execution and storage are replicated across a large number of nodes, makes resource consumption analysis highly relevant. This has led to the development of analyzers for specific platforms and languages. However, blockchain platforms present significant variability in languages and cost models, as well as over time. Approaches that facilitate the quick development and adaptation of cost analyses are thus potentially attractive in this context. We explore the application of a generic approach and tool for cost analysis to the problem of static inference of gas consumption bounds in smart contracts. The approach is based on Parametric Resource Analysis, a method that simplifies the implementation of analyzers for inferring safe bounds on different resources and with different resource consumption models. In addition, to support different input languages, the approach also makes use of translation into a Horn clause-based intermediate representation. To assess practicality we develop an analyzer for the Tezos platform and its Michelson language. We argue that this approach offers a rapid, flexible, and effective method for the development of cost analyses for smart contracts.

[1]  Gordon D. Plotkin,et al.  A structural approach to operational semantics , 2004, J. Log. Algebraic Methods Program..

[2]  Ben Wegbreit,et al.  Mechanical program analysis , 1975, CACM.

[3]  Kevin Hammond,et al.  Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs , 2003, IFL.

[4]  Georg Moser,et al.  Automated Amortised Resource Analysis for Term Rewrite Systems , 2018, FLOPS.

[5]  Daniel Davis Wood,et al.  ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER , 2014 .

[6]  Manuel V. Hermenegildo,et al.  Sized Type Analysis for Logic Programs (Technical Communication) , 2013 .

[7]  Zachary Kincaid,et al.  Closed forms for numerical loops , 2019, Proc. ACM Program. Lang..

[8]  Manuel V. Hermenegildo,et al.  Static Performance Guarantees for Programs with Runtime Checks , 2018, PPDP.

[9]  Graham Hutton,et al.  Liquidate your assets: reasoning about resource usage in liquid Haskell , 2020, Proc. ACM Program. Lang..

[10]  Elvira Albert,et al.  Closed-Form Upper Bounds in Static Cost Analysis , 2011, Journal of Automated Reasoning.

[11]  Manuel V. Hermenegildo,et al.  A general framework for static profiling of parametric resource usage* , 2016, Theory and Practice of Logic Programming.

[12]  Mathias Bourgoin,et al.  Introduction to the Tezos Blockchain , 2019, 2019 International Conference on High Performance Computing & Simulation (HPCS).

[13]  Manuel V. Hermenegildo,et al.  An Assertion Language for Constraint Logic Programs , 2000, Analysis and Visualization Tools for Constraint Programming.

[14]  Manuel V. Hermenegildo,et al.  Compile-Time Derivation of Variable Dependency Using Abstract Interpretation , 1992, J. Log. Program..

[15]  Atsushi Igarashi,et al.  Resource usage analysis , 2002, POPL '02.

[16]  Marco Gaboardi,et al.  Relational cost analysis , 2017, POPL.

[17]  David Pichardie,et al.  A Formally Verified WCET Estimation Tool , 2014, WCET.

[18]  Andrey Rybalchenko,et al.  Synthesizing software verifiers from proof rules , 2012, PLDI.

[19]  Jorge A. Navas,et al.  The SeaHorn Verification Framework , 2015, CAV.

[20]  David Pichardie,et al.  Verifying Constant-Time Implementations by Abstract Interpretation , 2019, ESORICS.

[21]  Jorge A. Navas,et al.  Safe upper-bounds inference of energy consumption for java bytecode applications , 2008, FM'08 2008.

[22]  Jorge A. Navas,et al.  User-Definable Resource Usage Bounds Analysis for Java Bytecode , 2009, BYTECODE@ETAPS.

[23]  Nick Szabo,et al.  Formalizing and Securing Relationships on Public Networks , 1997, First Monday.

[24]  Gilles Kahn,et al.  Natural Semantics , 1987, STACS.

[25]  Temesghen Kahsai,et al.  JayHorn: A Framework for Verifying Java programs , 2016, CAV.

[26]  John P. Gallagher,et al.  From Big-Step to Small-Step Semantics and Back with Interpreter Specialisation , 2020, VPT/HCVS@ETAPS.

[27]  Manuel V. Hermenegildo,et al.  An overview of Ciao and its design philosophy , 2011, Theory and Practice of Logic Programming.

[28]  Mads Rosendahl,et al.  Automatic complexity analysis , 1989, FPCA.

[29]  John P. Gallagher,et al.  A General Framework for Static Cost Analysis of Parallel Logic Programs , 2019, LOPSTR.

[30]  Elvira Albert,et al.  Decompilation of Java bytecode to Prolog by partial evaluation , 2009, Inf. Softw. Technol..

[31]  John P. Gallagher,et al.  Abstract Interpretation of PIC Programs through Logic Programming , 2006, 2006 Sixth IEEE International Workshop on Source Code Analysis and Manipulation.

[32]  Ugo Dal Lago,et al.  Automating sized-type inference for complexity analysis , 2017, Proc. ACM Program. Lang..

[33]  Peter J. Stuckey,et al.  Incremental analysis of constraint logic programs , 2000, TOPL.

[34]  Saumya K. Debray,et al.  Task granularity analysis in logic programs , 1990, PLDI '90.

[35]  Jürgen Giesl,et al.  Symbolic evaluation graphs and term rewriting: a general methodology for analyzing logic programs , 2012, PPDP.

[36]  Jorge A. Navas,et al.  A Flexible, (C)LP-Based Approach to the Analysis of Object-Oriented Programs , 2008, LOPSTR.

[37]  Natasha Sharygina,et al.  Computing Exact Worst-Case Gas Consumption for Smart Contracts , 2018, ISoLA.

[38]  Martin Hofmann,et al.  Multivariate amortized resource analysis , 2012, TOPL.

[39]  Manuel V. Hermenegildo,et al.  Integrated program debugging, verification, and optimization using abstract interpretation (and the Ciao system preprocessor) , 2005, Sci. Comput. Program..

[40]  Albert Rubio,et al.  Running on Fumes , 2019, Lecture Notes in Computer Science.

[41]  Martin Hofmann,et al.  Multivariate Amortised Resource Analysis for Term Rewrite Systems , 2015, TLCA.

[42]  Manuel V. Hermenegildo,et al.  Inferring Energy Bounds via Static Program Analysis and Evolutionary Modeling of Basic Blocks , 2017, LOPSTR.

[43]  Patrick Cousot,et al.  Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints , 1977, POPL.

[44]  Manuel V. Hermenegildo,et al.  Resource Usage Analysis of Logic Programs via Abstract Interpretation Using Sized Types* , 2014, Theory and Practice of Logic Programming.

[45]  Manuel V. Hermenegildo,et al.  Interval-based resource usage verification by translation into Horn clauses and an application to energy consumption , 2018, Theory and Practice of Logic Programming.

[46]  Alberto Pettorossi,et al.  Semantics-based generation of verification conditions by program specialization , 2015, PPDP.

[47]  John P. Gallagher,et al.  Inferring Parametric Energy Consumption Functions at Different Software Levels: ISA vs. LLVM IR , 2015, FOPARA.

[48]  Yoshihiko Futamura,et al.  Partial Evaluation of Computation Process--An Approach to a Compiler-Compiler , 1999, High. Order Symb. Comput..

[49]  Albert Rubio,et al.  GASOL: Gas Analysis and Optimization for Ethereum Smart Contracts , 2014, TACAS.

[50]  Manuel V. Hermenegildo,et al.  Towards execution time estimation in abstract machine-based languages , 2008, PPDP.

[51]  Yannis Smaragdakis,et al.  MadMax: surviving out-of-gas conditions in Ethereum smart contracts , 2018, Proc. ACM Program. Lang..

[52]  Elvira Albert,et al.  More Precise Yet Widely Applicable Cost Analysis , 2011, VMCAI.

[53]  Xiapu Luo,et al.  Under-optimized smart contracts devour your money , 2017, 2017 IEEE 24th International Conference on Software Analysis, Evolution and Reengineering (SANER).

[54]  Manuel V. Hermenegildo,et al.  Energy Consumption Analysis of Programs Based on XMOS ISA-Level Models , 2013, LOPSTR.

[55]  Jorge A. Navas,et al.  User-Definable Resource Bounds Analysis for Logic Programs , 2007, ICLP.

[56]  Marco Gaboardi,et al.  Relational cost analysis for functional-imperative programs , 2019, Proc. ACM Program. Lang..

[57]  Bernd Grobauer,et al.  Cost recurrences for DML programs , 2001, ICFP '01.

[58]  Sumit Gulwani,et al.  SPEED: precise and efficient static estimation of program computational complexity , 2009, POPL '09.

[59]  Saumya K. Debray,et al.  Cost analysis of logic programs , 1993, TOPL.

[60]  Manuel V. Hermenegildo,et al.  The ciao system , 2013 .

[61]  Manuel V. Hermenegildo,et al.  Sized Type Analysis for Logic Programs , 2013, Theory Pract. Log. Program..

[62]  Saumya K. Debray,et al.  Lower Bound Cost Estimation for Logic Programs , 1997, ILPS.

[63]  John P. Gallagher,et al.  Analysis of Imperative Programs through Analysis of Constraint Logic Programs , 1998, SAS.