Skip to content

Latest commit

Β 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

README.md

Symbolic Model Checking with BDDs

A BDD-based symbolic model checking framework implementing classic algorithms from "Symbolic Model Checking: 10^20 States and Beyond" (Burch et al., 1990).

Overview

This library verifies finite-state systems using Binary Decision Diagrams, handling systems with millions to billions of states by representing state sets symbolically rather than explicitly enumerating them.

Features

Core Capabilities

  • Transition Systems: Symbolic Kripke structures with present/next-state variables
  • CTL Model Checking: Full Computation Tree Logic (EX, AX, EF, AF, EG, AG, EU, AU)
  • LTL Model Checking: Linear Temporal Logic via BΓΌchi automata
  • Fairness Constraints: Strong and weak fairness for realistic liveness properties
  • Counterexample Generation: Linear traces (safety) and lasso traces (liveness)

Symbolic Operations

  • image(S, T): Forward reachability β€” βˆƒs. S(s) ∧ T(s, s')
  • preimage(S, T): Backward reachability β€” βˆƒs'. T(s, s') ∧ S(s')
  • Existential quantification and variable renaming

Project Structure

examples/model-checking/
β”œβ”€β”€ Cargo.toml
β”œβ”€β”€ README.md
β”œβ”€β”€ guide/
β”‚   └── main.typ            # Typst documentation
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs              # Public API
β”‚   β”œβ”€β”€ transition.rs       # Transition systems
β”‚   β”œβ”€β”€ ctl.rs              # CTL model checking
β”‚   β”œβ”€β”€ ltl.rs              # LTL model checking
β”‚   β”œβ”€β”€ fairness.rs         # Fairness constraints
β”‚   └── counterexample.rs   # Counterexample generation
└── examples/
    β”œβ”€β”€ abp.rs              # Alternating Bit Protocol
    β”œβ”€β”€ hanoi.rs            # Towers of Hanoi (planning)
    β”œβ”€β”€ tictactoe.rs        # Game solving (attractors)
    β”œβ”€β”€ mutex.rs            # Peterson's mutual exclusion
    β”œβ”€β”€ philosophers.rs     # Dining philosophers
    β”œβ”€β”€ counter.rs          # N-bit counter (scalability)
    └── traffic_light.rs    # Traffic light controller

Examples

Alternating Bit Protocol (abp.rs)

Demonstrates reliable communication over a lossy channel:

  • Fairness: Shows why liveness requires fairness constraints
  • Safety vs Liveness: AF fails without fairness, holds with fairness
  • Key insight: Adversarial schedulers can always prevent progress
cargo run --example abp --release

Towers of Hanoi (hanoi.rs)

BDD-based symbolic planning for the classic puzzle:

  • State space: 3^N configurations for N disks
  • Optimal solution: Symbolic BFS finds 2^N-1 minimum moves
  • Solution extraction: Displays step-by-step solution with visual diagrams
cargo run --example hanoi --release

Tic-Tac-Toe (tictactoe.rs)

Two-player game solving with attractor computation:

  • Winning regions: Computes states where each player can force a win
  • Drawing analysis: Confirms empty board is a draw with perfect play
  • Attractor algorithm: Backward fixpoint for game-theoretic analysis
cargo run --example tictactoe --release

Other Examples

  • mutex.rs: Peterson's algorithm for mutual exclusion
  • philosophers.rs: Dining philosophers deadlock analysis
  • counter.rs: N-bit counter demonstrating BDD scalability
  • traffic_light.rs: Simple traffic light controller

Temporal Logics

CTL (Computation Tree Logic)

Branching-time logic with path quantifiers (A/E) and temporal operators:

Formula Meaning
EX Ο† There exists a next state satisfying Ο†
AX Ο† All next states satisfy Ο†
EF Ο† There exists a path where Ο† eventually holds
AF Ο† On all paths, Ο† eventually holds
EG Ο† There exists a path where Ο† always holds
AG Ο† On all paths, Ο† always holds
E[Ο† U ψ] There exists a path where Ο† holds until ψ
A[Ο† U ψ] On all paths, Ο† holds until ψ

LTL (Linear Temporal Logic)

Linear-time logic for reasoning about individual execution paths:

Formula Meaning
X Ο† Ο† holds in the next state
F Ο† Ο† eventually holds (Future)
G Ο† Ο† always holds (Globally)
Ο† U ψ Ο† holds until ψ becomes true
Ο† R ψ ψ holds until (and including when) Ο† becomes true

Fairness Constraints

Fairness assumptions exclude unrealistic infinite behaviors:

  • Strong fairness: If enabled infinitely often, happens infinitely often
  • Weak fairness: If continuously enabled, eventually happens
// Without fairness: AF delivered FAILS (adversarial channel)
// With fairness:    AF delivered HOLDS (realistic behavior)

Algorithms

Fixpoint Computation

CTL operators are computed via least (ΞΌ) and greatest (Ξ½) fixpoints:

EF Ο†  = ΞΌZ. Ο† ∨ EX Z        [least fixpoint - start from βˆ…]
EG Ο†  = Ξ½Z. Ο† ∧ EX Z        [greatest fixpoint - start from all states]

Counterexample Generation

When properties fail, counterexamples explain why:

  • Linear traces: Path from initial state to violation (safety)

  • Lasso traces: Stem + loop structure (liveness)

    Linear:  sβ‚€ β†’ s₁ β†’ sβ‚‚ β†’ ... β†’ sβ‚™ (bad)
    Lasso:   [ sβ‚€ β†’ s₁ β†’ ... β†’ sβ‚– ]  β†’ [ sβ‚–β‚Šβ‚ β†’ ... β†’ sβ‚˜ β†’ sβ‚– ]
                                         ↑________________|
    

    Here, the loop from sβ‚– to sβ‚˜ demonstrates infinite violation.

Quick Start

use model_checking::*;
use bdd_rs::bdd::Bdd;
use std::rc::Rc;

// Create transition system
let bdd = Rc::new(Bdd::default());
let mut ts = TransitionSystem::new(bdd.clone());

// Declare state variable
let x = Var::new("x");
ts.declare_var(x.clone());

// Set initial state and transitions
let x_pres = ts.var_manager().get_present(&x).unwrap();
let initial = ts.bdd().apply_not(ts.bdd().mk_var(x_pres));
ts.set_initial(initial);

let x_trans = ts.assign_var(&x, ts.bdd().apply_not(ts.bdd().mk_var(x_pres)));
ts.set_transition(x_trans);

// Add labels and check properties
ts.add_label("on".to_string(), ts.bdd().mk_var(x_pres));
let ts = Rc::new(ts);

let checker = CtlChecker::new(ts.clone());
let property = CtlFormula::atom("on").ef(); // EF on
assert!(checker.holds_initially(&property));

Testing

cargo test --lib

All tests passing βœ“

References

  1. Symbolic Model Checking: 10^20 States and Beyond β€” Burch et al. (1990)
  2. Model Checking β€” Clarke, Grumberg, Peled (1999)
  3. Principles of Model Checking β€” Baier & Katoen (2008)
  4. NuSMV 2.0 User Manual β€” Cimatti et al. (2002)