Abstract
Verifying the safety of imperative programs is complicated by the interplay of mutability and aliasing. Traditional verification methods often lose precision when multiple pointers reference the same memory location, leading to "weak updates" and false positives. We present ConSORT, a type system that integrates fractional ownership with refinement types to enable precise, automated verification. By tracking memory permissions as rational values, ConSORT facilitates strong updates even in the presence of aliasing. Our evaluation demonstrates that ConSORT effectively verifies complex data structures like sorted lists and outperforms existing tools on benchmarks requiring sophisticated heap reasoning.
1. Introduction
In imperative languages such as C or Java, the state of a memory cell changes over time, and multiple variables can alias the same location. This combination makes it difficult for automated verifiers to maintain accurate invariants. When a pointer $p$ is updated, any invariant associated with an alias $q$ must also be adjusted. Without precise alias information, verifiers typically resort to conservative "weak updates," which discard specific knowledge about the memory cell's contents.
ConSORT (CONtext-Sensitive Ownership Refinement Types) addresses this by using ownership as a proxy for alias analysis. By embedding ownership directly into the type system, ConSORT allows for "strong updates"—where a type's logical predicate is completely replaced—when exclusive access is guaranteed.
2. The ConSORT Framework
The system relies on three pillars:
- Fractional Ownership Types: Each pointer is assigned an ownership value $r \in [0, 1]$. An ownership of 1 signifies exclusive access, permitting strong updates. Values between 0 and 1 indicate shared, read-only access, while 0 indicates potential mutation by an alias, requiring the system to discard specific refinements.
- Refinement Types: Types are augmented with logical predicates (e.g.,
int {v | v > 0}). ConSORT tracks the evolution of these predicates across program points. - Context Sensitivity: To handle function calls accurately, ConSORT employs call strings and context variables, allowing functions to be analyzed differently based on their invocation site.
2.1 Operational Semantics
The operational semantics of the core language define how the program state—comprising the heap ($H$), register file ($R$), and frame stack ($F$)—evolves through transitions denoted by $\longrightarrow_D$.
As shown in the figure above, rules like R-MKREF and R-DEREF manage the creation and access of memory references, while R-LET and R-LETINT handle variable binding and substitution. These rules form the formal basis for the subsequent constraint generation process.
3. Automated Inference
A key strength of ConSORT is its support for automated inference. Programmers are not required to provide manual annotations for every pointer. Instead, the system generates a set of constraints:
- Linear inequalities for ownership values.
- Horn clauses for refinement predicates.
These constraints are then solved using off-the-shelf SMT solvers like Z3. This approach allows the system to soundly discard information when ownership drops to zero, preventing false assumptions about aliased memory.
4. Evaluation
ConSORT was evaluated against the JayHorn benchmark suite and a custom suite of complex data structures.
- JayHorn Benchmarks: ConSORT correctly identified 29 out of 32 safe programs, matching the performance of the state-of-the-art JayHorn verifier in most cases.
- Data Structure Suite: ConSORT significantly outperformed JayHorn on implementations like
Sorted-ListandArray-List. While JayHorn struggled with "unbounded heap models," ConSORT's ownership-based approach allowed it to verify these structures fully automatically. - Precision: In the "Shuffle" benchmark, ConSORT successfully tracked ownership transfers between multiple live references, a task that typically causes symbolic alias analyses to fail.
5. Conclusion and Future Work
ConSORT demonstrates that combining fractional ownership with refinement types provides a powerful mechanism for verifying imperative programs. By treating ownership as a linear resource, the system achieves high precision without the overhead of a separate alias analysis. Future work will focus on extending refinements to refer to multiple memory locations and supporting conditional ownership based on runtime values.
Summary updated