Skip to content

Tags

Tags

old-route-2026-11-14

Toggle old-route-2026-11-14's commit message

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
feat: add the frontend of the source language in Lean (#238)

This adds `lean/frontend`, the compiler of the source language written in Lean: the lexer, the parser and the canonical printer, name resolution, static evaluation, the elaboration of each body to a typed tree, and the emission of packages of the core. It is the last of four changes that land the compiler route in Lean, after the core, the formal package and the language reference. The package requires Core and nothing else, and nothing requires it.

What it does with a program: it reads the source against `language/LANGUAGE.md`, resolves and lowers each declaration once, elaborates each instance of a function or a protocol to one typed tree (who holds, who computes, which role acts at each event), and emits the named program of the core from that tree. The core then admits the package (`Zkc.Core.admit`), constructs a declared scheme on the admitted package and projects role programs, and its executor runs them. The frontend has no check of facts and no theorem of its own: what it emits is checked by the core at every compilation, and its behaviour is tested against the reference.

How far it goes today: layer A of the language. Schnorr, Chaum–Pedersen, the OR proof and Sumcheck compile and run as interactive protocols; three schemes over a catalogue suite are constructed, admitted after each step and run (Schnorr, ten rounds of Sumcheck, the OR proof), with an honest proof accepted and changed proofs refused. A root that uses a form of a later layer (an oracle port, a `commit` line, a suite written in source, a generated member of the specification layer) waits, and the tool says which form it waits for; 11 of the 14 schemes of the worked programs wait. Nothing is compiled to native code on this route.

The Lean lane of the test driver, the reproduction script, the Nix checks and the guides register the package beside Core and Formal. Its test driver reads the reference of the repository by default.

## Verification

- `lake --no-cache build` in `lean/frontend` from a fresh worktree.
- `lake test` in `lean/frontend` against `language/`: 5,952 checks passed, none failed; with the comparison against a baseline of packages, which is kept outside the repository, 5,953, and the packages of 11,145 roots identical to the baseline. Among them: 502 conformance tests and 134 independent cases against their expected outcomes; the rules of §3 and §5 one by one; a generated program of 50,000 lines; packages of protocol roots admitted by the core; role programs run under the core's executor, with mutants of each package told apart from it; the derived Schnorr proof of 80 bytes equal to the bytes of an independent replay in Python, and 161 changed, shortened and extended proofs refused.
- The typed trees of every protocol of the corpus satisfy the invariants that the emitter relies on (0 violations).
- `lean/checks/check_library.py`, `check_package_ownership.py`, `audit_imports.py` with `--package frontend`, and `check_consumer_audit.py --package frontend`: pass.
- `.github/scripts/check-quick.sh` in `nix develop .#quick`; `nix build .#checks.x86_64-linux.sources` and `.#checks.x86_64-linux.format`.
- After this change `main` holds exactly the tree of the branch on which the four changes were prepared.
- Not run: `just test`, `just test-lean` as one command, and the optional CI lanes. No native source changes.

## Decisions

- **One typed tree per instance is the record of the written program**, and emission is from that tree. There is no second typing to compare with: admission by the core, the invariants of the trees, a digest of what each role does and the conformance suites are the checks.
- **The frontend emits names and the core lowers them.** Values, captures and sites are numbered by the core's lowering, with a check of shape, so the format and its producer change together.
- **A root waits; it is not approximated.** A form of a layer that is not implemented gives no package, and no provisional meaning stands in for it.
- **A refusal is worded from the core's explanation** where the core refuses, with the rule of the reference and the place in the source.
- **The frontend is trusted code, tested and not proved.** Its 464 partial functions are reviewed for bounded work and deterministic refusal; converting them is not planned.