# Depend on Sparkle from your own project This is the one install-and-depend procedure. It takes a new Lake project outside the Sparkle checkout to a built project that **produces a Sparkle proof** (`#ved_u1`) and **uses the theorem** from another module. The project it builds is not an illustration: it is the CI fixture [`Tests/Downstream/ProofConsumer`](../../Tests/Downstream/ProofConsumer), which the `proof-consumer` job of [downstream-smoke.yml](../../.github/workflows/downstream-smoke.yml) builds on every change, against the commit under test, through [`scripts/ci/proof_consumer.sh`](../../scripts/ci/proof_consumer.sh). If this page and the fixture ever differ, the fixture is right. What the names you import mean, and what the theorem says: [PublicAPI.md](PublicAPI.md). Which circuit shapes are supported: [../VED.md](../VED.md). ## What you need | | | |---|---| | **Sparkle version** | **v0.2.1 (once tagged)**. Until that tag exists, use the full 40-hex commit SHA named in the release notes of the candidate. `v0.2.0` is tagged but does **not** contain `SparkleProof`; do not pin it for this page. A branch name such as `main` moves; use it only to try things out, never in a project you want to rebuild later. | | **Lean toolchain** | The content of `lean-toolchain` **at the pinned Sparkle commit**; at the time of writing `leanprover/lean4:v4.36.0`. Your project must use the same one. (Sparkle itself also builds on the older versions listed under "Supported Lean versions" in the [README](../../README.md#supported-lean-versions); this page and its fixture use the pin.) Take it from the pin, not from `main` (see Step 1). | | **Lake** | The one that comes with that toolchain (install `elan`; it selects the toolchain from `lean-toolchain`). | | **C compiler** | **Required.** Sparkle's library links C code (`c_src`: the barrier and JIT libraries) into its precompiled library, so every Sparkle target needs a working `cc` / `clang` and `git`. On macOS install the Xcode command line tools. | | **OS** | Linux with glibc ≥ 2.34 (Ubuntu 22.04+, Debian 12+, Fedora 35+), macOS, or WSL2. The CI job for this fixture runs on Linux. | | **Time and disk** | The first build compiles Sparkle and its proof library from source; plan for minutes (the CI job records the first build, a no-change rebuild and a small-edit rebuild in its summary) and a few GB under `.lake/`. | ## Step 1 — Copy the project, and the toolchain, from the pinned commit The fixture is a complete Lake project. Take it from the commit you pin, so that fixture, toolchain and library are one and the same version: ```bash PIN= git clone https://github.com/Verilean/sparkle.git sparkle-src git -C sparkle-src checkout "$PIN" cp -r sparkle-src/Tests/Downstream/ProofConsumer my_proofs cd my_proofs cat lean-toolchain # already equal to the pinned commit's lean-toolchain ``` The project is: ``` my_proofs/ ├── lakefile.toml ← requires sparkle; two placeholders to fill (Step 2) ├── lean-toolchain ← equal to Sparkle's at the pin ├── ProofConsumer.lean ← library root: imports the three modules └── ProofConsumer/ ├── Produce.lean ← `import SparkleProof.Single`; two circuits, `#ved_u1`, pinned statements ├── Consume.lean ← another module: a theorem about the returned IR from `delay8.ved_u1` └── Refusal.lean ← a circuit that is refused, pinned as the expected result ``` If you start a project of your own instead of copying this one, the toolchain file is the only thing you must fetch by hand, **from the pin and not from `main`**: ```bash curl -s https://raw.githubusercontent.com/Verilean/sparkle/$PIN/lean-toolchain > lean-toolchain ``` ## Step 2 — Declare the dependency `lakefile.toml` of the fixture, verbatim (`@SPARKLE_URL@` and `@SPARKLE_REV@` are the only placeholders; `scripts/ci/proof_consumer.sh` fills in the same two): ```toml name = "proofconsumer" defaultTargets = ["ProofConsumer"] [[require]] name = "sparkle" git = "@SPARKLE_URL@" rev = "@SPARKLE_REV@" [[lean_lib]] name = "ProofConsumer" ``` Replace them: `@SPARKLE_URL@` with `https://github.com/Verilean/sparkle.git` and `@SPARKLE_REV@` with the pin (a full SHA, or the tag `v0.2.1` once it exists): ```bash # portable (GNU and BSD/macOS sed): write a new file, then move it over sed -e "s|@SPARKLE_URL@|https://github.com/Verilean/sparkle.git|" -e "s|@SPARKLE_REV@|$PIN|" \ lakefile.toml > lakefile.toml.new && mv lakefile.toml.new lakefile.toml ``` The package is called `sparkle` (the `name` must match the upstream package name). The library you import from is the `SparkleProof` / `Sparkle` family, not a library called `Sample`. ## Step 3 — First fetch and build ```bash lake update # first dependency fetch: clones sparkle into .lake/packages/, writes lake-manifest.json lake build ProofConsumer # builds Sparkle (long the first time), then Produce, Consume, Refusal ``` The build **is** the check. `Produce.lean` pins, with `#guard_msgs`, the type of the generated theorem, its axioms (`[propext, Classical.choice, Quot.sound]`) and the strict audit line; `Refusal.lean` pins the exact refusal text; `Consume.lean` proves a statement about the returned IR from `delay8.ved_u1` in a different module. A change in any of these fails the build. There is no `lake exe` and no `main` here: nothing is run, the theorems are checked when the files compile. Commit `lake-manifest.json` with your project; it records the exact revision Lake resolved. To read what the theorem says, start from [PublicAPI.md, section 5](PublicAPI.md#5-the-public-theorem-and-its-reuse-lemmas) and [`Consume.lean`](../../Tests/Downstream/ProofConsumer/ProofConsumer/Consume.lean). ### The same thing in one command [`scripts/ci/proof_consumer.sh`](../../scripts/ci/proof_consumer.sh) does Steps 1 to 3 in a fresh directory and, in addition, fails if the resolved dependency is not the pinned commit, if the toolchain differs, or if the build has a `sorry`. It is the script CI runs, on Linux; it uses GNU `sed -i` and `date +%s.%N`, so on macOS run Steps 1 to 3 by hand instead (or install GNU sed and coreutils). Run it from the directory that holds the clone of Step 1 (the parent of `my_proofs`, so `cd ..` if you are inside it): ```bash sparkle-src/scripts/ci/proof_consumer.sh https://github.com/Verilean/sparkle.git "$FULL_SHA" /tmp/my_proofs_check ``` (`FULL_SHA` is the 40-hex commit; the script takes the fixture from the checkout it lives in, which must be that same commit.) ## Step 4 — Re-running a release later (not the first fetch) After the first fetch you have a `lake-manifest.json`. To rebuild the same release on another machine or later, **do not run `lake update`**: it asks Lake to resolve the requirement again, which is what you want only when you deliberately move to another Sparkle version. ```bash git clone # includes lake-manifest.json and lean-toolchain cd lake build # fetches the revision recorded in lake-manifest.json ``` | You want | Run | |---|---| | first fetch of the dependency | `lake update`, then `lake build` | | rebuild exactly the pinned release (CI, another machine) | `lake build` with the committed `lake-manifest.json` | | move to a newer Sparkle | change `rev`, change `lean-toolchain` to the new pin's, `lake update`, `lake build`, commit both files | ## Step 5 — Your own circuit Add a module to the project's library `ProofConsumer` (the only `lean_lib` in `lakefile.toml`): create `ProofConsumer/Foo.lean` with one import and one `#ved_u1`, as in `Produce.lean`, and add `import ProofConsumer.Foo` to `ProofConsumer.lean`, the library root, so that `lake build ProofConsumer` builds it. (To use your own name instead, rename the library in `lakefile.toml`, its root file and its directory together.) ```lean -- ProofConsumer/Foo.lean import SparkleProof.Single open Sparkle.Core.Domain Sparkle.Core.Signal namespace MyProject def delay8 (x : Signal defaultDomain (BitVec 8)) : Signal defaultDomain (BitVec 8) := Signal.register 0#8 x #ved_u1 delay8 -- registers `MyProject.delay8.ved_u1`, or refuses and registers nothing end MyProject ``` Whether a shape is accepted is the support matrix in [../VED.md](../VED.md). A refusal is not a bug in your circuit and not a counterexample; it says only that this entry made no claim. To emit Verilog without a proof (the unverified `#synthesizeVerilog` route), write the circuit as in the [tutorial](../tutorial/README.md) (a feedback register is written with `circuit do`; a definition cannot refer to its own name) and import `Sparkle` and `Sparkle.Compiler.Elab`. The tutorial chapters are built by CI; this page does not repeat their examples. ## Common pitfalls - **`unknown module 'SparkleProof.Single'`** (or `unknown package`) — the pinned `rev` is a commit without `SparkleProof` (for example `v0.2.0`), or the `[[require]]` name is not `sparkle`. Look in `.lake/packages/sparkle/` for `SparkleProof/` and for the `lakefile.lean`. - **`.olean` / "compiled with a different version of Lean"** — your `lean-toolchain` is not the pin's. Copy `.lake/packages/sparkle/lean-toolchain` over it (and run `lake build` again). - **`lake build` fails in C (`cc: not found`, linker errors, missing headers)** — Sparkle has native code. Install a C compiler (`build-essential`, `clang`, or Xcode command line tools). This is not a Sparkle bug and not a toolchain mismatch. - **`version 'GLIBC_2.34' not found`** (from `cadical`) — a Lean-toolchain requirement on the OS; use a newer Linux (see the table above). - **The first `lake build` takes minutes** — it compiles Sparkle; later builds reuse it. - **`lake update` changed the revision** — you pinned a branch. Pin a SHA or tag. - **The refusal file fails** — the text pinned in `Refusal.lean` is the pinned commit's; use the fixture of the same commit as the library (Step 1).