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

Ownership Types for Verification of Programs with Pointer Arithmetic

Izumi Tanaka, Ken Sakayori, Naoki Kobayashi

TL;DR

Researchers from the University of Tokyo have extended the ConSORT type system to support pointer arithmetic, allowing for the fully automated verification of low-level programs. By treating "ownership" not as a single number but as a function over memory addresses, their tool can track memory safety and functional correctness even when pointers are shifted, split, or aliased.

What Problem Does This Paper Address?

Verifying low-level imperative code (like C) is a nightmare for automated tools. The primary culprits are mutable references and aliasing. If two pointers, x and y, point to the same memory cell, updating *x silently changes the value of *y. Traditional "refinement types" (which attach logical predicates to variables, e.g., "this integer is always > 0") struggle here because they don't naturally account for these hidden side effects.

A previous system called ConSORT solved this by combining refinement types with fractional ownership. If you own "1.0" of a memory cell, you can change its type (a "strong update"). If you own "0.5," you can only read it. However, ConSORT had a major blind spot: it couldn't handle pointer arithmetic (e.g., p + 1). In low-level code, a pointer isn't just a link to one box; it’s often a gateway to an entire contiguous region of memory.

Methods

The authors introduce a significant upgrade to the ConSORT framework. The key innovation is Functional Ownership.

  1. Ownership as a Function: Instead of a pointer having a single ownership value $o \in [0, 1]$, a pointer now has an ownership function $r(i)$. This function maps a relative offset $i$ to an ownership value. For example, a pointer might own "1.0" of the cell at offset 0, but "0.0" of everything else.
  2. Refinement as a Function: Similarly, the type of the value stored at an offset is now a function $\tau(i)$. This allows the system to reason that "the element at index $i$ is equal to $i$."
  3. Two-Phase Automated Inference:
    • Phase 1 (Ownership): The tool generates constraints on the ownership functions and uses the Z3 SMT solver to find a valid distribution of "who owns what" across the program's execution.
  4. Phase 2 (Refinement): Once ownership is settled, the tool generates Constrained Horn Clauses (CHCs) to verify the actual logic (the assertions). These are solved using HoIce.

The system also uses an alias hint (which can be automatically inserted via must-alias analysis) to help the type system redistribute ownership when pointers are incremented or decremented.

Datasets

The authors evaluated their prototype on a suite of benchmark programs designed to stress-test pointer manipulation:

  • Init: Recursively initializing an array to zero using pointer increments.
  • Sum (and variants): Calculating the sum of an array (accessing elements from the front, back, both ends, or via recursive division).
  • Copy-Array & Add-Array: Programs manipulating multiple pointers simultaneously to copy or sum arrays element-wise.

They compared their tool against SeaHorn, a state-of-the-art CHC-based verifier for C.

Key Insights and Ideas

  • Spatial Reasoning via Types: The "aha moment" is realizing that pointer arithmetic is essentially a shift in the domain of the ownership function. When you do q = p + 1, the ownership function for q is just the ownership function of p shifted by one.
  • Strong Updates in Arrays: Because the system tracks full ownership ($r(i) = 1$) for specific offsets, it can perform "strong updates" on individual array elements. It can know that p[0] changed from an unknown value to exactly 0 without losing information about the rest of the array.
  • Decoupling Heap Modeling: By using ownership types, the resulting logic problems (CHCs) are much simpler. They involve integer predicates rather than complex "theory of arrays" or "heap models," which often cause other solvers to time out.

Key Results

The prototype tool, written in OCaml, significantly outperformed SeaHorn on the provided benchmarks:

  • Efficiency: Most benchmarks were verified in under 3 seconds. The most complex, Add-Array (handling three pointers), took about 338 seconds.
  • Effectiveness: SeaHorn timed out (600s+) on almost all benchmarks except the smallest one (Init-10). This is because SeaHorn models the heap as a giant integer array, leading to complex predicates that are difficult for general-purpose solvers to crack.
  • Automation: The authors confirmed that the necessary alias annotations could be inserted automatically using standard alias analysis, meaning the user doesn't need to manually provide ownership hints.

Limitations and Future Work

While a major step forward, the paper notes several areas for improvement:

  • No Nested Pointers: The current system does not support "pointers to pointers" (e.g., int **p), which are common in complex C data structures.
  • Ownership Shape: The inference engine currently assumes ownership functions have a specific "rectangular" shape (owning a contiguous range $[l, u]$). It cannot yet handle "checkerboard" patterns or more complex distributions.
  • Polymorphism: The system lacks polymorphic function types, meaning a function's ownership behavior can't currently depend on the values of its arguments (e.g., a function that clears a number of cells specified by a pointer's value).

The authors plan to extend the tool to support the full C language and improve the efficiency of the ownership inference heuristic.

Summary updated

BibTeX
@inproceedings{tanaka2024ownership,
  author = {Izumi Tanaka and Ken Sakayori and Naoki Kobayashi},
  title = {{Ownership Types for Verification of Programs with Pointer Arithmetic}},
  booktitle = {PEPM},
  year = {2024},
  url = {https://openreview.net/forum?id=DNH9xk6Lpq},
}

Loading related content...

Figure