TL;DR
This paper introduces Verus, a novel tool that leverages Rust's linear type system and borrow checker to formally verify Rust programs. By integrating proof and specification languages directly into Rust, Verus allows developers to write verifiable low-level and concurrent code with greater assurance, bridging the gap between high-level language safety and deep functional correctness.
What Problem Does This Paper Address?
Developing high-assurance, low-level systems in languages like Rust presents a unique challenge. While Rust's sophisticated type system, including linear types and borrow checking, provides strong memory safety guarantees, it doesn't inherently prove functional correctness beyond type safety. For critical systems, formal verification is essential, but existing tools often require learning entirely new languages or formalisms, creating a steep barrier to adoption. Furthermore, certain programming patterns, like doubly-linked lists, can be awkward or even require unsafe Rust due to strict ownership rules. This paper addresses the need for a verification tool that seamlessly integrates with Rust, allowing programmers to express proofs and specifications using familiar Rust constructs while still achieving rigorous verification.
Methods
Verus employs a multi-pronged approach:
- Leveraging Rust's Type System: Verus directly uses Rust's linear types and borrow checker for its proofs and specifications. This means that ghost code (specifications and proofs) is checked for linearity and borrowing, mirroring the guarantees of executable code.
- Linear Ghost Permissions: A core innovation is the use of "linear ghost permissions." These are ghost objects that track ownership and access rights to memory, pointers, and concurrent resources. They behave like separation logic predicates but are integrated into Rust's type system, allowing for safe manipulation of low-level constructs.
- SMT-Based Verification: Verus translates verification conditions into SMT (Satisfiability Modulo Theories) queries, which are then solved by tools like Z3. This allows for automated proof checking of many properties.
- Mode System: Verus introduces a novel mode system that distinguishes between
spec(purely functional, total),proof(checked for linearity/borrowing, must terminate), andexec(executable Rust code). This system enforces different properties for each type of code. - Formalized Lambda Calculus: The paper formalizes Verus' concepts in a small lambda calculus, proving type safety, termination, and soundness of its mode system, linearity, and borrowing rules.
Datasets
Not discussed in the paper. The paper focuses on the Verus tool itself and demonstrates its capabilities through various examples and benchmarks of verified Rust programs.
Key Insights and Ideas
- Rust as a Verification Language: The paper argues that Rust's own type system, particularly its linearity and borrowing, can be a powerful foundation for verification, rather than just a target for verification. This is a significant shift from traditional approaches.
- Linear Ghost Permissions as a Bridge: The concept of linear ghost permissions elegantly bridges the gap between high-level Rust safety and low-level pointer manipulation, enabling verification of complex data structures and concurrent protocols without resorting to
unsafecode. - Seamless Integration: By using Rust itself for specifications and proofs, Verus dramatically lowers the barrier to entry for formal verification, making it more accessible to Rust developers.
- Mode System for Clarity: The
spec,proof, andexecmodes provide a clear separation of concerns, ensuring that different types of code adhere to appropriate soundness and termination properties.
Key Results
- Verified Examples: Verus has been demonstrated on a range of examples, including:
- Allocator pages
- XOR doubly-linked list
- Fibonacci number computation
- Vector operations
- String interner
- Memoization
- FIFO queue
- Reader-writer locks
- Performance: The paper reports verification times for these examples, with most taking only a few seconds, indicating efficient SMT encoding and solving.
- Safety Guarantees: Verus successfully verifies code that would typically require
unsafeRust, such as low-level pointer manipulation and concurrent data structures, by providing safe, ghost-based abstractions.
Limitations and Future Work
- Mutable Borrows: Verus currently only supports mutable borrows (
&mut) for function arguments. Mutable references in return values and explicit borrows on the right-hand side of assignments are not yet supported, though the authors believe this is an engineering challenge. unsafeCode: Verus does not support verification of code explicitly marked with Rust'sunsafekeyword. Its goal is to provide safe alternatives.- Crate Verification: Support for separate verification of multiple crates is missing.
- Pointer Model: The pointer model is simplified, primarily handling pointers into the global heap. A more comprehensive model for stack variables, cell interiors, etc., is a future direction.
- Concurrency: While Verus supports concurrency, its formalization in the paper focuses on a subset. Advanced concurrency features and fine-grained reasoning are areas for further development.
- Type System Limitations: Verus' reliance on Rust's type system means it inherits some of its limitations compared to dependent type systems found in tools like Coq or F*.
Future work includes lifting the limitations on mutable borrows, expanding the pointer model, and further integrating Verus with the Rust ecosystem.
Summary updated