Horn-ICE Learning for Synthesizing Invariants and Contracts

Deepak D'Souza, P. Ezudheen, Pranav Garg, P. Madhusudan, Daniel Neider

Introduction

Automated program verification is a cornerstone of software reliability, yet it remains bottlenecked by the difficulty of synthesizing inductive invariants—logical properties that hold throughout execution. This paper introduces Horn-ICE, a novel learning framework that bridges machine learning and formal logic to automate the discovery of these invariants and contracts.

The Challenge of Compositional Reasoning

Traditional "white-box" verification methods analyze code directly but often struggle with complex mathematical operations or pointers. "Black-box" learning, such as the ICE model (Implication Counter-Example), emerged as an alternative where a Learner guesses invariants based on samples from a Teacher. However, standard ICE models are limited to simple implications ($A \implies B$), making them ill-suited for concurrent or recursive programs where dependencies are better expressed as Horn clauses (e.g., $(A \wedge B) \implies C$).

The Horn-ICE Framework

The authors extend the ICE model to handle Horn clauses, enabling the verification of modular and concurrent code. The framework consists of a Teacher-Learner loop where the Teacher provides counter-examples and the Learner synthesizes conjectured invariants.

The Horn-ICE architecture showing the interaction between the Teacher, Learner, Boogie, and the Horn Solver.

Methods: Horn-DT Algorithm

The core innovation is the Horn-DT (Horn Decision Tree) algorithm. Unlike standard decision trees that treat data points independently, Horn-DT operates under "logical gravity":

  • Constraint Propagation: When the algorithm labels a data point, it uses a "pebbling" style algorithm to see which other points are "forced" to change labels to satisfy Horn constraints. This ensures the resulting decision tree is logically consistent.
  • Penalized Information Gain: The algorithm uses a modified entropy metric that penalizes splits cutting through Horn constraints, favoring simpler, more robust invariants.
  • Efficiency: Despite these constraints, Horn-DT maintains polynomial time complexity relative to the sample size.

Horn Clauses as a Universal Language

A key insight of the paper is that most verification rules—including Rely-Guarantee for threads and pre/post conditions for functions—can be naturally expressed as Horn clauses. This allows the learner to act as a general-purpose verification engine.

A sample program (a) and its corresponding verification conditions (b) expressed as Horn clauses.

Key Results and Evaluation

The researchers evaluated Horn-DT on 56 sequential benchmarks and 24 concurrent/recursive benchmarks.

  • Robustness: Horn-DT verified all 56 sequential programs, outperforming the leading white-box verifier SeaHorn, which failed on 13 cases (including 10 false positives).
  • Performance: Most benchmarks were solved in under one second, with complex concurrent proofs typically finishing within ten seconds.
  • Flexibility: The tool successfully synthesized complex "two-state" invariants required for modern software verification, proving its capability in handling sophisticated proof structures.

Limitations and Future Work

While powerful, Horn-DT depends on the quality of provided predicates. If the necessary building blocks (e.g., specific inequalities) are missing, the learner cannot synthesize the invariant. Future work aims to automate predicate discovery and extend the framework to more expressive logics beyond simple Horn clauses.

Conclusion

Horn-ICE represents a significant step forward in automated verification, demonstrating that integrating logical constraints into machine learning can solve complex proof synthesis problems that were previously intractable for black-box techniques.

Summary updated

BibTeX
@article{dsouza2018horn,
  author = {Deepak D'Souza and P. Ezudheen and Pranav Garg and P. Madhusudan and Daniel Neider},
  title = {{Horn-ICE Learning for Synthesizing Invariants and Contracts}},
  journal = {Proc. ACM Program. Lang.},
  year = {2018},
  doi = {10.1145/3276501},
}
Figure