RustHorn: CHC-based Verification for Rust Programs (full version)

Yusuke Matsushita, Takeshi Tsukada, Naoki KobayashiarXiv 2020 · DOI

Introduction

Automated program verification often relies on reducing code to Constrained Horn Clauses (CHCs), a logic format suitable for automated solvers. However, verifying pointer-manipulating programs remains a significant challenge due to the complexity of modeling heap memory. RustHorn addresses this by leveraging Rust’s unique ownership and borrowing system to translate programs into CHCs without the need for complex memory-array models.

The Challenge of Pointer Verification

Traditional verification techniques, such as those used for C, typically model the entire heap as a large array. Modifying a pointer is treated as an update to an index in this array. This approach forces solvers to find "quantified invariants"—logical statements that must hold for every possible memory index. Finding these invariants automatically is computationally expensive and often leads to timeouts or false alarms, particularly when dealing with recursive data structures like linked lists or trees.

The RustHorn Approach: Ownership and Prophecy

RustHorn exploits the guarantees provided by Rust’s borrow checker. Since the type system ensures that a mutable reference (&mut T) has exclusive access to its data, the verifier can represent a pointer as a pair of values $(a, a_\circ)$, where $a$ is the current value and $a_\circ$ is the "prophesied" value the data will take when the borrow ends.

Illustration of the prophecy variable mechanism during a function call.

As shown in Figure 1, when a function like take_max is called, the original variables a and b are effectively suspended (represented by dotted lines). The mutable references ma and mb track the state. When the borrowing period ends, the "future" value (e.g., the updated value 6) is returned to the original owner. This "functional purification" eliminates the need for a global heap model, making the resulting CHCs much easier for solvers to process.

Formalization: The COR Language

To provide a rigorous foundation, the authors introduced the Calculus of Ownership and Reference (COR). COR is a formalized core language for Rust that captures essential features like lifetimes, ownership, and recursive types. The authors proved that the translation from COR to CHCs is both sound (guaranteeing safety) and complete (ensuring that if a proof exists, it can be found).

Evaluation and Results

RustHorn was evaluated against SeaHorn, a state-of-the-art C verifier, using a variety of benchmarks including standard verification tasks and custom programs with complex pointer manipulations.

  • Recursive Data Structures: RustHorn successfully verified programs involving destructive updates to linked lists and trees—tasks where SeaHorn frequently failed due to the complexity of unbounded memory allocation.
  • Solver Compatibility: The translation produces CHCs that are highly compatible with modern solvers. While Z3's Spacer solver struggled with some recursive types, the HoIce solver, which is optimized for recursive functions, was able to verify them nearly instantly.
  • Performance: The translation process is highly efficient, typically completing in approximately 0.1 seconds per program.

Conclusion and Future Work

RustHorn demonstrates that Rust's ownership model is not just a tool for memory safety, but a powerful asset for formal verification. By bypassing the heap-as-array bottleneck, it enables the automated verification of complex, pointer-heavy programs.

Future work aims to extend RustHorn to support:

  • Unsafe Code: Integrating separation logic to reason about blocks where the borrow checker is bypassed.
  • Advanced Language Features: Adding support for closures and traits.
  • Total Correctness: Moving beyond safety properties to prove program termination and liveness.

Summary updated

BibTeX
@misc{matsushita2020rusthorn,
  author = {Yusuke Matsushita and Takeshi Tsukada and Naoki Kobayashi},
  title = {{RustHorn: CHC-based Verification for Rust Programs (full version)}},
  year = {2020},
  eprint = {2002.09002},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.09002},
}
Figure