Abstract
Verifying the correctness of programs that manipulate dynamic memory is a cornerstone of software reliability. However, the logics required to describe complex pointer-based data structures, such as doubly-linked lists or trees, are often undecidable. This paper introduces "structure simulation," a formal framework that allows developers to verify these complex structures by mapping them to simpler, tractable representations within decidable logics. By defining a first-order mapping ($\eta$) and simulation invariants ($SI$), the authors demonstrate how properties of complex structures can be automatically translated and proven in a simpler domain. The approach is validated through an implementation combining the TVLA shape analysis system with the MONA logic tool, successfully verifying non-trivial algorithms like destructive list division.
Introduction: The Decidability Dilemma
The verification of pointer-heavy code is notoriously difficult due to the need to reason about global properties like reachability and shape. For instance, ensuring that a list remains acyclic after an insertion requires a logic that can express transitive closure or similar concepts. This leads to a fundamental trade-off in formal logic: expressive logics capable of describing complex shapes are typically undecidable, while decidable logics (like MSO-E) are often too restricted to describe structures beyond simple function graphs where each node has at most one outgoing edge.
Structure Simulation: A Mirror World for Verification
The core innovation presented is "structure simulation." Instead of attempting to verify a program directly in a complex, undecidable logic, the authors propose building a mathematical "mirror" of the data structure in a simpler, decidable logic.
As shown in Figure 1, the framework consists of several key components:
- The Mapping ($\eta$): A first-order mapping that translates a "Representation" structure ($Rep$)—which is simple and fits within a decidable logic—into the "Original" structure ($Org$) used by the program.
- Simulation Invariants ($SI$): These are global constraints that define the valid states of the structures. They are crucial because programs often temporarily violate data structure invariants during intermediate steps of an operation (e.g., creating a temporary cycle while reversing a list).
- Formula Translation: A mechanism to automatically translate a property $\phi$ (intended for $Org$) into a property $\bar{\eta}(\phi)$ (intended for $Rep$).
The Simulation Theorem ensures that if the translated property holds for the representation, the original property must hold for the actual data structure. This allows developers to leverage the "weak" decidable logics to verify "strong" complex data structures.
Encoding Complex Structures
To make this framework practical, the authors provide specific translations for common data structures. For example, a doubly-linked list (DLL) can be represented as a function graph where backward pointers are encoded as reversed edges or specific unary predicates.
Figure 2 illustrates how various structures like binary trees and DLLs are mapped. In the case of a binary tree, the "left" and "right" child pointers are translated into edges in a way that preserves the functional nature required by the underlying decidable logic. The simulation invariants ($SI$) ensure that the resulting graph remains a valid representation of the intended structure, such as maintaining acyclicity or ensuring uniqueness of pointers.
Practical Implementation and Case Studies
The authors implemented this approach by interfacing TVLA (Three-Valued Logic Analysis), a system for shape analysis, with MONA, a tool for deciding logic formulas. This integration allows for the automatic discovery of program properties, reducing the burden on the user to provide exhaustive loop invariants.
A key case study involved a "Red-Black" list division program. This algorithm destructively splits a doubly-linked list into two based on a color attribute. During the process, backward pointers may temporarily point to "illegal" or intermediate locations. The simulation framework successfully tracked these states by using a simulation invariant that was flexible enough to accommodate these transient violations while still proving the final safety and correctness of the output lists.
Conclusion
Structure simulation provides a powerful bridge between the expressiveness needed for real-world programming and the rigor of decidable logics. By shifting the verification task to a simpler representation, it enables the automation of complex pointer reasoning. While the current approach requires manual definition of the mapping $\eta$ and the invariant $SI$, it represents a significant step toward fully automated verification of dynamic memory management. Future work aims to automate the generation of these mappings and extend the technique to even more generalized graph structures.
Summary updated