On The Formal Verification of Smart Contracts
On The Formal Verification of Smart Contracts
Abstract—In recent years, Blockchain-based systems have First, we show an example of an Ethereum Blockchain
experienced rapid growth. Although these systems are in Smart Contract implemented in Solidity [7].
production, they are not exempt from presenting defects in
The example shown in Figure 1 shows some basic func-
the design of their elements such as Smart Contracts. Design
defects in Smart Contracts lead to inconsistencies and conse- tions for an Ethereum Wallet (Ethereum electronic wallet).
quently to incorrect operation, which generates problematic The Smart Contract is composed of a constructor that
situations during and after the execution of the system. In this establishes the owner who can receive payments based on
paper, we describe an overview of main current approaches to messages, and a couple of functions to withdraw funds from
formally verify Smart Contracts. Moreover, it is proposed to
the wallet or to obtain information regarding the current
use Descriptive Logics to verify the consistency of functionality
in the designs of Smart Con- tracts. The balance between status of the amounts that the wallet owns. But, suppose
expressiveness and computational complexity of Descriptive that during the design of the Smart Contract, the withdraw
Logics, allow to model in an unified framework elusive Smart function presents inconsistencies such as handling negative
Contract properties, such as temporal and spatial ones. Fur- amounts or transferring amounts to wrong accounts. These
thermore, it will allow reliable and efficient verification of these
inconsistencies can compromise the operation of the Smart
properties.
Contract at some point in the execution and therefore not
Keywords-Formal Verification; Blockchain Systems; Smart meet the objectives set in its design.
Contracts; Description Logics.
We now present another example of an Algorand
Blockchain Smart Contract implemented in Python using
I. I NTRODUCTION PyTeal [8].
The example shown in Figure 2 presents a Smart Contract
Smart Contracts are immutable programs implemented on that has the function of donating an amount to a specific
a Blockchain that allow managing important assets. Then, it benefactor defined, with a procedure for signing the process.
is vitally important to verify it and thus guarantee its correct If it presents inconsistencies in its design, such as making
design, implementation and execution. Some authors (e.g., the transaction to an entity that is not a correct beneficiary, or
[1]–[4]) agree that it is advisable to carry out this verification that the signature does not have the necessary parameters, it
process before implementation, that is, during the design of can compromise its operation at some point in the execution
said Smart Contracts. Blockchain-based application devel- and again not meet the objectives set out in his design.
opers generally rely on a combination of tools and expertise Therefore, despite the fact that Smart Contracts have a
during the creation of Smart Contracts, but still are unable defined operation in any Blockchain, they are not exempt
to identify consistency issues in Smart Contract functions from presenting defects in their design that lead to in-
prior to implementation and execution, which can cause consistencies in their operation. The foregoing motivates
significant losses [5]. Based on the above, in this proposal, proposing to develop a model that allows verifying the
we consider to use formal verification methods based on consistency of operation in the designs of Smart Contracts,
Descriptive Logics [6] to build an automated verification before implementing and executing them, that is, when they
model making it possible to find consistency in the functions are designed.
defined within a Smart Contract.
Blockchain immutability represents a major difference
II. P RELIMINARIES
from other software systems. It is not possible to modify
a Smart Contract once it is executed on the Blockchain. Most of current systems and applications function in a
This increases security and transparency, but also avoids centralized manner, where an administrator or a group of
correcting defects in Smart Contracts once they have been administrators have access to the information to process, or-
validated and are on the Blockchain. Furthermore, if a ganize, or distribute it based on the objectives of the system
transaction is recorded as a consequence of the execution or dependency that uses it. So, centralized access can lead to
of a Smart Contract, it cannot be reversed. malicious acts such as collusion to favor particular interests,
Said immutability at the time of the execution of the these events increase the mistrust of users regarding the
Smart Contracts, is not exempt from presenting defects in services offered by systems or applications, motivating them
their design. To illustrate this, some examples are presented to seek more reliable, transparent and secure mechanisms
below. [9].
Figure 2. Smart Contract in PyTeal: Donation.
Figure 1. Smart Contract in Solidity: Wallet.
the following programming languages: is valid. This technique can be used to implement
automatic verification of rules on a system [17].
• Solidity. Is a statically typed, object-oriented program-
• Model Checking. Is a method for automatically con-
ming language created to enable the build of Smart
firming the correctness of finite-state systems. It refers
Contracts [7].
to the algorithms for fully and automatically evaluating
• PyTeal. PyTeal is a Python-based language binding for
the state space of a transition system to verify whether
Algorand Smart Contracts [8].
a particular system model satisfies a given specification
Smart Contracts, despite the fact that they are immutable, [2].
can present the following inconsistencies in their operation • Stochastic Model Checking. Is a method for calculating
[15]: the likelihood of the occurrence of certain events during
• Integer issues. When handling arithmetic values they the execution of a system [1].
result in output that exceeds an allocated size, or when
D. Descriptive Logics - DL
they result in values less than zero.
• Access control. It is linked to actions by unauthorized They are a family of formal knowledge representation
participants that violate system access rules and busi- languages. Many DLs are more expressive than propositional
ness logic, such as token minting, money withdrawal, logic but less expressive than first-order logic. In contrast
asset retention, stopping and updating contracts, prop- to the latter, the core reasoning problems for DLs are
erty transfer, auction bidding, votes etc. (usually) decidable, and efficient decision procedures have
been designed and implemented for these problems. There
C. Formal verification are general, spatial, temporal, spatio-temporal, and fuzzy
description logics, and each description logic presents a
The above concepts and examples (Figures 1 & 2) lead to different balance between expressive power and reasoning
the introduction of the concept of Formal Verification, which complexity by supporting different sets of [6] mathematical
is defined as the act of proving or disproving the correct constructors.
operation of the algorithms that are the basis of a system For example, Figure 3 represents the knowledge base of
with respect to a specific specification or formal property, a family tree of people, parents, children, etc. The structure
testing is performed using automated validation tools [16]. of the figure is also known as terminology and, in fact, it
Formal verification can be useful to prove the correct is intended to represent the generality or specificity of the
operation of systems built with, for example, cryptographic concepts involved. For example, the link between Mother
protocols, combinational circuits, digital circuits, or software and Father says that ”mothers are fathers”; this is sometimes
expressed as source code [5]. called an ”IS-A” [6] relationship.
There are different types of formal methods, of which we Description logics have been introduced with the aim of
highlight the following: providing a formal reconstruction of framework systems and
• Satisfiability Modulo Theories. Is is a verification tech- semantic networks. Initially, the research has focused on the
nique to prove correctness of system’s properties. Prop- inclusion of conceptual expressions. However, for certain
erties are expressed in a formal language and when all applications it turns out that it is necessary to represent
given properties are satisfied, it is said that the system knowledge by means of inclusion axioms [6].
Figure 5. Verification in Coq: Invalid transfers.
[6] The Description Logic Handbook: Theory, Implementation [22] K. Bhargavan, A. Delignat-Lavaud, C. Fournet, A. Gollamudi,
and Applications, 2nd ed. Cambridge University Press, 2007. G. Gonthier, N. Kobeissi, N. Kulatova, A. Rastogi, T. Sibut-
Pinote, N. Swamy, and S. Zanella-Béguelin, “Formal
[7] V. Buterin, “A next-generation smart contract and decentral- verification of smart contracts: Short paper,” in Proceedings
ized application platform—white paper,” Ethereum Project, of the 2016 ACM Workshop on Programming Languages
2014. and Analysis for Security, ser. PLAS ’16. New York, NY,
USA: Association for Computing Machinery, 2016, p. 91–96.
[8] J. Chen and S. Micali, “Algorand,” 2017. [Online]. Available: https://doi.org/10.1145/2993600.2993611
[9] T. T. Huynh, T. D. Nguyen, and H. Tan, “A survey on security [23] G. Bigi, A. Bracciali, G. Meacci, and E. Tuosto,
and privacy issues of blockchain technology,” 2019. Validation of Decentralised Smart Contracts Through
Game Theory and Formal Methods. Cham: Springer
[10] S. Verma, D. Yadav, and G. Chandra, “Introduction of formal International Publishing, 2015, pp. 142–161. [Online].
methods in blockchain consensus mechanism and its asso- Available: https://doi.org/10.1007/978-3-319-25527-91 1
ciated protocols,” IEEE Access, vol. 10, pp. 66 611–66 624,
2022.