Repository navigation
x86-64 residue analysis: classify each instruction once, linear order and meet - #4962
Merged
Merged
Conversation
The kernel spends nearly all of a residue check (`RTaint.rtaint`) on evaluating the analysis: every `RTaint.step` unfolded about ten wide matches on the instruction, `le` at hint taints compared slots quadratically, and so did `meet` at every `ite`. `rtaint` now evaluates functions proven equal to these (so every analysis, and every `keep_for%`, is the same): * `stepF`/`stepFn` classify the instruction before the taint is given, as the base analysis's `stepKDFn` does, so the kernel unfolds the matches on an instruction once; most instructions (`isPlain`) take the base step with the bounds of the register they write dropped, and stores without an index register a step of their own (`stepFn_eq`); * `leF` compares slots in one pass when one list is a sublist of the other in order, and numbers with `Nat.beq` (`leF_eq`); * `meetF` keeps equal slots as they are (`meetF_eq`, `meetT_eq`). `RScrub.Analysed.ok_of` now takes the end check `resOkF`, which checks only the window bytes `sec` lists (`resOkB_of_resOkF`), so its users gain without edits. `step` names its flags `flOf`; nothing else in `step`, `le`, `meet` or their soundness proofs changes. No TCB, Spec or generated code changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
alex
enabled auto-merge
November 11, 2026 15:49
reaperhulk
pushed a commit
that referenced
this pull request
Nov 11, 2026
#4962 moved resOkF, resOkB_of_resOkF and any_resOkB to ResidueScrub.lean; drop the copies here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
This was referenced Nov 11, 2026
reaperhulk
pushed a commit
that referenced
this pull request
Nov 11, 2026
… functions scrubbed The residue analysis (`RTaint`) now tracks the argument area above the return address: its length (`an`), its bytes that are the same in both runs (`sa`, from the public stack words) and the words that hold the address of a writable buffer passed on the stack (`sp`). A load `mov`/`mov32 d, [rsp + disp]` from the area gives a public register or a pointer into the buffer (`argPost`), so functions with more than six arguments can store through their stack-passed buffers. `ScrubAbi` carries the argument area and its no-wrap facts; `RScrub.init` sets `an`, `sa` and `sp`. Soundness is proven in `ResidueTaintSound.lean`. The kernel's fast paths (#4962) carry the new fields: `isPlain` excludes a `mov32` load based on `rsp` without an index (which `argPost` may change), `fastFn`/`fastStore` keep `an`/`sa`/`sp`, and `leF`/`meetF` compare and intersect them; `stepFn_eq`, `leF_eq` and `meetF_eq` still hold. The one-pass XTS data-unit functions `vg_aes_xts_{en,de}crypt_unit{,_to}_{vaes_vpclmul_avx512,vaes_vpclmul,aesni_pclmul}` now prove `NoResidue` with no stack wipe; their allowlist lines are removed. No TCB or Spec changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
reaperhulk
pushed a commit
that referenced
this pull request
Nov 11, 2026
… functions scrubbed The residue analysis (`RTaint`) now tracks the argument area above the return address: its length (`an`), its bytes that are the same in both runs (`sa`, from the public stack words) and the words that hold the address of a writable buffer passed on the stack (`sp`). A load `mov`/`mov32 d, [rsp + disp]` from the area gives a public register or a pointer into the buffer (`argPost`), so functions with more than six arguments can store through their stack-passed buffers. `ScrubAbi` carries the argument area and its no-wrap facts; `RScrub.init` sets `an`, `sa` and `sp`. Soundness is proven in `ResidueTaintSound.lean`. The kernel's fast paths (#4962) carry the new fields: `isPlain` excludes a `mov32` load based on `rsp` without an index (which `argPost` may change), `fastFn`/`fastStore` keep `an`/`sa`/`sp`, and `leF`/`meetF` compare and intersect them; `stepFn_eq`, `leF_eq` and `meetF_eq` still hold. The one-pass XTS data-unit functions `vg_aes_xts_{en,de}crypt_unit{,_to}_{vaes_vpclmul_avx512,vaes_vpclmul,aesni_pclmul}` now prove `NoResidue` with no stack wipe; their allowlist lines are removed. No TCB or Spec changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
reaperhulk
pushed a commit
that referenced
this pull request
Nov 12, 2026
… functions scrubbed The residue analysis (`RTaint`) now tracks the argument area above the return address: its length (`an`), its bytes that are the same in both runs (`sa`, from the public stack words) and the words that hold the address of a writable buffer passed on the stack (`sp`). A load `mov`/`mov32 d, [rsp + disp]` from the area gives a public register or a pointer into the buffer (`argPost`), so functions with more than six arguments can store through their stack-passed buffers. `ScrubAbi` carries the argument area and its no-wrap facts; `RScrub.init` sets `an`, `sa` and `sp`. Soundness is proven in `ResidueTaintSound.lean`. The kernel's fast paths (#4962) carry the new fields: `isPlain` excludes a `mov32` load based on `rsp` without an index (which `argPost` may change), `fastFn`/`fastStore` keep `an`/`sa`/`sp`, and `leF`/`meetF` compare and intersect them; `stepFn_eq`, `leF_eq` and `meetF_eq` still hold. The one-pass XTS data-unit functions `vg_aes_xts_{en,de}crypt_unit{,_to}_{vaes_vpclmul_avx512,vaes_vpclmul,aesni_pclmul}` now prove `NoResidue` with no stack wipe; their allowlist lines are removed. No TCB or Spec changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
reaperhulk
pushed a commit
that referenced
this pull request
Nov 12, 2026
#4962 moved resOkF, resOkB_of_resOkF and any_resOkB to ResidueScrub.lean; drop the copies here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes the kernel's evaluation of the x86-64 residue analysis (
rtaint) about twice as fast. No analysis result changes: each new function is proven equal to the one it replaces. The emitter writes no change undercrates/.It is framework only. It touches three files in
Proof/Framework/X86_64/:ResidueTaint.lean,ResidueTaintSound.leanandResidueScrub.lean. Nothing underTCB/orSpec/changes, norX86_64/Taint.leanor the genericTaint.lean, so no constant-time proof is rebuilt. No user of the analysis is edited.Why
Profiling the residue checks (callgrind,
diagnostics, prototypes) found that about 95% of their cost is the kernel. Three things dominate it:RTaint.stepunfolds about ten widematch ionInstr(writesSp,special,post,ubNew, the flags,storeW/writesMeminmbAfter,clobbers). On the same code, the base analysis alone takes 1.1 s of kernel time wherertainttakes 6.0 s.leis checked at every hint.Taint.meetruns at everyite.What
One classification per instruction:
RTaint.stepFn : Instr → RStepis shaped like the base analysis'sstepKDFn. Its one match on the instruction holds no taint, so the kernel evaluates it once per instruction. It has two fast paths:fastFn, for instructionsisPlainaccepts: the base step, with the written register's bounds dropped and the flags cleared.fastStore, for stores without an index register.Every other instruction falls back to
step.stepFn_eqproves(stepFn i).run τ = step τ i.Linear order:
leFcompares the slots as an ordered sublist, falling back to the quadratic check, and compares numbers withNat.beq.leF_eqprovesleF = le.Cheaper meet:
meetFkeeps the slots as they are when both sides are equal, and otherwise filters withKList.meetF_eqprovesmeetF = meet.Cheaper end check:
RScrub.Analysed.ok_ofnow checks only the bytesseclists (resOkF) and still concludesresOkB, throughresOkB_of_resOkF. The two checks accept exactly the same taints, and the 216 users ofok_ofin 90 files build unchanged.Compiled code: like
VG.KList, the three helpers written withList.rec(natsEq,subl,eqs3) carry@[implemented_by]for compiled code, each next to its equality lemma.rtaintnow usesstepF,meetFandleF. Its soundness fields reuse the existing proofs through these equalities, sostep_soundis unchanged.Cost
Measured locally with
lean -j2and the profiler, run one at a time on the same machine:ResidueTaintSound(14.8 → 18.3 s).No benchmark run: the generated code is unchanged.
Checks
All passed locally:
lake build;lake env lean --run Emit.lean(no change undercrates/), then--check;check_lean_public_imports.py --base origin/mainon the three modules;cargo fmt --check,cargo clippy --all-targets -- -D warnings;cargo test, and theVG_CPU_FEATURES=nonerun.Generated by Claude Code