spock 🖖
A modern, statically typed, natively compiled model checking and proof language.
Find the bugs in a design before they are in the code. spock tries every way your system can run, proves invariants for all sizes, and checks real runs against the spec. You write the spec in a language that reads like a little Rust. Live long and prosper.
- Specs read like Rust. The state is a struct, an action is a function that returns the
next state, and a property is a function that returns
Bool. - The shortest path to the bug. When an invariant fails, spock prints the fewest steps that reach it, and shows only what each step changed.
- Checks what TLA+ checks: invariants, deadlocks, properties of steps, temporal properties under weak and strong fairness, refinement between specs, and symmetry. On 180 models from the TLA+ examples, spock gives the same answers as TLC, or as the TLC-compatible everystate where TLC takes hours.
- Fast — on CPU and GPU. Specs compile to machine code via Cranelift and use every core. In our benchmarks, spock is about 10 times faster than TLC on the same cores, checking 59 million states in 36 seconds on a 12-core laptop.
- Exact-state GPU model checking (
--gpu).spock check --gpuJIT-compiles bit-packed exact-state kernels directly to Apple Silicon Metal 3.2 (macOS) and NVIDIA CUDA/PTX (Linux, zero-SDK dynamiclibcudawith PTX disk cache), scaling from inline hash tables to flat-to-partitioned exactSLABwith zero lossy fingerprints and automatic CPU fallback for ineligible models (or violation replay for shortest traces). Verified exact runs: EWD998 N=4 (248M exact states in 0.70 s BFS on RTX 2080 Ti CUDA / 1.33 s on Apple M4 Pro Metal), LamportMutex N=4 (561.7M exact states in 13.17 s on M4 Pro), and PaxosCommittwo_rms(1.32M exact 6-word states in 22.4 ms CUDA / 45 ms Metal). - Never checks the same thing twice. If nothing changed, the answer comes from the cache.
- Proves invariants for all sizes.
spock proveverifies inductive invariants across unbounded types (type RM;) and constants (const N: Int;), using a built-in EPR prover and Z3/cvc5, decodes failures into concrete two-state counterexamples, and automatically triages whether each CTI pre-state is reachable (real bug) or unreachable (strengtheninductive).spock check --symbolic --depth Nruns bounded symbolic checking via SMT. - Checks your code against the spec.
spock tracereads a log of a real run (from a file or stdin-), checks conformance and invariants, and enforces action/field/stutter coverage gates (--require-all-actions,--require-all-fields,--max-stutters). - Ready for CI. Running
spock(orspock test specs/) checks every model in parallel against itsexpectsetting (including bug models that must fail), exit codes say what was found, and--jsongives the full report.
Install
From Cargo (Rust 1.90 or newer):
$ cargo install --locked spock-cli
Or from npm / Bun (prebuilt binaries for macOS, Linux and Windows):
$ bun add -D spock-cli && bun run spock
Your first spec
Two processes each add one to a shared counter. Each one reads the counter into a register,
then writes the register plus one. Save this as counter.spock:
type Proc;
type Pc =
model two_procs
An action takes the current state and returns the next one. require says when it can run,
and any lets spock pick any process. A model says which values to check with and what must
hold. Check it:
$ spock check counter.spock
error: invariant State::no_lost_update is violated
--> counter.spock:36:8
|
36 | fn no_lost_update(self) -> Bool {
| ^^^^^^^^^^^^^^
a shortest behavior to a state that violates it, 5 states:
1 State::init
x = 0
pc = {a -> Read, b -> Read}
reg = {a -> 0, b -> 0}
2 State::read(a)
pc[a] = Write
3 State::read(b)
pc[b] = Write
4 State::write(a)
x = 1
pc[a] = Done
5 State::write(b)
pc[b] = Done
two_procs: 12 distinct states, depth 5 (13 generated in 0.00 s)
🖖 "Once you have eliminated the impossible, whatever remains, however improbable, must be the truth." — Spock
Both processes read 0 before either writes, so one update is lost and the counter ends at 1.
Check that something eventually happens
Invariants say nothing bad happens. Temporal properties say something good eventually does.
Add this to impl State:
and a model that checks it:
model finishes
$ spock check counter.spock --model finishes
error: temporal property State::finishes is violated
--> counter.spock:57:19
|
57 | properties = [State::finishes];
| ^^^^^^^^^^^^^^^
a behavior that violates it, 1 state, then stutters forever:
1 State::init
x = 0
pc = {a -> Read, b -> Read}
reg = {a -> 0, b -> 0}
finishes: 13 distinct states, depth 5 (15 generated in 0.00 s)
🖖 "Live long and prosper — though this behavior does neither." — Spock
Nothing forces a process to take a step, so the system may just stop. Say that next keeps
running whenever it can, and the property holds:
fairness = ;
$ spock check counter.spock --model finishes
finishes: ok, 13 distinct states, depth 5 (15 generated in 0.01 s) 🖖
Check a run of your code
Once the spec is right, check that the code follows it. Have the code log each step as a
line of JSON: the action, its arguments, and what it can see of the state after it. It may
leave out any part of the state. Here b read after a wrote, but still wrote 1:
$ spock trace counter.spock run.jsonl --model two_procs
error: no behavior of two_procs matches line 5 of run.jsonl
--> run.jsonl:5:1
|
5 | {"action":"write","args":["b"],"state":{"x":1}}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the spec's State::write(b) gives x = 2, and the line says x = 1
a behavior that matches lines 1 to 4, 4 states:
1 State::init // line 1
x = 0
pc = {a -> Read, b -> Read}
reg = {a -> 0, b -> 0}
2 State::read(a) // line 2
pc[a] = Write
3 State::write(a) // line 3
x = 1
pc[a] = Done
4 State::read(b) // line 4
pc[b] = Write
reg[b] = 1
two_procs: a behavior matches 4 of 5 states of run.jsonl (at most 1 candidate state, 7 generated in 0.00 s)
🖖 "Highly illogical. The trace departs from the specification." — Spock
A line without an action is any step, or none. A behavior spock check prints is a trace
too. When the code takes steps it can't log, such as a lost message, list their actions in
the model, hidden = [State::lose];, and any number of them may come between two lines.
In Rust tests, the spock_trace crate records traces directly (Trace::init/step) or
captures them from tracing (features = ["tracing"]) and log (features = ["log"])
events, checking them in-process or writing <test>.jsonl files via SPOCK_TRACE_DIR for
spock trace.
Coming from TLA+
| TLA+ | spock |
|---|---|
VARIABLES x, pc |
struct State { x: Int, pc: Map<Proc, Pc> } |
CONSTANT Proc, and Proc <- {a, b} in the .cfg |
type Proc;, and type Proc = {a, b}; in a model |
Init, Next |
action init() -> State, action next(self) -> State |
\E p \in Proc : A(p) |
any p: Proc { self.a(p) } |
\A p \in Proc : pc[p] = "done" |
all p: Proc { self.pc[p] == Done } |
| an enabling condition | require cond; |
x' = x + 1 /\ pc' = [pc EXCEPT ![p] = "done"] /\ UNCHANGED y |
Self { ..self, x: self.x + 1, pc: self.pc.update(p, Done) } |
[]P, <>P, P ~> Q |
always(..), eventually(..), leads_to(..) |
WF_vars(Next), SF_vars(A) |
weakly_fair(State::next), strongly_fair(State::a) |
INVARIANT, PROPERTY, SYMMETRY in the .cfg |
invariants = [..], properties = [..], symmetry = [..] in a model |
Learn more
specs/has 125 specs ported from the TLA+ examples, among them Paxos, two-phase commit, the bakery algorithm, dining philosophers and Dijkstra's termination detection.- The language guide covers types, functions, actions, properties, fairness and models.
spock --help,spock check --help,spock prove --help,spock test --helpandspock trace --helplist the options:--model,--gpu,--symbolic,--depth,--filter,--workers,--json,--no-cacheand more. Running barespockdefaults tospock test.- The exit code is 0 when everything holds, 10 for a false assumption, 11 for a deadlock, 12
for an invariant, 13 for a property, 15 when an SMT solver returns unknown, and 150 for an
error in the spec.
spock traceexits 0 when a behavior matches, 12 or 13 when it violates an invariant or step property, 14 when none matches, and 16 when a coverage gate fails.spock testexits 0 when every model matches itsexpect, and 1 otherwise. - Trace validation says how
spock tracematches a run against the spec, proofs & symbolic checking coversspock proveandspock check --symbolic, and GPU model checking coversspock check --gpu. spock skillprints a skill that teaches coding agents to write, check and trace specs. Install it withmkdir -p ~/.agents/skills/spock && spock skill > ~/.agents/skills/spock/SKILL.md.
Papers & citation
Two companion papers document the language, formal semantics, and implementation:
- Spock (systems & tutorial): Spock: Statically Typed Temporal Logic of Actions with Native Compilation, Automatic Proofs, and Trace Conformance (source)
- Typed TLA (formal foundations):
Typed Temporal Logic of Actions
(source, mechanized in pure Lean 4 under
formal/TypedTLA/)
If you use Spock, Typed TLA, or the Lean 4 mechanization in research, talks, benchmarks, or
derivative tools, please cite the relevant paper (also available via GitHub's Cite this
repository button in CITATION.cff):
License
MIT, in LICENSE. The specs in specs/ are ports of
tlaplus/Examples, MIT-licensed by the TLA+ project and
its contributors.