[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"d6MD7JF6zQ":3},"# lean-tee\n\n## In plain English\n\n**Prove that a public decision was made by the rules you published — without asking anyone to trust your server, and without locking into AWS Nitro.**\n\nImagine a compliance check, a vote, or a trade gate: someone submits an action, your policy program runs, and you get a yes/no (or richer) result. With lean-tee, that run produces a **receipt**: a small package that says *which program* ran, *what inputs* it saw, and *what it output*. Others — another team, a chain, a regulator, CI — can **check the receipt** and accept an honest result or reject a forged one. They do not need your cloud account or a sealed hardware box.\n\n**How SP1 fits in.** The production path runs that policy program inside [SP1](https://github.com/succinctlabs/sp1), a *zkVM* (think: a special computer that can prove what it executed). SP1 produces a cryptographic proof that *this exact guest program* saw *these inputs* and produced *this output*. lean-tee wraps that into a stable receipt and API. Checking the proof is much cheaper than trusting the operator — and cheaper than re-running everything yourself when you only need to know the result is real.\n\n**Lean 4 on SP1.** Beyond wrapping SP1, this repo adds a **Lean 4 toolchain path into the zkVM**: we port a Lean 4.32.1 runtime and compile measured guests Lean → C → RISC-V so the program that SP1 proves can be written and specified in Lean—not only as a Rust twin. Details: [docs/LEAN_SP1_GUEST.md](docs/LEAN_SP1_GUEST.md).\n\n**What this is not.** lean-tee does **not** hide secrets from the machine that runs it. If you need sealed keys or private data the host must never see, use a confidential enclave (e.g. AWS Nitro) for that part, and lean-tee for public, verifiable outcomes. More below and in [docs/VS_NITRO.md](docs/VS_NITRO.md).\n\n---\n\n## For builders\n\n**Portable integrity TEE compute for open systems** — measured guests, hashed receipts, and lean-grpc APIs so anyone can accept honest public results or cheaply reject forged ones — without AWS Nitro, sealed memory, or a cloud PKI root of trust.\n\n> **Not a confidentiality enclave.** lean-tee does **not** hide secrets from the host. It replaces Nitro’s *“prove this code ran on this I/O”* role for **public** workloads; it does **not** replace Nitro’s *“keep keys/data sealed”* role. Full matrix: **[docs/VS_NITRO.md](docs/VS_NITRO.md)**.\n\n| Profile | Prove | Verify | Use |\n| --- | --- | --- | --- |\n| **`lean-tee-v2`** | SP1 Hypercube RISC-V | Host verifies SP1; never trust client `proof_ok` alone | **Production integrity (default)** |\n| **`lean-tee-v1`** | Mock proof | Recompute resultHash + mock | **CI / demos only — never prod** |\n\nSet `LEAN_TEE_DEFAULT_PROFILE=lean-tee-v2` and wire `LEAN_TEE_PROVE_ADDR` to an SP1 `prove_server`. Mock must not be the hero or production path.\n\n**First-party guests:** `compliance_operator`, `voting_operator`, `onboarding_operator`, `trade_operator` ([registry](config/guests/registry.json)). Lean-specified programs: [GUEST_PROG.md](docs/GUEST_PROG.md).\n\n## Why open source this?\n\n- **Portable attestation** — verify on CI, another cloud, or a chain without embedding AWS PCR/NSM trust.\n- **Cheap reject** — forged receipts fail Accept; goldens + adversarial demos gate the algorithms.\n- **Spec-first** — Lean checkers + Rust `lean_tee_receipt` twin; wire proto is normative.\n- **Lean 4 toolchain on SP1** — measured guest is Lean-compiled (runtime port + Init allow-list); SP1 proves that Lean guest, not a hand-written substitute.\n- **Multi-guest enterprise shape** — ACL, audit, quotas, durable jobs ([ENTERPRISE.md](docs/ENTERPRISE.md)) without pretending to be Nitro.\n\n## Nitro in one glance\n\n| Need | Use |\n| --- | --- |\n| Integrity of public compute + multi-party verify | **lean-tee** |\n| Sealed secrets / KMS release to enclave PCRs | **AWS Nitro** (or similar confidential TEE) |\n| Both | Compose: confidential TEE for secrets + lean-tee for public receipts |\n\n## Quickstart (mock — CI/demo only)\n\nRequires Lean 4 (`lean-toolchain`), OpenSSL, and `lake update` (pulls [lean-grpc](https://github.com/RileyBetts/lean-grpc) v1.1.0).\n\n**This path uses `lean-tee-v1` mock prove. Do not treat it as production attestation.**\n\nFull setup: **[docs/GETTING_STARTED.md](docs/GETTING_STARTED.md)**.\n\n```bash\nlake build receiptTests teeServer teeClient teeLoopback\n./.lake/build/bin/receiptTests\n./scripts/standalone_demo.sh\n./scripts/adversarial_matrix_demo.sh\n./scripts/action_matrix_demo.sh\n./scripts/enterprise_control_demo.sh\n./scripts/cross_impl_golden_demo.sh\n./scripts/guest_prog_demo.sh\n./scripts/confidentiality_local_demo.sh\n```\n\n## Production path (`lean-tee-v2`)\n\nMeasured guest = **Lean 4 → C → SP1 RISC-V** (`host/guest_lean` + `host/lean_sp1_runtime/`). See [LEAN_SP1_GUEST.md](docs/LEAN_SP1_GUEST.md).\n\n1. Install SP1 (`sp1up`, including `--c-toolchain`) and build host with `--features sp1`.\n2. Run `prove_server` (CPU/network prover) and point `teeServer` at it:\n\n```bash\n# execute-only smoke (CI/nightly gate — no heavy prove by default)\nbash scripts/sp1_execute_ci.sh\n\n# careful local staged tests\nbash scripts/sp1_test_careful.sh\n```\n\n3. Server: `LEAN_TEE_DEFAULT_PROFILE=lean-tee-v2` + `LEAN_TEE_PROVE_ADDR=host:port` (never ship mock as the default).\n\nManual mock server (dev):\n\n```bash\n./.lake/build/bin/teeServer          # LEAN_TEE_PORT=50071\necho 'rules=vote.yes,vote.no' > /tmp/rules.txt\n./.lake/build/bin/teeClient 127.0.0.1:50071 vote.yes /tmp/rules.txt\n```\n\nRust Prove (mock, no `cargo prove`) — **CI/dev only**:\n\n```bash\ncd host && cargo build -p lean_tee_prove_server --no-default-features\nLEAN_TEE_PROVE_MODE=mock LEAN_TEE_PROVE_PORT=50072 \\\n  ./target/debug/prove_server\n```\n\n## Product contract (`lean-tee-v1` / `lean-tee-v2`)\n\n- Wire: [`proto/lean_tee/v1/tee.proto`](proto/lean_tee/v1/tee.proto)\n- `resultHash` domain: `lean-tee/v1` (length-prefixed SHA-256)\n- Mock `proof_ref` domain: `lean-tee/mock-proof/v1` (**not** production)\n- Default guest: `SHA256(\"lean-tee/compliance_operator/lean-sp1/v1\")` (empty `guest_id`)\n- Shared Rust algorithms: crate `lean_tee_receipt` under [`host/receipt`](host/receipt)\n- Production prove: SP1 Hypercube via `lean-tee-v2` + host verify\n\nDocs: [GETTING_STARTED](docs/GETTING_STARTED.md) · [PRODUCT](docs/PRODUCT.md) · [THREAT_MODEL](docs/THREAT_MODEL.md) · [CRYPTO](docs/CRYPTO.md) · [LEAN_SP1_GUEST](docs/LEAN_SP1_GUEST.md) · [GUEST_PROG](docs/GUEST_PROG.md) · [CONFIDENTIALITY](docs/CONFIDENTIALITY.md) · [VS_NITRO](docs/VS_NITRO.md) · [API](docs/API.md) · [ENTERPRISE](docs/ENTERPRISE.md) · [SLA](docs/SLA.md)\n\n## Layout\n\n| Path | Role |\n| --- | --- |\n| `LeanTee/` | Spec: hash, receipts, guests, control plane, gRPC services |\n| `proto/lean_tee/v1/` | Normative `.proto` |\n| `host/receipt` | Shared Rust receipt crypto (Anchor-linkable) |\n| `host/compliance_lib` | Multi-guest operator logic |\n| `host/prove_server` | tonic Prove (mock and/or SP1) |\n| `host/guest_lean` | Measured SP1 guest ELF (Lean→C→RISC-V) |\n| `host/lean_sp1_runtime/` | Lean 4.32.1 runtime overlays / shims for SP1 |\n| `host/lean_sp1_init_min/` | Minimal Init for the Lean guest |\n| `host/guest` | Legacy Rust twin (optional differential) |\n| `artifacts/sp1_guest_digests.json` | Published ELF / verifying-key digests |\n| `clients/python` | Python Execute / AcceptReceipt SDK |\n| `clients/rust` | Thin tonic Tee + Prove client |\n| `config/guests/` | First-party guest registry |\n| `Tests/` | Receipt + guest registry + gRPC loopbacks |\n| `docs/` | Product, Nitro, API, threat, SP1 guest guide / crib sheet |\n| `scripts/sp1_*.sh` | SP1 runtime/guest build, CI smoke, digests |\n| `scripts/*_demo.sh` | Standalone, adversarial, action, enterprise, golden, prove loopback |\n\nSP1 ownership split (Lean guest + glue vs upstream prover): [docs/LEAN_SP1_GUEST.md](docs/LEAN_SP1_GUEST.md#ownership-what-this-repo-contributes-vs-sp1).\n\n## Dependencies\n\n- [lean-grpc](https://github.com/RileyBetts/lean-grpc) **v1.1.0** — fetched by `lake update` (git pin in [`lakefile.lean`](lakefile.lean); see [docs/GETTING_STARTED.md](docs/GETTING_STARTED.md))\n- OpenSSL (`libssl-dev`, `pkg-config`)\n- Optional: [SP1](https://github.com/succinctlabs/sp1) toolchain (`sp1up`) for `lean-tee-v2` / `--features sp1` (upstream **MIT OR Apache-2.0**)\n\n## Community\n\n- [Getting started](docs/GETTING_STARTED.md) · [Contributing](CONTRIBUTING.md) · [Code of conduct](CODE_OF_CONDUCT.md) · [Security](SECURITY.md)\n- [Public release review scorecard](docs/RELEASE_REVIEW.md)\n\n## Status\n\n- [x] Receipt hashing + `acceptReceipt`\n- [x] lean-grpc Tee / Prove / Verify / AnchorSink\n- [x] Shared `lean_tee_receipt` + golden vectors\n- [x] Mock-first standalone demo + CI\n- [x] Multi-guest registry (compliance / voting / onboarding / trade)\n- [x] Enterprise control plane (ACL, audit, quotas, job dir, mTLS docs)\n- [x] SP1 prove path + host verify (`lean-tee-v2`); production default + gated execute CI\n- [x] Lean-compiled measured guest + runtime port / FENCE patches + Init allow-list\n- [x] GuestProg v1/v2 + LoadProgram ACL / size limits\n- [x] Optional local confidentiality (`confidentiality=local` sealed worker; not Nitro)\n- [x] Anchor Chain Strict Mode consumer + multi-guest mapping docs\n- [x] Published ELF/vk digests + SP1 integrity crib sheet\n\n## License\n\nApache-2.0 — see [LICENSE](LICENSE) and [NOTICE](NOTICE).\nFirst-party lean-tee code is Apache-2.0. Upstream SP1 is dual-licensed MIT OR Apache-2.0; we depend on it under its Apache-2.0 option.",1786349535569]