Out-of-Tree Modules (verify rustc) and ExtGateKit

Downstream Rust crates can supply project-specific specification models and external witness checkers outside anneal/ via --spec-file and --proof-file without editing anneal/trusted/ or anneal/theory/bundle-manifest.json, and both in-tree and out-of-tree proof authors can build reusable gates and dialect rule packs with Anneal.Hybrid.ExtGateKit.

1. Out-of-tree modules with cargo anneal verify rustc

cargo anneal verify rustc (and cargo anneal verify --request) accepts repeated --spec-file <MOD>=<PATH> and --proof-file <MOD>=<PATH> mappings from any directory:

cargo anneal verify rustc src/lib.rs \
  --crate-name my_target \
  --edition 2021 \
  --spec-file DomainModel=anneal_ext/DomainModel.lean \
  --spec-file Spec=proofs/Spec.lean \
  --proof-file ExtGates=anneal_ext/ExtGates.lean \
  --proof-file Proof=proofs/Proof.lean \
  --spec-decl Spec:Spec.specs \
  --theorem Proof:Proof.verify \
  --receipt-out receipt.json

(Pass --format json as well if you also want the JSON receipt printed on stdout instead of the human-readable summary.)

Equivalent request.json for cargo anneal verify --request:

{
  "schema_version": 1,
  "compilation": {
    "source_root": "src",
    "crate_root": "lib.rs",
    "crate_name": "my_target",
    "edition": "2021",
    "source_files": ["lib.rs"]
  },
  "scope": { "kind": "crate" },
  "proof": {
    "source_root": ".",
    "specification": "Spec.specs",
    "theorem": "Proof.verify",
    "sources": [
      { "module": "DomainModel", "path": "anneal_ext/DomainModel.lean", "role": "specification" },
      { "module": "Spec", "path": "proofs/Spec.lean", "role": "specification" },
      { "module": "ExtGates", "path": "anneal_ext/ExtGates.lean", "role": "proof" },
      { "module": "Proof", "path": "proofs/Proof.lean", "role": "proof" }
    ]
  }
}

Namespace, header, and bundling rules

  1. Non-reserved module roots: Authored --spec-file and --proof-file module names must not start with Anneal, Trusted, Init, Std, Lean, Lake, Captured, Expected, TrustedBoundary, or SpecPreflight (reserved so target files cannot shadow toolchain, model, or bundled theory modules). Use project-scoped roots such as DomainModel, ExtGates, or MyCrateProofs.
  2. One-way authority boundary (specification vs. proof):
    • --spec-file (role: "specification") modules belong to the human review surface, pass SpecPreflight syntax checks, and are SHA-256 pinned in the receipt's specification digest. They may import Init.*, Std.*, Trusted.*, and other declared specification modules, never Anneal.* or proof modules.
    • --proof-file (role: "proof") modules elaborate inside ExecSeal, may import bundled Anneal.* modules and sibling proof modules, and are kernel-replayed at trustLevel := 0 (loadExts := false) without expanding the human review surface.
  3. module vs. classic prelude headers: Captured always uses Lean 4 module mode (module followed by prelude), and Expected uses module mode whenever the primary Spec module starts with module (falling back to classic prelude when Spec omits module). Authored sources may therefore use module + prelude consistently across Spec and Proof, or omit module in Proof (do not put module on Proof when Spec omits module, since Lean forbids a module file from importing a non-module Expected).
  4. Bundled imports in stock cargo-anneal: Stock cargo-anneal stages the modules listed in theory/bundle-manifest.json (including Trusted.Framework, Anneal.InitLemmas, Anneal.Framework.StepWp, Anneal.MirWp, Anneal.LinearArith, Anneal.BitTrieLrat, Anneal.Backend, Anneal.Hybrid, Anneal.Hybrid.ExtGateKit, Anneal.ElfX86, and Anneal.ElfAArch64). Out-of-tree --proof-file helpers can import these bundled modules—or wrap custom external witness checkers directly over Anneal.Framework.StepWp.BoolCertCut—with zero edits to bundle-manifest.json (if your Proof module uses module + prelude, prepend module, replace import with public import, and open an @[expose] public section in ExtGates.lean as well):
prelude
import Init.Core
import Init.Data.Nat.Basic
import Anneal.InitLemmas
import Anneal.Framework.StepWp

namespace ExtGates

structure OutOfTreeGate (X Y W : Type) (Pre : X -> Prop) (Spec : X -> Y -> Prop) where
  maxWitness : X -> Nat
  wSize      : W -> Nat
  check      : X -> Y -> W -> Bool
  sound      : forall x y w, Pre x -> wSize w <= maxWitness x ->
    check x y w = true -> Spec x y

def gateBoundedCheck {X Y W : Type} {Pre : X -> Prop} {Spec : X -> Y -> Prop}
    (g : OutOfTreeGate X Y W Pre Spec) (p : X × Y × W) : Bool :=
  Nat.ble (g.wSize p.2.2) (g.maxWitness p.1) && g.check p.1 p.2.1 p.2.2

end ExtGates

2. Gate and dialect builders (Anneal.Hybrid.ExtGateKit)

Anneal.Hybrid.ExtGateKit provides Pass-1 builders over Anneal.Hybrid and Anneal.Backend. Because Anneal.Hybrid, Anneal.Backend, and Anneal.Hybrid.ExtGateKit (along with the Anneal.ElfX86 and Anneal.ElfAArch64 umbrellas) are bundled in theory/bundle-manifest.json, both in-tree theory/ modules and out-of-tree cargo anneal verify proofs can import them directly without a custom --proof-file wrapper:

  • mkNonVacuousSubgoalGate and mkWitnessFreeGate: Construct a NonVacuousGate (carrying a verified accepted-input witness via nonVacuousGate_inhabited) or a witness-free CertifiedGate, discharged via certGateCut_sound gate hPre (BoolCertCut.seal _ _ rfl).
  • ExtDialectOp.ext and mkDialectRulePackGate: Encode domain or target operations via ExtDialectOp.ext dialectId opId imm (normalized to 64-bit WellTypedVal values via evalExtDialectOp) and bundle rewrite theorems into a DialectRulePack carrying a mandatory entryInhabit witness. The resulting gate proves UnitValid tgt ∧ SemRefinesUnder ..., composing directly with Anneal.Backend.composePassGates and liftContractAlongRefinement.