Compositional Verification of Heap-Manipulating Programs Through Property-Guided Learning

Long H. Pham, Jun Sun, Quang Loc Le

Introduction

Verifying programs that manage memory via pointers—known as heap-manipulating programs—is a notoriously difficult task. While compositional verification simplifies the process by breaking programs into individual functions, it requires developers to provide formal "contracts" (preconditions and postconditions) for every component. Writing these specifications requires significant expertise in formal logic, creating a high barrier to entry for automated verification.

This paper introduces SLearner, a tool that automates the discovery of these specifications. By combining dynamic learning from test executions with a novel "memory graph mutation" technique, SLearner generates the necessary invariants to satisfy formal verifiers without human intervention.

Methodology: The SLearner Framework

The SLearner framework follows a multi-step process to infer program specifications. It first instruments the target program and runs it with various random inputs. During these executions, the tool records the state of the heap before and after function calls.

Memory Graphs and Feature Extraction

Heap states are represented as memory graphs, where nodes correspond to memory objects and edges represent pointer relationships.

A memory graph representing a heap state with pointers x and y.

To make these graphs processable by machine learning algorithms, SLearner converts them into boolean feature vectors. These features are drawn from a predefined library based on Separation Logic, covering both generic pointer properties and structure-specific invariants.

The library of logical features used to characterize memory graphs.

Classification and Mutation

SLearner uses a classification algorithm to find a boolean formula—an invariant—that distinguishes "positive" test cases (those that satisfy the program's goals) from "negative" ones (those leading to errors).

A key innovation of this work is Memory Graph Mutation. If initial tests do not provide enough data to find a robust invariant, SLearner systematically mutates memory graphs (e.g., by swapping pointers or adding nodes) to create synthetic states. This "stress-tests" the learned invariants and ensures they are strong enough for formal proof.

Evaluation and Results

The researchers evaluated SLearner on a suite of 110 programs involving 10 complex data structures, including Singly-linked lists, AVL Trees, and Red-Black Trees. The tool was integrated with two state-of-the-art verifiers: GRASShopper and HIP.

Key Results

  • Enhanced Verification: GRASShopper's success rate improved from 11/65 to 59/65 programs when using SLearner-generated specs. HIP, which could verify 0 programs without manual specs, successfully verified 27/45 complex programs with SLearner.
  • Impact of Mutation: The mutation step proved vital; without it, the number of verified programs in the GRASShopper suite dropped from 59 to 23.

Conclusion

SLearner demonstrates that "just-enough" invariants—those strong enough to prove a specific property—can be learned automatically. By bridging the gap between machine learning and formal logic, the framework significantly reduces the manual effort required for the rigorous verification of complex, heap-intensive software.

Summary updated

BibTeX
@inproceedings{pham2019compositional,
  author = {Long H. Pham and Jun Sun and Quang Loc Le},
  title = {{Compositional Verification of Heap-Manipulating Programs Through Property-Guided Learning}},
  booktitle = {APLAS},
  year = {2019},
  doi = {10.1007/978-3-030-34175-6\_21},
}
Figure