hn.today

Proof-oriented programming in Verus vs. Lean

willcrichton.net3 points0 comments
Screenshot of Proof-oriented programming in Verus vs. Lean

A comparison of Verus and Lean uses a verified bitset to show what proof-oriented programming looks like: specifications are proved against the implementation itself, rather than against a separate model. A bitset stores a fixed domain of numbers in 64-bit words, with set operations implemented through bit operations. Its correctness depends on two invariants: the word array has the right length, and padding bits outside the domain remain zero. The case study also defines containment by mapping each number to a word and bit, then models the structure as an ordinary set so implementation behavior can be related to familiar mathematical membership.

The languages encode these obligations differently. Lean makes the domain a type parameter and the word-array length part of its type, and carries the padding proof inside each bitset; bounded indices also make array access intrinsically safe. Verus follows Rust’s runtime-oriented representation, storing the domain as a field and expressing both invariants explicitly. Its specifications need quantifier and solver annotations, and methods state well-formedness preconditions. Lean’s supporting types and tactics make some specifications more concise, while Verus keeps code closer to idiomatic Rust; however, Verus may require verified unsafe code to eliminate bounds checks. The comparison highlights practical tradeoffs in representation, proof automation, runtime behavior, and the connection between verified specifications and executable code.

Read on willcrichton.net0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Show HN: Rust Commander

Show HN: Rust Commander

Rust Commander is a Rust terminal file manager modeled on Midnight Commander, with dual-pane navigation, a persistent shell, archive and remote browsing, and background file operations. Version 0.3.1 adds file-change alerts, viewer copy controls, customizable skins, and faster SFTP previews and copying. (github.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.