Hostname: page-component-89b8bd64d-9prln Total loading time: 0 Render date: 2026-05-08T18:17:08.281Z Has data issue: false hasContentIssue false

Verifying Catamorphism-Based Contracts using Constrained Horn Clauses

Published online by Cambridge University Press:  07 July 2022

EMANUELE DE ANGELIS
Affiliation:
IASI-CNR, Rome, Italy (e-mails: emanuele.deangelis@iasi.cnr.it, maurizio.proietti@iasi.cnr.it)
MAURIZIO PROIETTI
Affiliation:
IASI-CNR, Rome, Italy (e-mails: emanuele.deangelis@iasi.cnr.it, maurizio.proietti@iasi.cnr.it)
FABIO FIORAVANTI
Affiliation:
DEc, University of Chieti-Pescara, Pescara, Italy (e-mail: fabio.fioravanti@unich.it)
ALBERTO PETTOROSSI
Affiliation:
DICII, University of Rome “Tor Vergata”, Rome, Italy (e-mail: adp@iasi.cnr.it)
Rights & Permissions [Opens in a new window]

Abstract

We address the problem of verifying that the functions of a program meet their contracts, specified by pre/postconditions. We follow an approach based on constrained Horn clauses (CHCs) by which the verification problem is reduced to the problem of checking satisfiability of a set of clauses derived from the given program and contracts. We consider programs that manipulate algebraic data types (ADTs) and a class of contracts specified by catamorphisms, that is, functions defined by simple recursion schemata on the given ADTs. We show by several examples that state-of-the-art CHC satisfiability tools are not effective at solving the satisfiability problems obtained by direct translation of the contracts into CHCs. To overcome this difficulty, we propose a transformation technique that removes the ADT terms from CHCs and derives new sets of clauses that work on basic sorts only, such as integers and booleans. Thus, when using the derived CHCs there is no need for induction rules on ADTs. We prove that the transformation is sound, that is, if the derived set of CHCs is satisfiable, then so is the original set. We also prove that the transformation always terminates for the class of contracts specified by catamorphisms. Finally, we present the experimental results obtained by an implementation of our technique when verifying many non-trivial contracts for ADT manipulating programs.

Information

Type
Original Article
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (http://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2022. Published by Cambridge University Press
Figure 0

Figure 1. The set $\textsf{Reverse}$ of CHCs. For technical reasons (see Definition 1) all program properties are defined by total functions. In particular, for the empty list, the hd function returns the arbitrarily chosen value 0 (which is never used).

Figure 1

Figure 2. The set $\textsf{TransfReverse}$ of transformed CHCs. The clauses shown here are those derived from clauses 1-12 of $\textsf{Reverse}$ and goal 13. The clauses derived from goal 14 are listed in Appendix A of the extended version of this paper (De Angelis et al. 2022b).

Figure 2

Figure 3. (A) List catamorphism. (B) Tree catamorphism.

Figure 3

Figure 4. (C) Generalized list catamorphism. (D) Generalized tree catamorphism.

Figure 4

Figure 5. The catamorphisms count and bstree.

Figure 5

Figure 6. The Transformation Algorithm ${\mathcal{T}}_{\mathit{cata}}$.

Figure 6

Figure 7. The $\mathit{Define}$ procedure.

Figure 7

Figure 8. The ${\mathit{Unfold}}$ procedure.

Figure 8

Figure 9. The $\mathit{Apply\mbox{-}Contracts}$ procedure.

Figure 9

Figure 10. The $\mathit{Fold}$ procedure.

Figure 10

Figure 11. Deleting an element from a binary search tree: bstdel and its contract.

Figure 11

Table 1. Contracts proved by the VeriCat and AdtRem tools. Times are in ms