blob: 2ad81ce1545a01aa893c6601a9630427ffbd3ebc [file] [view]
<!-- Copyright 2026 The Fuchsia Authors
Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
<LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
This file may not be copied, modified, or distributed except according to
those terms. -->
# Workspace Composition and Role Binding
`cargo anneal verify` assembles Rust source files, captured MIR artifacts,
installed semantics and theory modules, generated claim modules, and user
Lean files inside an isolated temporary workspace before running isolated
Lean elaborator containment (`ExecSeal`) and fresh Lean kernel replay
(`TrustedBoundary`). Understanding how those inputs combine clarifies what an
untrusted proof can influence and what remains fixed by the verifier.
> [!NOTE]
> Earlier design documents ([architecture](architecture.md),
> [design](design.md), and [trust model](trust-model.md)) refer informally to
> `Mir.lean` as the captured MIR module. The shipped pipeline generates
> `capture/Captured.lean` (defining `Captured.program`), optional
> `capture/Captured/Shard_NNN.lean` modules, and `generated/Expected.lean`
> (defining `Expected.claim`).
## Entrypoints and canonical request assembly
Three CLI frontends in `trusted/cargo-anneal/src/verify.rs` normalize into the
same `Request` (`schema_version = 1`):
1. **Explicit request (`cargo anneal verify --request path/to/request.json`):**
Specifies `compilation` (`source_root`, `crate_root`, `crate_name`,
`crate_type`, `panic`, `overflow_checks`, `edition`, `target`,
`source_files`), `scope` (`{"kind": "crate"}` yielding `crate_verified` or
`{"kind": "selected_unit", "roots": [...], "instantiations": [...]}`
yielding `selected_unit_verified`), and `proof` (`source_root`,
`specification` defaulting to `"Spec.specs"`, `theorem` defaulting to
`"Proof.verify"`, and `{module, path, role}` entries with `role` in
`{"specification", "proof"}`). Inputs use `SymlinkPolicy::Reject`.
2. **Cargo manifest shortcut (`--manifest-path Cargo.toml --proof-dir <dir>`):**
Stages `.rs` files under a dependency-free primary target (rejecting build
scripts, proc-macros, and toolchain overrides), assigns role `specification`
to `Spec` / `Spec.*` modules and `proof` to all other `.lean` files, selects
`crate` unless `--select` or `--instantiate` is passed, and uses
`SymlinkPolicy::Reject`.
3. **Direct `rustc` wrapper (`cargo anneal verify rustc ...`):**
Accepts `rustc`-like compilation flags alongside `--spec-file` and
`--proof-file` and normalizes them into `Request` using
`SymlinkPolicy::DereferenceRegular`.
Both `load_request` and the `Cargo` shortcut enforce regular-file reading with
zero symlink traversal, and all entrypoints validate `--receipt-out` aliasing
before touching disk.
## Ephemeral workspace layout and reserved roots
During verification, `cargo-anneal` isolates tool-owned artifacts from
authored modules (`generated/Proof/IdTree.lean` appears when sharded capture is
active):
```text
work/
├── request.json # Canonical Request (request_sha256)
├── rust/<source_files...> # Verified Rust source snapshot
├── capture/
│ ├── capture.json # Capture Schema v5 receipt
│ ├── Captured.lean # TargetRole::Capture (`Captured.program`)
│ └── Captured/Shard_NNN.lean # Optional sharded capture modules
├── anneal/
│ ├── trusted/lean/Trusted/.../*.lean # TargetRole::Model (embedded semantics)
│ └── theory/Anneal/.../*.lean # TargetRole::Proof (embedded theory)
├── authored/<Module>.lean # User/attacker Lean files
├── generated/Expected.lean # TargetRole::Expected (`Expected.claim`)
├── generated/Proof/IdTree.lean # Optional sharded ID tree (TargetRole::Proof)
└── audit-request.json # Authenticated TargetAuditRequest checked by Checker / TrustedBoundary
```
Authored Lean sources cannot declare modules under reserved top-level roots
(`Captured`, `Expected`, `Trusted`, `Anneal`, `Init`, `Std`, `Lean`, `Lake`,
`TrustedBoundary`, `SpecPreflight`). Embedded `Anneal.*` theory helpers receive
`TargetRole::Proof`, never `Model` or `Specification`, so they undergo fresh
kernel replay alongside user proofs.
## Connecting `scope`, `mir_profile_version`, `Spec`, and `Expected.claim`
`cargo-anneal` generates `generated/Expected.lean` defining `Expected.claim`:
```lean
namespace Expected
def claim : Prop :=
_root_.Trusted.MirSemantics.<RootTheorem>
(_root_.Trusted.MirSemantics.<CrateCtor>.mk
_root_.Captured.program
_root_.<specification>)
end Expected
```
| `scope.kind` | `mir_profile_version` | `<RootTheorem>` | `<CrateCtor>` | Untainted `status` |
| :--- | :--- | :--- | :--- | :--- |
| `crate` | `1` | `CrateTheorem` | `Crate` | `crate_verified` |
| `crate` | `2` | `CrateTheoremV2` | `CrateV2` | `crate_verified` |
| `selected_unit` | `1` | `UnitTheorem` | `Crate` | `selected_unit_verified` |
| `selected_unit` | `2` | `UnitTheoremV2` | `CrateV2` | `selected_unit_verified` |
`TrustedBoundary` enforces `TargetRole.allows` (`Specification` cannot import
`Proof` or `Lean.*`/meta constants; `Expected` excludes `Proof`), confirms via
kernel `isDefEq` that `Expected.claim` and `<theorem>` match the canonical root
claim, and binds hashes across Receipt v3.
## Automated red-teaming composition contract
In [automated red-teaming](red-teaming.md), the defender pins all locked
inputs (`src/lib.rs`, `Spec.lean`, `request.json`, `Proof.lean`, or
`trusted/` + core `MirWp` files) using SHA-256 and file-metadata snapshots in
defender-private memory, and reserves top-level Lean module roots
(`Captured`, `Expected`, `Trusted`, `Anneal`, `Init`, `Std`, `Lean`, `Lake`,
`TrustedBoundary`, `SpecPreflight`, `Spec`, `Specs`, `IncorrectnessCheck`,
`IncorrectnessExpected`, and `src`) across `Proof/` submissions and outside
`Spec/`'s `Spec.*` and `theory/Anneal/`'s `Anneal.*` slots:
| Challenge ID | Defender-fixed inputs | Attacker-supplied slots | Bound claim / verification target |
| :--- | :--- | :--- | :--- |
| `proof_only_ub` | `src/lib.rs` (unconditional UB), `Spec.lean`, `request.json` | `Proof/*.lean`, `explanation.md` | `UnitTheorem` (`mir_profile_version = 1`) over defender `Captured.program` + `Spec.specs` |
| `proof_only_wrong_return` | `src/lib.rs` (`wrong_const`), `Spec.lean` (`Spec.specs` wrapping `Spec.returnsZero`), `request.json` | `Proof/*.lean`, `explanation.md` | `UnitTheorem` (`mir_profile_version = 1`) over defender `Captured.program` + `Spec.specs` |
| `spec_preflight_soundness` | `src/lib.rs` (`trigger_ub`), `request.json` (plus default `Proof.lean` when omitted) | `Spec/*.lean` (`Spec/Spec.lean` required), optional `Proof/*.lean`, `explanation.md` | `UnitTheorem` over `Captured.program` + untrusted `Spec.specs`, plus `olean_audit.lean` inspection of exported `lean-lib/Spec*.olean`s |
| `theory_audit_soundness` | `trusted/lean/`, `trusted/audit/{TrustedBoundary.lean,SpecPreflight.lean,library-lock.json}`, `theory/bundle-manifest.json`, and 10 core `MirWp` files | New `theory/Anneal.lean` / `theory/Anneal/**/*.lean`, `explanation.md` | `anneal-audit --anneal-root ... --lean ... --json` plus `olean_audit.lean` over compiled `Anneal.*` `.olean`s |