<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta>
      <journal-title-group>
        <journal-title>Workshop on Artificial Intelligence and Formal Verification, Logic, Automata, and Synthesis,
November</journal-title>
      </journal-title-group>
    </journal-meta>
    <article-meta>
      <title-group>
        <article-title>Revisiting Formal Verification in VeriSolid: An Analysis and Enhancements</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Atefeh Zareh Chahoki</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Marco Roveri</string-name>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Daniel Amyot</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>John Mylopoulos</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>University of Ottawa</institution>
          ,
          <country country="CA">Canada</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>University of Trento</institution>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2023</year>
      </pub-date>
      <volume>7</volume>
      <issue>2023</issue>
      <fpage>0000</fpage>
      <lpage>0001</lpage>
      <abstract>
        <p>While the immutability of smart contracts ensures unparalleled trust and transparency, it is also a doubleedged sword, as any coding errors can lead to substantial financial losses and complex mitigation endeavours. VeriSolid is a security mitigation tool that offers a 'correct by design' platform, enabling developers to create and verify smart contracts using predefined property templates. After ensuring the correctness of the design, VeriSolid facilitates the automatic generation of equivalent Solidity code. Our motivational example is a prominent decentralized exchange (DEX), Uniswap, which is responsible for over 82% of DEX transactions. Our experiments uncover and resolve verification issues in two out of four VeriSolid templates. Additionally, we propose seven new templates, enhancing the VeriSolid platform through its open-source project. This research endeavor has yielded a significant enhancement in VeriSolid's coverage percentage, which represents the percentage of available software requirement specifications that can be formally represented and verified in VeriSolid. This study increased it from 45.6% to 90.5% based on a dataset consisting of 555 requirement specifications, thus enabling the verification of a wider range of property specifications.</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Automated Verification</kwd>
        <kwd>Blockchain</kwd>
        <kwd>Code Generation</kwd>
        <kwd>Finite State Machines</kwd>
        <kwd>Security</kwd>
        <kwd>Smart Contracts</kwd>
        <kwd>Solidity</kwd>
        <kwd>Temporal Logic</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. Introduction and motivation</title>
      <p>
        Smart contracts, evolving from cryptocurrencies pioneered by Bitcoin [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], offer decentralized,
trustless execution of computable functions. They serve as a global computing platform, allowing
parties to interact and transact without relying on a centralized authority or trusting each other
implicitly. Ethereum [
        <xref ref-type="bibr" rid="ref2 ref3">2, 3</xref>
        ] introduced this transformative technology, thriving due to various
blockchain imlementations, new languages, and business adoption [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. However, blockchain’s
decentralization unveils vulnerabilities, exemplified by the DAO attack [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], underlining substantial
ifnancial risks due to the irreversibility inherent in smart contracts and emphasizing the urgent
need for innovative security solutions for its specific vulnerabilities [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
      </p>
      <p>
        Solutions are varied [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] and include secure programming practices and developer patterns [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]
to mitigate common vulnerabilities, automated vulnerability-detection tools [
        <xref ref-type="bibr" rid="ref10 ref11 ref9">9, 10, 11</xref>
        ] targeting
specified properties, and formal verification approaches [
        <xref ref-type="bibr" rid="ref12">12, 13</xref>
        ], offering robust verification
guarantees. The first category relies on programmer adherence, the second lacks contract-specific
focus, and the third, although vital for ensuring correctness, poses automation challenges.
      </p>
      <p>We have selected the Uniswap V2 Solidity code from the decentralized exchange (DEX)
ecosystem as our real-world motivational example [14]. DEXs operate without intermediaries,
facilitating peer-to-peer cryptocurrency transactions in a non-custodial manner. Our selection
criteria included transaction count and percentage of total volume across all monitored DEXs on
Etherscan.io. Uniswap V2 accounted for 82.51% of total transactions [15].</p>
      <p>VeriSolid [16] employs a correct-by-design approach for smart contract development,
emphasizing correctness during the design phase before code generation. However, our testing
revealed verification errors and challenges in specifying desired properties, resulting in execution
outcomes misaligned with defined properties. This paper addresses these issues, significantly
improving VeriSolid’s coverage from 45.6% to 90.5% across a dataset of 555 specifications,
thereby enabling broader property verification.</p>
      <p>We offer a concise overview of VeriSolid in Section 2, with an analysis of and improvements to
VeriSolid’s functionality in Section 3. Our contributions have been integrated into the VeriSolid
codebase, now accessible to the community. Section 4 summarizes our findings and outlines
potential future enhancements.</p>
    </sec>
    <sec id="sec-2">
      <title>2. VeriSolid</title>
      <p>VeriSolid is a correct-by-design tool that enables users to design contracts by modeling them as
state machines. Using the Solidity language, users can specify details such as transition guards,
statements, inputs, and contract definitions (e.g., internal variables). The user has access to
predefined templates to specify desired properties on the contract. Once verification is triggered,
VeriSolid translates the designed model and specified properties into BIP [ 17, 18] and then into
CTL (Computational Tree Logic) [19] specifications in nuXmv [20]. The nuXmv tool subsequently
verifies whether the CTL properties hold for the contract model. In the case of negative results, it
provides counterexamples at the nuXmv level and then translates them back to the BIP level. In
this paper, we assume the reader has basic knowledge of CTL [21].</p>
    </sec>
    <sec id="sec-3">
      <title>3. VeriSolid Analysis and Extensions</title>
      <p>While specifying our Uniswap model and verifying properties within the VeriSolid environment,
a surprising incorrect verification verdict resulting from the second and third templates (Table 1)
came to our attention. We explain this issue using a simpler model, i.e., one of the predefined
smart contracts of the VeriSolid project called “RockPaperScissors” and depicted in Fig. 1.</p>
      <p>The problematic scenario can be observed by providing “close#cancelPlay” as values to the
second template definition (Table 1), which hence asserts that “the event (close) can happen only
after the event (cancelPlay)”. Surprisingly, the verification tool yields a result indicating that this
property holds, despite our intuitive understanding suggesting otherwise. The same issue is also
encountered with the third template, with parameters “close#cancelReveal#finish”, which asserts
that “if (close) happens, (cancelReveal) can happen only after (nfiish) happens”. Once again, the
verification reports that this property holds, despite the property trivially not holding.</p>
      <p>Our investigation revealed that in the original VeriSolid tool, weak until ([ ]) properties
were incorrectly encoded in nuXmv as strong until ([ ]) properties with an additional fairness
constraint. Specifically, this encoding occurred for templates 2 and 3 (Table 1), which led to
the generation of fairness constraints for the first (resp. third) parameter of the 2  (resp. 3)
template [22]. These wrong encodings are the root cause of the issues described previously.</p>
      <p>Fairness constraints must be satisfied infinitely often within the system [ 23]. However, this
encoding does not accurately capture the semantics of weak until properties. For instance, in the
scenarios described earlier, it would require visiting innfiitely often states such as “close” in the
second template example and “finish” in the third template example, which is impossible due
to the absence of a loopback mechanism. Since FAIRNESS(p) is used in nuXmv to restrict the
verification to executions in which p holds infinitely often, this results in the fact that there are no
paths satisfying this property; consequently any property becomes trivially true [21]. To address
this issue, proper encoding of weak until using constructs supported by the verification engine is
required. To this extent, we can leverage the equivalence [ ] = ¬[¬ (¬ ∧ ¬)] (see
e.g., [24]), and rewrite each occurrence of weak until accordingly wherever needed.</p>
      <p>We have also extended the supported verification templates of VeriSolid according to the most
common CTL patterns [25]. Table 1 presents the VeriSolid property templates’ logical
descriptions and categorizations [25] between parentheses. The “CTL Formula” column represents the
encoding in CTL. “Sts.” corresponds to the status: “–” (unchanged), “fixed” (resolved in this
paper), “impl” (introduced in a VeriSolid paper [16], implemented here), and “new” (introduced
and implemented here). The last column reveals pattern coverage on a 555-example dataset [25].
The table encompasses all patterns with a score exceeding 1 in [25]. Our work significantly boosts
VeriSolid’s coverage, from 45.6% to 90.5%, enhancing its property verification capabilities. With
these improvements, it is now possible to continue our analysis of the Uniswap smart contract.</p>
    </sec>
    <sec id="sec-4">
      <title>4. Conclusion and Future Work</title>
      <p>In this paper, we have improved the verification capabilities of VeriSolid, a correct-by-design
development environment for smart contracts. Our investigations on this tool revealed incorrect
encodings in nuXmv of two property templates. We corrected these issues and further contributed
by implementing twelve new property templates. As a result, the verification templates now cover
90.5% of the 555 specification examples collected by Dwyer [ 25]. All these contributions are
now available in the VeriSolid Git repository [26].</p>
      <p>For future work, we are considering the following items. First, extend the current verification
using advanced features in nuXmv by, e.g., encoding patterns in Linear Temporal Logic (LTL) [27]
to then utilize advanced SAT-based model checking algorithms. Second, allow infinite state
variables (reals, integers) beyond Boolean variables in guards and use SMT-based verification [ 28]
available in nuXmv. Third, add checks to ensure the specified model is deadlock-free (each state
has at least one future state). Fourth, bring back counterexamples in user level inspection. Finally,
increase the granularity of the “lock” concept from FSolidM [29] (VeriSolid’s predecessor) to
eradicate reentrancy vulnerability in a “foolproof” manner, ensuring single transition execution
at a time and preventing function nesting. Since this mechanism is overly restrictive, it is
recommended to establish distinct locks for each method. Furthermore, we can offer users
to define specific locks for individual transitions to ensure mutual exclusivity in concurrent
transaction executions.
We thank Dr. A. Mavridou for her invaluable support throughout this research endeavor. We
extend our appreciation to the anonymous reviewers whose insightful comments greatly
contributed to enhancing the paper’s quality. Prof. M. Roveri acknowledges partial funding from the
CrossCon EU-funded project under Grant Agreement 101070537.
[13] I. Grishchenko, M. Maffei, C. Schneidewind, A semantic framework for the security analysis
of Ethereum smart contracts, in: Principles of Security and Trust: 7th International
Conference, POST 2018, Springer, 2018, pp. 243–269. doi:10.1007/978-3-319-89722-6_10.
[14] etherscan.io, Uniswap (UNI) token tracker | Etherscan, 2023. URL: https://etherscan.io/
token/0x1f9840a85d5af5bf1d1762f925bdaddc4201f984.
[15] etherscan.io, DEX activity | Etherscan, 2023. URL: http://etherscan.io/stat/dextracker.
[16] A. Mavridou, A. Laszka, E. Stachtiari, A. Dubey, VeriSolid: Correct-by-design smart
contracts for Ethereum, in: International Conference on Financial Cryptography and Data
Security. FC 2019, Springer, 2019, pp. 446–465. doi:978-3-030-32101-7_27.
[17] A. Basu, S. Bensalem, M. Bozga, J. Combaz, M. Jaber, T. Nguyen, J. Sifakis, Rigorous
component-based system design using the BIP framework, IEEE Softw. 28 (2011) 41–48.</p>
      <p>URL: https://doi.org/10.1109/MS.2011.27. doi:10.1109/MS.2011.27.
[18] S. Bliudze, A. Cimatti, M. Jaber, S. Mover, M. Roveri, W. Saab, Q. Wang, Formal
verification of infinite-state BIP models, in: International Symposium on Automated
Technology for Verification and Analysis, Springer, 2015, pp. 326–343. doi: 10.1007/
978-3-319-24953-7_25.
[19] E. M. Clarke, E. A. Emerson, Design and synthesis of synchronization skeletons using
branching time temporal logic, in: Workshop on logic of programs, Springer, 1981, pp.
52–71. doi:10.1007/BFb0025774.
[20] R. Cavada, A. Cimatti, M. Dorigatti, A. Griggio, A. Mariotti, A. Micheli, S. Mover,
M. Roveri, S. Tonetta, The nuXmv symbolic model checker, in: Computer Aided
Verification: 26th International Conference, CAV 2014, Springer, 2014, pp. 334–342.
doi:10.1007/978-3-319-08867-9_22.
[21] C. Baier, J.-P. Katoen, Principles of model checking, MIT Press, 2008.
[22] A. Mavridou, VerifyContract.js, 2023. URL: https://github.com/anmavrid/smart-contracts/
blob/master/src/plugins/VerifyContract/VerifyContract.js.
[23] R. Cavada, A. Cimatti, G. Keighren, E. Olivetti, M. Pistore, M. Roveri, NuSMV 2.6 tutorial,
2015. URL: https://nusmv.fbk.eu/NuSMV/tutorial/v26/tutorial.pdf.
[24] M. Dwyer, Property pattern mappings for CTL, 2023. URL: https://matthewbdwyer.github.</p>
      <p>io/psp/patterns/ctl.html.
[25] M. B. Dwyer, G. S. Avrunin, J. C. Corbett, Patterns in property specifications for finite-state
verification, in: Proceedings of the 21st International Conference on Software Engineering,
1999, pp. 411–420. doi:10.1145/302405.302672.
[26] A. Mavridou, VerifyContract.js, 2023. URL: https://github.com/anmavrid/smart-contracts.
[27] A. Pnueli, The temporal logic of programs, in: 18th Annual Symposium on Foundations
of Computer Science, Providence, Rhode Island, USA, 31 October - 1 November 1977,
IEEE Computer Society, 1977, pp. 46–57. URL: https://doi.org/10.1109/SFCS.1977.32.
doi:10.1109/SFCS.1977.32.
[28] C. W. Barrett, R. Sebastiani, S. A. Seshia, C. Tinelli, Satisfiability Modulo Theories, volume
185 of Frontiers in Artificial Intelligence and Applications , IOS Press, 2009. doi:10.3233/
978-1-58603-929-5-825.
[29] A. Mavridou, A. Laszka, Designing secure Ethereum smart contracts: A finite state machine
based approach, in: Financial Cryptography and Data Security. FC 2018, Springer, 2018,
pp. 523–540. doi:978-3-662-58387-6_28.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>S.</given-names>
            <surname>Nakamoto</surname>
          </string-name>
          ,
          <article-title>Bitcoin: A peer-to-peer electronic cash system, Decentralized business review (</article-title>
          <year>2008</year>
          ). URL: https://bitcoin.org/bitcoin.pdf.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>V.</given-names>
            <surname>Buterin</surname>
          </string-name>
          ,
          <article-title>A next-generation smart contract and decentralized application platform</article-title>
          ,
          <year>2014</year>
          . URL: https://cobesto.com/preview-file/whitepaper-Ethereum.pdf, Ethereum white paper.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>G.</given-names>
            <surname>Wood</surname>
          </string-name>
          ,
          <article-title>Ethereum: A secure decentralised generalised transaction ledger</article-title>
          ,
          <year>2014</year>
          . URL: http://gavwood.com/paper.pdf,
          <source>Ethereum project yellow paper.</source>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>S.</given-names>
            <surname>Dhaiouir</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Assar</surname>
          </string-name>
          ,
          <article-title>A systematic literature review of blockchain-enabled smart contracts: platforms, languages, consensus, applications and choice criteria</article-title>
          ,
          <source>in: Research Challenges in Information Science: 14th International Conference, RCIS 2020</source>
          , Springer,
          <year>2020</year>
          , pp.
          <fpage>249</fpage>
          -
          <lpage>266</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>030</fpage>
          -50316-1_
          <fpage>15</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>Q.</given-names>
            <surname>DuPont</surname>
          </string-name>
          ,
          <article-title>Experiments in algorithmic governance: A history and ethnography of “the DAO,” a failed decentralized autonomous organization, in: Bitcoin and beyond</article-title>
          , Routledge,
          <year>2017</year>
          , pp.
          <fpage>157</fpage>
          -
          <lpage>177</lpage>
          . doi:
          <volume>10</volume>
          .4324/9781315211909-8.
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>N.</given-names>
            <surname>Atzei</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Bartoletti</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Cimoli</surname>
          </string-name>
          ,
          <article-title>A survey of attacks on Ethereum smart contracts (SoK)</article-title>
          ,
          <source>in: Principles of Security and Trust</source>
          , Springer,
          <year>2017</year>
          , pp.
          <fpage>164</fpage>
          -
          <lpage>186</lpage>
          . doi:
          <volume>10</volume>
          .1007/ 978-3-
          <fpage>662</fpage>
          -54455-
          <issue>6</issue>
          _
          <fpage>8</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>H.</given-names>
            <surname>Chen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Pendleton</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Njilla</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Xu</surname>
          </string-name>
          ,
          <article-title>A survey on Ethereum systems security: Vulnerabilities, attacks, and defenses</article-title>
          ,
          <source>ACM Computing Surveys</source>
          <volume>53</volume>
          (
          <year>2021</year>
          -05-
          <issue>31</issue>
          )
          <fpage>1</fpage>
          -
          <lpage>43</lpage>
          . doi:
          <volume>10</volume>
          .1145/3391195.
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>The</given-names>
            <surname>Solidity</surname>
          </string-name>
          <string-name>
            <surname>Authors</surname>
          </string-name>
          ,
          <source>Security considerations - Solidity 0.8.14 documentation</source>
          ,
          <year>2022</year>
          . URL: https://docs.soliditylang.org/en/develop/security-considerations.html.
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>K.</given-names>
            <surname>Bhargavan</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Delignat-Lavaud</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            <surname>Fournet</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Gollamudi</surname>
          </string-name>
          , G. Gonthier,
          <string-name>
            <given-names>N.</given-names>
            <surname>Kobeissi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Kulatova</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Rastogi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Sibut-Pinote</surname>
          </string-name>
          ,
          <string-name>
            <given-names>N.</given-names>
            <surname>Swamy</surname>
          </string-name>
          ,
          <article-title>Formal verification of smart contracts: Short paper</article-title>
          ,
          <source>in: Proceedings of the 2016 ACM Workshop on Programming Languages and Analysis for Security</source>
          ,
          <year>2016</year>
          , pp.
          <fpage>91</fpage>
          -
          <lpage>96</lpage>
          . doi:
          <volume>10</volume>
          .1145/2993600.2993611.
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>L.</given-names>
            <surname>Luu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.-H.</given-names>
            <surname>Chu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Olickel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Saxena</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Hobor</surname>
          </string-name>
          ,
          <article-title>Making smart contracts smarter</article-title>
          ,
          <source>in: Proceedings of the 2016 ACM SIGSAC conference on computer and communications security</source>
          ,
          <year>2016</year>
          , pp.
          <fpage>254</fpage>
          -
          <lpage>269</lpage>
          . doi:
          <volume>10</volume>
          .1145/2976749.2978309.
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>P.</given-names>
            <surname>Tsankov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Dan</surname>
          </string-name>
          , et al.,
          <article-title>Securify: Practical security analysis of smart contracts</article-title>
          ,
          <source>in: Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security</source>
          ,
          <year>2018</year>
          , pp.
          <fpage>67</fpage>
          -
          <lpage>82</lpage>
          . doi:
          <volume>10</volume>
          .1145/3243734.3243780.
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>Y.</given-names>
            <surname>Hirai</surname>
          </string-name>
          ,
          <article-title>Defining the ethereum virtual machine for interactive theorem provers</article-title>
          ,
          <source>in: International Conference on Financial Cryptography and Data Security. FC 2017</source>
          , Springer,
          <year>2017</year>
          , pp.
          <fpage>520</fpage>
          -
          <lpage>535</lpage>
          . doi:
          <volume>10</volume>
          .1007/978-3-
          <fpage>319</fpage>
          -70278-0_
          <fpage>33</fpage>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>