Date: 2025-10-30 Purpose: Evaluate formal verification tools for proving correctness of Levenshtein distance functions
Multiple formal verification tools are available for Rust, each with different strengths, limitations, and use cases. This document evaluates their suitability for verifying the correctness of our Levenshtein distance implementations.
Type: Bounded model checking Backing: AWS-funded, actively maintained Repository: https://github.com/model-checking/kani
Strengths:
Limitations:
Suitability for Distance Functions: ⭐⭐⭐⭐ (4/5)
Type: Deductive verification (uses Viper as backend) Backing: Academic (ETH Zürich), well-documented Repository: https://github.com/viperproject/prusti-dev
Strengths:
Limitations:
Suitability for Distance Functions: ⭐⭐⭐⭐⭐ (5/5)
Type: Deductive verification (uses Why3 as backend) Backing: French research institute (Inria) Repository: https://github.com/creusot-rs/creusot
Strengths:
Limitations:
Suitability for Distance Functions: ⭐⭐⭐⭐ (4/5)
Type: Translation to Coq Backing: Formal verification company (formal.land) Repository: https://github.com/formal-land/coq-of-rust
Strengths:
Limitations:
Suitability for Distance Functions: ⭐⭐ (2/5)
Type: SMT-based verification Backing: CMU research Website: https://verus-lang.github.io/
Strengths:
Limitations:
Suitability for Distance Functions: ⭐⭐ (2/5)
Reasons:
Implementation Plan:
cargo install prusti-cli#[requires], #[ensures]#[ensures(result >= 0)] // Non-negativity
#[ensures(source == target ==> result == 0)] // Identity
#[ensures(result == old(standard_distance(target, source)))] // Symmetry
cargo prustiIf Prusti cannot handle recursive memoization patterns:
use prusti_contracts::*;
#[pure]
#[ensures(result >= 0)]
#[ensures(source == target ==> result == 0)]
#[ensures(result == standard_distance(target, source))] // Symmetry
pub fn standard_distance(source: &str, target: &str) -> usize {
// ... implementation
}
// Triangle inequality (more complex, may need helper lemmas)
#[ensures(
standard_distance(a, c) <=
standard_distance(a, b) + standard_distance(b, c)
)]
pub fn triangle_inequality_holds(a: &str, b: &str, c: &str) -> bool {
true
}
Formal verification is feasible for our distance functions. Prusti offers the best balance of power, usability, and suitability for our use case. Property-based testing with proptest provides excellent confidence already, but formal verification with Prusti could provide mathematical proofs of correctness for critical properties.
Recommendation: Start with Prusti for the iterative distance functions, as they are simpler and will help us learn the tool. If successful, extend to recursive implementations.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |