proof-scaling
Use when proving `Expected.claim` in Anneal Lean modules, diagnosing Lean RSS or heartbeat timeouts, choosing `Model + DomainProof` vs `MirRefines`, or authoring Pass-1 `Anneal.*` lemmas under TrustedBoundary. Not for CLI basics (use cargo-anneal) or changing specs (use spec-authoring).
Warnings for the author
- Listed once through the skills extension, as skills/proof-scaling/SKILL.md: this copy is identical.
Scale Anneal Lean proofs
Use this skill once Spec.lean / Spec.* is frozen (spec-authoring) and
direct execProg simplification stalls, blows memory, or hits kernel reduction
limits. Never weaken Specs.safety or Specs.property to force a proof
through.
Step 1: Pre-flight environment and MIR support check
Before decomposing a proof, verify the toolchain actually captures the target:
- Run
cargo anneal verify ... --artifacts <dir>once and inspectcapture/capture.json(selected,program) andgenerated/Expected.lean. Ifunsupportedorcompiler_failedappears, stop and report the exact unsupported Rust construct rather than refactoring blindly. - Respect host memory budgets: prefer interactive Lean 4 LSP queries (your
editor, host
lake serve, or, in an Anneal repository checkout,ci/anneal-lspfor zero-lakefilerequest.jsonunits and in-memorytrytactic checks with no.leanedits; once clean, verify the final receipt withcargo anneal verify) over repeated coldlake env leanruns, and do not launch parallel unboundedleanbuilds. In an Anneal repository checkout, wrap CLIlean/lake/cargoinvocations inci/anneal-lean-run; outside a repository checkout, pass--lean-memory-mb <MB>tocargo annealor wrap CLIlake/leanbuilds in an OS cgroup memory cap. On delegatedsystemd --userLinux hosts,ci/anneal-lean-runreconcilesanneal-workloads.slicein the user manager'sUnitPath(MemoryMax,MemoryHighat 94%,MemorySwapMax=0,ManagedOOMMemoryPressure=killat 40% PSI, reloadingsystemd --useron change) and enforces a scopeMemoryMax/MemorySwapMax=0cap (--memory-max-mb <MB>overrides thatMemoryMaxand derivedlean -M, clamped to the slice ceiling on cgroup-capped hosts unless--unsafe-ignore-cgroupis passed). Without an active Linux usersystemdscope (including non-systemd Linux and macOS),ci/anneal-lean-runenforces no OS memory cap (--memory-max-mb <MB>only sets Lean's-Mallocator flag for directleanandlake env lean, notlake buildorcargo). Separately,cargo anneal verify --lean-memory-mb <MB>sets-Moncargo-anneal's internal Lean runs (subject to its mode floors) regardless ofsystemd. - Diagnose Day-2 Rust bugs first (
cargo-annealStep 0): ifExpected.leanreveals a missing guard or bad branch in Rust, fix Rust or escalate the spec mismatch before tuning tactics.
Step 2: Choose the right proof architecture
Pick the smallest decomposition matching the code pattern:
Model + DomainProof(pure/arithmetic/bitwise code): Separate a clean pure Lean modelMfrom MIR execution: proveMirRefinesModel(the captured MIR returnsM xwithout UB/divergence) once via WP/PureLift, then proveSpec (M x)purely mathematically overM(DomainProof).Scalar == unsafe SIMD(optimized/SIMD code): Prove equivalence (or refinement) between theunsafe/vectorized MIR and a simple scalar reference model, rather than rewriting production Rust into slow "verifiable" code.- Keep
Expected.leanuntouched: Never bypassExpected.claimor smuggle axioms/tactics intoSpec.*. IfPureLift/MirWpfails to discharge an inner block cleanly, refine invariants on clean boundary sub-lemmas.
Step 3: Certificate-first and 6 algebraic representation shifts
Reach first for the bundled Anneal.* certificate and lemma libraries shipped
with cargo anneal (listed in share/anneal/theory/bundle-manifest.json in an
installed bundle), then apply structural representation shifts:
Bundled cert & lemma modules (shipped with cargo anneal):
- Zero-manual-WP MIR abstract-interpretation PCC (
AutoProve, unsigned & signedi8..i128/isize,bool,unit, Bourdoncle cutpoints):Anneal.AiPcc,Anneal.AiPcc.MirPcc,Anneal.AiPcc.MirBridge,Anneal.AiPcc.MirTransfer,Anneal.AiPcc.ReducedProduct,Anneal.AiPcc.Tnum,Anneal.AiPcc.WrappedInterval,Anneal.AiPcc.BitArith - Linear arithmetic Farkas certificates (replaces
omegain restricted theory modules):Anneal.LinearArith - Bitvector/SAT LRAT certificates and linear
BitVecoffset normalization (replacesbv_decidein restricted theory modules):Anneal.BitTrieLrat,Anneal.BitVec,Anneal.BitVecArith,Anneal.PureLift.BvLin - Classical law-of-excluded-middle & core
Inithelpers (replacesby_casesin restricted theory modules):Anneal.ClassicalEm,Anneal.InitLemmas,Anneal.NatBitwise - MIR WP, step cores, symbolic execution, and envelope soundness:
Anneal.MirWp,Anneal.MirWp.Core,Anneal.MirWp.Execution,Anneal.MirWp.Reflection,Anneal.MirWp.Scalars,Anneal.MirWp.V2Memory,Anneal.MirWp.V2StepShield,Anneal.Wp,Anneal.Scalar,Anneal.MirTotal.Ops,Anneal.MirTotal.StepCore,Anneal.MirSymExec,Anneal.MirSymExec.Bits,Anneal.MirSymExecCall,Anneal.Framework,Anneal.Framework.Link,Anneal.Framework.StepWp,Anneal.CppEquiv,Anneal.PureLift.CppBridge - Loop invariants, byte/chunk layouts, forcing,
whnf/rewrite firewalls, path trees, and SCC sharding:Anneal.LoopInv,Anneal.LeBytes,Anneal.ListChunks,Anneal.SpineForce,Anneal.Firewall,Anneal.PTree,Anneal.SccSharding,Anneal.SccSharding.BinChunkTree,Anneal.SccSharding.InterprocCallModel
Note: Anneal.MirTotal.Ops, Anneal.MirTotal.StepCore,
Anneal.PureLift.BvLin, and Anneal.PureLift.CppBridge are bundled with
cargo anneal above, while unbundled modules in an Anneal source checkout
(such as Anneal.PureLift, Anneal.Simd, Anneal.Core, and the rest of
MirTotal and PureLift) are available only inside the repository tree
(bundle-manifest.json lists the bundled subset).
When and how to use Anneal.LinearArith (and ci/farkas_cert_gen.py):
Reach for Anneal.LinearArith (bundled in both cargo-anneal and
google/anneal) when proving multi-variable linear Nat/Int inequalities or
parity/alignment floor cuts inside Pass-1 (prelude + Init.*-only) proofs
where omega is unavailable or kernel reduction stalls (use
Anneal.BitVec/Anneal.BitTrieLrat for bitwise/SAT problems, or rfl for
closed constants). Directly write a NatCutGoal/IntCutGoal + List CutStep
proof checked by checkNatCutGoal_sound/checkIntCutGoal_sound with rfl.
In an Anneal source checkout (not installed with standalone cargo-anneal),
run python3 ci/farkas_cert_gen.py with --domain <nat|int>, --hyp "...",
and --goal "..." (or fetch the script from https://github.com/google/anneal)
to emit a balanced certificate bounded within Lean's default maxRecDepth=512
and --max-nodes search budget.
Kernel-recursion & whnf guardrails (avoid #4292 / #4295 traps):
-
Use
Anneal.AiPcc.MirPcc(AutoProve) first for acyclic scalar/signed safety:AutoProve.bodyVerified_of_autoVerifyAcyclic rfl rfl rfldischargesBodyVerifiedfor unsigned/signed integer,bool, andunitbodies with zero manual WP stepping. For loops,AutoProve.bodyVerified_of_autoVerifyCutpointsverifies caller-supplied Bourdoncle cutpointMirAbsEnvinvariants in one pass. -
Abstract-modulus
Nfor signed casts &BitVec 128arithmetic: Never unfoldInt.subNatNat (2^128) kor concrete2^64/2^128numerals inside kernelwhnf(Lean's C++ kernel hits(kernel) deep recursion detected). Rewrite viaAnneal.MirWp.Scalars:evalIntToIntCast_signed_of_nonneg,evalIntToIntCast_signed_of_neg,evalIntToIntCast_signed_same_width,decodeScalar_signed_of_lt_half,decodeScalar_signed_of_ge_half,truncateScalar_unsigned_eq,truncateScalar_signed_eq, andevalBinOp_{bitAnd,bitOr,bitXor,shl_unsigned,shr_unsigned}_eq,evalBinOp_{add_unsigned,cmp}_eq. -
Flat entry locals: On bodies with many locals or storage annotations, precompute
entryLocalsTail bodyonce into a concretetail : List LocalSlotwithhTail : entryLocalsTail body = tail := rfl, rewriteinitLocalsLoop body args 0 body.localstoentryLocals body args tailviainitLocalsLoop_eq_entryLocals hValid (by decide) hTail, and pass that equality toAnneal.MirWp.safe_of_entryLocals/returns_of_entryLocals/executes_of_entryLocalsinstead of repeatedly unfoldinginitLocalsLoop/hasStorageAnnotation:-- Replace placeholders (`[...]`, `hSafeFromEntryLocals`) for your `body`: private def myTail : List LocalSlot := [...] -- concrete `entryLocalsTail` private theorem myTail_eq : entryLocalsTail body = myTail := rfl -- In the proof (`hValid : ValidEntryArgs body args`): have hLoc := initLocalsLoop_eq_entryLocals hValid (by decide) myTail_eq exact safe_of_entryLocals hLoc hSafeFromEntryLocals -- placeholder proof -
Beware
zetaHave& dead-branchDecidabletraps: Do not leave unusedhavebindings carrying large concrete expressions in scope acrossrfl/decide/dsimp, and do not reduceif h : P then ... else ...on symbolic2^64/2^128inequalities without first discharging the branch viaite_prop_true/ite_prop_falseorAnneal.InitLemmas(nat_mod_*,nat_div_*,int_ofNat_*,int_subNatNat_*,bool_*). Rundsimp onlybeforerwonlet-boundOps.leanbodies:rwturns eachletinto a non-dependenthave, whichdsimp only(zetaHave := false) then leaves alone. -
Prefer scalar closed forms over unfolding
Ops.lean(Anneal.MirWp.Scalars):- Decoding:
decodeScalar_unsigned_of_lt,decodeScalar_signed_of_lt_half,decodeScalar_signed_of_ge_half,truncateScalar_unsigned_eq,truncateScalar_signed_eq. - Casts:
evalIntToIntCast_unsigned,evalIntToIntCast_signed_of_nonneg,evalIntToIntCast_signed_of_neg,evalIntToIntCast_signed_same_width,evalIntToIntCast_bool. - Arithmetic and shifts at every width and signedness, in terms of
decodeScalar:evalBinOp_add_eq,evalBinOp_sub_eq,evalBinOp_mul_eq,evalBinOp_shl_eq,evalBinOp_shr_eq. - Unsigned closed forms:
evalBinOp_add_unsigned_eq,evalBinOp_sub_unsigned_eq,evalBinOp_mul_unsigned_eq,evalBinOp_shl_unsigned_eq,evalBinOp_shr_unsigned_eq,evalBinOp_shl_unsigned_signed_rhs_eq,evalBinOp_shr_unsigned_signed_rhs_eq(for untypedi32or other signed shift-amount literals), and, without overflow,evalBinOp_addUnchecked_unsigned_of_lt,evalBinOp_mulUnchecked_unsigned_of_lt,evalBinOp_subUnchecked_unsigned_of_le. - Bitwise and comparisons:
evalBinOp_bitAnd_eq,evalBinOp_bitOr_eq,evalBinOp_bitXor_eq,evalBinOp_cmp_eq. - Negative values stay behind abstract moduli
(
bvOfInt_negSucc_mod_of_dvd,truncateBits_bvOfInt_negSucc_toNat), so the kernel never subtracts a symbolic value from a literal2^128.
- Decoding:
6 algebraic representation shifts (when elaboration or whnf explodes):
- Import
prelude+ targetedInit.*(~152 MiBvs~473 MiB): Both pinnedcargo anneal verifyand repository theory checks reject monolithicimport Initfail-closed; importpreludeplus only targetedInit.*modules (the repository theory tree admits only the51foundation-locked modules, whereas pinnedcargo anneal verifyon target crates also admits sysroot modules covered by its embedded library lockfile, such asInit.Data.BitVec.Basic). - Defunctionalize closures and higher-order combinators: Replace captured
funclosures inside proof-carrying states with small inductive tags + an explicitevalfunction so kernel unification never reduces huge lambda terms. - Zero-
Prop-arg@[irreducible]barriers + flat-tuplecasesOn: Wrap large sub-expressions behind@[irreducible]definitions taking data args only (noPropfields hiding proofs inside data terms), and destructure flat product tuples withcasesOnrather than chained.1/.2projections. - Logarithmic lookup & chunked lists: Replace linear
Listindexing / deeply nested updates withAnneal.PTree(path trees) orAnneal.ListChunks. - Control reduction eagerly: Use
Anneal.SpineForceto force spine shapes beforerw/simpinstead of lettingwhnfunfold deep bitvectors/states. - Lift pure regions first: Factor pure computation with
Anneal.MirWp,Anneal.LoopInv, andAnneal.BitVec(and unbundledAnneal.PureLiftin an Anneal source checkout) before reasoned arithmetic/bitvector certs.
Step 4: Pass-1 TrustedBoundary rules (repository checkout only)
Target proof modules (TargetRole::Proof) in standalone crates import bundled
Anneal.* modules to prove Expected.claim and skip this step. Inside an
Anneal source checkout, when authoring Pass-1 libraries in the repository
theory or correspondence trees (SourceRole.theory), TrustedBoundary.lean
enforces:
- Imports:
prelude+ foundation-lockedInit.*+Trusted.*+ repository theory modules (the correspondence tree also admits sysroot foundationInit.*/Std.*/Lean.*, vendoredlean-miri, and sibling correspondence modules); axioms strictly in[propext, Quot.sound, Classical.choice]; zero._unsafe_rec. - Forbidden tactics/items:
omega,bv_decide,by_cases,native_decide,decide!,rfl',sorry,run_tac,sleep,dbg_trace,unhygienic,grind, and+native/+kernel(Parser.Tactic.configItem). - Allowed Pass-1 tactics (
allowedTheoryTacticKindsinTrustedBoundary.lean):
apply, cases, change, constructor, decide, dsimp, exact,
first, induction, injection, intro, left, refine, revert,
right, rw, simp, subst, have, let, nomatch, repeat, rfl,
unfold, funext, <;>
Step 5: Escape Tabu verification cliffs
If proof complexity crosses > 15:1 Lean-to-Rust LOC or you remain stuck on
the same goal across 2 focused turns without shrinking the remaining goal:
- Do not thrash. Stop adding ad-hoc
simprules or raw case splits. - Isolate the bottleneck: Extract the smallest failing sub-lemma or check
whether a Rust helper extraction / loop split / invariant rewrite makes the
MIR WP cleanly separable (propose Rust helper refactors to the caller; do
not silently alter
Spec.*or out-of-scope Rust files). - Rollback failed exploratory proof edits (
git checkout -- ...on your own scratch proof branch) before trying a new representation shift from Step 3. - Once
Expected.claimelaborates cleanly without--allow-sorry-in-proof, return tocargo-annealto capture and report the final untainted Receipt v3.
Files of this skill
This skill has no supporting files.