rspin verifies models written in Promela, the language of the
SPIN model checker, and finds concurrency bugs
(races, deadlocks, protocol errors, LTL violations) by exhaustively exploring
every interleaving.
Unlike SPIN, rspin does not generate and compile C code. It interprets
Promela directly, so verification starts immediately. Safety checks run on all
your CPU cores. Safety counterexamples are the shortest possible, and
error messages point at your source.
$ rspin verify examples/race.pml
rspin 0.1.0 · verifying race.pml
▸ safety (assertions, invalid end states)
✘ assertion violated
counterexample (8 steps):
1 init:0 race.pml:14 run worker()
2 init:0 race.pml:14 run worker()
3 worker:1 race.pml:8 tmp = count; tmp++
4 worker:2 race.pml:8 tmp = count; tmp++
5 worker:1 race.pml:10 count = tmp
6 worker:2 race.pml:10 count = tmp
7 init:0 race.pml:15 (_nr_pr == 1)
8 init:0 race.pml:16 assert(count == 2) ← assertion violated
state:
globals count = 1
init:0 line 16
states 16 stored, 3 matched, 18 transitions
search depth 6, state vector 8 bytes, 6.1 KiB memory
time 0.001s (12,549 states/s, 8 threads)
Highlights
- ⚡ No compile step.
spin -a && cc pan.c && ./pan becomes rspin verify model.pml.
Small and medium models finish in milliseconds instead of seconds.
- 🧵 Multi-core safety checking. A parallel, level-synchronous BFS over a
lock-striped state store.
- 📏 Shortest counterexamples. BFS finds the shortest trail to every safety
violation, so you don’t have to run iterative shortening by hand.
- ✂️ Strong reductions. Partial-order reduction (with
xr/xs channel
assertions and a level-based BFS cycle proviso), statement merging, and
atomic-sequence collapsing. On several classic models rspin stores fewer
states than SPIN.
- 🔮 LTL built in. It checks every
ltl { } property of the model by default,
plus never claims and non-progress cycles. Liveness can be checked under
weak fairness (--fair). rspin ltl2ba replaces spin -f.
- 🩺 Friendly diagnostics. rustc-style errors with source snippets and
“did you mean” suggestions. Trails show printf output and the final state.
- 🧪 Tested against SPIN itself. Every CI run generates random models and
checks that rspin and SPIN reach the same verdicts.
- 🌐 Runs in the browser. The playground
is the same engine compiled to WebAssembly.
- 🤖 Works in CI.
--json output, meaningful exit codes, a single
static binary.

Install
cargo install --git https://github.com/karamage/rspin
Prebuilt binaries for Linux, macOS and Windows are attached to each
release.
Usage
rspin model.pml # random simulation (like `spin model.pml`)
rspin run -p -g model.pml # print every step and the final state
rspin run -i model.pml # interactive simulation
rspin verify model.pml # safety + every ltl property + never claim
rspin verify --ltl mutex model.pml # one LTL property
rspin verify -f '[] (x >= 0)' m.pml # an LTL formula from the command line
rspin verify --fair --ltl live m.pml # liveness under weak fairness
rspin verify --np model.pml # non-progress cycles
rspin verify -j 4 --safety m.pml # 4 threads, safety only
rspin verify --json model.pml # machine-readable results for CI
rspin replay model.pml # replay the counterexample in model.pml.trail
rspin ltl2ba '[] (p -> <> q)' # LTL → Büchi automaton as a never claim
rspin dot model.pml | dot -Tsvg > cfg.svg # control-flow graphs
rspin check model.pml # parse/type-check and summarize
Exit status: 0 when no errors are found, 1 when a property is violated,
2 for usage or model errors.
Coming from SPIN? Option mapping
| SPIN |
rspin |
spin model.pml |
rspin model.pml |
spin -p -g model.pml |
rspin run -p -g model.pml |
spin -a model.pml && cc -o pan pan.c && ./pan |
rspin verify --safety model.pml |
./pan -a (acceptance cycles, never claim / ltl) |
rspin verify (all properties) or --never / --ltl NAME |
./pan -a -f |
rspin verify --fair |
./pan -l (compiled with -DNP) |
rspin verify --np |
./pan -E / ./pan -A |
rspin verify -E / -A |
./pan -m N |
rspin verify -m N |
cc -DNOREDUCE |
rspin verify --no-por |
cc -DHC4 (hash compaction) |
rspin verify --compact |
spin -t -p model.pml |
rspin replay model.pml |
spin -f 'formula' |
rspin ltl2ba 'formula' |
spin -DNAME=val |
rspin -DNAME=val ... |
Benchmarks
Wall-clock time for an exhaustive safety check on an Apple M1 (4 performance +
4 efficiency cores). SPIN 6.5.3’s time is the full pipeline: spin -a, cc -O2 -DSAFETY
and ./pan. rspin uses its default settings (all cores). Models are in
benchmarks/; run benchmarks/run.sh to reproduce.
| Model |
SPIN states |
SPIN time |
rspin states |
rspin time |
Speedup |
| Peterson filter lock, N=4 |
1,026,754 |
1.77 s |
72,797 |
0.06 s |
31× |
| Peterson filter lock, N=5 |
56,427,356 |
49.9 s |
4,556,797 |
1.96 s |
25× |
| Dining philosophers, N=8 |
3,628,673 |
6.66 s |
3,628,673 |
1.34 s |
5.0× |
| Dining philosophers, N=9 |
23,378,445 |
49.7 s |
25,611,985 |
13.5 s |
3.7× |
| Sliding window protocol, W=5 |
12,798 |
1.41 s |
6,363 |
0.02 s |
83× |
Dining philosophers with N=8 is a like-for-like comparison: both tools store exactly the same
3,628,673 states. Elsewhere the state counts differ because the two tools reduce the state space in different
ways. rspin merges deterministic local statements and collapses atomic
sequences more aggressively.
Single-threaded, rspin’s interpreter is roughly as fast per state as SPIN’s
compiled pan on these models. The speedups come from removing the C
compilation step, using multiple cores, and storing fewer states.
Promela support
Supported:
- Types:
bit, bool, byte, short, int, unsigned : N, pid, mtype
(including named mtypes), arrays, typedef structs (nested, in messages,
struct copy).
- Processes:
proctype, active [N], init, parameters, run (also as an
expression), provided clauses, _pid, _nr_pr.
- Control flow:
if/do with else, break, goto, labels, atomic,
d_step, unless, for (i : a .. b), for (x in array), for (m in chan),
select (i : a .. b), timeout, skip.
- Channels: buffered and rendezvous,
!, !! (sorted send), ?, ??
(random receive), ?<..> (copy), ?[..] (poll), eval(), len, empty,
nempty, full, nfull, xr/xs, local channels.
- Properties:
assert, end/progress/accept labels, never { } (including
assert inside claims), ltl name { } with [], <>, X, U, W, V/R,
->, <-> and the word forms, remote references P[pid]@label and
P[pid]:var, np_, enabled(), pc_value().
- Preprocessor:
#define (object and function-like), #include,
#if/#ifdef/#ifndef/#elif/#else, inline.
Not supported (yet): embedded C (c_code, c_expr, …), process priorities,
trace/notrace, STDIN, _last, bitstate hashing (use --compact).
How it works
.pml ─▶ preprocessor ─▶ parser ─▶ AST ─▶ compiler ─▶ control-flow graphs + state layout
│
┌──────────────────────────────────────────┴────────────────────┐
▼ ▼
safety: parallel BFS liveness: nested DFS
(level-synchronous, sharded store, (CVWY + stack hits) or
level-based POR proviso, shortest trails) SCC search with weak fairness
- State vector. Packed bytes: globals, then channels, then processes,
each value stored at its natural width. Variables resolve to byte offsets at
compile time.
- Control-flow graphs. Statements become transitions between locations.
Epsilon edges (
goto, break, block boundaries) are eliminated at compile
time, and else is resolved per selection.
- Partial-order reduction. Locations whose transitions touch only
process-local data (or use exclusive channels under
xr/xs) form ample sets.
Termination is handled dynamically, and the BFS cycle proviso only forces full
expansion when a reduced successor lies on an earlier level.
- Statement merging and atomic collapsing. Chains of deterministic local
statements execute as one step. Intermediate states inside atomic sequences
are not stored, as in SPIN.
- LTL. Negation normal form, then a GPVW tableau, degeneralization,
state merging, and removal of states that cannot reach an accepting cycle.
- Counterexamples. Each stored state keeps a parent link and a 64-bit
fingerprint. A trail is rebuilt by re-expanding along the fingerprint path.
--compact keeps only the fingerprints.
Correctness
A model checker you can’t trust is worse than none. rspin is checked in four
ways:
tests/models/: each model declares its expected verdicts.
Every check runs under 12 search configurations (BFS/DFS, POR on/off,
full/compact store, 1/4 threads), and every counterexample is replayed and
independently validated.
- Unit tests for the preprocessor, parser, store and the LTL translator. The
translator is tested against an automaton-acceptance oracle.
scripts/fuzz_vs_spin.py: random Promela models
verified by both SPIN and rspin. Assertion and deadlock verdicts must agree.
This runs in CI on every push and has already caught one partial-order
reduction bug.
- Weak-fairness verdicts were cross-checked against SPIN’s
pan -a -f.
Using rspin as a library
use rspin::{Frontend, compile::ClaimSel, verify::{verify, VerifyOpts}};
let fe = Frontend::from_str("demo.pml", "byte n; active [2] proctype p() { n++; assert(n <= 2) }")?;
let model = fe.model(&ClaimSel::None)?.model;
let outcome = verify(&model, &VerifyOpts::default())?;
assert!(outcome.violation.is_none());
Roadmap
- Bitstate (supertrace) hashing
- Parallel liveness checking
- Counterexample minimization for LTL trails
- Process priorities,
trace assertions
- Language server (diagnostics and hover in editors)
Contributions are very welcome. Bug reports with a small .pml file are
especially useful.
Acknowledgements
rspin is an independent reimplementation inspired by SPIN, created by
Gerard J. Holzmann, whose book The SPIN Model Checker and decades of work
on explicit-state verification made this project possible. rspin is not
affiliated with the SPIN project.
License
Licensed under either of Apache License, Version 2.0 or
MIT license at your option.
评论