Skip to content

Latest commit

Β 

History

416 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Leslie: TLA in Lean 4

TLA+ is considered to be exhaustively-testable pseudocode, and its use likened to drawing blueprints for software systems; TLA is an acronym for Temporal Logic of Actions.

(from TLA+ - Wikipedia)

Leslie is a shallow embedding of the Temporal Logic of Actions (TLA) in Lean 4. It provides a framework for specifying and verifying concurrent and distributed systems with machine-checked proofs.

The library includes:

  • Refinement mappings (Abadi-Lamport) with stuttering and invariants
  • Multi-action specifications (ActionSpec) with gated atomic actions
  • CIVL-style layered refinement with mover types and Lipton reduction
  • Round-based distributed algorithms using the Heard-Of (HO) model, with proof rules for round invariants, process-local invariants, and round refinement
  • Cutoff theorems for symmetric threshold protocols, reducing parameterized verification (all n) to finite model checking (n ≀ K)
  • Random simulation for testing invariants before formal verification

Building

Requires elan with Lean 4 v4.27.0.

lake build

Usage

Add this project into your lakefile.lean and then:

import Leslie

See MANUAL.md for a complete user guide covering specifications, invariants, refinement, and layered verification.

See docs/round-based-tutorial.md for a tutorial on round-based algorithms, the Heard-Of model, and cutoff reasoning.

Project Structure

Leslie/
β”œβ”€β”€ Basic.lean              Core TLA definitions, syntax, and operators
β”œβ”€β”€ Refinement.lean         Spec structure and refinement mapping theorems
β”œβ”€β”€ Action.lean             GatedAction, ActionSpec (multi-action specs)
β”œβ”€β”€ Layers.lean             CIVL-style layers, mover types, Lipton reduction
β”œβ”€β”€ Round.lean              Round-based algorithms (HO model), proof rules
β”œβ”€β”€ Cutoff.lean             Cutoff theorems for symmetric threshold protocols
β”œβ”€β”€ Simulate.lean           Random trace simulation for testing
β”œβ”€β”€ Rust/
β”‚   β”œβ”€β”€ CoreSemantics.lean  Lean-side semantics for the Rust protocol core
β”‚   └── RuntimeSemantics.lean Lean-side semantics for the Rust runtime contract
β”œβ”€β”€ Rules/
β”‚   β”œβ”€β”€ Basic.lean          Core TLA rules (always, eventually, until, etc.)
β”‚   β”œβ”€β”€ StatePred.lean      State predicate rules, init_invariant
β”‚   β”œβ”€β”€ LeadsTo.lean        Leads-to reasoning (transitivity, consequence)
β”‚   β”œβ”€β”€ BigOp.lean          Big conjunction/disjunction operators
β”‚   └── WF.lean             Weak fairness (WF1 rule)
β”œβ”€β”€ Tactics/
β”‚   β”œβ”€β”€ Basic.lean          tla_unfold, tla_merge_always, etc.
β”‚   β”œβ”€β”€ Modality.lean       Modal operator tactics
β”‚   β”œβ”€β”€ Structural.lean     tla_intros
β”‚   └── StateFinite.lean    simp_finite_exec_goal
β”œβ”€β”€ Gadgets/
β”‚   β”œβ”€β”€ TheoremLifting.lean #tla_lift command
β”‚   └── TheoremDeriving.lean @[tla_derive] attribute
β”œβ”€β”€ Examples/
β”‚   β”œβ”€β”€ CounterRefinement.lean      Simple refinement with stuttering
β”‚   β”œβ”€β”€ TwoPhaseCommit.lean         2PC with refinement proof
β”‚   β”œβ”€β”€ TicketLock.lean             Layered refinement + mover proofs
β”‚   β”œβ”€β”€ KVStore.lean                Key-value store, 3 safety properties
β”‚   β”œβ”€β”€ Paxos.lean                  Single-decree Paxos (14 actions)
β”‚   β”œβ”€β”€ LeaderBroadcast.lean        Round-based leader broadcast
β”‚   β”œβ”€β”€ FloodMin.lean               Flood-min consensus with refinement
β”‚   β”œβ”€β”€ BallotLeader.lean           Leader election (general n, pigeonhole)
β”‚   β”œβ”€β”€ OneThirdRule.lean           OTR consensus (agreement + validity)
β”‚   β”œβ”€β”€ OneThirdRuleCutoff.lean     OTR via cutoff (config-level lock inv)
β”‚   └── VRViewChange.lean           VR view change safety
β”œβ”€β”€ rust/
β”‚   β”œβ”€β”€ Cargo.toml                  Rust crate for communication, protocol, and driver code
β”‚   └── src/
β”‚       β”œβ”€β”€ comm.rs                 Round-based communication abstractions
β”‚       β”œβ”€β”€ protocol.rs             Pure protocol trait
β”‚       └── driver.rs               Runs a protocol over a communication object
└── docs/
    β”œβ”€β”€ round-based-tutorial.md     Tutorial: HO model and cutoff reasoning
    β”œβ”€β”€ mc-tactic-plan.md           Plan: model-checking tactic
    β”œβ”€β”€ zero-one-rule.md            Plan: value domain reduction
    β”œβ”€β”€ communication-contract.md   Runtime contract for tag-based inbox collection
    β”œβ”€β”€ rust-verification-v2.md     Revised Rust verification architecture
    └── rust-verification-plan-v2.md Revised implementation plan

Examples at a Glance

Interleaving protocols (ActionSpec)

Example What it demonstrates Status
CounterRefinement Basic refinement with stuttering Complete
TwoPhaseCommit Refinement with invariant (10 actions) Complete
TicketLock Layered refinement, mover types Complete
KVStore Key-value store, 3 safety properties Complete
Paxos Quorum intersection, 14 actions Spec complete, 2 sorry

Round-based protocols (HO model)

Example What it demonstrates Status
LeaderBroadcast Leader-follower agreement (2 processes) Complete
FloodMin Flood-min consensus + refinement to consensus spec Complete
BallotLeader Leader election for general n (majority pigeonhole) Complete
OneThirdRule Agreement (lock invariant) + validity, general n Complete
OneThirdRuleCutoff Lock invariant via cutoff, reliable + unreliable comm Complete
VRViewChange Viewstamped Replication view change safety 1 sorry

Key results

  • Agreement for OneThirdRule (OneThirdRule.lean): Fully machine-checked proof that the OneThirdRule consensus algorithm satisfies agreement for any number of processes n, under the 2/3-communication predicate. The proof uses a lock invariant (super-majorities persist once established) and pigeonhole (two super-majorities can't coexist). Also proves validity: any decided value was an initial value.

  • Cutoff theorem (Cutoff.lean): For symmetric threshold protocols with communication closure, safety at all n reduces to checking n ≀ K where K = ⌈kΒ·Ξ±_den/(Ξ±_denβˆ’Ξ±_num)βŒ‰+1. Fully proved including the scaling lemma, partition sum, and weighted partition sum.

  • Unreliable communication (OneThirdRuleCutoff.lean): The lock invariant is preserved under any valid nondeterministic successor constrained by the HO communication predicate β€” not just the deterministic reliable case.

Documentation

Thanks

Leslie is ported from the 'Lentil' implementation, which came out of the coq-tla library.

About

No description, website, or topics provided.

Resources

Stars

15 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages