<!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>Upcycling Formal Specifications for Similar Implementa- tions with Arís</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Kuruvilla George Aiyankovil</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Rosemary Monahan</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>P. O'Donoghu</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Maynooth University</institution>
          ,
          <addr-line>Co. Kildare</addr-line>
          ,
          <country country="IE">Ireland</country>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>Rosemary.Monahan</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>We describe the Arís system for creating new formal specifications for source code by transferring existing specifications to similar implementations. We show the code graphs underlying its operation, graph matching supports retrieval, and pattern completion enables transfer of specifications to new implementations. A theorem prover formally verifies the new specifications.</p>
      </abstract>
      <kwd-group>
        <kwd>formal specifications</kwd>
        <kwd>source code</kwd>
        <kwd>graph representation</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>
        While formal verification of source code has become more popular in many real-world
applications, successfully verifying the code requires three critical activities: writing
formal specifications describing the task to be achieved; writing the source code for
that task; and proving the correctness of the source code against this specification
        <xref ref-type="bibr" rid="ref2">(Greengard, 2021)</xref>
        . Many verification tools use the design-by-contract approach to
annotate implementations with formal specifications and axioms so that they can generate
the proof obligations required to verify that the implementation satisfies its
specification
        <xref ref-type="bibr" rid="ref3">(Dross et al., 2021)</xref>
        . Specifications are written as a formal contract which defines
the preconditions (requires clauses) that must hold, for the implementation to establish
the postconditions (ensures clauses). An automated theorem prover verifies correctness
of the implementation wrt its specification, requiring axioms to assist the prover written
as assertions, invariants, and variants clauses.
      </p>
      <p>
        Writing specifications and supporting axioms for the proofs require expert training
and experience, contributing to poor uptake of verification by industry, unless required
to meet safety standards
        <xref ref-type="bibr" rid="ref4">(Huisman, Gurov, &amp; Malkis, 2020)</xref>
        . Our work eases the burden
of these two activities by retrieving a similar verified implementation from an existing
repository of verified source code and reusing it to creating formal specifications and
proof support for a target implementation.
1.1 Related Work
Our work differs from related work on code completion, automatic code generation etc.
Some of its operation is more akin to code clone detection using conceptual graphs. An
image below highlights one specification for a simple C# implementation, using CBR
to transfer this specification to functionally similar code. We can describe Arís as:
operating on executable source code, working at the statement level of granularity,
Copyright © 2021 for this paper by its authors. Use permitted under
Creative Commons License Attribution 4.0 International (CC BY 4.0).
      </p>
      <p>Arís
performing static code analysis with extractive dependency graphs. Similar graphs are
used to infer similar specifications.</p>
      <p>
        In the Arís system
        <xref ref-type="bibr" rid="ref1">(Pitu et al, 2013)</xref>
        source code is parsed and the resulting Abstract
Syntax Tree is analysed to generate a code graph. Arís represents all problems and
solution cases as distinct graphs, utilizing 18 categories of nodes and 6 types of relations.
Nodes can contain information obtained directly from the source code, such as
identifier names, the beginning of a block of code, assignment statements etc.
      </p>
      <p>An important part of Arís concerns its
representation of cases, focused on semantic
graphs generated from examination of the
Abstract Syntax Tree of a program, which is in
turn generated using the ILSpy decompiler.</p>
      <p>public ResizeDemo(int size0) {</p>
      <p>Contract.Requires(0 &lt;= size0);
this.elements = new int[size0];
this.count = 0; }
Retrieval finds the largest common subgraph between a code graph containing
specifications and one without. Graph Matching (ISMAGS, VF3) combines the influences
of topological similarity with label categories for paired nodes and paired edges.
Reuse. Inter-graph mappings that include paired variable nodes are examined and
compatible data-types identified, which involve identifying the original C# source code.
The locations of the specifications are identified in the problem cases.
Revise. Transferrable specifications are identified and are updated to match their new
problem context, including updating the variable names.</p>
      <p>Retain. Source code with specifications is added to the project for compilation and
verification by the Z3 theorem prover. Successfully verified methods can support
subsequent inferences, potentially extending the reach of the initial specifications.
3</p>
      <p>ICCBR CBR Demos &amp; Showcases - Aris video at https://youtu.be/gbbw_LOxoDs</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <surname>Pitu</surname>
            ,
            <given-names>M</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Grijincu</surname>
            ,
            <given-names>D</given-names>
          </string-name>
          , Li,
          <string-name>
            <surname>P</surname>
          </string-name>
          , Saleem,
          <string-name>
            <surname>A</surname>
          </string-name>
          , Monahan,
          <string-name>
            <surname>R</surname>
          </string-name>
          ,
          <string-name>
            <surname>O</surname>
          </string-name>
          'Donoghue,
          <string-name>
            <surname>D.P.</surname>
          </string-name>
          (
          <year>2013</year>
          )
          <article-title>Arís: Analogical Reasoning for reuse of Implementation &amp; Specification</article-title>
          .
          <source>Proc. Artificial Intelligence for Formal Methods (AI4FM)</source>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <surname>Greengard</surname>
            ,
            <given-names>S,</given-names>
          </string-name>
          <article-title>Formal software verification measures up</article-title>
          ,
          <source>Communications of the ACM</source>
          , Volume
          <volume>64</volume>
          ,
          <string-name>
            <surname>Issue</surname>
            <given-names>7</given-names>
          </string-name>
          ,
          <year>June 2021</year>
          , https://doi.org/10.1145/3464933.
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <surname>Dross</surname>
          </string-name>
          et al (
          <year>2021</year>
          ).
          <source>VerifyThis</source>
          <year>2019</year>
          :
          <article-title>a program verification competition</article-title>
          .
          <source>International Journal on Software Tools for Technology Transfer</source>
          ,
          <fpage>1</fpage>
          -
          <lpage>11</lpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <surname>Huisman</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          ,
          <string-name>
            <surname>Gurov</surname>
            ,
            <given-names>D.</given-names>
          </string-name>
          , &amp;
          <string-name>
            <surname>Malkis</surname>
            ,
            <given-names>A.</given-names>
          </string-name>
          (
          <year>2020</year>
          ).
          <article-title>Formal Methods: From Academia to Industrial Practice. A Travel Guide</article-title>
          . arXiv preprint arXiv:
          <year>2002</year>
          .07279.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>