When you verify a real application, you quickly run into two very different kinds of bugs:
- Function bugs: an off-by-one in a scheduler, a seat allocator that leaks on edge sizes, or a tally function that drops a vote. These happen inside a single call, across inputs of any size.
- System bugs: a user confirming an expired hold before a sweeper runs, a stale worker waking up after a pause and double-committing, or a WebSocket closing mid-
awaitwhile an offline edit is flushing. These only happen over time, across multiple actors.
LemmaScript excels at the first half: proving a single TypeScript function obeys its //@ contracts for all inputs. Quint excels at the second: exploring concurrent histories, clocks, retries, and failures across an entire system.
The awkward part of using both tools side by side is (was!) the gap between them, which required you to write your logic once in TypeScript and again in Quint, and you had to just trust that your LemmaScript contracts captured your system invariants, and that your real implementation matched your Quint model.
We created lemmascript-quint to close this gap and connect the two mechanically. You can use it as a standalone companion package.
Three capabilities in lemmascript-quint
Instead of trying to transpile arbitrary TypeScript into Quint, lemmascript-quint reads LemmaScript’s resolved contracts (lsc info --typed --bodies) and provides a CLI (emit, check, mutate, verify) plus a TypeScript model-based testing harness (lemmascript-quint/connect) covering three capabilities:
TypeScript + //@ contracts
│
├── LemmaScript (Dafny/Lean) ──► Code obeys contracts (for all inputs)
│
└── lemmascript-quint
├── 1. check / verify ──► Export contracts into Quint & check protocols
├── 2. mutate ──► Drop clauses to test which ones carry weight
└── 3. connect (harness) ──► Replay Quint traces against your real TS app
- Export contracts, not duplicated logic (
emit/check/verify): Your types, preconditions, postconditions, and simple folds become a.contracts.qntmodule automatically (emitgenerates it;checkalso runsquint typecheck). Quint never re-implements your search or merge logic — it chooses nondeterministically from whatever return values your LemmaScript contracts allow. Once your protocol spec imports that module, you can simulate it or runlemmascript-quint verifyfor bounded exhaustive model checking via TLC or Apalache. That closes the classic blind spot of proof-based verification: Dafny will happily prove a too-weak postcondition with zero errors, whereas Quint will exploit the slack to violate your system invariant. Iteratively, those counterexamples help you see which//@ ensuresclauses to add. - Test which clauses carry weight (
mutate): Once Quint passes,mutatepushes in the opposite direction — removing each//@ ensuresclause (and individual conjuncts inside boolean guards) one by one and re-checking your system invariant. A counterexample confirms that a clause is actually needed (and shows the failure it prevents); if the invariant still holds without it, you’ve found either a redundant clause or a blind spot in your system invariant. - Lock your real app to the protocol (
lemmascript-quint/connect): Rather than a CLI subcommand,lemmascript-quint/connectis a TypeScript test harness (import { runQuintMBT } from "lemmascript-quint/connect"). It takes traces generated byquint run --mbtand replays them step-by-step against your actual async TypeScript runtime (IndexedDB, WebSockets, transactional stores), asserting exact state equality after every transition.
For the full mechanics of how types, quantifiers, and folds lower cleanly into Quint, see TRANSLATION.md.
Approach: Modeling the System From Contracts
The approach of using LemmaScript contracts as the declarative model in Quint has several advantages.
Implementation independence
First, we’re following an assume-guarantee discipline, a classic compositional verification discipline that breaks a big verification problem into parts connected by explicit contracts:
- Each component proves a guarantee assuming the other components obey their contracts.
- Every assumption made by one layer must be discharged as a guarantee proved by another layer.
The payoff of this discipline is modularity: neither side (not the assumption nor the guarantee) needs to inspect the other’s internals, and you can freely change a component’s implementation as long as it still meets the same contract.
The Quint model does not rely on the complex function implementations (aside from simple structural folds), yet is a sound over-approximation of the verified functions: if you trust that those functions satisfy their contracts (via the Dafny or Lean proofs), then you can assume the model is correctly accounting for them via the contracts.
Adversarial verification
Second, we are actually checking the LemmaScript contracts adversarially with Quint. If the contracts are too weak, the Quint model is unable to verify the properties at the system level, and flags the gaps. We have so far been auditing contract gaps with claimcheck, which checks formal contracts against human intent using an LLM, but doesn’t reason about whether a contract is strong enough for the overall system. Quint complements it by checking for those system-level gaps mechanically (a gap we have long wanted to close in the LemmaScript ecosystem).
Declarative Fit
Finally, the contract level is a much more appropriate declarative starting point for Quint, because Quint deals with declarative statements involving quantifiers like our contracts, rather than imperative or recursive loops. In addition to the contracts, we do translate the TypeScript functions that appear in specifications, using a lowering to folds, which are supported by Quint.
Boundaries
LemmaScript proves function-level contracts over unbounded inputs, whereas Quint explores finite, bounded domains via randomized trace simulation (quint run) by default, or exhaustive model checking (lemmascript-quint verify with TLC or Apalache). Likewise, lemmascript-quint/connect uses model-based testing to check the unverified async shell against sampled Quint traces, catching races without requiring a proof of the runtime. Finally, the contract translator fails loudly rather than silently dropping a clause, so the Quint model is never weakened by accident.
What this combination catches, in practice
To build out and test the plugin, we used four different case studies (listed below). Here are two examples of how the added plugin prevented bugs in both the LemmaScript spec itself (a contract gap) as well as bugs in the shell code that our verifier doesn’t touch.
A missing check in a LemmaScript contract (Baton)
Baton is a lease-based job queue. When a worker claims a job, the broker hands it a time-limited lease and a monotonically increasing fencing token. Before the worker can renew or complete the job, a verified TypeScript guard checks whether its token is still valid:
export function canAcceptToken(j: Job, worker: string, token: number, now: number): boolean {
//@ verify
//@ ensures \result === (j.status === "leased" && j.worker === worker && j.token === token && now < j.leaseUntil)
return j.status === "leased" && j.worker === worker && j.token === token && now < j.leaseUntil;
}
If you (or your agent) accidentally omit now < j.leaseUntil from both the contract and the body, LemmaScript’s prover will still pass with 0 errors — a weaker guard is easy to prove.
Because lemmascript-quint check exports canAcceptToken’s //@ ensures contract directly into Quint, running lemmascript-quint mutate tests each of the four checks one by one against Baton’s protocol invariant:
- Dropping
now < j.leaseUntilis caught with a 17-state counterexample trace: Quint finds a schedule where a worker’s lease expires and the worker still commits the job before a background sweeper reclaims it. - Dropping
j.worker === workersurvives: Not because of a missing invariant, but because Baton’s strictly monotonic fencing tokens are already globally unique across workers — matchingj.token === tokenalready identifies the owner.
That is the payoff of connecting the two tools: LemmaScript proves your TypeScript code matches its contracts for all inputs, while Quint tells you which clauses in those contracts your system’s properties actually depend on.
For example, in Baton (specs/baton.qnt:457-471), the user writes AtMostOnceCommitInv (combined into SafetyInv) over the history of committed jobs:
- No job is committed more than once,
- Every committed job is
"done"with a matching fencing token, and - Every commit happened before its lease expired (
eff.committedAt < eff.leaseUntil).
That separation is why mutate isn’t circular: the contract is a local function-level spec in TypeScript, while the protocol invariant is the global system-level property you actually care about in Quint. When mutate drops now < j.leaseUntil from canAcceptToken, Quint finds a multi-step trace that violates eff.committedAt < eff.leaseUntil.
An async race in the unverified shell (Folio)
Even when your core logic is proven, the stateful shell around it can still break. Take Folio, an offline-first shared checklist. Your edits are saved locally in the browser first, and a small Sync class pushes them to the server over a WebSocket whenever you’re online. Folio’s merge logic was already proven in LemmaScript, and its sync client already had passing unit tests and a real server integration test.
Whenever you edit the checklist, Sync.send() checks that the WebSocket is open, reads the latest local changes from storage, and sends them to the server. In the code, it looked like this:
private async send() {
// 1. Guard: bail out if the WebSocket isn't open
if (!this.ready || this.ws?.readyState !== WebSocket.OPEN || this.stopped) return;
// 2. Pause while reading the latest edits from local storage
const list = await store.load(this.id);
// 3. Push them over the WebSocket
if (list?.dirty && !list.revoked) {
this.status("saving");
this.ws.send(encode({ type: "sync", cells: list.cells }));
}
}
At a glance, step 1 looks completely safe: we checked this.ws before using it. Yet the very first time we wired lemmascript-quint/connect up to the real Sync class, model-based testing crashed on step 3 with TypeError: Cannot read properties of undefined (reading 'send').
Quint had generated a short sequence of events our hand-written tests never tried:
- The user makes an edit while connected.
send()starts, passes the guard in step 1, and pauses atawait store.load(this.id). - While
send()is waiting on local storage, the list owner revokes the share link. The server closes the WebSocket, and the socket’sonclosehandler setsthis.wstoundefined. store.load()finishes andsend()resumes at step 3, wherethis.wsis nowundefined, crashing the sync client.
The fix was a single line: re-check that the WebSocket is still open after the await. Hand-written tests missed it because they tested edits and link revocations one after the other; Quint generated overlapping schedules automatically, and lemmascript-quint/connect replayed that exact sequence against the real TypeScript code.
Case study apps:
Every push to lemmascript-quint verifies four real TypeScript applications end-to-end in CI:
- Quintet (try the app · origin post) — A concert-hall seat-hold and FIFO waitlist app. Where the contract-oracle idea started: deleting one completeness line in TypeScript breaks Quint’s system invariant in 10 ms.
- Folio (try the app) — An offline-first shared checklist running on Cloudflare Workers, SQLite Durable Objects, and IndexedDB. Combines a verified CRDT core with async sync model-based testing and access-link revocation.
- Baton (try the app) — A lease-based job queue with monotonic fencing tokens and interactive step-by-step playbooks showing zombie workers getting fenced out in real time.
- Runoff (try the app) — A live ranked-choice (Instant-Runoff Voting) group poll app on Cloudflare Workers and Durable Objects, backed by Dafny ballot-conservation proofs and exhaustive TLC model checking across every reachable state of a bounded poll.
Try it:
Use it in a project alongside LemmaScript: npm install -g lemmascript-quint
Or play with and contribute to source:
With Node.js >= 20, LemmaScript, and Quint, try it in runoff-lemmascript:
# Generate and typecheck Quint contracts from your verified TypeScript
lemmascript-quint check src/tally.ts
# Check which contract clauses your system invariant actually relies on
lemmascript-quint mutate src/tally.ts --spec=specs/runoff.qnt --invariant=RunoffSafety
# Exhaustively model-check a finite protocol module (TLC / Apalache)
lemmascript-quint verify specs/runoff.qnt --main=runoff_exhaustive --invariant=RunoffSafety --verifier=tlc
Dig deeper in README.md and TRANSLATION.md, or explore any of the four apps above.