<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE article PUBLIC "-//NLM//DTD Journal Publishing DTD v2.3 20070202//EN" "journalpublishing.dtd">
<article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" article-type="review-article">
<front>
<journal-meta>
<journal-id journal-id-type="publisher-id">Front. Blockchain</journal-id>
<journal-title>Frontiers in Blockchain</journal-title>
<abbrev-journal-title abbrev-type="pubmed">Front. Blockchain</abbrev-journal-title>
<issn pub-type="epub">2624-7852</issn>
<publisher>
<publisher-name>Frontiers Media S.A.</publisher-name>
</publisher>
</journal-meta>
<article-meta>
<article-id pub-id-type="doi">10.3389/fbloc.2019.00008</article-id>
<article-categories>
<subj-group subj-group-type="heading">
<subject>Blockchain</subject>
<subj-group>
<subject>Review</subject>
</subj-group>
</subj-group>
</article-categories>
<title-group>
<article-title>Formal Models of Bitcoin Contracts: A Survey</article-title>
</title-group>
<contrib-group>
<contrib contrib-type="author">
<name><surname>Bartoletti</surname> <given-names>Massimo</given-names></name>
<xref ref-type="aff" rid="aff1"><sup>1</sup></xref>
<uri xlink:href="http://loop.frontiersin.org/people/570157/overview"/>
</contrib>
<contrib contrib-type="author" corresp="yes">
<name><surname>Zunino</surname> <given-names>Roberto</given-names></name>
<xref ref-type="aff" rid="aff2"><sup>2</sup></xref>
<xref ref-type="corresp" rid="c001"><sup>&#x0002A;</sup></xref>
<uri xlink:href="http://loop.frontiersin.org/people/574226/overview"/>
</contrib>
</contrib-group>
<aff id="aff1"><sup>1</sup><institution>Dipartimento di Matematica e Informatica, Universit&#x000E0; di Cagliari</institution>, <addr-line>Cagliari</addr-line>, <country>Italy</country></aff>
<aff id="aff2"><sup>2</sup><institution>Dipartimento di Matematica, Universit&#x000E0; di Trento</institution>, <addr-line>Trento</addr-line>, <country>Italy</country></aff>
<author-notes>
<fn fn-type="edited-by"><p>Edited by: Stefano Bistarelli, University of Perugia, Italy</p></fn>
<fn fn-type="edited-by"><p>Reviewed by: Andrea De Salve, University of Palermo, Italy; Laura Ricci, University of Pisa, Italy; Francesco Buccafurri, Mediterranea University of Reggio Calabria, Italy</p></fn>
<corresp id="c001">&#x0002A;Correspondence: Roberto Zunino <email>roberto.zunino&#x00040;unitn.it</email></corresp>
<fn fn-type="other" id="fn001"><p>This article was submitted to Non-Financial Blockchain, a section of the journal Frontiers in Blockchain</p></fn></author-notes>
<pub-date pub-type="epub">
<day>21</day>
<month>08</month>
<year>2019</year>
</pub-date>
<pub-date pub-type="collection">
<year>2019</year>
</pub-date>
<volume>2</volume>
<elocation-id>8</elocation-id>
<history>
<date date-type="received">
<day>03</day>
<month>04</month>
<year>2019</year>
</date>
<date date-type="accepted">
<day>31</day>
<month>07</month>
<year>2019</year>
</date>
</history>
<permissions>
<copyright-statement>Copyright &#x000A9; 2019 Bartoletti and Zunino.</copyright-statement>
<copyright-year>2019</copyright-year>
<copyright-holder>Bartoletti and Zunino</copyright-holder>
<license xlink:href="http://creativecommons.org/licenses/by/4.0/"><p>This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) and the copyright owner(s) are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms.</p></license>
</permissions>
<abstract><p>Although Bitcoin is mostly used as a decentralized application to transfer cryptocurrency, over the last 10 years there have been several studies on how to exploit Bitcoin to execute <italic>smart contracts</italic>. These are computer protocols which allow users to exchange bitcoins according to complex pre-agreed rules. Some of these studies introduce formal models of Bitcoin contracts, which specify their behavior in non-ambiguous terms, in some cases providing tools to automatically verify relevant contract properties. In this paper, we survey the formal models proposed in the scientific literature, comparing their expressiveness and applicability in the wild.</p></abstract> <kwd-group>
<kwd>blockchain</kwd>
<kwd>smart contracts</kwd>
<kwd>cryptocurrencies</kwd>
<kwd>formal models</kwd>
<kwd>concurrency</kwd>
</kwd-group>
<counts>
<fig-count count="6"/>
<table-count count="1"/>
<equation-count count="18"/>
<ref-count count="37"/>
<page-count count="11"/>
<word-count count="8064"/>
</counts>
</article-meta> 
</front>
<body>
<sec sec-type="intro" id="s1">
<title>1. Introduction</title>
<p>Smart contracts were originally conceived in Szabo (<xref ref-type="bibr" rid="B37">1997</xref>) as agreements among two or more parties, that can be enforced automatically without a trusted intermediary. The recent surge of applications like Bitcoin and Ethereum has revived the idea of smart contract, because of the possibility of creating and transferring crypto-assets in a decentralized way. These applications are run by a peer-to-peer network of nodes, which collectively maintain a public, append-only data structure, called <italic>blockchain</italic>. The basic usage of the blockchain is to record transactions of crypto-assets between users. In Bitcoin, one can exploit some advanced features of transactions to extend this basic usage: at an abstract level, transactions can be interpreted as updates to the global state of a contract, and the sequence of transactions on the blockchain determines the state of each contract&#x02014;and, accordingly, the crypto-assets owned by each user. In Ethereum this mechanism is made more explicit, as transactions are calls to procedures of contracts.</p>
<p>The first proposal to implement smart contracts on Bitcoin dates back at least to Bitcoin wiki (<xref ref-type="bibr" rid="B18">2012</xref>), when simple contracts were proposed that delegate an external entity (like an oracle or an escrow service) to regulate transfers of bitcoins. Going beyond these basic contracts, Andrychowicz et al. (<xref ref-type="bibr" rid="B4">2014c</xref>) demonstrated how to exploit some advanced features of Bitcoin transactions to implement the <italic>timed commitment</italic> protocol. This is a contract which allows a participant to commit to a secret, ensuring that either she reveals the secret before a certain deadline, or she pays a penalty to another participant. The time commitment protocol is the basic building block of more sophisticated contracts, like lotteries and other gambling games, since it allow players to choose their moves independently through a public channel, ensuring non-repudiation. In particular, multi-player lotteries in Bitcoin have been thoroughly investigated, starting from the version in Andrychowicz et al. (<xref ref-type="bibr" rid="B4">2014c</xref>), which requires each player to deposit a quadratic collateral in the number of players, to the versions in Bartoletti and Zunino (<xref ref-type="bibr" rid="B12">2017</xref>) and Miller and Bentov (<xref ref-type="bibr" rid="B30">2017</xref>), which enable lotteries without collaterals using Bitcoin extensions. More general forms of fair multiparty computations were proposed in Andrychowicz et al. (<xref ref-type="bibr" rid="B2">2014a</xref>), Bentov and Kumaresan (<xref ref-type="bibr" rid="B16">2014</xref>), and Kumaresan and Bentov (<xref ref-type="bibr" rid="B26">2014</xref>). Contingent payments contracts, allowing users to trade solutions of a class of NP problems, were proposed in Banasik et al. (<xref ref-type="bibr" rid="B10">2016</xref>) and Maxwell (<xref ref-type="bibr" rid="B29">2016</xref>).</p>
<p>All the works mentioned above share a common trait: they describe smart contracts in an informal manner, by using protocol narrations where, besides the usual actions of cryptographic protocols (e.g., sending and signing messages, computing hashes, verifying signatures), participants can also read and append transactions to the Bitcoin blockchain. Transactions, as well, are expressed informally, relying upon a simplified intuition of their behavior in Bitcoin. The lack of formal models of Bitcoin contracts is an obstacle to their verification. The current practice in the scientific literature is that each time a new contract is proposed, it is accompanied by a paper-and-pencil proof of correctness. Besides being a time-consuming task, doing these proofs by hand is error-prone, since for complex contracts is it quite likely to miss some corner cases, or to misinterpret the behavior of some Bitcoin transactions. This is a critical issue: since smart contracts cannot be changed after deployment, and they may handle the ownership of valuable crypto-assets, attackers may be tempted to exploit their vulnerabilities to steal or tamper with these assets. Automatic verification tools for Bitcoin contracts would help to overcome these issues.</p>
<p>Starting from Andrychowicz et al. (<xref ref-type="bibr" rid="B3">2014b</xref>), a few formal models of Bitcoin contracts have been proposed in the scientific literature. They are based on different modeling techniques, ranging from timed automata to process algebras and &#x003BB;-calculi, and pursue different goals: some works are focused on contracts that can actually be run on Bitcoin, while some others propose extensions of Bitcoin; some works enable the verification of contract properties, while some others just provide an executable semantics.</p>
<p>In this paper, we survey the existing formal models of Bitcoin contracts, applying them to a common basic use case: the timed commitment. We start in section 2 by providing the needed background on Bitcoin; then, in sections 3&#x02013;7 we illustrate the models, and in section 8 we compare them along various directions: expressiveness, usability, and suitability for verification. This comparison can help programmers to choose the right model for their decentralized application. In section 9 we also briefly overview a parallel research direction, that is the study of formal models contracts in other blockchain platforms, like Ethereum.</p></sec>
<sec id="s2">
<title>2. Background</title>
<p>In this section we give a minimalistic introduction to Bitcoin (Nakamoto, <xref ref-type="bibr" rid="B32">2008</xref>), focusing on the aspects related to contracts; see (Bonneau et al., <xref ref-type="bibr" rid="B19">2015</xref>) for a broader overview. Bitcoin is a decentralized infrastructure to securely transfer currency (the <italic>bitcoins</italic>, <inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>) between users. Transfers of bitcoins are represented as <italic>transactions</italic>, and the history of all transactions is stored in a public, append-only, distributed data structure called <italic>blockchain</italic>. The blockchain is maintained by the nodes of the Bitcoin network; a subset of them, called <italic>miners</italic>, gather the transactions sent by users, aggregate them in blocks, and try to append these blocks to the blockchain. A consensus protocol based on moderately-hard &#x0201C;proof-of-work&#x0201D; puzzles is used to resolve conflicts that may happen when different miners concurrently try to extend the blockchain, or when some miner attempts to append a block with invalid transactions. The security of the consensus protocol relies on the assumption that miners are <italic>rational</italic> (i.e., that following the protocol is more convenient than trying to attack it). To make this assumption hold, miners receive some economic incentives for performing the time-consuming computations required to solve the puzzles. Part of these incentives is given by the <italic>fees</italic> paid by users upon each transaction.</p>
<p>To illustrate how transfers of bitcoins work, we consider two transactions <inline-formula><mml:math id="M1"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>0</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> and <inline-formula><mml:math id="M2"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula>, which we represent graphically as follows:</p>
<table-wrap position="float">
<graphic xlink:href="fbloc-02-00008-t0001.tif"/>
</table-wrap>
<p>The transaction <inline-formula><mml:math id="M3"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>0</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> contains <italic>v</italic><sub>0</sub> Satoshis (1 bitcoin = 10<sup>8</sup> Satoshis). A user can redeem this amount by publishing another transaction (e.g., <inline-formula><mml:math id="M4"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula>), whose <monospace>in</monospace> field contains the identifier of <inline-formula><mml:math id="M5"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>0</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> (its <monospace>hash</monospace>), and whose <monospace>in-script</monospace> field makes the <monospace>out-script</monospace> of <inline-formula><mml:math id="M6"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>0</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> evaluate to true. When this happens, the value of <inline-formula><mml:math id="M7"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>0</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> is transferred to the new transaction <inline-formula><mml:math id="M8"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula>, and <inline-formula><mml:math id="M9"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>0</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> becomes unredeemable. In the example above, the two transactions are using a pattern called <italic>Pay to public key (P2PK)</italic>. Namely, executing the output script starts with a signature <inline-formula><mml:math id="M10"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>s</mml:mi><mml:mi>i</mml:mi><mml:mi>g</mml:mi><mml:mi>A</mml:mi></mml:mstyle></mml:math></inline-formula> on top of an evaluation stack, and then proceeds by pushing also <inline-formula><mml:math id="M11"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>p</mml:mi><mml:mi>u</mml:mi><mml:mi>b</mml:mi><mml:mi>K</mml:mi><mml:mi>e</mml:mi><mml:mi>y</mml:mi><mml:mi>A</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula>. Then, the opcode <inline-formula><mml:math id="M12"><mml:mrow><mml:mstyle style="font-family:courier;color:#8f5864"><mml:mtext>OP_CHECKSIG</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> verifies, using the public key <inline-formula><mml:math id="M13"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>p</mml:mi><mml:mi>u</mml:mi><mml:mi>b</mml:mi><mml:mi>K</mml:mi><mml:mi>e</mml:mi><mml:mi>y</mml:mi><mml:mi>A</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula>, if <inline-formula><mml:math id="M14"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>s</mml:mi><mml:mi>i</mml:mi><mml:mi>g</mml:mi><mml:mi>A</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula> is a valid signature of <inline-formula><mml:math id="M15"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula>. If this check succeeds, and <italic>v</italic><sub>1</sub> &#x02264; <italic>v</italic><sub>0</sub>, then <inline-formula><mml:math id="M16"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> can be appended to the blockchain, specifying a new condition for redeeming <italic>v</italic><sub>1</sub> Satoshis. For instance, if the output script of <inline-formula><mml:math id="M17"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> is <inline-formula><mml:math id="M18"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>p</mml:mi><mml:mi>u</mml:mi><mml:mi>b</mml:mi><mml:mi>K</mml:mi><mml:mi>e</mml:mi><mml:mi>y</mml:mi><mml:mi>B</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M19"><mml:mrow><mml:mstyle style="font-family:courier;color:#8f5864"><mml:mtext>OP_CHECKSIG</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, then <inline-formula><mml:math id="M20"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> is effectively moving <italic>v</italic><sub>1</sub> Satoshis from the user with public key <inline-formula><mml:math id="M21"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>p</mml:mi><mml:mi>u</mml:mi><mml:mi>b</mml:mi><mml:mi>K</mml:mi><mml:mi>e</mml:mi><mml:mi>y</mml:mi><mml:mi>A</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula> to that with key <inline-formula><mml:math id="M22"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>p</mml:mi><mml:mi>u</mml:mi><mml:mi>b</mml:mi><mml:mi>K</mml:mi><mml:mi>e</mml:mi><mml:mi>y</mml:mi><mml:mi>B</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula>. Further, the difference <italic>v</italic><sub>0</sub>&#x02212;<italic>v</italic><sub>1</sub> Satoshis is transferred from the user with key <inline-formula><mml:math id="M23"><mml:mrow><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mi>p</mml:mi><mml:mi>u</mml:mi><mml:mi>b</mml:mi><mml:mi>K</mml:mi><mml:mi>e</mml:mi><mml:mi>y</mml:mi><mml:mi>A</mml:mi></mml:mstyle></mml:mrow></mml:math></inline-formula> to the miner which has appended the block enclosing <inline-formula><mml:math id="M24"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mn>1</mml:mn></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula> to the blockchain.</p>
<p>The previous example shows the simple case of transactions with only one input and one output. In general, transactions can have multiple inputs and outputs, and can specify more complex redeeming conditions. A transaction with multiple inputs redeems <italic>all</italic> the (outputs of) transactions in its <monospace>in</monospace> fields, by providing a suitable <monospace>in-script</monospace> for each of them. Transactions with multiple outputs may have only some of them redeemed by a subsequent transaction; each output has its own value, and the sum of the values of all the outputs must be greater than or equal to the sum of the values of the inputs. Other transaction fields can be used to specify time constraints on when a transaction can appear on the blockchain.</p>
<p>An informal presentation of the Bitcoin scripting language is in Antonopoulos (<xref ref-type="bibr" rid="B5">2017</xref>), while an executable formalization of a significant fragment of this language is in Klomp and Bracciali (<xref ref-type="bibr" rid="B25">2018</xref>). In this paper we do not investigate the actual Bitcoin scripting language: rather, we focus on the higher-level languages that can be used to model Bitcoin contracts.</p></sec>
<sec id="s3">
<title>3. Balzac</title>
<p>Balzac (for &#x0201C;<italic>Bitcoin Abstract Language, analyZer and Compiler&#x0201D;</italic>) is a formal model and a toolchain for Bitcoin contracts, composed by a <italic>transaction model</italic>, and an <italic>endpoint protocol model</italic>. The transaction model is an abstraction layer over the Bitcoin transactions sketched in section 2: it features a modeling language for transactions, with a formal semantics (Atzei et al., <xref ref-type="bibr" rid="B9">2018b</xref>) and an online tool (<ext-link ext-link-type="uri" xlink:href="https://blockchain.unica.it/balzac/">https://blockchain.unica.it/balzac/</ext-link>) that translates Balzac transactions into standard Bitcoin transactions. The endpoint protocol model (Atzei et al., <xref ref-type="bibr" rid="B7">2018a</xref>) specifies the behavior of the participants involved in the smart contract, allowing them to exchange messages, to inspect the blockchain, and to append transactions. We now briefly illustrate the two models, by applying them to formalize the timed commitment protocol. The protocol involves two participants: a <italic>committer</italic> <inline-formula><mml:math id="M25"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> who chooses a secret, and promises to reveal it within a given <monospace>deadline</monospace>, and a <italic>receiver</italic> <inline-formula><mml:math id="M26"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> who will either know the secret, or otherwise obtain 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>.</p>
<p>Overall, the protocol uses three transactions: <inline-formula><mml:math id="M27"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> and <inline-formula><mml:math id="M28"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> specified by <inline-formula><mml:math id="M29"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> (in <xref ref-type="fig" rid="F1">Figure 1</xref>, left), and <inline-formula><mml:math id="M30"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> specified by <inline-formula><mml:math id="M31"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> (in <xref ref-type="fig" rid="F1">Figure 1</xref>, right). The committer <inline-formula><mml:math id="M32"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> uses <inline-formula><mml:math id="M33"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to commit to her secret, and to deposit the reward for <inline-formula><mml:math id="M34"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>, which is taken from an unspent transaction <inline-formula><mml:math id="M35"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>FundsA</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. Committing to a secret <monospace>s</monospace> is obtained by appending to the blockchain <inline-formula><mml:math id="M36"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h,sigAc)</monospace> where <monospace>h</monospace> &#x0003D; <monospace>sha256(s)</monospace> is the SHA256 hash of <monospace>s</monospace>, and <monospace>sigAc</monospace> is a signature of <inline-formula><mml:math id="M37"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> on <inline-formula><mml:math id="M38"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. This signature is needed to authorize the transfer of currency from <inline-formula><mml:math id="M39"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>FundsA</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to <inline-formula><mml:math id="M40"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. Since the hash <monospace>h</monospace> occurs in <inline-formula><mml:math id="M41"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M42"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mo>.</mml:mo><mml:mtext>output</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, it becomes public, but the secret <monospace>s</monospace> is not revealed. As specified in its <inline-formula><mml:math id="M43"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>output</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field, <inline-formula><mml:math id="M44"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> can be redeemed in two ways: either by revealing the secret and providing <inline-formula><mml:math id="M45"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature, or by providing <inline-formula><mml:math id="M46"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature after the <monospace>deadline</monospace>.</p>
<fig id="F1" position="float">
<label>Figure 1</label>
<caption><p>Balzac transactions for the timed commitment protocol.</p></caption>
<graphic xlink:href="fbloc-02-00008-g0001.tif"/>
</fig>
<p>Once <inline-formula><mml:math id="M47"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> is on the blockchain, <inline-formula><mml:math id="M48"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> can append <inline-formula><mml:math id="M49"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h,s,sigAr)</monospace> to redeem it. For this to succeed, <monospace>h</monospace> must be the hash specified within <inline-formula><mml:math id="M50"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, and <monospace>s</monospace> must be one of its preimages. Instead, <monospace>sigAr</monospace> must be a signature by <inline-formula><mml:math id="M51"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> on <inline-formula><mml:math id="M52"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. Appending <inline-formula><mml:math id="M53"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to the blockchain makes the witnesses in its <inline-formula><mml:math id="M54"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>input</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field public: in particular, <inline-formula><mml:math id="M55"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> will know the secret <monospace>s</monospace>. Note that, after <inline-formula><mml:math id="M56"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> is on the blockchain, <inline-formula><mml:math id="M57"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> cannot change her secret: indeed, trying to append a transaction <inline-formula><mml:math id="M58"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h,s2,sigAr)</monospace> with <monospace>sha256(s2)</monospace> &#x02260; <monospace>h</monospace> would fail. Appending <inline-formula><mml:math id="M59"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transfers the balance back to <inline-formula><mml:math id="M60"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, since its <inline-formula><mml:math id="M61"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>output</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field is only satisfied by a witness <monospace>x</monospace> which is <inline-formula><mml:math id="M62"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature on the redeeming transaction. We remark that Balzac exploits the SegWit feature of Bitcoin (Lombrozo et al., <xref ref-type="bibr" rid="B27">2015</xref>): this is why the <inline-formula><mml:math id="M63"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>input</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field of <inline-formula><mml:math id="M64"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> refers to <inline-formula><mml:math id="M65"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h,_)</monospace>, i.e., the transaction <inline-formula><mml:math id="M66"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> with only the parameter <monospace>h</monospace> specified. Indeed, the second parameter is only used within the witnesses of <inline-formula><mml:math id="M67"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, so it does not contribute to its identifier according to SegWit.</p>
<p>Finally, <inline-formula><mml:math id="M68"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> can be used by <inline-formula><mml:math id="M69"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> to punish <inline-formula><mml:math id="M70"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> if she does not reveal her secret before the <monospace>deadline</monospace>. More specifically, <inline-formula><mml:math id="M71"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h)</monospace> redeems <inline-formula><mml:math id="M72"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h,_)</monospace> after the <monospace>deadline</monospace>, using <inline-formula><mml:math id="M73"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature <monospace>sig(kB)</monospace> on <inline-formula><mml:math id="M74"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> as a witness in <inline-formula><mml:math id="M75"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M76"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mo>.</mml:mo><mml:mtext>input</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. The <inline-formula><mml:math id="M77"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>absLock</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field prevents <inline-formula><mml:math id="M78"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to appear on the blockchain earlier than the <monospace>deadline</monospace>, ensuring that <inline-formula><mml:math id="M79"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> has enough time to reveal her secret by using <inline-formula><mml:math id="M80"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. Note that <inline-formula><mml:math id="M81"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> might attempt to violate this time constraint by choosing a lower value for the <inline-formula><mml:math id="M82"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>absLock</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field before computing his signature <monospace>sig(kB)</monospace>; however, doing so would make <inline-formula><mml:math id="M83"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M84"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mo>.</mml:mo><mml:mtext>output</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> fail, since <inline-formula><mml:math id="M85"><mml:mrow><mml:mstyle style="font-family:courier;color:#00afb4"><mml:mtext>checkDate</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>deadline</monospace> ensures that the <inline-formula><mml:math id="M86"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>absLock</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field of the redeeming transaction (in our case, <inline-formula><mml:math id="M87"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>) does not refer to an earlier time. Once <inline-formula><mml:math id="M88"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> is on the blockchain, it can be redeemed using <inline-formula><mml:math id="M89"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature, only: so, <inline-formula><mml:math id="M90"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> effectively allows <inline-formula><mml:math id="M91"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> to claim <inline-formula><mml:math id="M92"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s funds as his own, as a compensation for <inline-formula><mml:math id="M93"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s misbehavior. We remark that this version of <inline-formula><mml:math id="M94"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> slightly differs from the one in Atzei et al. (<xref ref-type="bibr" rid="B7">2018a</xref>), where also <inline-formula><mml:math id="M95"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature was used. Here, the use of <inline-formula><mml:math id="M96"><mml:mrow><mml:mstyle style="font-family:courier;color:#00afb4"><mml:mtext>checkDate</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> makes this additional signature unneeded.</p>
<p>Note that the transactions in <xref ref-type="fig" rid="F1">Figure 1</xref> are not enough to completely specify the protocol, as they do not describe the actual behavior of participants. For instance, the transactions do not describe whether <inline-formula><mml:math id="M97"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> chooses to reveal the secret or not, and they do not say whether <inline-formula><mml:math id="M98"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> will eventually opt to use <inline-formula><mml:math id="M99"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>.</p>
<p>A natural behavior for <inline-formula><mml:math id="M100"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> could be to commit to the secret, and then reveal it before the deadline. We formalize this behavior using the Balzac endpoint protocol language, as follows:</p>
<graphic xlink:href="fbloc-02-00008-e0001.tif"/>
<p>The prefix <inline-formula><mml:math id="M101"><mml:mstyle mathcolor="#ed007e"><mml:mtext>put</mml:mtext></mml:mstyle></mml:math></inline-formula> <inline-formula><mml:math id="M102"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula><monospace>(h, sigAc)</monospace> appends <inline-formula><mml:math id="M103"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to the blockchain, provided that the transaction <inline-formula><mml:math id="M104"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>FundsA</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> occurs unredeemed on the blockchain. Note that <monospace>sigAc</monospace> is <inline-formula><mml:math id="M105"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;a signature on <inline-formula><mml:math id="M106"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h,_)</monospace>: neglecting the second parameter is possible because this parameter would only affect the witnesses of <inline-formula><mml:math id="M107"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, and witnesses are not covered by Bitcoin signatures (indeed, were signatures also covering witnesses, it would be unfeasible to include a signature as a witness, since it would need to sign itself). The prefix <inline-formula><mml:math id="M108"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> ! <monospace>h</monospace> sends to <inline-formula><mml:math id="M109"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> the hash of chosen secret. Then, <inline-formula><mml:math id="M110"><mml:mstyle mathcolor="#ed007e"><mml:mtext>put</mml:mtext></mml:mstyle></mml:math></inline-formula> <inline-formula><mml:math id="M111"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h, s, sigAr)</monospace> appends <inline-formula><mml:math id="M112"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to the blockchain, revealing the secret. Note that this specification does not impose time constraints on actions: in particular, it does not ensure that <inline-formula><mml:math id="M113"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> is appended before the deadline. Modeling this behavior would be possible by extending the language with urgent operators, as in Nicollin and Sifakis (<xref ref-type="bibr" rid="B33">1991</xref>).</p>
<p>A possible behavior of the receiver <inline-formula><mml:math id="M114"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> is specified by the following protocol <inline-formula><mml:math id="M115"><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:msub></mml:mrow></mml:math></inline-formula>, where the subprotocols <inline-formula><mml:math id="M116"><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#ed007e"><mml:mi>o</mml:mi><mml:mi>k</mml:mi></mml:mstyle></mml:msub></mml:mrow></mml:math></inline-formula> and <inline-formula><mml:math id="M117"><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#ed007e"><mml:mi>n</mml:mi><mml:mi>o</mml:mi><mml:mi>k</mml:mi></mml:mstyle></mml:msub></mml:mrow></mml:math></inline-formula> are left unspecified:</p>
<graphic xlink:href="fbloc-02-00008-e0002.tif"/>
<p>In this protocol, <inline-formula><mml:math id="M118"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> first receives from <inline-formula><mml:math id="M119"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> (and saves in <italic>x</italic>) the hash committed to within the transaction <inline-formula><mml:math id="M120"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. The prefix <inline-formula><mml:math id="M121"><mml:mstyle mathcolor="#ed007e"><mml:mtext>ask</mml:mtext></mml:mstyle></mml:math></inline-formula> <inline-formula><mml:math id="M122"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> (<italic>x</italic>, _) waits until a transaction of the form <inline-formula><mml:math id="M123"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>(<italic>x, y</italic>) is indeed on the blockchain, for some value of <italic>y</italic> (while <italic>x</italic> is fixed, and it corresponds to the hash received from <inline-formula><mml:math id="M124"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>). Then, <inline-formula><mml:math id="M125"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> proceeds by executing <inline-formula><mml:math id="M126"><mml:mrow><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi><mml:mo>&#x02032;</mml:mo></mml:mstyle></mml:mrow></mml:math></inline-formula>, a guarded choice between two actions. The leftmost guard is satisfied when a transaction of the form <inline-formula><mml:math id="M127"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>(<italic>x, y, z</italic>) is on the blockchain, for some <italic>y</italic> and <italic>z</italic>. If the leftmost prefix is fired, the variable <inline-formula><mml:math id="M128"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:mtext>T</mml:mtext></mml:mrow></mml:mstyle></mml:math></inline-formula> is bound to the actual <inline-formula><mml:math id="M129"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction on the blockchain: from there, <inline-formula><mml:math id="M130"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> extracts the secret, and uses it in the continuation <inline-formula><mml:math id="M131"><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#ed007e"><mml:mi>o</mml:mi><mml:mi>k</mml:mi></mml:mstyle></mml:msub></mml:mrow></mml:math></inline-formula>. The rightmost guard is enabled only when the transaction <inline-formula><mml:math id="M132"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> can be appended to the blockchain, i.e., after the <monospace>deadline</monospace>. Firing the prefix <inline-formula><mml:math id="M133"><mml:mstyle mathcolor="#ed007e"><mml:mtext>put</mml:mtext></mml:mstyle></mml:math></inline-formula> <inline-formula><mml:math id="M134"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>(<italic>x</italic>) appends <inline-formula><mml:math id="M135"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to the blockchain, allowing <inline-formula><mml:math id="M136"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> to get his reward, and to continue with <inline-formula><mml:math id="M137"><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#ed007e"><mml:mi>n</mml:mi><mml:mi>o</mml:mi><mml:mi>k</mml:mi></mml:mstyle></mml:msub></mml:mrow></mml:math></inline-formula>.</p>
<p>The overall behavior of the participants involved in a contract is defined in Atzei et al. (<xref ref-type="bibr" rid="B7">2018a</xref>) as an LTS between <italic>systems</italic>. A system is the parallel composition of the protocols of all participants, written <inline-formula><mml:math id="M138"><mml:mrow><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle><mml:mo stretchy="false">[</mml:mo><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>P</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:msub><mml:mo stretchy="false">]</mml:mo><mml:mo stretchy="false">|</mml:mo></mml:mrow></mml:mrow><mml:mrow><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle><mml:mo stretchy="false">[</mml:mo><mml:mrow><mml:msub><mml:mstyle style="font-family:courier;color:#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:msub><mml:mo stretchy="false">]</mml:mo><mml:mo stretchy="false">|</mml:mo></mml:mrow></mml:mrow><mml:mo>&#x022EF;</mml:mo></mml:math></inline-formula>, and the blockchain, written as a pair (<inline-formula><mml:math id="M139"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>, <italic>t</italic>), where <inline-formula><mml:math id="M140"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> is a sequence of timestamped transactions (<inline-formula><mml:math id="M141"><mml:mstyle mathcolor="#91268f"><mml:mrow><mml:msub><mml:mtext>T</mml:mtext><mml:mi>i</mml:mi></mml:msub></mml:mrow></mml:mstyle></mml:math></inline-formula>, <italic>t</italic><sub><italic>i</italic></sub>), and <italic>t</italic> is the current time (greater than the time of all transactions in <inline-formula><mml:math id="M142"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>). For instance, we show a trace of our timed commitment specification, starting from a system <inline-formula><mml:math id="M143"><mml:mrow><mml:mi>S</mml:mi><mml:mo>=</mml:mo><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle><mml:mo stretchy="false">[</mml:mo><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>P</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:msub><mml:mo stretchy="false">]</mml:mo><mml:mo stretchy="false">|</mml:mo></mml:mrow></mml:mrow><mml:mrow><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle><mml:mo stretchy="false">[</mml:mo><mml:mrow><mml:msub><mml:mstyle style="font-family:courier;color:#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle style="font-family:courier;color:#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:msub><mml:mo stretchy="false">]</mml:mo><mml:mo stretchy="false">|</mml:mo></mml:mrow></mml:mrow></mml:math></inline-formula> (<inline-formula><mml:math id="M144"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>, <italic>t</italic>), where the blockchain <inline-formula><mml:math id="M145"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> contains an unredeemed <inline-formula><mml:math id="M146"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>FundsA</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, and <italic>t</italic> &#x0003C; <monospace>deadline</monospace> &#x02212; 1. We have the trace:</p>
<graphic xlink:href="fbloc-02-00008-e0003.tif"/>
<p>where <inline-formula><mml:math id="M147"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext><mml:mo>&#x00027;</mml:mo></mml:mstyle></mml:math></inline-formula> &#x0003D; <inline-formula><mml:math id="M148"><mml:mstyle mathvariant="bold" mathcolor="#91268f"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> (<inline-formula><mml:math id="M149"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h, sigAc)</monospace>, <italic>t</italic>)(<inline-formula><mml:math id="M150"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <monospace>(h, s, sigAr)</monospace>,) <monospace>deadline</monospace> &#x02212; 1)</p>
<graphic xlink:href="fbloc-02-00008-e0004.tif"/>
<p>Note that the time advances at the fifth step of the computation, but, at the subsequent step, <inline-formula><mml:math id="M151"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> manages to append <inline-formula><mml:math id="M152"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> before the <monospace>deadline</monospace>, withdrawing her deposit. After that, the receiver <inline-formula><mml:math id="M153"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> obtains the secret <monospace>s</monospace>, and uses it within the continuation <inline-formula><mml:math id="M154"><mml:mrow><mml:msub><mml:mstyle mathcolor="#ed007e"><mml:mi>Q</mml:mi></mml:mstyle><mml:mstyle mathcolor="#ed007e"><mml:mi>o</mml:mi><mml:mi>k</mml:mi></mml:mstyle></mml:msub></mml:mrow></mml:math></inline-formula>(<monospace>s</monospace>).</p></sec>
<sec id="s4">
<title>4. Ivy</title>
<p>Ivy (<ext-link ext-link-type="uri" xlink:href="https://ivy-lang.org/bitcoin">https://ivy-lang.org/bitcoin</ext-link>) is an abstraction layer over Bitcoin scripts, featuring a compiler from its abstract language to standard Bitcoin scripts. We exemplify Ivy by modeling the timed commitment protocol in <xref ref-type="fig" rid="F2">Figure 2</xref>. The <inline-formula><mml:math id="M155"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M156"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> describes the two redeeming conditions for the first transaction (corresponding to the output script within the transaction <inline-formula><mml:math id="M157"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> in section 3). Each condition is specified by a <inline-formula><mml:math id="M158"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>clause</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> construct. The <monospace>reveal</monospace> clause requires a preimage of the hash <monospace>h</monospace>, and a signature by <monospace>Alice</monospace> verifiable with her public key <monospace>kApub</monospace>. This clause can be redeemed by a transaction using the script within <inline-formula><mml:math id="M159"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M160"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> (the witnesses of this transaction are not included in the Ivy contract). The <inline-formula><mml:math id="M161"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> clause can be satisfied only after the <monospace>deadline</monospace>, and it requires <monospace>Bob</monospace> to provide his signature, verifiable with <monospace>kBpub</monospace>. This is done by a transaction using the script within <inline-formula><mml:math id="M162"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M163"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>.</p>
<fig id="F2" position="float">
<label>Figure 2</label>
<caption><p>Ivy scripts for the timed commitment protocol.</p></caption>
<graphic xlink:href="fbloc-02-00008-g0002.tif"/>
</fig>
<p>Each Ivy <inline-formula><mml:math id="M164"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> describes only the output script, while there are no constructs to model the other parts of the transactions&#x02014;they can be programmed in Javascript when using Ivy as a Javascript library. For instance, Ivy does not specify that the transaction using <inline-formula><mml:math id="M165"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M166"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> should have <inline-formula><mml:math id="M167"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M168"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> as its input, nor that it should have an <monospace>absLock</monospace> field set to <monospace>deadline</monospace> (or later) in order to correctly redeem <inline-formula><mml:math id="M169"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> <inline-formula><mml:math id="M170"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. By contrast, Balzac includes all this information in its transaction code, allowing the tool to perform some sanity checks on the whole set of transactions, e.g., that each witness correctly redeems its own input. Such kind of checks have to be done in Ivy in an interactive way, by testing the code in its web playground. This requires to provide explicit parameters to each <inline-formula><mml:math id="M171"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>contract</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, as well as the <monospace>absLock</monospace>.</p></sec>
<sec id="s5">
<title>5. Simplicity</title>
<p>Simplicity (O&#x00027;Connor, <xref ref-type="bibr" rid="B35">2017</xref>) is an alternative language for Bitcoin scripts, aimed at replacing the Bitcoin scripting language with a more easily analyzable one, neglecting backward compatibility with Bitcoin. Technically, it is a first-order simply-typed &#x003BB;-calculus. Its types include a unit type 1, product types <italic>A</italic> &#x000D7; <italic>B</italic>, and sum types <italic>A</italic> &#x0002B; <italic>B</italic>, but no function types. More complex types are defined in terms of these basic ones: for instance, the type of booleans is defined as 2 &#x0003D; 1 &#x0002B; 1, while fixed-length bitstring types are defined e.g., as Hash256 &#x0003D; 2<sup>256</sup> &#x0003D; 2&#x000D7;2 &#x000D7; &#x022EF; . By construction, each type is inhabited by finitely many values. Because of this, Simplicity can be proven to be universal, i.e., its combinators allow to define any function <italic>f</italic> : <italic>A</italic> &#x022A2; <italic>B</italic> between types <italic>A</italic> and <italic>B</italic>.</p>
<p>Among the primitive combinators, we find <monospace>pair</monospace> <italic>a b</italic> : <italic>C</italic> &#x022A2; <italic>A</italic> &#x000D7; <italic>B</italic> which constructs a pair with the outputs of functions <italic>a</italic> : <italic>C</italic> &#x022A2; <italic>A</italic> and <italic>b</italic> : <italic>C</italic> &#x022A2; <italic>B</italic>. Dually, <monospace>take</monospace> <italic>t</italic> : <italic>A</italic> &#x000D7; <italic>B</italic> &#x022A2; <italic>C</italic> applies <italic>t</italic> : <italic>A</italic> &#x022A2; <italic>C</italic> to the first component of the input pair, while <monospace>drop</monospace> <italic>s</italic> : <italic>A</italic> &#x000D7; <italic>B</italic> &#x022A2; <italic>C</italic> applies <italic>s</italic> : <italic>B</italic> &#x022A2; <italic>C</italic> to the second component. Values in sum types can be eliminated using <monospace>case</monospace> <italic>s t</italic>:(<italic>A</italic>&#x0002B;<italic>B</italic>) &#x000D7; <italic>C</italic> &#x022A2; <italic>D</italic>, which checks whether its first input is a &#x0201C;left&#x0201D; value of type <italic>A</italic> or a &#x0201C;right&#x0201D; value of type <italic>B</italic>. In the former case, <monospace>case</monospace> <italic>s t</italic> applies <italic>s</italic> : <italic>A</italic> &#x000D7; <italic>C</italic> &#x022A2; <italic>D</italic> to the inputs, otherwise it applies <italic>t</italic> : <italic>B</italic> &#x000D7; <italic>C</italic> &#x022A2; <italic>D</italic>. Note that <monospace>case</monospace> generalizes the usual &#x0201C;if-then-else&#x0201D; expression, which only operates on booleans. Simplicity features an identity combinator <monospace>iden</monospace> : <italic>A</italic> &#x022A2; <italic>A</italic>, and a composition combinator <italic>s</italic>; <italic>t</italic> : <italic>A</italic> &#x022A2; <italic>C</italic> which sequences the combinators <italic>s</italic> : <italic>A</italic> &#x022A2; <italic>B</italic> and <italic>t</italic> : <italic>B</italic> &#x022A2; <italic>C</italic>. Finally, the combinator <monospace>unit</monospace> : <italic>A</italic> &#x022A2; 1 discards any value of any type <italic>A</italic>, while <monospace>fail</monospace> : <italic>A</italic> &#x022A2; 1 causes the program to abort unsuccessfully, making the transaction redemption fail.</p>
<p>To showcase how Simplicity can be used in modeling Bitcoin contracts, we replace the <inline-formula><mml:math id="M172"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>output</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> scripts in the Balzac transactions of the timed commitment protocol (<xref ref-type="fig" rid="F1">Figure 1</xref>) with equivalent Simplicity programs. Note that all the other fields of the transactions remain unchanged, since Simplicity does not feature a model of transactions (this is because O&#x00027;Connor, <xref ref-type="bibr" rid="B35">2017</xref> focuses on scripts, without detailing how to use them to formalize multi-transaction smart contracts like the timed commitment).</p>
<p>We start by modeling some constant values. These are combinators that can take as input a value of any type <italic>A</italic>, and return a constant value (neglecting the input). More precisely, we assume the following:
<list list-type="bullet">
<list-item><p><monospace>kApub</monospace> : <italic>A</italic> &#x022A2; PubKey models the public key of <inline-formula><mml:math id="M173"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> (similarly, <monospace>kBpub</monospace> : <italic>A</italic> &#x022A2; PubKey for <inline-formula><mml:math id="M174"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>);</p></list-item>
<list-item><p><monospace>deadline</monospace> : <italic>A</italic> &#x022A2; Date models the deadline before which <inline-formula><mml:math id="M175"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> should reveal her secret;</p></list-item>
<list-item><p><monospace>h</monospace> : <italic>A</italic> &#x022A2; Hash256 models the hash of the secret committed by <inline-formula><mml:math id="M176"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>.</p></list-item>
</list></p>
<p>Simplicity also features combinators that operate on the (implicit) redeeming transaction. For instance, <monospace>txHash</monospace> : 1 &#x022A2; Hash256 returns the hash of such a transaction (to keep our treatment simple, here we neglect the signature modifiers, affecting which parts of a transactions are considered). The combinator <monospace>txHash</monospace> is often used together with <monospace>versig</monospace> : Signature &#x000D7; (PubKey &#x000D7; Hash256) &#x022A2; 2, which verifies a given signature against a public key and the hash of the signed message. The result of <monospace>versig</monospace> is a boolean, denoting whether the verification succeeded or not. In our example we also use the combinators <monospace>equal</monospace> : Hash256 &#x000D7; Hash256 &#x022A2; 2, which checks whether two hashes are equal, and <inline-formula><mml:math id="M177"><mml:mrow><mml:mstyle style="font-family:courier;color:#00afb4"><mml:mtext>checkDate</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>:Date &#x022A2; 1, which verifies that the <inline-formula><mml:math id="M178"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>absLock</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> field in the (implicit) redeeming transaction contains a later date than the one provided as input, failing in the other case. Further, the combinator <monospace>witness</monospace> extracts the witness from the (implicit) redeeming transaction.</p>
<p>We start by describing the <inline-formula><mml:math id="M179"><mml:mrow><mml:mstyle style="font-family:courier;color:#006eb9"><mml:mtext>output</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> script of the <inline-formula><mml:math id="M180"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction, since it is the simplest one (it is just a signature verification on the redeeming transaction). The Simplicity program is the following:</p>
<preformat>
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;(pair&#x000A0;witness&#x000A0;(pair&#x000A0;kApub&#x000A0;txHash)&#x000A0;;&#x000A0;pair&#x000A0;versig
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;unit&#x000A0;;&#x000A0;case&#x000A0;fail&#x000A0;unit)
</preformat>
<p>Here, <monospace>witness</monospace> : 1 &#x022A2; Signature denotes a signature provided by the redeeming transaction. It is used to form a triple with the public key of <inline-formula><mml:math id="M181"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> and the hash of the redeeming transaction. This triple is then fed to <monospace>versig</monospace> for verification. If the signature verification fails, the combinator <monospace>fail</monospace> aborts the program preventing <inline-formula><mml:math id="M182"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to be redeemed. Otherwise, if the verification succeeds, <monospace>unit</monospace> is used to allow the redemption. The output script used in the <inline-formula><mml:math id="M183"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction is similar.</p>
<p>The <inline-formula><mml:math id="M184"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction is more complex, since its output script involves two conditions, which can be satisfied by witnesses of two forms: either a pair containing <inline-formula><mml:math id="M185"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature and her secret, or <inline-formula><mml:math id="M186"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature (but only after the <monospace>deadline</monospace>). We uniformly represent these cases by assuming that <monospace>witness</monospace> has a sum type, <monospace>witness</monospace> : 1 &#x022A2; (Signature &#x000D7; Secret256) &#x0002B; Signature. Then, the output script is the following program:</p>
<preformat>
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;(pair&#x000A0;witness&#x000A0;unit&#x000A0;;&#x000A0;case&#x000A0;(take&#x000A0;SA)&#x000A0;(take&#x000A0;SB))
</preformat>
<p>The program above checks whether the witness is of the &#x0201C;left&#x0201D; form Signature &#x000D7; Secret256 or of the &#x0201C;right&#x0201D; form Signature. In the first case, the program applies <monospace>SA</monospace> to the pair at hand, while in the second case it applies <monospace>SB</monospace> to the signature.</p>
<p>The subprograms <monospace>SA</monospace> : Signature &#x000D7; Secret256 &#x022A2; 1 and <monospace>SB</monospace> : Signature &#x022A2; 1 are as follows:</p>
<preformat>
&#x000A0;&#x000A0;&#x000A0;&#x000A0;SA&#x000A0;=&#x000A0;(pair
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;(drop&#x000A0;(pair&#x000A0;sha256&#x000A0;h&#x000A0;;&#x000A0;pair&#x000A0;equal&#x000A0;unit&#x000A0;;
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;case&#x000A0;fail&#x000A0;unit))
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;(take&#x000A0;(pair&#x000A0;iden&#x000A0;(pair&#x000A0;kApub&#x000A0;txHash)&#x000A0;;
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;pair&#x000A0;versig&#x000A0;unit&#x000A0;;&#x000A0;case&#x000A0;fail&#x000A0;unit))
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;;&#x000A0;unit)
&#x000A0;&#x000A0;&#x000A0;&#x000A0;SB&#x000A0;=&#x000A0;(pair&#x000A0;iden&#x000A0;(pair&#x000A0;kBpub&#x000A0;txHash)
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;;&#x000A0;pair&#x000A0;versig&#x000A0;unit
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;;&#x000A0;case&#x000A0;fail&#x000A0;(take&#x000A0;(deadline&#x000A0;;&#x000A0;checkDate)))
</preformat>
<p>Intuitively, <monospace>SA</monospace> constructs a pair 1 &#x000D7; 1 and then discards it using the final <monospace>unit</monospace>. The value of the pair is indeed immaterial, but the evaluation of its components verifies the witnesses. Indeed, in the first component we compute the hash of the provided secret using <monospace>sha256</monospace> and we compare it with the committed hash <monospace>h</monospace>. If these hashes are <monospace>equal</monospace>, the combinator <monospace>case</monospace> evaluates <monospace>unit</monospace>, resulting in a success; otherwise, if they differ, <monospace>case</monospace> evaluates <monospace>fail</monospace>, causing a failure. Instead, the second component verifies the signature in the witness against the public key of <inline-formula><mml:math id="M187"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> and the hash of the (implicit) redeeming transaction. This program is analogous to the one used for the <inline-formula><mml:math id="M188"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction.</p>
<p>The program <monospace>SB</monospace> verifies a signature in a similar way, except that when the verification succeeds, instead of simply evaluating <monospace>unit</monospace> and succeed, we evaluate <monospace>deadline ;</monospace> <monospace>checkDate</monospace> to check that the <monospace>absLock</monospace> field of the redeeming transaction is correct.</p></sec>
<sec id="s6">
<title>6. Uppaal</title>
<p>Andrychowicz et al. (<xref ref-type="bibr" rid="B3">2014b</xref>) model Bitcoin contracts in Uppaal (Behrmann et al., <xref ref-type="bibr" rid="B15">2004</xref>), a model checking framework based on Timed Automata (TA; Alur and Dill, <xref ref-type="bibr" rid="B1">1994</xref>). The idea is that the behavior of each participant in a contract (including the adversary) is modeled as a TA, and the overall system is the network obtained by composing these TAs, plus a TA which models the Bitcoin network.</p>
<p>The overall system state is given by the current <italic>location</italic> of each TA, the values of all the <italic>clocks</italic> used in the TAs, and the values of a set of global <italic>variables</italic>. Transitions between locations are guarded by a predicate on the global variables and the clocks, and can trigger an update of the global variables. Each location has an invariant (true by default), which must be satisfied as long as the TA stays in that location. Both predicates and updates are defined through a C-like procedural language. A network of TAs can be model-checked, using a simplified version of TCTL (timed computation tree logic) to express queries.</p>
<p>We illustrate this modeling technique by slightly adapting the timed commitment contract in Andrychowicz et al. (<xref ref-type="bibr" rid="B3">2014b</xref>), to make it coherent with the models in the previous sections (in particular, to avoid using <inline-formula><mml:math id="M189"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature in <inline-formula><mml:math id="M190"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>). This model exploits global variables to represent the current state of the Bitcoin network (e.g., which transactions have been sent or confirmed), as well as the knowledge of the participants (e.g., private keys and secrets). The initial knowledge is set by the procedure <monospace>init_prot</monospace> (see <bold>Figure 4</bold>, lines <inline-formula><mml:math id="M191"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>19</mml:mn></mml:mstyle></mml:math></inline-formula>&#x02013;<inline-formula><mml:math id="M192"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>24</mml:mn></mml:mstyle></mml:math></inline-formula>).</p>
<p>We show in <xref ref-type="fig" rid="F3">Figure 3</xref> (left) the TA modeling the Bitcoin network. Essentially, the transition labeled <monospace>init_bc()</monospace> initializes the state of all the needed transactions, calling the procedure <monospace>init_bc</monospace> to update the state (see <xref ref-type="fig" rid="F4">Figure 4</xref>, lines <inline-formula><mml:math id="M193"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>1</mml:mn></mml:mstyle></mml:math></inline-formula>&#x02013;<inline-formula><mml:math id="M194"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>8</mml:mn></mml:mstyle></mml:math></inline-formula>). Besides the four protocol transactions (an initial deposit, <inline-formula><mml:math id="M195"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, <inline-formula><mml:math id="M196"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, and <inline-formula><mml:math id="M197"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>), <monospace>init_bc</monospace> creates four additional transactions, used by the adversary to attempt to disrupt the contract by redeeming the protocol transactions. After <monospace>init_bc</monospace>, the TA waits until the participants broadcasts some transaction (<monospace>is_waiting</monospace>), and fulfills such requests (<monospace>try_to_confirm</monospace>). The invariant on the rightmost location ensures that each transaction is confirmed within <monospace>MAX_LATENCY</monospace> of sending it. Moreover, the TA also sets the flag <monospace>timelock_passed</monospace> on all the transactions when the time specified by their <monospace>timelock</monospace> field is reached, so that they can now be appended.</p>
<fig id="F3" position="float">
<label>Figure 3</label>
<caption><p>Uppaal timed automata for the blockchain network <bold>(Left)</bold> and for the adversary <bold>(Right)</bold>.</p></caption>
<graphic xlink:href="fbloc-02-00008-g0003.tif"/>
</fig>
<fig id="F4" position="float">
<label>Figure 4</label>
<caption><p>Snippet of Uppaal code for the timed commitment contract.</p></caption>
<graphic xlink:href="fbloc-02-00008-g0004.tif"/>
</fig>
<p>The TA modeling the adversary has a single location, with a self-loop (<xref ref-type="fig" rid="F4">Figure 4</xref>, right). This TA simply tries to append to the blockchain any transaction, in a non-deterministic fashion (<monospace>try_to_append</monospace>). Before modifying the state of the blockchain, the procedure <monospace>try_to_append</monospace> verifies that the adversary can indeed satisfy the output scripts of the input transactions. This is checked by <monospace>can_create_input_script</monospace> (see <xref ref-type="fig" rid="F5">Figure 5</xref>, lines <inline-formula><mml:math id="M198"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>10</mml:mn></mml:mstyle></mml:math></inline-formula>&#x02013;<inline-formula><mml:math id="M199"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>16</mml:mn></mml:mstyle></mml:math></inline-formula>). This procedure deals separately with standard and non-standard output scripts. Standard output scripts are dealt with by <monospace>know_signature</monospace>, which checks that either the signature or the private key are known. Non-standard output scripts are hard-coded within <monospace>can_create_input_script</monospace> : in our example, this only happens for the script in <inline-formula><mml:math id="M200"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, which is detected by <monospace>o.script == 0</monospace> at line <inline-formula><mml:math id="M201"><mml:mstyle style="font-family:courier;color:#3853a4"><mml:mn>13</mml:mn></mml:mstyle></mml:math></inline-formula>. The script is satisfied either by <inline-formula><mml:math id="M202"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature (using <monospace>C_KEY</monospace>) and the secret, or by <inline-formula><mml:math id="M203"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s signature (using <monospace>R_KEY</monospace>) when the <monospace>timelock</monospace> is after the deadline. Note that the implementation of <monospace>can_create_input_script</monospace> strictly depends on the contract at hand, in particular on all the non-standard output scripts used by the contract.</p>
<fig id="F5" position="float">
<label>Figure 5</label>
<caption><p>Uppaal timed automaton for an honest receiver B.</p></caption>
<graphic xlink:href="fbloc-02-00008-g0005.tif"/>
</fig>
<p>Finally, in <xref ref-type="fig" rid="F5">Figure 5</xref> we show the TA describing the behavior of an honest receiver <inline-formula><mml:math id="M204"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>. The TA initially waits for a confirmed <inline-formula><mml:math id="M205"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction. If that transaction is not confirmed within <monospace>MAX_LATENCY</monospace>, <inline-formula><mml:math id="M206"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> does not accept the commitment, and moves to location <monospace>failure</monospace>. Otherwise, <inline-formula><mml:math id="M207"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> checks that he can construct the input script for <inline-formula><mml:math id="M208"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> (this is always true, since <inline-formula><mml:math id="M209"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> knows <monospace>R_KEY</monospace>) and then <monospace>accept</monospace>s the commitment. After that, <inline-formula><mml:math id="M210"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> simply tries to append the <inline-formula><mml:math id="M211"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> transaction as soon as it is enabled (<monospace>try_to_send</monospace>).</p>
<p>Uppaal can be used to verify that the given model behaves as expected. For instance, when <inline-formula><mml:math id="M212"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> is impersonated by the adversary, an expected property is that in all runs where <inline-formula><mml:math id="M213"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> does not reject the commitment (<monospace>failure</monospace>), after time <monospace>DEADLINE&#x0002B;MAX_LATENCY</monospace> either <inline-formula><mml:math id="M214"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> knows the committed secret (<monospace>know_secret[0]</monospace>) or he earns a reward (<monospace>hold_bitcoins</monospace>). This property is formalized by the following TCTL formula, which is verified as true by Uppaal:</p>
<preformat>
&#x000A0;&#x000A0;A[]&#x000A0;(not&#x000A0;BobTA.failure&#x000A0;and&#x000A0;time&#x000A0;&#x0003E;=
&#x000A0;&#x000A0;&#x000A0;DEADLINE&#x0002B;MAX_LATENCY)&#x000A0;imply
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;(parties[BOB].know_secret[0]&#x000A0;or
&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;&#x000A0;hold_bitcoins(parties[BOB])&#x000A0;==&#x000A0;1)
</preformat>
</sec>
<sec id="s7">
<title>7. BitML</title>
<p>Bartoletti and Zunino (<xref ref-type="bibr" rid="B13">2018</xref>) express Bitcoin contracts through a simple process calculus, named BitML. The workflow of BitML contracts consists of three phases. First, participants can broadcast a <italic>contract advertisement</italic>, which specifies the actual contract and the preconditions to its execution (e.g., depositing given amounts of bitcoins). Then, participants can accept some contract by fulfilling all the required preconditions. When all the needed participants have fulfilled the preconditions, the contract is stipulated and can be executed. Executing the contract will eventually result in a transfer of the bitcoins deposited by participants, according to the logic defined by the contract.</p>
<p>A contract advertisement is modeled as a term of the form {<inline-formula><mml:math id="M215"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula>}<inline-formula><mml:math id="M216"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>, where <inline-formula><mml:math id="M217"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula> is the contract, specifying the rules to transfer bitcoins, while <inline-formula><mml:math id="M218"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula> is the set of preconditions. Preconditions (<xref ref-type="fig" rid="F6">Figure 6</xref>, left) may require participants to deposit some <inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>, or to commit to some secret. For instance, our timed commitment contract requires the following preconditions:</p>
<graphic xlink:href="fbloc-02-00008-e0005.tif"/>
<p>This means that <inline-formula><mml:math id="M219"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> must put a persistent deposit (named <italic>x</italic>) of 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>, and must commit to a secret <italic>a</italic> before the contract starts. Instead, <inline-formula><mml:math id="M220"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> puts a null deposit, named <italic>y</italic> (here, for simplicity we have omitted the transaction fees). Once the two deposit has been used for stipulating the contract, either <inline-formula><mml:math id="M221"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> or <inline-formula><mml:math id="M222"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> will redeem 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/> by executing the contract.</p>
<fig id="F6" position="float">
<label>Figure 6</label>
<caption><p>Syntax of BitML contracts and preconditions.</p></caption>
<graphic xlink:href="fbloc-02-00008-g0006.tif"/>
</fig>
<p>A contract is a guarded choice of branches, with the syntax in <xref ref-type="fig" rid="F6">Figure 6</xref>, right. For instance, with the precondition <inline-formula><mml:math id="M223"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula> above, we can model the timed commitment contract in BitML as follows:</p>
<graphic xlink:href="fbloc-02-00008-e0006.tif"/>
<p>Contract <inline-formula><mml:math id="M224"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula> is a guarded choice between two branches, separated by the &#x0002B; operator. The first branch <monospace>reveal</monospace> <italic>a</italic>. <monospace>withdraw</monospace> <inline-formula><mml:math id="M225"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> can be taken only by <inline-formula><mml:math id="M226"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, by revealing the previously committed secret <italic>a</italic>. After that, anyone can execute <monospace>withdraw</monospace> <inline-formula><mml:math id="M227"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, which transfers the 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/> deposit back to <inline-formula><mml:math id="M228"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>. Instead, the second branch <monospace>after</monospace> <monospace>deadline</monospace> : <monospace>withdraw</monospace> <inline-formula><mml:math id="M229"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> can be taken only after the <monospace>deadline</monospace>. Its execution causes the deposit to be transferred to <inline-formula><mml:math id="M230"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>. Intuitively, stipulating <inline-formula><mml:math id="M231"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula> in BitML corresponds, in Balzac, to appending the transaction <inline-formula><mml:math id="M232"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Commit</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula> to the blockchain. Further, taking the first branch of <inline-formula><mml:math id="M233"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula> corresponds to appending <inline-formula><mml:math id="M234"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Reveal</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>, while taking the second branch corresponds to appending <inline-formula><mml:math id="M235"><mml:mrow><mml:mstyle style="font-family:courier;color:#91268f"><mml:mtext>Timeout</mml:mtext></mml:mstyle></mml:mrow></mml:math></inline-formula>. In spite of this similarity, BitML uses higher level code, which does not directly describe the Bitcoin transactions, but rather focuses on how the bitcoins are transferred.</p>
<p>We remark that a BitML contract only specifies which moves may be taken by participants, while their actual behavior must be specified separately from the contract, through <italic>strategies</italic>. Strategies roughly play the same role as Balzac endpoint protocols, even if in Bartoletti and Zunino (<xref ref-type="bibr" rid="B13">2018</xref>) they are simply modeled as algorithms, and not expressed in a specific formal language.</p>
<p>The semantics of BitML is a labeled transition system between configurations, which are the parallel composition of terms of the following form:
<list list-type="bullet">
<list-item><p>{<inline-formula><mml:math id="M236"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula>}<inline-formula><mml:math id="M237"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>, representing an advertisement of contract <inline-formula><mml:math id="M238"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula> with preconditions <inline-formula><mml:math id="M239"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula>;</p></list-item>
<list-item><p>&#x02329;<inline-formula><mml:math id="M240"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>, <italic>v</italic>&#x0232A;<sub><italic>x</italic></sub>, representing a stipulated contract, holding a current balance of <italic>v</italic><inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>. The name <italic>x</italic> uniquely identifies the contract in a configuration;</p></list-item>
<list-item><p>&#x02329;<inline-formula><mml:math id="M241"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, <italic>v</italic>&#x0232A;<sub><italic>x</italic></sub> representing a fund of <italic>v</italic><inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/> owned by <inline-formula><mml:math id="M242"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, and with unique name <italic>x</italic>;</p></list-item>
<list-item><p><inline-formula><mml:math id="M243"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>[&#x003C7;], representing <inline-formula><mml:math id="M244"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s <italic>authorization</italic> to perform some operation &#x003C7;;</p></list-item>
<list-item><p>{<inline-formula><mml:math id="M245"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> : <italic>a&#x00023;N</italic>}, representing that <inline-formula><mml:math id="M246"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> has <italic>committed</italic> to a random secret <italic>a</italic> with (secret) length <italic>N</italic>;</p></list-item>
<list-item><p><inline-formula><mml:math id="M247"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> : <italic>a&#x00023;N</italic>, representing that <inline-formula><mml:math id="M248"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> has <italic>revealed</italic> her secret <italic>a</italic> (with its length <italic>N</italic>);</p></list-item>
<list-item><p><italic>t</italic> &#x02208; &#x02115; is a global time (can only occur once in a configuration).</p></list-item>
</list></p>
<p>Once stipulated, contracts start their execution with a balance, initially set to the sum of the persistent deposits required by the preconditions. Running a contract will affect its balance, when participants deposit/withdraw funds to/from the contract. Back to our timed commitment contract, let the initial configuration be &#x00393; &#x0003D; &#x02329;<inline-formula><mml:math id="M249"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>&#x0232A;<sub><italic>x</italic></sub> &#x02223; &#x02329;<inline-formula><mml:math id="M250"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>, 0<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>&#x0232A;<sub><italic>y</italic></sub> &#x02223; <italic>t</italic>, with <italic>t</italic> &#x0003C; <monospace>deadline</monospace>. A possible computation where <inline-formula><mml:math id="M251"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> reveals her secret and then redeems the deposit is the following:</p>
<graphic xlink:href="fbloc-02-00008-e0007.tif"/>
<p>Step (1) advertises {<inline-formula><mml:math id="M252"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula>}<inline-formula><mml:math id="M253"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>, which refers to the deposits <italic>x</italic> and <italic>y</italic>, available in the initial configuration &#x00393;. At step (2), <inline-formula><mml:math id="M254"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> commits to a secret <italic>a</italic>, with length <italic>N</italic>. The term <inline-formula><mml:math id="M255"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>[&#x00023; &#x025B9; {<inline-formula><mml:math id="M256"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula>}<inline-formula><mml:math id="M257"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>] witnesses that <inline-formula><mml:math id="M258"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s secrets have been committed to. Similarly, at step (3) <inline-formula><mml:math id="M259"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> adds the term <inline-formula><mml:math id="M260"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula>[&#x00023; &#x025B9; {<inline-formula><mml:math id="M261"><mml:mstyle mathcolor="#ed007e"><mml:mi>G</mml:mi></mml:mstyle></mml:math></inline-formula>}<inline-formula><mml:math id="M262"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>]. At steps (4)&#x02013;(5), <inline-formula><mml:math id="M263"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> and <inline-formula><mml:math id="M264"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> give their authorization to stipulate <inline-formula><mml:math id="M265"><mml:mstyle mathcolor="#ed007e"><mml:mi>C</mml:mi></mml:mstyle></mml:math></inline-formula>, by providing their authorizations to spend the deposits <italic>x</italic> and <italic>y</italic>, respectively. At step (6) the contract is stipulated, transferring the deposits <italic>x</italic> and <italic>y</italic> to the contract. At step (7), <inline-formula><mml:math id="M266"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> reveals her secret. After that, the action <monospace>reveal</monospace> <italic>a</italic> is performed at step (8), reducing the contract to <monospace>withdraw</monospace> <inline-formula><mml:math id="M267"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>, and discarding the <monospace>after</monospace> branch. Finally, step (9) performs the <monospace>withdraw</monospace> <inline-formula><mml:math id="M268"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> action, producing a fresh deposit <italic>x</italic><sub>3</sub> with 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/> redeemable by <inline-formula><mml:math id="M269"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>.</p>
<p>We also show a computation where <inline-formula><mml:math id="M270"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula> does not reveal her secret, and <inline-formula><mml:math id="M271"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> waits until <italic>t</italic>&#x02032; &#x0003E; <monospace>deadline</monospace> to redeem <inline-formula><mml:math id="M272"><mml:mstyle mathcolor="#009a55"><mml:mtext>A</mml:mtext></mml:mstyle></mml:math></inline-formula>&#x00027;s deposit. Starting from <inline-graphic xlink:href="fbloc-02-00008-i0002.tif"/> at time <italic>t</italic>, we have the following steps:</p>
<graphic xlink:href="fbloc-02-00008-e0008.tif"/>
<p>The first step lets the time pass, making the deadline expire. In the second step, <inline-formula><mml:math id="M274"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> fires the prefix <monospace>withdraw</monospace> <inline-formula><mml:math id="M275"><mml:mstyle mathcolor="#009a55"><mml:mtext>B</mml:mtext></mml:mstyle></mml:math></inline-formula> within the <monospace>after</monospace>, and in this way he collects 1<inline-graphic xlink:href="fbloc-02-00008-i0001.tif"/>.</p>
<p>Bartoletti and Zunino (<xref ref-type="bibr" rid="B13">2018</xref>) also introduce a compiler from BitML contracts into standard Bitcoin transactions. In this way, participants can effectively execute BitML contracts on the Bitcoin network, by appending the obtained transactions according to their strategies. The compiler enjoys a computational soundness property, which basically ensures that computational attacks to compiled contracts at the Bitcoin level are also observable at the BitML level. In practice, this result can be exploited to prove the correctness of static analyses on BitML contracts, like the one for liquidity presented in Bartoletti and Zunino (<xref ref-type="bibr" rid="B14">2019</xref>).</p></sec>
<sec sec-type="discussion" id="s8">
<title>8. Discussion</title>
<p>The works we have discussed in this survey serve different purposes, and consequently the formal models they introduce have substantial differences. Uppaal and Simplicity are the models which allow more expressiveness, not being constrained to be translated into actual Bitcoin transactions. On the other side, Balzac, Ivy and BitML can be compiled into Bitcoin, and so they suffer from the limitations of the Bitcoin scripting language&#x02014;although in a different way. Balzac covers most of the features of Bitcoin, including Segregated Witnesses, signature modifiers, and temporal constraints. Similarly, Ivy seems to cover most of the features of Bitcoin scripts. So, Balzac and Ivy seem suitable to specify any contract actually realizable on top of Bitcoin. BitML poses some limits to expressiveness, which however are exploited for verification purposes, as we will discuss below. For instance, BitML cannot exploit signature modifiers besides all-inputs / all-outputs, and it requires participants to sign all the transactions potentially used in a contract <italic>before</italic> stipulation. As a consequence of these limitations, BitML cannot express e.g., infinite-state crowdfunding contracts, which instead are expressible as Balzac endpoint protocols (Atzei et al., <xref ref-type="bibr" rid="B7">2018a</xref>), where signatures can be provided at any moment. Since this kind of contracts are inherently infinite-state (because the set of participants is not known a priori), modeling them in Uppaal seems unfeasible as well. Notwithstanding the limitations, BitML can express a wide variety of common contracts, as discussed in Bartoletti et al. (<xref ref-type="bibr" rid="B11">2018</xref>).</p>
<p>The higher level of abstraction featured by BitML allows for expressing complex contracts more succinctly than in the other models. For instance, a slight variant of the timed commitment contract where both participants are both committers and receivers can be specified in 3 lines of BitML (Bartoletti and Zunino, <xref ref-type="bibr" rid="B13">2018</xref>), while it requires 9 transactions (18, also considering those for the adversary) in Uppaal (Andrychowicz et al., <xref ref-type="bibr" rid="B3">2014b</xref>), as well as in the other transaction-based models. Another advantage of BitML is that it allows programmers to focus on high-level behaviors (revealing secrets, providing authorizations, checking deadlines, &#x02026;), rather than struggling with the low-level details of Bitcoin transactions (hashes, signatures, scripts, &#x02026;). Simplicity provides an alternative language for Bitcoin output scripts based on algebraic types, which, compared with Bitcoin scripts, can help the protocol designer to structure the data in a more rigorous way than using bare bit-strings. In this way, Simplicity also enables type checking, which helps to reduce programming errors. On the other hand, Simplicity differs from many declarative languages by using a point-free notation, which can be rather inconvenient to use directly, without leveraging a transformation from a more human-friendly point-full language (as in Cunha and Pinto <xref ref-type="bibr" rid="B20">2005</xref>). Ivy follows an imperative paradigm, allowing the user to specify the redeeming condition as a block of statements to be executed. Instead, Balzac output scripts are boolean expressions. Ivy allows multiple <monospace>clause</monospace>s within a contract, which are instead modeled as a disjunction in Balzac output scripts. Compared with Simplicity, Balzac and Ivy scripts are more restrictive, as they are bound to be encodable to Bitcoin scripts; instead, Simplicity scripts are meant as a replacement of Bitcoin ones. Among the models we have discussed, Uppaal is the only one which features a procedural language, which is used to define the various components of the Bitcoin network (including the participants in the contract). On the one hand, this language is quite flexible, as it could be used to model Bitcoin extensions; on the other hand, contract designers must pay special attention to craft models that can actually be executed in Bitcoin.</p>
<p>All the models presented in this paper (except Ivy) feature a formal semantics, and they all implement some form of checks on the code. Both Ivy and Balzac perform some basic type checking; further, since Balzac provides a view of all the transactions composing a contract, it also performs some complex sanity checks, e.g., whether the witnesses satisfy the predicates of the input transactions. Also Simplicity performs type checking, but with richer types; further, it features a static analysis to predict an upper bound to the memory consumption of the execution of scripts. BitML and Uppaal can also verify complex contract properties expressed in LTL, by model-checking the state space of the contract. Although this state space is potentially infinite for BitML, verification is possible through the finite-state abstraction in Bartoletti and Zunino (<xref ref-type="bibr" rid="B14">2019</xref>). Verification of Uppaal models is possible through the Uppaal model checker (<ext-link ext-link-type="uri" xlink:href="http://www.uppaal.org">http://www.uppaal.org</ext-link>); a tool for verifying BitML contracts is available (Atzei et al., <xref ref-type="bibr" rid="B8">2019</xref>). There also exists a formalization of BitML in Agda (<ext-link ext-link-type="uri" xlink:href="https://github.com/omelkonian/formal-bitml">https://github.com/omelkonian/formal-bitml</ext-link>), which allows for verifying properties of BitML contracts through a proof assistant.</p>
<p>A summary of the comparison between the models is in <xref ref-type="table" rid="T2">Table 1</xref>.</p>
<table-wrap position="float" id="T2">
<label>Table 1</label>
<caption><p>Comparison between the models of Bitcoin contracts.</p></caption>
<table frame="hsides" rules="groups">
<thead><tr>
<th valign="top" align="left"><bold>Model</bold></th>
<th valign="top" align="left"><bold>Expressiveness</bold></th>
<th valign="top" align="left"><bold>Abstraction level</bold></th>
<th valign="top" align="left"><bold>Verification</bold></th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top" align="left">Balzac</td>
<td valign="top" align="left"> &#x0003D; Bitcoin</td>
<td valign="top" align="left">Set of transaction</td>
<td valign="top" align="left">Basic type checking &#x0002B; sanity checking</td>
</tr>
<tr>
<td valign="top" align="left">Ivy</td>
<td valign="top" align="left"> &#x0003D; Bitcoin</td>
<td valign="top" align="left">Script</td>
<td valign="top" align="left">Basic type checking</td>
</tr>
<tr>
<td valign="top" align="left">Simplicity</td>
<td valign="top" align="left">&#x0003E; Bitcoin</td>
<td valign="top" align="left">Script</td>
<td valign="top" align="left">Type checking (with <italic>simple types</italic>)</td>
</tr>
<tr>
<td valign="top" align="left">Uppaal</td>
<td valign="top" align="left">&#x0003E; Bitcoin</td>
<td valign="top" align="left">Set of transaction &#x0002B; TA</td>
<td valign="top" align="left">LTL model checking</td>
</tr>
<tr>
<td valign="top" align="left">BitML</td>
<td valign="top" align="left">&#x0003C; Bitcoin</td>
<td valign="top" align="left">Contract</td>
<td valign="top" align="left">LTL model checking</td>
</tr>
</tbody>
</table>
</table-wrap>
</sec>
<sec sec-type="conclusions" id="s9">
<title>9. Conclusions</title>
<p>In this paper we have compared the various languages and models for Bitcoin contracts. The need for formal modeling of Bitcoin contracts is motivated by the surprising complexity that these contracts may exhibit: for instance, the literature reports the use of Bitcoin to implement financial services, auctions, timed commitments, lotteries, and a variety of other gambling games (Atzei et al., <xref ref-type="bibr" rid="B7">2018a</xref>, <xref ref-type="bibr" rid="B8">2019</xref>). Our survey aims to help programmers to choose the right model for their contracts, based on the required expressiveness and available verification tools.</p>
<p>A parallel line of research is that on formal models of smart contracts running on alternative blockchains. Currently, the main target of this research is Ethereum, the most widespread platform for smart contracts so far. Driven by the proliferation of vulnerabilities of Ethereum contracts (Atzei et al., <xref ref-type="bibr" rid="B6">2017</xref>) which have caused major money losses, many researchers have studied models and verification techniques to make Ethereum contracts more secure (Miller et al., <xref ref-type="bibr" rid="B31">2018</xref>). Several papers focus on EVM, the bytecode language interpreted by Ethereum clients, as well as the target of the compilation of high-level contract languages, like Solidity. Luu et al. (<xref ref-type="bibr" rid="B28">2016</xref>) give a partial formalization of the semantics of EVM, and exploit symbolic execution to detect some common vulnerability patterns of EVM contracts. Grishchenko et al. (<xref ref-type="bibr" rid="B22">2018b</xref>) and Hildenbrandt et al. (<xref ref-type="bibr" rid="B23">2018</xref>) formalize executable semantics of EVM, validated against the official Ethereum test suite; these semantics are the basis of static verifiers of EVM contracts, like e.g., Grishchenko et al. (<xref ref-type="bibr" rid="B21">2018a</xref>). Bhargavan et al. (<xref ref-type="bibr" rid="B17">2016</xref>) translate EVM into <bold>F</bold><sup>&#x0002A;</sup>, and uses its verification tools to detect vulnerabilities. Hirai (<xref ref-type="bibr" rid="B24">2017</xref>) uses the Isabelle/HOL proof assistant (Nipkow et al., <xref ref-type="bibr" rid="B34">2002</xref>) to verify the EVM code obtained by compiling a fragment of the Ethereum Name Service. Sergey et al. (<xref ref-type="bibr" rid="B36">2018</xref>) propose a strongly typed intermediate language for contracts, which are modeled as Communicating Automata; this richer structure (compared to EVM) simplifies formal reasoning, making contracts more amenable to verification.</p></sec>
<sec id="s10">
<title>Author Contributions</title>
<p>RZ and MB equally contributed to all parts of the paper.</p>
<sec>
<title>Conflict of Interest Statement</title>
<p>The authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.</p></sec></sec>
</body>
<back>
<ack><p>MB is partially supported by Aut. Reg. of Sardinia projects <italic>Sardcoin</italic> and <italic>Smart Collaborative Engineering</italic>. RZ is partially supported by MIUR PON <italic>Distributed Ledgers for Secure Open Communities</italic>.</p>
</ack>
<ref-list>
<title>References</title>
<ref id="B1">
<citation citation-type="journal"><person-group person-group-type="author"><name><surname>Alur</surname> <given-names>R.</given-names></name> <name><surname>Dill</surname> <given-names>D. L.</given-names></name></person-group> (<year>1994</year>). <article-title>A theory of timed automata</article-title>. <source>Theor. Comput. Sci.</source> <volume>126</volume>, <fpage>183</fpage>&#x02013;<lpage>235</lpage>. <pub-id pub-id-type="doi">10.1016/0304-3975(94)90010-8</pub-id></citation></ref>
<ref id="B2">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Andrychowicz</surname> <given-names>M.</given-names></name> <name><surname>Dziembowski</surname> <given-names>S.</given-names></name> <name><surname>Malinowski</surname> <given-names>D.</given-names></name> <name><surname>Mazurek</surname> <given-names>L.</given-names></name></person-group> (<year>2014a</year>). <article-title>&#x0201C;Fair two-party computations via Bitcoin deposits,&#x0201D;</article-title> in <source>Financial Cryptography Workshops</source> Vol. <volume>8438</volume> of LNCS (<publisher-loc>Christ Church</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>105</fpage>&#x02013;<lpage>121</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-662-44774-1_8</pub-id></citation></ref>
<ref id="B3">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Andrychowicz</surname> <given-names>M.</given-names></name> <name><surname>Dziembowski</surname> <given-names>S.</given-names></name> <name><surname>Malinowski</surname> <given-names>D.</given-names></name> <name><surname>Mazurek</surname> <given-names>&#x00141;.</given-names></name></person-group> (<year>2014b</year>). <article-title>&#x0201C;Modeling Bitcoin contracts by timed automata,&#x0201D;</article-title> in <source>International Conference on Formal Modeling and Analysis of Timed Systems (FORMATS)</source>, Vol. <volume>8711</volume> of LNCS (<publisher-loc>Florence</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>7</fpage>&#x02013;<lpage>22</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-319-10512-3_2</pub-id></citation></ref>
<ref id="B4">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Andrychowicz</surname> <given-names>M.</given-names></name> <name><surname>Dziembowski</surname> <given-names>S.</given-names></name> <name><surname>Malinowski</surname> <given-names>D.</given-names></name> <name><surname>Mazurek</surname> <given-names>L.</given-names></name></person-group> (<year>2014c</year>). <article-title>&#x0201C;Secure multiparty computations on Bitcoin,&#x0201D;</article-title> in <source>IEEE Symposium on Security and Privacy</source> (<publisher-loc>Berkeley, CA</publisher-loc>) <fpage>443</fpage>&#x02013;<lpage>458</lpage>. <pub-id pub-id-type="doi">10.1109/SP.2014.35</pub-id></citation></ref>
<ref id="B5">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Antonopoulos</surname> <given-names>A. M.</given-names></name></person-group> (<year>2017</year>). <source>Mastering Bitcoin: Programming the Open Blockchain, 2nd Edn.</source> (<publisher-loc>Sebastopol, CA</publisher-loc>: <publisher-name>O&#x00027;Reilly Media, Inc.</publisher-name>).</citation></ref>
<ref id="B6">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Atzei</surname> <given-names>N.</given-names></name> <name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Cimoli</surname> <given-names>T.</given-names></name></person-group> (<year>2017</year>). <article-title>&#x0201C;A survey of attacks on Ethereum smart contracts (SoK),&#x0201D;</article-title> in <source>POST</source>, Vol. <volume>10204</volume> of LNCS (<publisher-loc>Uppsala</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>164</fpage>&#x02013;<lpage>186</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-662-54455-6_8</pub-id></citation></ref>
<ref id="B7">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Atzei</surname> <given-names>N.</given-names></name> <name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Cimoli</surname> <given-names>T.</given-names></name> <name><surname>Lande</surname> <given-names>S.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2018a</year>). <article-title>&#x0201C;SoK: unraveling Bitcoin smart contracts,&#x0201D;</article-title> in <source>POST</source>, Vol. <volume>10804</volume> of LNCS (<publisher-loc>Thessaloniki</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>217</fpage>&#x02013;<lpage>242</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-319-89722-6</pub-id></citation></ref>
<ref id="B8">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Atzei</surname> <given-names>N.</given-names></name> <name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Lande</surname> <given-names>S.</given-names></name> <name><surname>Yoshida</surname> <given-names>N.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2019</year>). <article-title>&#x0201C;Developing secure Bitcoin contracts with BitML,&#x0201D;</article-title> in <source>ESEC/FSE</source> (<publisher-loc>Tallinn</publisher-loc>). <pub-id pub-id-type="doi">10.1145/3338906.3341173</pub-id></citation></ref>
<ref id="B9">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Atzei</surname> <given-names>N.</given-names></name> <name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Lande</surname> <given-names>S.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2018b</year>). <article-title>&#x0201C;A formal model of Bitcoin transactions,&#x0201D;</article-title> in <source>Financial Cryptography and Data Security</source>, Vol. <volume>10957</volume> of <italic>LNCS</italic> (<publisher-loc>Santa Barbara</publisher-loc>: <publisher-name>Springer</publisher-name>). <pub-id pub-id-type="doi">10.1007/978-3-662-58387-6</pub-id></citation></ref>
<ref id="B10">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Banasik</surname> <given-names>W.</given-names></name> <name><surname>Dziembowski</surname> <given-names>S.</given-names></name> <name><surname>Malinowski</surname> <given-names>D.</given-names></name></person-group> (<year>2016</year>). <article-title>&#x0201C;Efficient zero-knowledge contingent payments in cryptocurrencies without scripts,&#x0201D;</article-title> in <source>ESORICS</source>, Vol. 9879 of <italic>LNCS</italic> (<publisher-loc>Heraklion</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>261</fpage>&#x02013;<lpage>280</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-319-45741-3_14</pub-id></citation></ref>
<ref id="B11">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Cimoli</surname> <given-names>T.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2018</year>). <article-title>&#x0201C;Fun with bitcoin smart contracts,&#x0201D;</article-title> in <source>ISoLA</source> (<publisher-loc>Limassol</publisher-loc>), <fpage>432</fpage>&#x02013;<lpage>449</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-030-03427-6_32</pub-id></citation></ref>
<ref id="B12">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2017</year>). <article-title>&#x0201C;Constant-deposit multiparty lotteries on Bitcoin,&#x0201D;</article-title> in <source>Financial Cryptography Workshops</source>, Vol. <volume>10323</volume> of LNCS (<publisher-loc>Sliema</publisher-loc>: <publisher-name>Springer</publisher-name>). <pub-id pub-id-type="doi">10.1007/978-3-319-70278-0</pub-id></citation></ref>
<ref id="B13">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2018</year>). <article-title>&#x0201C;BitML: a calculus for Bitcoin smart contracts,&#x0201D;</article-title> in <source>ACM CCS</source> (<publisher-loc>New York, NY</publisher-loc>: <publisher-name>ACM</publisher-name>). <pub-id pub-id-type="doi">10.1145/3243734.3243795</pub-id></citation></ref>
<ref id="B14">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bartoletti</surname> <given-names>M.</given-names></name> <name><surname>Zunino</surname> <given-names>R.</given-names></name></person-group> (<year>2019</year>). <article-title>&#x0201C;Verifying liquidity of bitcoin contracts,&#x0201D;</article-title> in <source>POST</source>, Vol. <volume>11426</volume> of LNCS (<publisher-loc>Cham</publisher-loc>: <publisher-name>Springer</publisher-name>).</citation></ref>
<ref id="B15">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Behrmann</surname> <given-names>G.</given-names></name> <name><surname>David</surname> <given-names>A.</given-names></name> <name><surname>Larsen</surname> <given-names>K. G.</given-names></name></person-group> (<year>2004</year>). <article-title>&#x0201C;A tutorial on Uppaal,&#x0201D;</article-title> in <source>Formal Methods for the Design of Real-Time Systems</source>, Vol. 3185 of <italic>LNCS</italic> (<publisher-loc>Bertinoro</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>200</fpage>&#x02013;<lpage>236</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-540-30080-9_7</pub-id></citation></ref>
<ref id="B16">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bentov</surname> <given-names>I.</given-names></name> <name><surname>Kumaresan</surname> <given-names>R.</given-names></name></person-group> (<year>2014</year>). <article-title>&#x0201C;How to use Bitcoin to design fair protocols,&#x0201D;</article-title> in <source>CRYPTO</source>, Vol. <volume>8617</volume> of LNCS (<publisher-loc>Santa Barbara, CA</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>421</fpage>&#x02013;<lpage>439</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-662-44381-1_24</pub-id></citation></ref>
<ref id="B17">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bhargavan</surname> <given-names>K.</given-names></name> <name><surname>Delignat-Lavaud</surname> <given-names>A.</given-names></name> <name><surname>Fournet</surname> <given-names>C.</given-names></name> <name><surname>Gollamudi</surname> <given-names>A.</given-names></name> <name><surname>Gonthier</surname> <given-names>G.</given-names></name> <name><surname>Kobeissi</surname> <given-names>N.</given-names></name> <etal/></person-group>. (<year>2016</year>). <article-title>&#x0201C;Formal verification of smart contracts,&#x0201D;</article-title> in <source>PLAS</source> (<publisher-loc>Vienna</publisher-loc>).</citation></ref>
<ref id="B18">
<citation citation-type="web"><person-group person-group-type="author"><collab>Bitcoin wiki</collab></person-group> (<year>2012</year>). <source>Bitcoin wiki- Contracts</source>. Available online at: <ext-link ext-link-type="uri" xlink:href="https://en.bitcoin.it/wiki/Contract">https://en.bitcoin.it/wiki/Contract</ext-link></citation></ref>
<ref id="B19">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Bonneau</surname> <given-names>J.</given-names></name> <name><surname>Miller</surname> <given-names>A.</given-names></name> <name><surname>Clark</surname> <given-names>J.</given-names></name> <name><surname>Narayanan</surname> <given-names>A.</given-names></name> <name><surname>Kroll</surname> <given-names>J. A.</given-names></name> <name><surname>Felten</surname> <given-names>E. W.</given-names></name></person-group> (<year>2015</year>). <article-title>&#x0201C;SoK: Research perspectives and challenges for Bitcoin and cryptocurrencies,&#x0201D;</article-title> in <source>IEEE Symposium on Security and Privacy</source> (<publisher-loc>San Jose, CA</publisher-loc>), <fpage>104</fpage>&#x02013;<lpage>121</lpage>. <pub-id pub-id-type="doi">10.1109/SP.2015.14</pub-id></citation></ref>
<ref id="B20">
<citation citation-type="web"><person-group person-group-type="author"><name><surname>Cunha</surname> <given-names>A.</given-names></name> <name><surname>Pinto</surname> <given-names>J. S.</given-names></name></person-group> (<year>2005</year>). <article-title>Point-free program transformation</article-title>. <source>Fundam. Inform.</source> <volume>66</volume>, <fpage>315</fpage>&#x02013;<lpage>352</lpage>. Available online at: <ext-link ext-link-type="uri" xlink:href="https://content.iospress.com/articles/fundamenta-informaticae/fi66-4-02">https://content.iospress.com/articles/fundamenta-informaticae/fi66-4-02</ext-link></citation></ref>
<ref id="B21">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Grishchenko</surname> <given-names>I.</given-names></name> <name><surname>Maffei</surname> <given-names>M.</given-names></name> <name><surname>Schneidewind</surname> <given-names>C.</given-names></name></person-group> (<year>2018a</year>). <article-title>&#x0201C;Foundations and tools for the static analysis of Ethereum smart contracts,&#x0201D;</article-title> in <source>CAV</source>, Vol. <volume>10981</volume> of LNCS (<publisher-loc>Oxford, UK</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>51</fpage>&#x02013;<lpage>78</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-319-96145-3_4</pub-id></citation></ref>
<ref id="B22">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Grishchenko</surname> <given-names>I.</given-names></name> <name><surname>Maffei</surname> <given-names>M.</given-names></name> <name><surname>Schneidewind</surname> <given-names>C.</given-names></name></person-group> (<year>2018b</year>). <article-title>&#x0201C;A semantic framework for the security analysis of ethereum smart contracts,&#x0201D;</article-title> in <source>POST</source>, Vol. <volume>10804</volume> of LNCS (<publisher-loc>Thessaloniki</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>243</fpage>&#x02013;<lpage>269</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-319-89722-6_10</pub-id></citation></ref>
<ref id="B23">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Hildenbrandt</surname> <given-names>E.</given-names></name> <name><surname>Saxena</surname> <given-names>M.</given-names></name> <name><surname>Rodrigues</surname> <given-names>N.</given-names></name> <name><surname>Zhu</surname> <given-names>X.</given-names></name> <name><surname>Daian</surname> <given-names>P.</given-names></name> <name><surname>Guth</surname> <given-names>D.</given-names></name> <etal/></person-group>. (<year>2018</year>). <article-title>&#x0201C;KEVM: A complete formal semantics of the Ethereum Virtual Machine,&#x0201D;</article-title> in <source>IEEE Computer Security Foundations Symposium (CSF)</source> (<publisher-loc>Oxford, UK</publisher-loc>: <publisher-name>IEEE Computer Society</publisher-name>), <fpage>204</fpage>&#x02013;<lpage>217</lpage>. <pub-id pub-id-type="doi">10.1109/CSF.2018.00022</pub-id></citation></ref>
<ref id="B24">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Hirai</surname> <given-names>Y.</given-names></name></person-group> (<year>2017</year>). <article-title>&#x0201C;Defining the Ethereum Virtual Machine for interactive theorem provers,&#x0201D;</article-title> in <source>Financial Cryptography Workshops</source>, Vol. <volume>10323</volume> of LNCS (<publisher-loc>Sliema</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>520</fpage>&#x02013;<lpage>535</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-319-70278-0_33</pub-id></citation></ref>
<ref id="B25">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Klomp</surname> <given-names>R.</given-names></name> <name><surname>Bracciali</surname> <given-names>A.</given-names></name></person-group> (<year>2018</year>). <article-title>&#x0201C;On symbolic verification of Bitcoin&#x00027;s script language,&#x0201D;</article-title> in <source>Workshop on Cryptocurrencies and Blockchain Technology (CBT)</source>, Vol. <volume>11025</volume> of LNCS (<publisher-loc>Barcelona</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>38</fpage>&#x02013;<lpage>56</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-030-00305-0_3</pub-id></citation></ref>
<ref id="B26">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Kumaresan</surname> <given-names>R.</given-names></name> <name><surname>Bentov</surname> <given-names>I.</given-names></name></person-group> (<year>2014</year>). <article-title>&#x0201C;How to use Bitcoin to incentivize correct computations,&#x0201D;</article-title> in <source>ACM CCS</source> (<publisher-loc>Scottsdale, AZ</publisher-loc>), <fpage>30</fpage>&#x02013;<lpage>41</lpage>. <pub-id pub-id-type="doi">10.1145/2660267.2660380</pub-id></citation></ref>
<ref id="B27">
<citation citation-type="web"><person-group person-group-type="author"><name><surname>Lombrozo</surname> <given-names>E.</given-names></name> <name><surname>Lau</surname> <given-names>J.</given-names></name> <name><surname>Wuille</surname> <given-names>P.</given-names></name></person-group> (<year>2015</year>). <source>Segregated Witness (Consensus Layer) BIP 141</source>. Available online at: <ext-link ext-link-type="uri" xlink:href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki">https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki</ext-link></citation></ref>
<ref id="B28">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Luu</surname> <given-names>L.</given-names></name> <name><surname>Chu</surname> <given-names>D.-H.</given-names></name> <name><surname>Olickel</surname> <given-names>H.</given-names></name> <name><surname>Saxena</surname> <given-names>P.</given-names></name> <name><surname>Hobor</surname> <given-names>A.</given-names></name></person-group> (<year>2016</year>). <article-title>&#x0201C;Making smart contracts smarter,&#x0201D;</article-title> in <source>ACM CCS</source> (<publisher-loc>Vienna</publisher-loc>), <fpage>254</fpage>&#x02013;<lpage>269</lpage>. <pub-id pub-id-type="doi">10.1145/2976749.2978309</pub-id></citation></ref>
<ref id="B29">
<citation citation-type="web"><person-group person-group-type="author"><name><surname>Maxwell</surname> <given-names>G.</given-names></name></person-group> (<year>2016</year>). <source>The First Successful Zero-Knowledge Contingent Payment</source>. Available online at: <ext-link ext-link-type="uri" xlink:href="https://bitcoincore.org/en/2016/02/26/zero-knowledge-contingent-payments-announcement/">https://bitcoincore.org/en/2016/02/26/zero-knowledge-contingent-payments-announcement/</ext-link></citation></ref>
<ref id="B30">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Miller</surname> <given-names>A.</given-names></name> <name><surname>Bentov</surname> <given-names>I.</given-names></name></person-group> (<year>2017</year>). <article-title>&#x0201C;Zero-collateral lotteries in Bitcoin and Ethereum,&#x0201D;</article-title> in <source>EuroS&#x00026;P Workshops</source> (<publisher-loc>Paris</publisher-loc>), <fpage>4</fpage>&#x02013;<lpage>13</lpage>. <pub-id pub-id-type="doi">10.1109/EuroSPW.2017.44</pub-id></citation></ref>
<ref id="B31">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Miller</surname> <given-names>A.</given-names></name> <name><surname>Cai</surname> <given-names>Z.</given-names></name> <name><surname>Jha</surname> <given-names>S.</given-names></name></person-group> (<year>2018</year>). <article-title>&#x0201C;Smart contracts and opportunities for formal methods,&#x0201D;</article-title> in <source>ISoLA</source>, Vol. <volume>11247</volume> of LNCS (<publisher-loc>Cham</publisher-loc>: <publisher-name>Springer</publisher-name>), <fpage>280</fpage>&#x02013;<lpage>299</lpage>. <pub-id pub-id-type="doi">10.1007/978-3-030-03427-6_22</pub-id></citation></ref>
<ref id="B32">
<citation citation-type="web"><person-group person-group-type="author"><name><surname>Nakamoto</surname> <given-names>S.</given-names></name></person-group> (<year>2008</year>). <source>Bitcoin: A Peer-to-Peer Electronic Cash System</source>. Available online at: <ext-link ext-link-type="uri" xlink:href="https://bitcoin.org/bitcoin.pdf">https://bitcoin.org/bitcoin.pdf</ext-link></citation></ref>
<ref id="B33">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Nicollin</surname> <given-names>X.</given-names></name> <name><surname>Sifakis</surname> <given-names>J.</given-names></name></person-group> (<year>1991</year>). <article-title>&#x0201C;An overview and synthesis on timed process algebras,&#x0201D;</article-title> in <source>CAV</source> (<publisher-loc>Aalborg</publisher-loc>), <fpage>376</fpage>&#x02013;<lpage>398</lpage>. <pub-id pub-id-type="doi">10.1007/3-540-55179-4_36</pub-id></citation></ref>
<ref id="B34">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Nipkow</surname> <given-names>T.</given-names></name> <name><surname>Paulson</surname> <given-names>L. C.</given-names></name> <name><surname>Wenzel</surname> <given-names>M.</given-names></name></person-group> (<year>2002</year>). <source>Isabelle/HOL: A Proof Assistant for Higher-Order Logic</source>, Vol. <volume>2283</volume> (<publisher-loc>Berlin</publisher-loc>: <publisher-name>Springer Science &#x00026; Business Media</publisher-name>).</citation></ref>
<ref id="B35">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>O&#x00027;Connor</surname> <given-names>R.</given-names></name></person-group> (<year>2017</year>). <article-title>&#x0201C;Simplicity: A new language for blockchains,&#x0201D;</article-title> in <source>PLAS</source> (<publisher-loc>Sliema</publisher-loc>). <pub-id pub-id-type="doi">10.1145/3139337.3139340</pub-id></citation></ref>
<ref id="B36">
<citation citation-type="book"><person-group person-group-type="author"><name><surname>Sergey</surname> <given-names>I.</given-names></name> <name><surname>Kumar</surname> <given-names>A.</given-names></name> <name><surname>Hobor</surname> <given-names>A.</given-names></name></person-group> (<year>2018</year>). <article-title>Scilla: a smart contract intermediate-level language</article-title>. <source>CoRR</source> abs/1801.00687</citation></ref>
<ref id="B37">
<citation citation-type="web"><person-group person-group-type="author"><name><surname>Szabo</surname> <given-names>N.</given-names></name></person-group> (<year>1997</year>). <source>Formalizing and securing relationships on public networks. <italic>First Monday</italic> 2</source>. Available online at: <ext-link ext-link-type="uri" xlink:href="https://firstmonday.org/ojs/index.php/fm/article/view/548/469-publisher=First">https://firstmonday.org/ojs/index.php/fm/article/view/548/469-publisher=First</ext-link></citation></ref>
</ref-list> 
</back>
</article>