Skip to content
Stuart Jackson edited this page Nov 22, 2026 · 8 revisions

Proofs

Code here is proved, not only tested: every decision is a small TypeScript function annotated with LemmaScript, translated to Dafny, and proved to match a hand-written model of how the marketplace must behave. This is the platform's way of working, taken from atlas, and the direction for all SimpleApps development.

Sources:

  • LemmaScript (lsc, kept on its latest release, 0.6.11 here; on each upgrade re-check atlas's gap list and run pnpm proofs): TypeScript to Dafny, the //@ annotations, .dfy.gen vs .dfy
  • Dafny reference: the language and verifier (dafny verify, 4.11 here)
  • atlas (clones/atlas): .claude/rules/proofs.md for the rules, models/PROCESS.md for the process, and models/LSC-GAPS.md for where lsc's translation differs from JavaScript. Read the gaps list before using a construct for the first time

The pieces

Piece Path What it is
Model models/Marketplace.dfy Hand-written Dafny: what each rule means (CalVer, skill keys and names, the description limit, the token budget, connector URLs), with lemmas about shipped values. Written before the code
Proved code scripts/rules.ts Each rule as a pure function with //@ verify and //@ ensures, listed in LemmaScript-files.txt
Generated Dafny scripts/rules.dfy.gen, scripts/rules.dfy lsc writes .dfy.gen; .dfy is the same plus hand proof steps, additions only
Link models/links/scripts-rules.dfy <function>MatchesModel lemmas: the code decides exactly what the model says
Runtime pin scripts/rules.test.ts Each rule agrees with the regex it replaced on thousands of generated inputs, so the proof is about the code that actually runs
Shell scripts/validate.ts Reads files and reports; calls the proved rules for every decision about a value

lemmascript.json sets JavaScript string semantics (UTF-16 code units), as atlas does, so the proofs count characters the way the code does.

Rules

  • Code is TypeScript. LemmaScript proves only TypeScript, so all code in this repo MUST be TypeScript (.ts, or .tsx in a mod): no Python, and no new JavaScript. Scripts run with Node's type stripping (node scripts/validate.ts), so there is no build step. The only exceptions are tool configs that their tools load as JavaScript (eslint.config.mjs, prettier.config.mjs) and scripts/check-banned-strings.sh, a shell wrapper around git grep with no decisions of its own.
  • Model first. A new rule starts in models/Marketplace.dfy, then the code, then the link.
  • Every decision is proved. File reading, JSON, regex, await, and classes stay in thin unproved shells that only call proved functions (lsc can't translate them; atlas models/LSC-GAPS.md).
  • No escapes. Hand-written Dafny (the model, links, and additions to a generated .dfy) MUST NOT use assume, {:axiom}, {:verify false}, {:trusted}, or expect. scripts/validate.ts fails one.
  • Tests still pin the runtime at 100% coverage: a proof is about the Dafny translation, and a test shows JavaScript agrees.
  • After changing a proved .ts: pnpm exec lsc regen --backend=dafny scripts/<file>.ts, then re-add any hand proof steps.

Running

Command Does
pnpm proofs lsc check (regenerate, check additions-only, verify the code), then dafny verify the model and links
pnpm quality Includes the escape check and the runtime pins

pnpm proofs MUST pass before /submit (Deployment#submit). Like atlas, it is not in CI or the hooks: it needs Dafny installed locally (brew install dafny).

Not yet proved

  • The status line mod's decisions (meter colours, cache ages, wrapping): next, by pulling them out of hooks/register.tsx into proved functions (Mods).
  • scripts/check-banned-strings.sh: shell; git grep does the matching.

Clone this wiki locally