# Public API and the guarantee behind it (0.2) This page is the one place that says **what a downstream project may depend on** in the verified-synthesis part of Sparkle, and **what the theorem you get is about**. The current support matrix (which circuit shapes each entry covers) is [../VED.md](../VED.md); this page does not repeat it. The DSL itself (`Signal`, `circuit do`, the synthesis commands) is documented in [SignalDSL_Syntax.md](SignalDSL_Syntax.md) and the tutorial and is not covered here. Everything in the tables below exists in this checkout and is run by a file named next to it. If a name is not in a table, it is not promised, and nothing here describes an entry, a plugin or an RTL front end that does not exist: in particular there is no entry that takes an arbitrary SystemVerilog file and proves it, although a SystemVerilog parser exists (`Tools/SVParser`). ## 1. Status words | Word | Meaning | |---|---| | **public** | Kept in 0.2.x with the same name and the same meaning. Changed only by a soundness fix (section 6). | | **experimental** | Works and is tested, may change or move in any minor release (0.3, …) without a deprecation period. Not a basis for a downstream proof library. | | **internal** | Implementation detail. May change in any release, including 0.2.x patch releases. Do not import it for its own sake, and do not build on it. | The `Tools.*` modules are **not** public as a group. Most of them are the implementation of the entries, or research code. Only the modules named "public" in section 2 are. ## 2. Imports | Import | Status | What it gives | Build it | Runnable example | |---|---|---|---|---| | `SparkleProof.Core` | **public** | The statement and its meaning (`U1Stmt`, `Contract`, `InputsOk`, `st0`, `srcOf`, `OutputsStmt`, …, the IR semantics they unfold to), `#ved_strict_audit`, and the extraction lemmas of section 5. **No entry command.** | `lake build SparkleProof.Core` | [`Tests/Ved/SparkleProofFacadeCheck.lean`](../../Tests/Ved/SparkleProofFacadeCheck.lean) (the lemmas), imports `SparkleProof.Single` | | `SparkleProof.Single` | **public** | `#ved_u1` (section 3) plus everything in `SparkleProof.Core` | `lake build SparkleProof.Single` | [`docs/research/examples/Delay8.lean`](../research/examples/Delay8.lean), [`tutorial/Ex1_Register.lean`](../research/examples/tutorial/Ex1_Register.lean), [`Ex2_Enable.lean`](../research/examples/tutorial/Ex2_Enable.lean), [`Ex6_OwnLemma.lean`](../research/examples/tutorial/Ex6_OwnLemma.lean) | | `Tools.VedU1Entry`, `Tools.VedU1Contract`, `Tools.VedStrictAudit` | **public** (compatibility) | The pre-0.2 import names. `SparkleProof.Single` / `Core` import them and add nothing to the command; both spellings give the same command, the same theorem type and the same axioms (checked by `Tests/Ved/SparkleProofFacadeCheck.lean`). Kept in 0.2.x. | `lake build Tools.VedU1Entry` | the examples above, which still use this import | | every other `Tools.*` module (`Tools.Ved*`, `Tools.Deep*`, `Tools.SVParser.*`, …) | see section 4 | | | | | `Sparkle.*` | outside this page | the DSL, IR, compiler | | | `SparkleProof` is **one** `lean_lib` in `lakefile.lean` that owns exactly these two modules; it imports the `Tools.*` libraries and copies nothing from them. The facade is thin in what it exports, **not** in what it costs to build: `SparkleProof.Single` has the same build closure as `Tools.VedU1Entry` (it needs the compiler `Sparkle.Compiler.Elab`), and every target here needs the C compiler, because `Sparkle` links the `c_src` barrier and JIT libraries into its precompiled library. Measured times are in section 8. Use the examples from the checkout root. `lake env lean docs/research/examples/Delay8.lean` after `lake build Tools.VedU1Entry` (or `SparkleProof.Single`) runs the first one, and the file exits 0 only if every `#guard_msgs` it contains matches. A project outside the checkout that depends on Sparkle gets the same two imports; the exact dependency line and pin belong to the introduction in [How_To_Use.md](How_To_Use.md). ## 3. Commands | Command | Status | Use | Runnable example | |---|---|---|---| | `#ved_u1 f` | **public** | Synthesise declaration `f` **once**, and register `f.ved_u1` only if the theorem is kernel-checked and strictly audited (section 7). Covers the single-module shapes in [VED.md, "Single module"](../VED.md#single-module-plain-bodies). | `Delay8.lean`, `Ex1_Register.lean`, `Ex2_Enable.lean` (accepted), `Delay8.lean` `pair8` (refused, pinned with `#guard_msgs (error)`) | | `#ved_strict_audit d` | **public** | Accept `d` only if its reachable axiom closure is a subset of `{propext, Classical.choice, Quot.sound}`; otherwise an error naming the offenders. It checks the closure only, **not** that `d` has the expected type or belongs to a given artifact. | `Tests/Ved/StrictAuditCheck.lean` | | `#verify_elab_deep f`, `#ved_u1_deep f` | experimental | deep embedding and multi-register routes | `Tests/Ved/U1DeepCheck.lean` | | `#ved_u1_packed f` | experimental | one packed output port (`PackedStmt`) | `tutorial/Ex5_WaysPast.lean` (A) | | `#ved_u1_struct f` | experimental | structure of output signals, register-free | `Tests/Ved/U1StructOutCheck.lean` | | `#ved_u1_mem f`, `#ved_u1_mem_packed f` | experimental | memories (`MemStmt`) | `Tests/Ved/VedMemCheck.lean` | | `#ved_u1_hier f`, `#ved_u2_hier f` | experimental | module hierarchy (`U1HStmt`, `U2HStmt`, `U2HRStmt`) | `tutorial/Ex3_Hierarchy.lean`, `Ex4_Contrast.lean` | | `#ved_write_checked KIND f "x.sv" …` | experimental | check once, then write the SV / C++ / JIT files from the checked design | `Tests/Ved/WriteCheckedCheck.lean` | | `#ved_axioms_raw d`, `#ved_audit_generated ns` | experimental | measurement and read-only reports; they accept nothing | `Tests/Ved/StrictAuditCheck.lean` | | all other `#ved_*` commands (for example `#ved_mem_classify`), `ved_*` tactics and `ved.*` options | internal | | | The experimental commands keep working in 0.2.x as they do today (they are not removed in a patch release) but their statements, names and scope may change in a minor release, and none of them is part of `SparkleProof`. ## 4. Names a run creates, and the modules behind them `#ved_u1 f` adds these constants. (Names are in the namespace of `f`.) | Name | Status | What it is | |---|---|---| | `f.ved_u1 : U1Stmt f.ved_contract f.ved_mod f'` | **public** | the theorem (section 5; `f'` is `f` itself, or the term derived from it, see below) | | `f.ved_mod : Sparkle.IR.AST.Module` | **public** | the IR module that **that** synthesis run returned, as a closed term checked to denote it | | `f.ved_contract : Tools.VedU1Contract.Contract` | **public** | the port table: the declaration's input/output structure, port names, clock/reset names, register initial values | | `f.ved_outs`, `f.ved_body`, `f.ved_tbl` and other `f.ved_*` helpers | internal | auxiliary constants of the proof; not part of the statement, and may be renamed | | Module family | Status | |---|---| | `Tools.VedU1Entry`, `Tools.VedU1Contract`, `Tools.VedStrictAudit` | public (compatibility imports, section 2) | | `Tools.VedU1PackedEntry`, `Tools.VedU1Deep`, `Tools.VedU1StructOut`, `Tools.VedMemEntry`, `Tools.VedU1HierEntry`, `Tools.VedU2HierRegEntry`, `Tools.VedWriteChecked` (the entry of each experimental command above) | experimental | | `Tools.SVParser.*` (SystemVerilog parser, emitter semantics) | experimental | | `Tools.VedU1*` (other), `Tools.VedCompose*`, `Tools.VedU2Hier*`, `Tools.Deep*`, `Tools.VedMem*`, `Tools.VedH3*`, `Tools.ConeFold*`, and the rest of `Tools.*` | internal | `checkU1E`, `ProofSrc.term`, `vedU1EntryOn` and the writers' low-level hooks (`Tools.VedWrite*`, `Tools.VedInvocation*`) are **internal and not an extension API**. They exist so that `Tests/Ved/*` can inject a substituted declaration, module or proof and see it refused. In particular `checkU1E` accepts **any** statement term and module you hand it, so a success of `checkU1E` does not carry the guarantee of section 5; the link to the declaration is a property of the path `#ved_u1` takes (`stmtOf` → `vedU1EntryS`). There is no prover-plugin interface in 0.2: you cannot hand a proof, a lemma or a tactic to `#ved_u1` that its automatic proof will use. ## 5. The public theorem, and its reuse lemmas For a declaration `f` accepted by `#ved_u1`, `f.ved_u1 : U1Stmt f.ved_contract f.ved_mod f'`, where ``` U1Stmt c m f := CorrStmt c ∧ ShapeStmt c m ∧ WidthStmt c m ∧ OrderStmt m ∧ OutputsStmt c m f ``` ### Target, original declaration * **Target IR.** `f.ved_mod`: the module the single `synthesizeCombinational` call of that `#ved_u1` command returned (not the optimised IR and not a re-synthesis). The term is built by `toExpr` and checked to evaluate back to the same module. * **Original declaration.** `f'` is built from your declaration `f`, by `stmtOf`, and is one of: `f` itself; or `f` specialised at `defaultDomain` when it has a leading implicit `DomainConfig` binder (the `OK` line says "specialised at defaultDomain"; this is **not** a statement about every domain); or, for a result that is a `×`-tree or structure of signals, a lambda that bundles the projections of `f`'s value. Describe it as a fixed term derived from the declaration, not as "the constant `f`" in every case. The statement is not weaker than that term and not about a different, easier specification. * **What it does not say.** It does not prove the synthesiser correct in general: it checks this one returned module against this one declaration. ### Conditions (the meaning of the statement) | Part | Condition | |---|---| | input | `InputsOk c m ins`: every data input fits its declared width at every cycle, and the reset input is `0` at every cycle. The **clock input is not constrained**, and no claim is made about clock edges, timing, reset waveforms or reset ≠ 0. | | initial state | `st0 c m`: each register starts at the initial value `c.inits` records from the module (`encodeInit`), other state at 0. | | domain | the synchronous cycle model of `Sparkle/IR/Semantics.lean` (`runModule`), one step per cycle, single clock. Not an arbitrary `DomainConfig`. | | horizon | every `K`; at every cycle `t < K` | | outputs | **every** output port (all projections of the result), not a selection | | order | `OrderStmt m`: some arrangement of the body assigns each wire before reading it, and the netlist is well-formed (no combinational cycle, no self-read, no undriven read, one driver per name, every output driven). `OutputsStmt` quantifies over **all** well-ordered arrangements; the module itself is not reordered. Running the body in its own order is claimed only if `woCheck [] m.body = true` (decidable). | | not claimed | equality of internal dead state; behaviour for inputs outside `InputsOk` | ### Allowed axioms The reachable closure of `f.ved_u1` is a subset of `{propext, Classical.choice, Quot.sound}` (`#ved_strict_audit`). There are no name-pattern exceptions; `sorryAx`, `Lean.ofReduceBool` (`native_decide`), the `bv_decide` auxiliary axioms and any added axiom are rejected. The audit alone does not check the theorem's type or artifact; `#ved_u1` checks those first (section 7). ### Reuse lemmas (`SparkleProof.Core`, **public**) Do not select a conjunct with `.2.2.2.2`; the shape of the conjunction is not a compatibility promise. Use: | Lemma | Says | |---|---| | `SparkleProof.u1_corr`, `u1_shape`, `u1_width` | the matching conjunct (`CorrStmt`, `ShapeStmt`, `WidthStmt`) | | `SparkleProof.u1_order` | `OrderStmt m`: the output statement is not vacuous | | `SparkleProof.u1_outputs` | `OutputsStmt c m f` | | `SparkleProof.u1_outputsOn_body` | the same for `m.body` in its own order, given `woCheck [] m.body = true` | | `SparkleProof.u1_output_agrees` | needs `woCheck [] m.body = true` (the body in its own order is well-ordered). Output agreement: on admissible inputs and any `K`, the run exists and every output at every cycle `t < K` equals `srcOf c f ins o.name t` | | `SparkleProof.u1_output_at` | needs `woCheck [] m.body = true`, like `u1_output_agrees`. The same for one cycle and one port | They are proved from the standard axioms only (pinned with `#print axioms` and `#guard_msgs`). Runnable use, from a generated theorem to a statement about the returned module with no `.2.2.2.2`: `delay8_ir` at the end of [`Tests/Ved/SparkleProofFacadeCheck.lean`](../../Tests/Ved/SparkleProofFacadeCheck.lean) (`lake build Tests.Ved.SparkleProofFacadeCheck`). The older `Ex6_OwnLemma.lean` does the same with `.2.2.2.2` and is kept as it is. ## 6. What 0.2.x keeps, what a minor may change * **0.2.x keeps** (public items only): the two `SparkleProof.*` imports and the three `Tools.*` compatibility imports; the commands `#ved_u1` and `#ved_strict_audit`; the names `f.ved_u1`, `f.ved_mod`, `f.ved_contract`; the name and the meaning of `U1Stmt`, `InputsOk`, `st0`, `srcOf`, `OutputsStmt`, `OrderStmt` and the IR semantics they use (a change of **meaning**, such as a different initial state or input condition, is a breaking change even if every name stays); the `SparkleProof.u1_*` lemmas; the accepted/refused behaviour on the circuits the pinned examples and the `Tests/Ved` regression checks cover (a refusal there may become an acceptance with the same statement; an acceptance is not turned into a refusal except under the next point). * **A minor release (0.3, …) may change** every experimental item, the set of circuit shapes an entry accepts, error text, and internal items; it may remove deprecated public items after a stated deprecation in a release note. * **Soundness fixes take priority.** If the statement or the checker is found to be too weak or wrong, it is fixed even in a patch release, even if that rejects a theorem that was accepted before or changes a public statement. The release notes then carry a migration note (what changed, which accepted results are affected, how to re-run). Lean toolchain compatibility is a separate matter from this API: only the toolchain a release is checked with is supported. ## 7. Three guarantees, and what failure means Keep three claims apart; this page and [../VED.md](../VED.md) are about the first. 1. **Source → IR (public for `#ved_u1`).** The theorem of section 5. `#ved_u1` accepts only when: (a) the expected `Prop` is built from the declaration-derived term and the registered module and contract; (b) the generated proof elaborates against it, and the theorem is added to the kernel **synchronously** with exactly that type, whose stored type is compared with the rebuilt expected `Expr`; (c) the strict audit accepts. Its success is a statement about that IR run under the IR semantics, relative to Lean's kernel, the statement definitions and the audit. Listing the generated theorems, or `#ved_strict_audit` on its own, does not force an asynchronously elaborated proof to be finished and does not check the target; only the registration inside the entry does. 2. **IR → SystemVerilog model (experimental, conditional).** There is a theorem that the emitter's AST-level output has the same trace as the IR **under a width-checking hypothesis** (`Tools.SVParser.EmitSem.certified_forward_trace_module`, in the import closure of `Tools.ConcatNorm`) and a syntactic round trip for a fragment (`Tools.SVParser.RoundtripProof.lower_emit_id`; the shipping lowerer is a `partial def` with no general unfolding equations, so the proof is about total twins tied to it by executable checks). Neither is imported by `SparkleProof`. 3. **The printed SystemVerilog text (not proved in general).** There is no general theorem from the source to the final SV text. `#ved_write_checked` ties the written files to the checked design (byte comparison in its check); that fixes which design was written, it does not prove the printer. **Failure.** A refusal is `VED U1 REFUSED f [stage]: …`: no theorem was registered and no claim is made. A refusal is **not a counterexample**: it says that this entry could not build the theorem (unsupported shape, `synthesis` failure, no admissible `order`, proof search failure, …). The stages are listed in [VED.md](../VED.md#accepted-and-refused). Resource limits are **not** machine-separated from ordinary refusals today: a heartbeat or recursion limit while elaborating the proof is reported as `[proof]`, in the kernel step as `[kernel]`, and inside the checker as `[checker]`; before the checker starts, a heartbeat or recursion exception raised while reading the table or during synthesis, and an interrupt, propagate as their own errors. So a `[proof]`, `[kernel]` or `[checker]` refusal may be a timeout, and a timeout must never be counted as an expected refusal or as a success: a runner that classifies results has to treat those stages as "unknown unless the refusal text is exactly the expected one". Such a runner is `scripts/proof/run_core.py` (section 10): it decides the resource-limit class first, so a heartbeat text that is wrapped in `VED U1 REFUSED … [proof]` is still not an expected refusal. A refusal removes the constants the checker added; it does not undo what synthesis did before the checker began (environment changes in caches or files). ## 8. Build commands and measured cost Each public entry is built by one explicit target; no default executable and no IP library is a prerequisite. | Command | Closure | Native dependency | |---|---|---| | `lake build SparkleProof.Core` | `Tools.VedU1Contract`, `Tools.VedStrictAudit` and `Sparkle.IR.*`, `Sparkle.Core.Signal` | C compiler; `libsparkle_Sparkle` precompiled with the `c_src` barrier/JIT archives | | `lake build SparkleProof.Single` | adds the compiler and the U1 proof machinery (`Tools.VedU1Entry` closure) | the same | Core is not free of the native link: `Tools.VedU1Contract` imports `Sparkle.Core.Signal`, which needs the precompiled `Sparkle` library. The two targets differ in how much Lean they compile, not in whether they need a C compiler. Times of the checks above, on the node they were measured on, are recorded in the pull request that introduced the facade. ## 9. Which check guards which promise The promises of section 5 and section 7, and the check that fails if one is weakened. The checks are the `Tests/Ved/*Check.lean` files named here (VED CI builds them); none is copied for the public import: `SparkleProof.Single` adds no declaration; `SparkleProof.Core` adds only the extraction lemmas and does not copy or change the entry, the statement or the audit. So the old checks run on the same code. `SparkleProofFacadeCheck` shows that, and adds the two controls below. | Promise | Guarded by | |---|---| | **P1** The theorem is about the declaration `f` (or the term derived from it) and the module that one synthesis returned, not an easier statement or another module | `U1EntryCheck`: same type with another meaning (identity into the delay's statement and back), mutated modules (init, output, width, constant), another declaration's proof or artifact, each refused at `[proof]`; `U1DomainCheck`: the `defaultDomain` specialisation, and mutated or swapped statements for the representatives; `U1MultiOutCheck`: the bundled statement; `SparkleProofFacadeCheck` §2: the public import gives the same theorem type | | **P2** The expected statement is rebuilt and compared, and the audit runs | `U1EntryCheck` §1 (statement constant of the registered theorem), the `ctl*` controls above; `StrictAuditCheck` (the audit alone: it does not check the type, see section 3); `SparkleProofFacadeCheck` §2 (`example : U1Stmt … := f.ved_u1`) | | **P3** Closure inside `{propext, Classical.choice, Quot.sound}`, no name exceptions | `StrictAuditCheck`: `native_decide`, `Lean.ofReduceBool`, an added axiom (also one named like an auxiliary), `sorry`, a missing declaration; `U1EntryCheck` §7 (`native_decide` proof refused at `[audit]`); `SparkleProofFacadeCheck` §3 (the lemmas' axioms) and §4 (a proof resting on an added axiom is refused at `[audit]` through the public import) | | **P4** All outputs, and an order must exist; no vacuous statement | `U1ContractCheck`: missing output, merged inputs, width mismatch, `OrderOk` controls (`decide`); `U1MultiOutCheck`: dropped, swapped and renamed outputs, changed initial value or value; `U1EntryCheck`: `ctlInit`, `ctlOut`, `ctlNoOut`, `ctlInAssign` | | **P5** The assumptions are the stated ones; the clock is not fixed; `defaultDomain` is not "every domain" | `U1ContractCheck` §3 (the full statement for every clock stream and run length); `U1DomainCheck` (other implicit binders, instance binders and a fixed non-default domain are refused at `[table]`). This is also the documentation in section 5; no test can show that a sentence is not over-claimed | | **P6** A refusal is not a counterexample, and a resource limit is not a refusal | the corpus (section 10): `control-heartbeat` and `control-wallclock` must be `timeout-or-resource-limit`, and `run_core.py --selftest` pins the case in which the message looks like a refusal; the consumer fixture pins its refusal by its exact text (`Tests/Downstream/ProofConsumer`, `Refusal.lean`) | | **P7** The IR → SystemVerilog boundary is not claimed beyond what is checked | `WriteCheckedCheck`: the written files are those of the checked design (swapped design, tampered top or child, dropped or reordered child, extra module, renamed top are refused at `[written]` and no file is written); the "not proved" part is only stated (section 7), not testable | | **P8** Only a synchronously registered and checked theorem counts as success | **indirect**: every control above is refused inside the command, with the checker's constants absent afterwards (`U1EntryCheck`, `U1MultiOutCheck`, `U1DomainCheck`: `expectRefused`; `SparkleProofFacadeCheck` §4). No test submits a proof that would only fail when an asynchronous task is awaited; the listing commands are documented, not tested, as not forcing it | | User-supplied lemma for one local condition (experimental `ved.mem.userLemma`) | `VedSupplementCheck`: a lemma of the wrong type or for another circuit, with `sorry`, with `native_decide`, with an open hypothesis, an unknown constant, a definition are all refused and the final theorem has the automatic run's type and the standard axioms. Not part of the public entry | What no check covers on purpose: that the synthesiser is correct in general (not claimed, section 5), and the printed SystemVerilog text (section 7). ## 10. Reproduction set and runner `Tests/ProofCorpus/manifest.tsv` lists eight cases (accepted, sequential, public lemma reuse, an intended refusal, two tamper refusals, and two limit controls). Most point to files that already exist (`docs/research/examples`, `Tests/Ved`); only the refusal, tamper and control files are new, in `Tests/ProofCorpus/Cases/`. From a checkout, after the toolchain is installed: ``` python3 -I scripts/proof/run_core.py --out /tmp/proof-corpus # builds the public targets, runs every case python3 -I scripts/proof/run_core.py --selftest # classifier checks only, no Lean ``` For each case it records the candidate commit, toolchain, OS, the outcome (`accepted`, `expected-refusal`, `timeout-or-resource-limit`, `infrastructure-error`, `unexpected-result`), the exit code, the check of the theorem's statement and axioms, and the log path; `summary.md` is generated from `results.jsonl`. The outcome is decided from Lean's messages, not from the exit code, and a limit hit is decided first. The corpus is a small reproduction of the 0.2 claims; it is **not** the old 327-row snapshot (`docs/research/data/coverage-327.tsv` is kept as it was and is not regenerated here). A separate consumer outside the checkout is `Tests/Downstream/ProofConsumer`, run by the `proof-consumer` job of `downstream-smoke.yml` (`scripts/ci/proof_consumer.sh`).