Repository navigation
x86-64: the residue analysis and scrub, an allowlist that only shrinks, and SHA-256, Poly1305 and ChaCha20 apply without residue - #4836
Merged
Conversation
RTaint extends the x86-64 taint analysis to the stack a function uses: it follows frames, calls and returns, bounded indices (clamped, or masked), pointers kept in public slots, zeroing idioms and buffer bytes the contract makes public, and finds the registers and stack granules that may hold secrets on return; it is proven sound (ResidueTaintSound). scrubReg follows a registration's code with a tail (Impl.Scrub.X86_64.scrubTail) that clears the vector registers and general-purpose registers the code may write and wipes those granules, and proves NoResidue and the same contract. withScrub does so given the analysis (Analysed, checked by the kernel with taint_decide), and leaves the registration as it is without one. CLAUDE.md and the adding-a-primitive skill say how to convert a function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
ci/check_residue_allowlist.py, a step of the Static checks job, refuses a line of ci/residue_allowlist.txt that the base branch does not have: a new x86-64 function proves that it returns without secret residue rather than joining the list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
…idue Each scrubbed (StreamFn.scrub) for the scalar, AVX2 and SHA-NI compression functions; their lines leave ci/residue_allowlist.txt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
Poly1305's init, finalize and update over the scalar vg_poly1305_blocks, and ChaCha20's apply over each implementation of vg_chacha20_xor (scalar, SSSE3, AVX2, AVX-512, AVX-512VL), scrubbed with withScrub. A generic caller's instance takes its analysis from the implementation (BlocksImpl.update, XorImpl.apply); the vector Poly1305 updates have none: the analysis does not follow ldmxcsr. apply's analysis starts with the state's count of keystream bytes left public, which its contract leaks (pubOk). ChaCha20-Poly1305 calls Poly1305's init code as vg_poly1305_init_core, since the exported vg_poly1305_init now clears what it leaves. Their lines leave ci/residue_allowlist.txt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa
This was referenced Nov 9, 2026
Merged
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.
Follows #4741, which added the property (
NoResidue) and the allowlist to the TCB. This PR proves the property for the first x86-64 functions and adds the framework that proves it. No trust change: nothing underTCB/orSpec/changes.The framework
The residue analysis (
Proof/Framework/X86_64/ResidueTaint.lean, proven sound inResidueTaintSound.lean). It extends the x86-64 taint analysis to the stack below the caller's stack pointer. It follows frames, calls and returns, and tracks:cmp; cmovb, or masked);At the end it lists the registers and stack granules that may hold secrets.
The scrub (
Impl/Scrub/X86_64.lean,Proof/Framework/X86_64/Scrub.lean,ResidueScrub.lean,ResidueKeep.lean).scrubRegfollows a registration's code with a tail that:It proves
NoResidueand the same contract, and setsRegistration.residue.withScrubtakes the analysis as a kernel-checked certificate (Analysed, bytaint_decide), so nothing runs at emit time. Givennone, it leaves the registration as it was.The ratchet
ci/check_residue_allowlist.py, a new step of the Static checks job, rejects any line ofci/residue_allowlist.txtthat the base branch does not have. The emitter already rejects a listed function that has a proof or no longer exists. So the list only shrinks, and converting a function removes its line. CLAUDE.md and theadding-a-primitiveskill now say this.Effect on other PRs: from now on, a PR that adds an x86-64 function proves the property instead of adding a line. That includes:
First conversions (17 lines off the list, 881 → 864)
vg_sha256_update,_finalizeand_digest, each for the scalar, AVX2 and SHA-NI implementations. MdStream x86-64: bound each indexed buffer store by clamping its index #4745's clamped buffer stores made these possible.vg_poly1305_init,vg_poly1305_finalize, andvg_poly1305_updateover the scalarvg_poly1305_blocks.vg_poly1305_init_core, since the exportedvg_poly1305_initnow clears what it leaves.ldmxcsr.vg_chacha20_applyover everyvg_chacha20_xorimplementation (scalar, SSSE3, AVX2, AVX-512, AVX-512VL). x86-64 ChaCha20 apply: keep the data and its length in r14 and r15, and take the state back after vg_chacha20_xor #4748's register change made these possible. The analysis starts with the state's count of keystream bytes left public, which the contract already letsapplyleak.Each registration file only binds the scrubbed registration, built in
Proof/.scrubRegcopies every other field,extraandvendorincluded, so what dispatch chooses does not change.Checks
lake build(all modules),Emit.lean --check, the Static checks job,check_lean_public_imports.pyon the 19 changed modules: pass.cargo fmt --check,cargo clippy --all-targets -- -D warnings: pass.cargo testwith Wycheproof, with every CPU feature and withVG_CPU_FEATURES=none: pass.sha256 poly1305 chacha20against TCB: x86-64 functions return without secret residue, but those an allowlist names #4741's merge, on an AMD EPYC 7763, one interleaved run. Nothing slowed by more than 5 ns:none(scalar), SHA-NI, AVX-512 and AVX-512VL: within ±1.6% at every size from 32 B to 16 KiB.avx,avx2,bmi1,bmi2(the AVX2 implementation): 3.4% slower at 32 B (140 → 145 ns), falling to 0.9% at 256 B.update(VG_CPU_FEATURES=none) is 7.1% slower at 64 B (56 → 60 ns), 3.3% at 480 B, 2.1% at 1 KiB, and unchanged from 4 KiB. Configurations that choose a vectorupdate(not converted) are within ±3.2%.none), which is noise.update, which is not converted.🤖 Generated with Claude Code
https://claude.ai/code/session_015ajQWxYnEynffr2A7QLPVa