NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Propositional Reasoning about Safety and Termination of Heap-Manipulating Programs

Cristina David, Daniel Kroening, Matt Lewis

Abstract

Verifying programs that manipulate dynamic memory is notoriously difficult due to the complex interplay between pointer structures (shape) and numeric properties (arithmetic). This paper introduces Singly-Linked lists with Height (SLH), a new logic designed to reason about potentially cyclic, singly-linked lists. The core contribution is the proof of a "small model property" for SLH, which allows complex verification conditions regarding safety and termination to be reduced to bit-vector arithmetic. This reduction enables the use of efficient, off-the-shelf SAT solvers. The authors implement this theory in a tool called SHAKIRA, which demonstrates high efficiency in verifying standard list operations and generating concrete counterexamples for buggy code.

Introduction

The verification of heap-manipulating programs remains a significant challenge in formal methods. The difficulty arises from the need to simultaneously track the shape of the heap—including cycles and shared tails—and the arithmetic properties, such as the lengths of list segments. For instance, a program might only be safe if a pointer reaches NULL in a specific number of steps, or a loop might only terminate if two lists have equal lengths.

Existing verification tools often face a trade-off: they either struggle with the arithmetic of list lengths or become undecidable when attempting to handle complex pointer sharing and cycles. SLH aims to bridge this gap by providing a logic that is expressive enough for real-world list operations while remaining computationally tractable.

The SLH Logic and Semantics

The SLH logic includes a suite of functions to inspect heap states, such as checking for pointer aliasing (alias), paths between nodes (isPath), shortest path lengths (pathLength), nullity (isNull), and circularity (circular). Furthermore, it defines the semantics for "pure" versions of standard heap mutations, including node creation (new), pointer assignment (assign), field lookup (lookup), and field update (update).

Semantics of heap operations and logical predicates in SLH.

As shown in the figure above, the logic provides a formal way to describe how operations like x = y->next or x->next = y transform the heap structure. By formalizing these transitions, the authors can reason about the state of the heap at any point in a program's execution.

The Small Model Property and SAT Reduction

The mathematical cornerstone of this work is the Small Model Property. The authors prove that if a property in SLH is false, there must exist a "small" counterexample heap. To prove this, they utilize Heap Homeomorphism, a concept borrowed from topology.

The intuition behind homeomorphism is to treat long, unbranched chains of nodes as single weighted edges. If a chain has no external pointers entering or leaving its middle nodes, its specific length is less important than its existence as a path. By simplifying complex heaps into "kernels," the authors show that the essential properties of a heap can be preserved in a structure whose size is proportional only to the number of pointer variables in the program.

Because the models are guaranteed to be small, the entire verification problem can be encoded into bit-vector arithmetic. The authors use CBMC (a bounded model checker) to translate these arithmetic constraints into a SAT formula. This allows the use of non-linear operations (like modulo or division on list lengths) that are typically problematic for other verification logics.

Experimental Evaluation

The authors implemented their approach in a tool called SHAKIRA and evaluated it against a suite of C-like programs. These benchmarks included standard operations like list traversal, reversal, and sorting, as well as programs requiring non-linear arithmetic (e.g., a "divides" function implemented via list lengths).

Key Results

  • Efficiency: SHAKIRA verified 40 safety Verification Conditions (VCs) in just 5.9 seconds.
  • Termination: Proving total correctness (termination) requires numeric ranking functions that decrease each iteration. SHAKIRA successfully solved 25 termination VCs in 9.6 seconds.
  • Counterexample Generation: For programs with bugs—such as null-pointer dereferences or infinite loops—the tool produced minimal heap structures (averaging 3–6 nodes). These concrete examples provide developers with clear evidence of why a program fails.

Conclusion

SLH provides a powerful framework for reasoning about singly-linked lists by leveraging the small model property to enable SAT-based verification. Unlike Separation Logic, which often requires strict memory ownership, SLH allows for arbitrary pointer sharing and cycles, making it well-suited for "messy" real-world code.

Current limitations include the restriction to singly-linked structures and the requirement for manual loop invariants and ranking functions. Future work may extend this logic to more complex data structures like trees or doubly-linked lists and integrate it with automated invariant synthesis tools.

Summary updated

BibTeX
@inproceedings{david2015propositional,
  author = {Cristina David and Daniel Kroening and Matt Lewis},
  title = {{Propositional Reasoning about Safety and Termination of Heap-Manipulating Programs}},
  booktitle = {ESOP},
  year = {2015},
  doi = {10.1007/978-3-662-46669-8\_27},
}
Figure