Trace Requirements to Machine-Checked Proofs with MARS 1.0

MARS 1.0 gives every requirement a stable ID, a SHA-256 digest of its exact wording and a proof obligation, so editing the sentence flags every row that relied on it. How MARS checks a requirement

Each obligation is a typed Lean 4 statement or a recorded open gap. The compiler links requirement manifests, Quint models, Veil proofs and implementation theorems into one graph, and it keeps bounded-search results apart from proofs. mars check needs MoonBit and a C compiler for the native build. audit adds Lean 4.35.0, Quint 0.35.0 for a pinned Quint model, and the Veil workspace for Veil proof bindings.

Celestial Proof Orrery

Module
Link to this view

TokenEscrow 1.0.0: 12 rows, 16 graph edges, 10 / 10 sources covered.

Scope
Discharged proof Typed OWED Open refinement Search evidence Trust / constants Audit unknown Stale source

Module rows

Module summary

Rows
12
Graph edges
16
Sources covered
10 / 10
Model proofs
Awaiting audit
Impl. proofs
Awaiting audit
Outstanding
Awaiting audit

Follow one requirement

Trace a requirement from its source sentence through bounded search and model proof. Then inspect an implementation obligation and see how a source edit affects the audited graph.

View graph
Read the Token Escrow code examples

One requirement across five layers

A requirement enters MARS 1.0 as an EARS sentence with a cryptographic digest and exits as an audited machine-checked proof, a typed OWED obligation, or an open gap. The five layers below follow ESC-001 and the journal gap in TokenEscrow.

  1. EARS prose and DrWatt digest

    Each source statement carries a stable UUIDv4 and a domain-separated SHA-256 digest in requirements.json. Changing a single character in the sentence changes the digest and invalidates every covering row.

    {
      "id": "ESC-001",
      "uid": "96e708c6-1190-4f00-b2f9-90f1dcf85f96",
      "statement": "The escrow model shall conserve one token across the sender, escrow and recipient accounts.",
      "statement_digest": "sha256-ears-utf8-v1:a51aa484d29771291ffc32d175fc77ee086401e95f761b2f2b5fe2c608f02053"
    }
  2. Quint transition model (Level 1: Bounded search)

    token_escrow.qnt defines the state variables, transitions, conservation invariant, and settlement witness. Exhaustive search checks the 12-cell baseline and mutant matrix across two mutants ("Duplicated lock" and "Missing receipt"). Level 1 produces evidence only and never discharges a requirement.

    module token_escrow {
      var sender: int
      var escrow: int
      var recipient: int
      var receipt: bool
    
      val inv_conserved = sender + escrow + recipient == 1
      val wit_settled = recipient == 1 and receipt
    }
  3. Veil and Lean 4 model proof (Level 2: Model proof)

    token_escrow_proofs.lean proves holds% inv_conserved by induction over every reachable state of the pinned Quint IR (b561d04a…4f214). The Lean 4.35.0 kernel checks the theorem under standard logical axioms (propext, Classical.choice, Quot.sound). The proof trusts the Quint→Veil embedding.

    theorem inv_conserved_holds : holds% inv_conserved := by
      intro th s hr
      cases reachable_location th s hr <;>
        dsimp [inv_conserved, FieldRepresentation.get, getFrom] <;> grind
  4. MARS obligation graph

    obligations.mars binds the DrWatt digest, the LeanRuntime hook catalog, the Quint model pin, and the Veil declaration into one hash-addressed row (68f6df5b…db198). A model-scope proof closes Conservation at Level 2 and makes no claim about the implementation. The line status stubbed declares the shape of the obligation: its full statement is pinned and a named proof enters the audit. It does not mean the proof is a placeholder. The audit decides the row's audited state, here a discharged model proof, and the inspector shows it beside the declared status.

    mars 1.0
    module TokenEscrow version 1.0.0
    -- Excerpt from mars-next/examples/token_escrow/obligations.mars
    
    requirement Conservation:
      trust LeanRuntime
      status stubbed
      scope model
      priority MUST
      THE `inv_conserved` SHALL PROVE `holds% inv_conserved`
      proof veil `token_escrow.inv_conserved_holds` from quint Protocol invariant inv_conserved
      covers "96e708c6-1190-4f00-b2f9-90f1dcf85f96" digest "sha256-ears-utf8-v1:a51aa484d29771291ffc32d175fc77ee086401e95f761b2f2b5fe2c608f02053"
      covers "97493ae6-eddb-44eb-a0ae-95a3230589d2" digest "sha256-ears-utf8-v1:ee62d638bde380c79cbfc24024da7536be3af992118ba929d5bc764d5424917b"
    end
  5. Typed OWED implementation refinement (Level 3: Implementation refinement)

    Implementation theorems are separate Lean obligations at Level 3. In TokenEscrow, Debit proves one arithmetic fact (amount - 1 < amount for a funded Nat balance, with witness and drop non-vacuity certificates). The theorem names no implementation function: it shows how a Level 3 row is written and audited. Its fidelity exact line is the author's claim that the statement matches the source, and the kernel does not check that claim. JournalMonotone, JournalReplay and JournalReorder elaborate their full Lean types and stay typed OWED release blockers.

    mars 1.0
    module TokenEscrow version 1.0.0
    -- Excerpt from mars-next/examples/token_escrow/obligations.mars
    
    requirement JournalMonotone:
      trust JournalRuntime
      status signature
      scope implementation
      priority MUST
      role gap
      owner "Journal maintainers"
      subject previous : `Nat`
      subject incoming : `Nat`
      THE `JournalMonotone` SHALL PROVE `previous ≤ Escrow.record previous incoming`
      conclusion `previous ≤ Escrow.record previous incoming`
      covers "63e66275-4a4e-428e-9842-7cdbc48884fd" digest "sha256-ears-utf8-v1:8e9b131ae6f0f50ab03a34e4612c4790f45512c3aa7a8bd82c6d438456b8ee3f"
    end

Run your first check

A complete MARS 1.0 module needs only a header and one requirement. Clone the Selûne repository and work from its root, because the commands below call ./bin/selune. Save the Inventory module below as inventory.mars there. The repository does not ship this file, but examples/hello-selune/obligations.mars is a ready example. check validates the syntax and emits machine-readable JSON diagnostics, and audit shows the typed OWED Lean obligation.

mars 1.0
module Inventory version 1.0.0

requirement NextCount:
  status signature
  subject count : `Nat`
  THE `count` SHALL PROVE `Nat.succ count ≠ count`
  conclusion `Nat.succ count ≠ count`
end

Quickstart with ./bin/selune mars

The launcher builds the native MoonBit 1.0 RC1 compiler in libs/mars when needed, then runs it. Building the native CLI needs a C compiler beside MoonBit, because it links a small C stub. A row checked with moon prove also needs an SMT solver such as Z3 or CVC5. To run audit, install Lean 4.35.0 through elan, Quint 0.35.0 to audit a pinned Quint model, and the Veil workspace for Veil proof bindings. docs/DEVEX-ONBOARDING.md in the repository gives the commands for all three. Without Lean, the audit fails closed and reports no proof.

./bin/selune mars check inventory.mars
# OK module=Inventory rows=1 diagnostics=0 stale_sources=0

./bin/selune mars check inventory.mars --format json
# {"ok":true,"diagnostics":[]}

./bin/selune mars audit inventory.mars
# OWED NextCount marsRow_4e657874436f756e74 : ∀ (count : Nat), Ne count.succ count

Direct native MoonBit binary

moon also builds the compiler on its own as a native binary, with Draft 2020-12 schema validation built in. Its self-test runs live Lean 4.35.0, Quint 0.35.0 and Veil checks on the token_escrow example, and the acceptance checklist runs them again, so install those first.

(cd libs/mars && moon build --frozen --target native --release --deny-warn cmd)

libs/mars/_build/native/release/build/cmd/cmd.exe self-test
libs/mars/_build/native/release/build/cmd/cmd.exe verify-checklist \
  mars-next/examples/token_escrow/checklist.toml

MARS 1.0 without Selûne

MARS 1.0 is a specification language with its own compiler, written entirely in MoonBit 1.0 RC1, and it does not need Selûne. A scan of the core specification and compiler finds no project-specific names. A renamed copy passes checking and coverage with its original Quint, Lean and DrWatt files and no project-specific glue scripts.

Assurance levels and trust boundaries

MARS 1.0 claims for each row only what its evidence supports. Finite model checking never discharges a requirement. A model-level proof never closes an implementation row. Every compiler hook that the audit reaches appears in an explicit budget. The labels on this page (discharged, typed OWED, open) are row states, separate from the ten verdicts a single check records (proved, passed, failed and the rest). A discharged row has a proof that passed the Lean kernel audit, so the requirement is proved at the row's scope. A typed OWED row or an open row has no accepted proof, and MARS claims nothing for it. Neither is a failed check, and search evidence never proves a requirement.

How the checker gives each requirement row its closure label:

 requirement row: declared status            initial closure label
 -------------------------------------       ---------------------
 DrWatt digest mismatch (any status)   --->  stale-source
 open                                  --->  open
 blocked                               --->  blocked
 signature                             --->  owed
 stubbed + audited `proof veil`        --->  model-proved
 stubbed + audited `proof lean`
          scope model                  --->  model-proved
          scope implementation         --->  implementation-proved
 stubbed, audit missing or failed      --->  owed

 audited = kernel audit passed, no row errors, not stale-source,
           fidelity not `weakened`
 Then: a proved row whose USES or GIVEN row is not proved -> owed

Level 1: Bounded search

Bounded model checking, exhaustive finite search, simulation runs, and mutant matrices produce evidence only and never discharge an obligation. In TokenEscrow, exhaustive search runs the baseline model and each mutant against every invariant, and each mutant must break the invariants it names. In SeluneQueue, a seeded simulation reaches the witness w_cancelled, which shows that a candidate can be cancelled.

Level 2: Model proof

Veil and Lean 4 prove an invariant for every reachable state of the pinned Quint model IR. The proofs trust the Quint→Veil embedding. The SeluneQueue model (spec/commit_queue.qnt) fixes three candidates, two definitions and a speculation depth of 3, so its proofs cover that instance. Both modules also audit a model-scope proof of the conjunction of their invariants, CombinedSafety.

Level 3: Implementation refinement

A separate Lean obligation states the property of the implementation. Neither example module proves that its shipped code refines its model. The one discharged Level 3 row, Debit, proves a lemma about natural numbers (amount - 1 < amount) with non-vacuity witness and drop certificates. The lemma names no implementation function, and its fidelity exact line is the author's assertion, which the kernel does not check. The three journal obligations stay typed OWED. QueueImplementation, the refinement from the merge queue's model to its MoonBit code, is an open gap: a prose statement that waits for a Lean type and a proof.

Kernel logical axioms

The Veil proofs in both audited modules depend only on the three standard logical axioms of the Lean 4.35.0 kernel: propext, Classical.choice and Quot.sound. The audit rejects any other axiom unless the row's trust catalog budgets it, and it always rejects sorryAx.

Runtime compiler hooks (LeanRuntime)

The flags in trust LeanRuntime are Lean runtime compiler hooks (extern, implemented_by, unsafe) inspected by the audit. They are not logical axioms. The audit reaches them because it walks every declaration a proof uses, including definitions. The proofs in both modules use no native_decide. Each row can select trust catalogs, and the audit rejects any compiler hook it reaches unless the row's trust budget allows it. TokenEscrow keeps LeanRuntime for its proofs and JournalRuntime for its journal rows, and the queue's LeanRuntime adds extern Int.tdiv to the escrow's. Read both catalogs in token_escrow/obligations.mars and selune_commit_queue/obligations.mars.

Grammar and core constructs

Every snippet below parses under mars-next/spec/GRAMMAR.ebnf. The Inventory module, the removal delta and the trust and policy example are written for this page. The other excerpts come from the example modules at commit eb405a6, the inputs the orrery shows, and check in place inside them.

Every file begins with mars 1.0 and a versioned module header (or a delta header). Requirements declare a status, typed subjects, a THE ... SHALL clause, and a non-trivial conclusion.

mars 1.0
module Inventory version 1.0.0

requirement NextCount:
  status signature
  subject count : `Nat`
  THE `count` SHALL PROVE `Nat.succ count ≠ count`
  conclusion `Nat.succ count ≠ count`
end

Stale-source digest simulator

DrWatt hashes each requirement statement as sha256-ears-utf8-v1: followed by the lowercase hex SHA-256 of ASCII("drwatt:requirement-statement:v1") + 0x00 + UTF-8(statement). Edit the statement below and the page recomputes the digest with WebCrypto as you type. The source manifest records the original digest. Each covering row pins that digest in obligations.mars. When an edit changes the digest, stale-source marks those rows. An unbound source has no covering rows to mark.

Token escrow: ESC-001 (Conservation)
Manifest statement digest
sha256-ears-utf8-v1:a51aa484d29771291ffc32d175fc77ee086401e95f761b2f2b5fe2c608f02053
Computed WebCrypto SHA-256 digest
sha256-ears-utf8-v1:a51aa484d29771291ffc32d175fc77ee086401e95f761b2f2b5fe2c608f02053

The statement matches the ESC-001 manifest digest. Covering row Conservation is fresh.

Simulated row diagnostics

{
  "ok": true,
  "diagnostics": []
}

Audited modules

The compiler checked both modules from their eb405a6 inputs. The table summarizes the pinned outputs: rows from the resolved graphs and proof states from the companion audit receipts. Each module lists its outstanding implementation work as typed OWED obligations or an open gap.

Metric TokenEscrow 1.0.0 SeluneQueue 1.0.0
Rows in resolved graph 12 (LeanRuntime, Numerals, JournalRuntime, Protocol, 8 requirements) 10 (LeanRuntime, Queue, 8 requirements)
Edges in resolved graph 16 (models, proof, trust) 22 (models, proof, trust, 1 row: QueueImplementation → CombinedSafety)
Sources covered / present 10 / 10 (ESC-001…ESC-010) 1 / 18 (only SEL-005 concerns the merge queue)
Audited inductive model proofs 4 (Conservation, NoOverdraft, DeliveryReceipt, CombinedSafety) 7 (SafeRevision, ReadSetAtCommit, ClosureEvidence, AcceptedHistory, CancelledPublication, FiveInvariants, CombinedSafety)
Audited implementation proofs 1 (Debit: amount - 1 < amount for funded Nat; witness and drop) 0
Outstanding work 3 typed OWED journal obligations (JournalMonotone, JournalReplay, JournalReorder) 1 open refinement (QueueImplementation, owner "Merge queue maintainers")
Quint search configuration mode exhaustive, witness wit_settled, 2 mutants, 12 matrix cells mode simulation (max-steps = 4, max-samples = 100, seed = 2), witness w_cancelled, 0 mutants
LeanRuntime hook budget 77 flags 78 flags (adds extern Int.tdiv)

Native MoonBit 1.0 RC1 toolchain

The MARS 1.0 compiler in libs/mars/ is native MoonBit 1.0 RC1 code. It implements the MARS grammar and the Draft 2020-12 JSON Schemas, and hands an audit manifest to an independent auditor written in Lean 4.35.0, libs/mars/lean/MarsAudit.lean.

./bin/selune mars runs the compiler's native CLI, mars1. Its library packages build and test on wasm, native and js, and the CLI's integration tests run on native. The native CLI calls Quint 0.35.0, Veil and Lean 4.35.0 only when a command needs them. mars1 self-test replays the regression fixtures. mars1 verify-checklist runs the acceptance checklist in a module's checklist.toml: it audits the module, confirms the expected OWED rows and the release_ready: false verdict, runs the mutation tests, and repeats check --fresh and coverage on a renamed copy that keeps its original Quint, Lean and DrWatt files.

mars1 audit sends every bound obligation and every typed OWED expectation to the Lean auditor. Lean first compiles the proof files and the expected statements that the compiler generates. The auditor imports the compiled modules with loadExts := false and compares each proof's type with its expected statement. It checks universe levels, the axioms each proof reaches, the compiler hooks against the row's trust catalogs, and the non-vacuity certificates. For a typed OWED row it prints an OWED record with the expected declaration and its type, and a prose gap stays open in the graph.

Why MoonBit

The MARS compiler and Selûne's core libraries are written in MoonBit. One tool, moon, type-checks code, runs unit, snapshot and property tests, proves contracts with SMT solvers and builds for native, Wasm and JavaScript. In the repository's timing receipt, reports/moon-incremental-receipt.json, moon check --target js after a one-function edit to the SelûneCraft game took a median of 114 ms.

A missing case is a compile error

The MoonBit team describes the type system as sound, with no run-time type errors in MoonBit code. At an extern declaration to C, JavaScript or Wasm, the programmer answers for a signature that matches the foreign function. Add a variant to an enum and moon check reports every match that does not handle it and names the missing case. Selûne builds with --deny-warn, so that report stops the build, and an agent gets it at the edit, not as a bug later. Patterns also match strings, arrays, JSON values and bit fields, so parsing code stays short.

Tests and proofs in one tool

moon test runs the test blocks that sit next to the code. moon test --update writes the value of an empty inspect into the source as a snapshot. moon testcli pins the stdout, stderr and exit status of a real binary, and @quickcheck.check shrinks a failing property to a smaller input that still fails.

moon prove checks contracts written in the MoonBit source. The toolchain lowers preconditions, postconditions and loop invariants to Why3, which sends each obligation to Z3, CVC5 or Alt-Ergo. In the SelûneCraft survival kernel it proves that, for health from 0 through 20 and damage of zero or more, apply_damage returns a value from zero through the old health. For a row that declares an x-moonprove target and status, mars check --fresh compares the declared status with a live moon prove run on the target's package. The row's proof credit still comes from the Lean or Veil audit. The MARS obligations on this page are audited in Lean, with Veil for the model proofs.

One source for native, Wasm and the browser

One source compiles to native and Wasm, the two tier-1 backends, and to JavaScript for browsers. On native, MoonBit counts references with the Perceus algorithm. On JavaScript and Wasm-GC it reuses the host's garbage collector. SelûneCraft builds one engine for JavaScript, Wasm-GC and native, and the same test suite passes on all three. The MARS compiler's library packages build for wasm, native and js.

What a developer weighs

MoonBit is at its 1.0 release candidate, and its compiler takes bug fixes only. The MoonBit team targets February 18, 2027 for the full release with the stable core library, when the core/async and core/archive APIs become stable. This repository pins 1.0.0-rc1+3c0520448 in toolchain.lock. When the pin moves, moon fix applies a proposed fix when it still matches the source and every backend that compiles the file proposes it.

Why3 1.7.2 ships inside the MoonBit toolchain, so moon prove needs only an SMT solver on the machine, and toolchain.lock pins Z3 and CVC5. Selûne links SQLite through its own C stub rather than the native-only community binding on Mooncakes.

Sources from the MoonBit team: MoonBit home page, The MoonBit 1.0 Compiler Is Stable, MoonBit 0.9: Introducing First-Class Formal Verification, Building Agents, MoonBit is all you need and One Language, Multiple Targets.