<!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 />
    <article-meta>
      <title-group>
        <article-title>Validation of Smart Contracts Using Process Mining</article-title>
      </title-group>
      <contrib-group>
        <aff id="aff0">
          <label>0</label>
          <institution>Institute AIFB Karlsruhe Institute of Technology</institution>
          ,
          <country country="DE">Germany</country>
        </aff>
      </contrib-group>
      <fpage>13</fpage>
      <lpage>16</lpage>
      <abstract>
        <p>Smart contracts are self-executing contracts de ning rules for negotiating, verifying the ful llment of rules and executing the agreement using formal code. They run on top of a blockchain. Errors in smart contracts are costly and are mostly found too late after execution, which is too late for xing. To improve the validation of executed smart contracts, this paper suggests a process mining based approach. For this, we present an approach for the extraction of meaningful event logs from a blockchain. The event log can be imported in any process mining tool and validation and veri cation techniques can be used allowing to diagnose (non)conformity in smart contracts by means of common quality measures and with low latency after smart contract execution.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>
        Blockchain is a decentralized, peer to peer network, which makes use of
cryptography to securely host applications and store data, \where non-trusting members
can interact with each other without a trusted intermediary in a veri able
manner" [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]. Smart contracts, which run on top of a blockchain, are self-executing
contracts de ning rules for negotiating, verifying the ful llment of rules and
executing the agreement using formal code. Figure 1 shows the process of a smart
contract. First, a smart contract is written in a programming language (e.g.,
write smart
contract
include
contract into
blockchain
smart
contract
contract
included
negotiate
contract
      </p>
      <p>execute
conditions contract
are met
query
blockchain
contract
executed optional
query
results
error analysis by means of verification / validation</p>
      <p>Solidity). Subsequently, the smart contract is deployed in the blockchain and
becomes part of the blockchain. When all conditions are met, the smart contract
executes itself. Veri cation by means of formal methods or validation by means
of simulation might take place in di erence phases (i.e., at compile time and
runtime). To analyze smart contracts after its execution, the optional activity \query
blockchain" (see Figure 1) can be appended to the process referring to
querying the blockchain. We motivate the need for smart contract validation by the
following example. Figure 2 shows the vehicle manufacture example of a smart
contract1 within the smart contract process of Figure 1. This smart contract
consists of Participants with the attributes &lt;Person, Regulator, Manufacturer&gt;,
Assets with the attributes &lt;Order, Vehicle&gt; and Transactions with the
attributes &lt;PlaceOrder, UpdateOrderStatus, SetupDemo&gt;. Assume that someone
aims to analyze the smart contract and query the blockchain with placeOrder,
updateOrderStatus and setupDemo (see activity \query blockchain" in Figure
2). Further, assume that the value of Vehicle is changed from SCRAPPED to
ACTIVE or Order is changed from VEHICLEORDER ASSIGNED to DELIVERED
although no prior assignment of a vehicle owner took place. The queries would
only return the current value of attributes and could not detect any errors.
Although such semantic errors can pass compilation and execution phases, they
have to be prevented since they lead to incorrect or unexpected behavior.
2</p>
    </sec>
    <sec id="sec-2">
      <title>Related Works</title>
      <p>
        Related works on smart contract analysis can be distinguished by the time point
of analysis. Approaches related to compile time aim to identify syntax or
typechecking errors, see for reference [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. Runtime-based analysis try to identify
se1 https://www.npmjs.com/package/vehicle-manufacture-network
Validation of Smart Contracts Using Process Mining
mantic errors [
        <xref ref-type="bibr" rid="ref3 ref4 ref5">3,4,5</xref>
        ]. Compared to existing approaches on semantic error veri
cation of smart contracts [
        <xref ref-type="bibr" rid="ref3 ref4 ref5">3,4,5</xref>
        ], this paper suggests a process mining approach
and is superior to existing work as follows. Our approach does not require to
specify additional smart contract properties as required in [
        <xref ref-type="bibr" rid="ref3 ref5">3,5</xref>
        ]. The logical ow
of smart contracts is analyzed in terms of well-known Petri-net based validation
and veri cation techniques. Also, the e cient implementation of our approaches
allows to generate the process model with only low latency after the smart
contract execution.
3
      </p>
    </sec>
    <sec id="sec-3">
      <title>Process Mining based Approach to Smart Contract</title>
    </sec>
    <sec id="sec-4">
      <title>Validation</title>
      <p>This next section suggests our process mining-based approach. Process mining
takes event logs, records of the sequence of steps, and discovers a de-facto model
of the processes. Mandatory attributes of an event log are a caseID, activity and
time-stamp. Although, transactions of a blockchain are logged, the logs are of no
avail for process mining due to their transactional data structure that cannot be
directly mapped to an event log. We implemented the extraction of event logs
from a blockchain for Hyperledger Fabric and Composer. We omitted to continue
working with Ethereum due to several reasons. Currently, Ethereum does not
target business smart contracts and thus the interest is low to nd semantic errors.
Also, too many empty blocks are mined from Ethereum, which unnecessarily
expand and complicate the event log. To extract event log activities our approach
relies on the queries queryChain and getProcessLog. The query queryChain
requests from a client to register on the blockchain and returns ledger blocks
as JSON objects. Note, that a direct extraction of events from the smart
contract is not possible since a smart contract requires a prior execution before
events can be extracted. The extracted events, thus, refer to \block writes" in
the blockchain. Block writes are the part of a block that contains a list of unique
IDs and the associated key value pairs that are written by a transaction2. The
getProcessLog query returns block writes through iteration and transcribing
each block as a trace of an event log. This means that the block writes
contain the complete new record, not just the value change of attributes. Assume
the attribute color of the object car1=ftype:pickup, color:redg is changed from
red to blue, then the new block write is car1=ftype:pickup, color:blueg. To
identify value changes, we compare the block writes. For this purpose, the last
state before the change (=identical ID) is stored and compared with the
current state. To ease the comparison, the possibly nested objects are transformed
into a at data structure. If a value is changed or new attributes are added,
an event is transcribed. The event name consists of three attributes ranging
from 1=abstract to 3=concrete, which might be exemplary eventLevel1=\asset
updated", eventLevel2=\color changed" and eventLevel3=\color changed from
red to blue". Besides the eventLevel and the eventName attributes, an
event2 https://hyperledger-fabric.readthedocs.io/en/release-1.3/readwrite.html
De nition is de ned, which aggregates simple events to complex events.
Assume an eventLevel=\eventLevel3", eventName=\This is now a red pickup" and
eventDe nition=[color=. &gt;red] &amp;&amp; [make=. &gt; pickup]. The evaluation of the
regular expression to true, is considered a complex event. The process model
extracted from an exemplary smart contract is shown in Figure 3. The source code
of our project can be downloaded from https://github.com/FrankDuchmann/
hf-event-extraction.</p>
    </sec>
    <sec id="sec-5">
      <title>Conclusion</title>
      <p>
        This paper presented an approach for event log extraction from Hyperledger
Fabric and Composer. The event logs can be processed by any process mining
tool. We consider an event as the result of a transaction, which goes beyond the
simpli ed solution of [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. In the future we plan to target event log extraction
from Ethereum.
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Dannen</surname>
            ,
            <given-names>C.</given-names>
          </string-name>
          :
          <article-title>Introducing Ethereum and Solidity: Foundations of Cryptocurrency and Blockchain Programming for Beginners</article-title>
          , Berkely, CA, USA (
          <year>2017</year>
          )
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Amani</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Begel</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Bortin</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Staples</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          :
          <article-title>Towards verifying ethereum smart contract bytecode in isabelle/hol</article-title>
          . In
          <source>: Proceedings of the 7th ACM SIGPLAN. CPP</source>
          <year>2018</year>
          , New York, NY, USA, ACM (
          <year>2018</year>
          )
          <volume>66</volume>
          {
          <fpage>77</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Azzopardi</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Ellul</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pace</surname>
            ,
            <given-names>G.J.:</given-names>
          </string-name>
          <article-title>Monitoring smart contracts: Contractlarva and open challenges beyond</article-title>
          . In Colombo,
          <string-name>
            <given-names>C.</given-names>
            ,
            <surname>Leucker</surname>
          </string-name>
          , M., eds.: Runtime Veri cation, Springer (
          <year>2018</year>
          )
          <volume>113</volume>
          {
          <fpage>137</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Azzopardi</surname>
            ,
            <given-names>S.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pace</surname>
            ,
            <given-names>G.J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Schapachnik</surname>
            ,
            <given-names>F.</given-names>
          </string-name>
          :
          <article-title>On observing contracts: Deontic contracts meet smart contracts</article-title>
          .
          <source>In: JURIX. Volume 313 of Frontiers in Arti cial Intelligence and Applications</source>
          ., IOS Press (
          <year>2018</year>
          )
          <volume>21</volume>
          {
          <fpage>30</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <surname>Ellul</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Pace</surname>
            ,
            <given-names>G.J.:</given-names>
          </string-name>
          <article-title>Runtime veri cation of ethereum smart contracts</article-title>
          . In: EDCC, IEEE Computer Society (
          <year>2018</year>
          )
          <volume>158</volume>
          {
          <fpage>163</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>Di</given-names>
            <surname>Ciccio</surname>
          </string-name>
          ,
          <string-name>
            <given-names>C.</given-names>
            ,
            <surname>Cecconi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            ,
            <surname>Mendling</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            ,
            <surname>Felix</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            ,
            <surname>Haas</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            ,
            <surname>Lilek</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            ,
            <surname>Riel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            ,
            <surname>Rumpl</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            ,
            <surname>Uhlig</surname>
          </string-name>
          ,
          <string-name>
            <surname>P.</surname>
          </string-name>
          :
          <article-title>Blockchain-based traceability of inter-organisational business processes</article-title>
          .
          <source>In: Business Modeling and Software Design</source>
          , Springer (
          <year>2018</year>
          )
          <volume>56</volume>
          {
          <fpage>68</fpage>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>