Automated Red-Teaming Harness

A formal verifier‘s soundness guarantee is only as strong as its resistance to adversarial inputs: untrusted proofs or programs must never trick the tool into accepting a broken crate, tampering with verifier inputs, or masking a failure inside an ambiguous error. Anneal’s red-teaming harness (ci/redteam/) treats Anneal itself as the system under test—pinning known-broken Rust crates and specifications on the defender side, accepting untrusted attacker submissions into strictly bounded input slots, and running verification with no relaxation flags and an isolated .olean cache.

This core harness provides input containment, phase-attributed integrity pinning, the mandatory brief contract (explanation.md), deduplication, proof-only challenges, specification-preflight .olean soundness checks, and offline repository theory-audit checks. A follow-up change will add joint code-and-proof challenges with an executable Rust/Miri oracle onto the shared outcome-to-verdict contract below.

Attacker/defender model and trust boundaries

  1. Isolated ephemeral staging: Submissions arrive as a directory or tar archive (plain, gzip, bzip2, or xz with bounded decompression memory and stream limits). Only regular files inside allowed slots (Proof/*.lean with Proof/ stripped at staging so Proof/Helper.lean becomes module Helper and Proof/Proof.lean proves Proof.verify : Expected.claim, plus challenge-specific Spec/*.lean or theory/Anneal/**/*.lean slots, explanation.md, and optional advisory manifest.json) are admitted. Symlinks, hardlinks (st_nlink > 1), .. traversals, backslashes, NUL bytes, depth > 16, Unicode case collisions, reserved roots (including Spec and src in Proof/), defender asset collisions, and missing briefs fail closed as INVALID_SUBMISSION.

    Example attack: Placing Proof/Spec.lean or a symlinked theory/Anneal/MirWp.lean inside a submission attempts to shadow or inspect defender files; staging rejects both as INVALID_SUBMISSION before running any verifier tool.

  2. Defender-private integrity inventory: The defender writes locked Rust sources, specifications or trusted//MirWp theory modules, and synthesized request.json files exclusively (O_CREAT | O_EXCL | O_NOFOLLOW) and snapshots their SHA-256 digests and inode/mode/link/mtime metadata in private memory before staging attacker files. (Attackers can still read staged defender inputs under OS checks, so verification relies on integrity pinning and ExecSeal, not secrecy.)

  3. Outer host isolation and phase-attributed compromise detection: Running untrusted red-team submissions exercises attacker-controlled code against the same containment mechanisms under test, while rustc MIR capture runs outside ExecSeal and anneal-audit repository preflight runs outside an inner sandbox. The harness therefore enforces an outer credential-free boundary: by default it wraps cargo anneal verify, inspect, anneal-audit, .olean compilation, and olean_audit.lean in an empty-rootfs, netless Linux Bubblewrap (bwrap --unshare-all) sandbox with no access to host home directories, SSH/Git credentials, host /tmp, or repository working trees (binding only explicit tool binaries and toolchain directories, while ExecSeal, via Bubblewrap or Landlock/seccomp, runs nested inside with scrubbed environment variables, an isolated .olean cache via --olean-cache-dir, and zero --allow-* flags). If outer bwrap is unavailable, evaluate and replay-tripwires fail closed as HARNESS_ERROR unless --isolated-host (or ANNEAL_REDTEAM_ISOLATED_HOST=1) confirms execution inside a disposable, credential-free container or VM with no ambient tokens or credential files. If any submission mutates, replaces, adds, makes unreadable (chmod 0o111), or deletes defender-locked files, pinned .olean outputs, or pinned tool binaries (including anneal-audit and olean_audit.lean) during staging, verify, inspect, or audit, the harness reports ATTACKER_WON_HARNESS_COMPROMISED (P0, highest-severity soundness or integrity escape) with compromise_phase and per-file expected and actual SHA-256 digests regardless of exit code or timeout (terminating any lingering process-group descendants before checks run). Only verify-phase compromise sets sandbox_escape_detected: true.

    Example attack: A custom elaborator or post-build command atomically replaces Spec.lean with identical bytes or drops an extra file into trusted/; checking inode numbers, metadata, and strict subtree file sets in a finally: block catches the swap and classifies it by phase.

  4. Zero-weakening verification and .olean kernel auditing: cargo anneal verify requires elaboration_sandbox != "none", strict Receipt v3 checks (allowing only standard Lean axioms and baseline accepted limitations—review-surface coverage and binary correspondence—while rejecting any extra deferrals or verification taint flags), --receipt-out equality with stdout, and cargo anneal inspect cross-checks (--require-untainted, --require-containment, --verify-artifacts, --require-exact-artifacts). An exit-0 verify on a known-broken defender target (PROOF_HACK or SPEC_PREFLIGHT_HACK) always counts as ATTACKER_WON_ANNEAL_COMPROMISED: clean verify + inspect acceptance deduplicates by witness_hash, while self-reported policy, sandbox, sorry_declarations, or audit anomalies, drifted exit-0 Receipt v3 envelopes, unsafe artifacts/ entries, missing, non-UTF-8, or mismatched --receipt-out files, or inspect rejections, timeouts, signals, or invalid output are recorded as deterministic deduplication anomalies rather than discarded as HARNESS_ERROR. Exit code 1 counts as DEFENDER_HELD_ANNEAL_FAIL_CLOSED only on a valid untainted Receipt v3 reporting proof_failed (verified against a per-scenario sorry-proof control confirming the defender fixture compiles to audit sorryAx, including deterministic heartbeat/recursion limits) or proof-phase unsupported. For spec_preflight_soundness and theory_audit_soundness, ci/redteam/olean_audit.lean also inspects compiled .olean artifacts (including all compiled Anneal.* theory dependencies staged via isolated per-module outputs into a read-only theory-lib directory) at trustLevel := 0 with loadExts := false, sysroot-first search order, and fresh kernel replay (Kernel.Environment.replay) inside Bubblewrap to catch custom axioms, sorryAx, debug.skipKernelTC, compiler reflection (Lean.ofReduceBool, Lean.trustCompiler), unsafe, unpaired partial or opaque declarations, @[implemented_by]/@[extern]/@[csimp]/ @[export]/@[init] codegen hooks, forbidden effectful Lean.* (banLeanRoot), IO/Task/Internal.UV/Std.Async/Std.Http/ System.* escapes, debug/pointer/dynlib identifiers (dbgTrace, withPtr*, loadDynlib), spec/theory panic checks, disallowed export aliases, transitive dependency escapes, reserved-namespace definitions (Proof/Specs/Incorrectness*), and direct False theorems—while mirroring Anneal's policy (_unsafe_rec pairing, Lean.Omega.*, pure Lean.Loop theory helpers, and realized matcher splitters) so benign helpers remain held. Any .olean violation triggers ATTACKER_WON_ANNEAL_COMPROMISED even if verify exited 1 (anneal_verify_ok: false).

    Example attack: A specification or theory helper hides a custom axiom, set_option debug.skipKernelTC true, or @[implemented_by] attribute past syntactic preflight (or a broken theory/ module is skipped when anneal-audit exits 0). Inspecting and kernel-replaying the compiled .olean directly surfaces RT-SP-<12hex> or RT-TA-<12hex>, normalizing violation categories so symbol renames share one bug ID while leaving clean omega specs and recursive helpers held.

Outcome-to-verdict truth table

Every red-team evaluation maps to one of eight shared verdict names (critical bugs are tagged P0, medium human-review findings P1 or P2, and repeating identical findings share deterministic RT-ESC-<12hex>, RT-PH-<12hex>, RT-SP-<12hex>, or RT-TA-<12hex> IDs):

VerdictScope & statusMeaningSeverity & dedup
INVALID_SUBMISSIONImplementedMalformed layout, link, out-of-slot file, reserved Lean module root, defender collision, missing/invalid explanation.md, or bad JSON schema.Non-bug (null)
ATTACKER_WON_HARNESS_COMPROMISEDImplemented (staging, verify, inspect, audit; oracle planned)Defender-locked asset or tool mutated, replaced, added, or deleted regardless of exit code or timeout; records compromise_phase and tampered_assets.P0 (RT-ESC-<12hex>)
ATTACKER_WON_ANNEAL_COMPROMISEDImplementedDefender assets intact; on known-broken targets, strict verify + inspect passed, verify exited 0 despite envelope/--receipt-out/audit/taint/inspect anomalies, or .olean audit exposed a bypass.P0 (RT-PH-* / RT-SP-* / RT-TA-*)
DEFENDER_HELD_ANNEAL_FAIL_CLOSEDImplementedDefender intact; Anneal rejected input (valid proof_failed/unsupported exit 1 or attributed anneal-audit failure), or benign theory passed.Held (null)
HARNESS_ERRORImplementedCrash, signal kill, missing tool, bad JSON, invalid exit-1 receipt, broken defender baseline, or timeout (exit 2; reserved in shared schema for oracle timeouts/OOMs).Inconclusive (null)
DEFENDER_HELD_CODE_CORRECTPlanned (code+proof)Defender assets intact; verify + inspect AND executable Miri/rustc oracle clean without semantics edits or explicit bug claims.Held (null)
DEFENDER_HELD_AUDIT_CATCHPlanned (code+proof)Defender assets intact; clean oracle, while submitted Lean semantics updates fail anneal-audit or semantics regression checks (preservation canaries).Held (null)
NEEDS_HUMAN_REVIEWPlanned (code+proof)(P1) Clean verify + oracle + passing semantics updates & canaries; OR (P2) clean verify + oracle with explicit prose_only_claim flag.P1 / P2

Mandatory brief, schema, and exit codes

Every submission across all challenges MUST include a top-level explanation.md (non-empty UTF-8 Markdown, <= 64 KiB). Missing or invalid files fail closed as INVALID_SUBMISSION. The harness excludes explanation.md and optional manifest.json from the verifier directory and from deduplication witness_hash hashes, surfacing only a SHA-256 digest and path-scrubbed excerpt in trace_artifacts under two supported modes:

  1. Human and AI-agent red-teamers: Explain the targeted weakness and walk through the submitted files.
  2. Programmatic generators (fuzzers and mutators): Emit a deterministic stand-in brief identifying the generator, seed or mutation strategy, and artifact interpretation. Because every submission must include explanation.md, it never triggers NEEDS_HUMAN_REVIEW alone (P2 triage is reserved for the explicit prose_only_claim flag in planned challenges).

CLI exit codes and output receipt (anneal-redteam-receipt/v1):

  • evaluate: Writes the JSON receipt (verdict, defender_integrity_ok, sandbox_escape_detected, compromise_phase, tampered_assets, proposed_severity, anneal_verify_ok, anneal_inspect_ok, target_sha, target_tree_oid, tool_provenance, verify_status, dedup, trace_artifacts), exiting 0 for any definitive outcome (including ATTACKER_WON_* and INVALID_SUBMISSION) and 2 only on HARNESS_ERROR.
  • replay-tripwires: Re-evaluates stored witnesses (anneal-redteam-replay/v1), exiting 0 if verdict matches a bypass for --expected-bug-id, 1 if not reproduced or mismatched, and 2 on HARNESS_ERROR.

Challenges and usage

Always run evaluate and replay-tripwires inside a throwaway, credential-free outer container or VM (outside outer bwrap, pass --isolated-host or ANNEAL_REDTEAM_ISOLATED_HOST=1 only after ensuring zero SSH, Git, cloud, or repo write access).

python3 -I -B ci/redteam/harness.py list-scenarios --json
Challenge IDDefender targetAttacker slotsBypass condition (ATTACKER_WON_ANNEAL_COMPROMISED)
proof_only_ubSafe trigger_ub() -> usize calling usize::MAX.unchecked_add(1), trivial Spec.specs.Proof/*.lean (Proof/Proof.lean required), explanation.md, optional manifest.jsonAny exit-0 verify acceptance on this broken target scores a P0 bypass (strict clean pass or drifted exit-0).
proof_only_wrong_returnSafe wrong_const() -> u64 { 1 } vs. Spec.specs (Spec.returnsZero requiring 0).Proof/*.lean (Proof/Proof.lean required), explanation.md, optional manifest.jsonAny exit-0 verify acceptance on this broken target scores a P0 bypass (strict clean pass or drifted exit-0).
spec_preflight_soundnessSafe trigger_ub() -> usize and request.json (plus default non-sorry Proof.lean if Proof/ is omitted).Spec/*.lean (Spec/Spec.lean required), optional Proof/*.lean, explanation.md, optional manifest.jsonAny exit-0 verify acceptance on trigger_ub, OR compiled Spec* .oleans contain forbidden axioms, codegen hooks, effects, or reserved-root decls.
theory_audit_soundnessPinned trusted/lean/, trusted/audit/{TrustedBoundary.lean,SpecPreflight.lean,library-lock.json} (with pinned anneal-audit), theory/bundle-manifest.json, and the 10-module MirWp core closure.theory/Anneal.lean or theory/Anneal/**/*.lean, explanation.md, optional manifest.jsonanneal-audit exits 0 with broken/non-standard .olean checks (axioms, unsafe/partial, @[implemented_by]/@[csimp], effects, Trusted.*, False theorem), whereas clean helpers remain held.
python3 -I -B ci/redteam/harness.py evaluate \
  --scenario proof_only_ub --submission-dir /path/to/sub --json-out /tmp/r.json

python3 -I -B ci/redteam/harness.py evaluate \
  --scenario theory_audit_soundness --submission-dir /path/to/sub \
  --auditor /path/to/anneal-audit --lean /path/to/lean --json-out /tmp/r.json

python3 -I -B ci/redteam/harness.py replay-tripwires \
  --scenario proof_only_ub --submission-dir /path/to/sub --json-out /tmp/w.json

python3 -I -B -m unittest discover -s ci/redteam -v

Related docs: Trust model, Architecture, Workspace composition, Elaborator containment and Receipt v3, and Prompt template.