Abstract
Toman et al. have proposed a type system for automatic verification of low-level programs, which combines ownership types and refinement types to enable strong updates of refinement types in the presence of pointer aliases. We extend their type system to support pointer arithmetic, and prove its soundness. Based on the proposed type system, we have implemented a prototype tool for automated verification of the lack of assertion errors of low-level programs with pointer arithmetic, and confirmed its effectiveness through experiments.
Introduction
Verifying low-level imperative code, such as C, remains a significant challenge for automated tools. The primary obstacles are mutable references and the pervasive issue of aliasing. When multiple pointers reference the same memory location, an update through one pointer implicitly affects the state observed through another. Traditional refinement types, which attach logical predicates to variables (e.g., an integer restricted to positive values), often fail to account for these side effects without complex and computationally expensive heap modeling.
Researchers from the University of Tokyo have addressed this by extending the ConSORT type system. ConSORT originally combined refinement types with fractional ownership to enable "strong updates"—the ability to change a variable's refinement type when full ownership is held. However, it lacked support for pointer arithmetic, a staple of low-level programming. This work introduces a system that treats ownership and refinements as functions over memory offsets, allowing for the fully automated verification of programs that manipulate pointers through arithmetic.
Methodology: Functional Ownership and Refinement
The core innovation of this research is the transition from scalar ownership values to Functional Ownership.
Ownership and Refinement as Functions
Instead of assigning a single ownership value $o \in [0, 1]$ to a pointer, the system assigns an ownership function $r(i)$. This function maps a relative offset $i$ to an ownership value. For example, a pointer $p$ might own $1.0$ of the cell at $p+0$ but $0.0$ at other offsets. Similarly, the type of the value stored at an offset is represented by a function $\tau(i)$. This enables the system to express complex invariants over arrays, such as "the element at index $i$ is equal to $i$."
As illustrated in the code snippet above, ownership types allow the system to track that the value pointed to by x has changed from 0 to 1. This "strong update" is sound because the system knows x has full ownership ($ref^1$), precluding the existence of conflicting aliases that could be affected by the write.
Formal Semantics and Pointer Arithmetic
To support pointer arithmetic, the operational semantics were extended to represent pointers as pairs of a base address and an offset. Pointer arithmetic (e.g., $p + z$) is modeled as a simple shift in the offset.
The rules detailed above, specifically R-ADDPTR, formalize how the system tracks these shifts. The system also utilizes alias hints to redistribute ownership when pointers are incremented or decremented. These hints can be automatically inserted via standard must-alias analysis, maintaining a high degree of automation.
Automated Verification Pipeline
The verification process is split into two automated phases:
- Ownership Inference: The tool generates constraints on ownership functions and utilizes the Z3 SMT solver to find a valid distribution of ownership across the program's execution.
- Refinement Inference: Once ownership is settled, the tool generates Constrained Horn Clauses (CHCs) to verify the actual program logic and assertions. These are solved using HoIce.
By using ownership types to handle heap reasoning, the resulting CHCs are significantly simplified, involving integer predicates rather than complex "theory of arrays" models that often cause general-purpose solvers to time out.
Experimental Evaluation
The prototype tool, implemented in OCaml, was evaluated against a suite of benchmarks designed to stress-test pointer manipulation, including recursive array initialization and multi-pointer array summations. The results were compared against SeaHorn, a state-of-the-art CHC-based verifier for C.
- Efficiency: Most benchmarks were verified in under 3 seconds. The most complex,
Add-Array(handling three pointers), took approximately 338 seconds. - Effectiveness: SeaHorn timed out (exceeding 600 seconds) on nearly all benchmarks except the simplest cases. This is because SeaHorn models the heap as a giant integer array, leading to complex predicates that are difficult for general solvers to crack.
Conclusion and Future Work
This work demonstrates that functional ownership types provide a powerful and efficient framework for verifying low-level programs with pointer arithmetic. While a major step forward, the current system does not yet support nested pointers (e.g., int **p) or non-contiguous ownership shapes. Future research will focus on extending the tool to support the full C language and improving the efficiency of the ownership inference heuristics.
Summary updated