Prototype Lean 4 protocol verification alongside TLA+ - #254
Closed
kyleve wants to merge 3 commits into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
./lean-check, a Lean verification skill, ongoing docs, and immutable Lean/Elan attributionRecommendation
Keep this PR draft and keep both implementations. Do not adopt Lean as the TLA replacement yet.
Lean is compelling for typed models, unbounded inductive safety proofs, small kernel-checked proof terms, source-reviewable strengthening lemmas, and excellent language/editor tooling. TLC remains materially better for this repository's current workflow when the requirement is automatic bounded exploration, deadlock detection, liveness under fairness, and immediate counterexample traces. This prototype reaches complete finite-case and safety parity but not the required unbounded fairness/deadlock parity. Substituting the diagnostic BFS would weaken the semantics and violate the migration criterion.
A follow-up may delete TLA only after kernel-checking
EventuallySettled,DeliveredRemovalEventuallyStops,DeliveredRemovalEventuallyRetires, and deadlock freedom for TrackingReconciliation and RemoteDeviceRemoval.Language and tooling comparison
TypeOK; implicit[Next]_varsstutteringAction → State → Option State; explicit behavior stuttersReachable; private strengthening lemmas when public invariants are not inductiveBehavior,Eventually,LeadsTo, and TLA-compatibleWeakFair; proof is manualCHECK_DEADLOCK TRUEStdand theorem/model mapping; nonative_decide, custom axioms,sorry, oradmitLean's reference says successful build means the kernel accepted the theorem; it also explains why
decideremains kernel-reduced while native evaluation expands trust. Lake is the standard incremental package/build tool and Elan reads a checked-in version-specificlean-toolchain. TLA+ is intentionally a high-level mathematical specification language, and TLC is its engineering-oriented model checker. Sources: Lean reference, proof validation, Lake, Elan, TLA+ overview, TLC repository/tooling.Alternatives evaluated
Parity matrix
EventuallySettledand deadlock theoremBenchmarks
Measured on Apple Silicon macOS 26.5.2 on 2026-08-12. RSS is
/usr/bin/time -lp; download/storage figures are artifact/cache sizes, not committed bytes. Typed representation intentionally changes state counts.The Lean search uses exact equality through
Std.HashSet; hashes only index buckets. Its results are diagnostic and are not referenced by any theorem.Validation
./tla-checkbaseline: all 9 specs / 25 cases passed before prototype work (45.07s, 513,851,392 B peak RSS)./tla-check TrackingReconciliation RemoteDeviceRemoval: all liveness/deadlock configurations and controls passed./lean-check: all 9 modules built; all 25 diagnostic cases matched expectations./lean-check --list: listed all 9 models./lean-check StorePerformSerialization: selected model passed./lean-check UnknownSpec: exited 1 with the expected unknown-spec error./lean-check: 55.64s, 795,459,584 B peak RSS; original caches restored afterward./lean-check: 2.68s, 387,350,528 B peak RSSbash -n lean-checksorry,admit, newaxiom, ornative_decidein Lean sources./attributionand./attribution --check./swiftformat --lint./sync-agentsand skill-creator validationgit diff --checkSwift test suites skipped: this is opt-in formal-model/tooling/documentation work and changes no Swift production behavior.
Limitations