A 20-file beginner course (chapters 0 to 14, with sub-chapters 1b, 7b, 7c, 8b and 8c) on writing, synthesising, and proving hardware in Sparkle.
docs/tutorial/
├── md/ ← MASTER (.md, edit here)
│ └── Ch??_*.md ← 20 chapter files
├── Notebooks/ ← lake_lib srcDir
│ ├── Gen/ ← gitignored, regenerated from md/
│ │ ├── Ch??_*.lean ← lake build target
│ │ └── notebooks/ch*.ipynb ← JupyterLab
│ ├── Solutions/ ← hand-written reference proofs
│ │ └── Ch*.lean
├── Display.lean ← portable Display.* fallback
├── Notebooks.lean ← lib root (manual import list)
├── build-from-md.sh ← `xlean-convert` driver
└── README.md ← this file
Edit chapter content in md/. Run
build-from-md.sh to regenerate the
Notebooks/Gen/ artefacts; CI and the Docker image do this
automatically.
| # | Title | Markdown master |
|---|---|---|
| 0 | Setup | md/Ch00_Setup.md |
| 1 | Lean 4 for HDL Authors | md/Ch01_LeanForHdl.md |
| 1b | Your First Sparkle Project | md/Ch01b_YourFirstProject.md |
| 2 | Combinational Circuits | md/Ch02_Combinational.md |
| 3 | Sequential Circuits | md/Ch03_Sequential.md |
| 4 | Modules and Composition | md/Ch04_Modules.md |
| 5 | Verilog Generation | md/Ch05_Verilog.md |
| 6 | Proofs: LTL Invariants | md/Ch06_LTL.md |
| 7 | Proofs: Equivalence Checking | md/Ch07_Equivalence.md |
| 7b | Equivalence across number types (FP, fixed-point, quantisation) | md/Ch07b_FpQuantEquivalence.md |
| 7c | Synthesis With a Proof Attached (#ved_u1) |
md/Ch07c_VerifiedSynthesis.md |
| 8 | Netlist Generation with Yosys | md/Ch08_Yosys.md |
| 8b | Three Ways to Simulate, One Interface (pure-Lean / JIT / Verilator) | md/Ch08b_Simulation.md |
| 8c | From Signal to Silicon — DFF, clocks, STA, gate count, ASIC vs FPGA mapping | md/Ch08c_Silicon.md |
| 9 | FPGA Bring-Up | md/Ch09_FPGA.md |
| 10 | Sparkle Architecture | md/Ch10_Architecture.md |
| 11 | Running the web3 Signing Device on Real Hardware | md/Ch11_Web3Signer.md |
| 12 | Control, Estimation, and the Engineering of Precision | md/Ch12_ControlPrecision.md |
| 13 | GPU Simulation: Monte-Carlo Sweeps and Systolic Arrays | md/Ch13_GpuSimulation.md |
| 14 | Market Making on Silicon: a Quoting Engine with a Proved Position Bound | md/Ch14_HftMarketMaking.md |
Notebooks.lean imports every chapter, 0 to 14, so lake build TutorialNotebooks type-checks the Lean cells that xlean-convert
puts into each generated chapter file. The tests a chapter mentions
(for example lake exe hft-quote-test and lake exe cuda-sim-test)
check the related implementation in the repository, not the chapter's
cells.
The Sparkle tutorial Docker image ships everything pre-installed: Lean, Lake, xeus-lean, JupyterLab, yosys, nextpnr-ice40, nextpnr-ecp5, icestorm, and prjtrellis.
docker run --rm -p 8888:8888 ghcr.io/verilean/sparkle-tutorial:latestOpen http://localhost:8888 in your browser. See
docker/tutorial/README.md.
Switching chapters. Close each chapter's tab (
File → Close and Shut Down Notebook…or the×on the tab) before opening the next one. Each open notebook holds a Lean kernel; starting a second kernel while the first is alive can deadlock the new one at startup. The image overrides JupyterLab's default so closing the tab also shuts the kernel down — but you have to do the closing. In-place "Restart Kernel and Run All" within a chapter is unaffected.
git clone https://github.com/Verilean/sparkle.git
cd sparkle
# 1. Build xlean-convert from upstream xeus-lean.
git clone https://github.com/Verilean/xeus-lean /tmp/xeus-lean
(cd /tmp/xeus-lean && lake build xlean-convert)
export PATH="/tmp/xeus-lean/.lake/build/bin:$PATH"
# 2. Regenerate Notebooks/Gen/ from md/.
bash docs/tutorial/build-from-md.sh
# 3. Typecheck the code cells of every chapter (Notebooks.lean imports
# chapters 0 to 14).
lake build TutorialNotebooks
# 4. (optional) launch JupyterLab to actually run the cells.
jupyter lab docs/tutorial/Notebooks/Gen/notebooks/Edit a chapter by editing its md/Ch??_*.md file.
Cell-format conventions:
```leanfences become executable code cells.```text(or any other tag, like```bash) stays as illustrative content inside the surrounding Markdown cell.- Plain Markdown is rendered as-is.
See md/README.md for the full conventions and
the synthesis-safety rules every ```lean cell must follow.
.github/workflows/build.yml defines a tutorial-notebooks job
that builds xlean-convert from upstream xeus-lean, runs
build-from-md.sh, and then lake build TutorialNotebooks. A
chapter whose code cells stop typechecking fails CI.
The verified-synthesis work behind Chapter 7c (per-circuit proofs, the paused compiler
general theorem, the row-by-row coverage table, related work and open problems) is described
in docs/research/README.md.