Verus vs. Lean: proof-oriented programming on a verified bitset
Verus and Lean are two proof-oriented programming[1] languages that the author expects to catch on. The post compares them through a small case study: a verified bitset, a data structure for sets of numbers over a small fixed domain. It notes that verification tools often check a model of a system, not the system itself.
The Rust version stores the domain as a struct field, while Lean encodes it as a type parameter, so the length of the word array is part of the type. Rust stores words as unboxed integers, whereas in Lean each word is boxed individually unless specialized arrays are used. Rust's usize can overflow, so (d + 63) / 64 overflows for large domains, but Lean uses natural numbers of unbounded size.
A bitset has two key invariants[2]: the correct number of words and zero bits outside the domain. Lean already encodes the length, so it needs only the padding invariant and attaches the proof to the structure as a field. Verus needs both invariants in one wf function, where quantifiers are more verbose and a #[trigger] annotation guides the SMT solver[3]. The author used requires and ensures on every method, because #[type_invariant] did not work well with longer-lived mutable borrows.
Repository Verus github.com
Verus is a tool for verifying Rust code: you write specifications and proofs that check low-level systems code is correct.
Repository Lean github.com
Read the original willcrichton.netDiscussion
Sources
-
willcrichton.net
Proof-Oriented Programming in Verus vs. Lean

