Skip to content

ML-KEM: remove dead declarations and modules - #4354

Merged
reaperhulk merged 4 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-mlkem
Nov 6, 2026
Merged

reaperhulk merged 4 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-mlkem

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 (DSA) and #4314 (ECDSA), this removes the ML-KEM and ML-KEM-1024 proof and implementation declarations that nothing reachable uses: 986 declarations (944 ML-KEM, 42 ML-KEM-1024), including 24 whole modules.

  • Nothing in Spec/, TCB/, src/ or the generated crates changes. Emit.lean --check passes, so the emitted code is identical.
  • 336 files, +104 / −10,796.

How "dead" was decided

The method of tools/deadcode/README.md (on the tooling branch):

  • Graph. A declaration-level graph from the .ilean files of a full build.
  • Live roots. Every declaration in Artifacts/, Generic/, Variants/, TCB/ and VerifiedGarbageTest/; the non-Spec modules the lakefile names; the modules the top-level *.lean files import.
  • Uses the .ilean files don't record:
    • Literals found by name (rw_lit, lit_decide, taint_decide): every module-level command of a module the roots import is live, with what it materializes.
    • Tactics, macros and notation: a module that defines syntax is never deleted.
    • Attributes and instances: anything with a simp-set or instance attribute in a module the roots import is live.
  • Applied to a fixed point, then the full build as the arbiter.

For this PR I added one more conservative rule (below, "Kept on purpose"): a name that a tactic, macro or elaborator body mentions is kept, as are the auxiliary declarations of macro_rules/elab_rules. Quotations leave no .ilean reference, and a missing lemma inside first | … | … would only make a tactic fall through silently rather than fail the build.

Removed

Modules (24):

  • Impl/MlKem/AArch64/Dot (the 32-bit fused dot product; the 16-bit DotW stays)
  • Proof/MlKem/AArch64/Dot/{Accumulate,Arithmetic,Ready,Reduce}
  • Proof/MlKem/AArch64/Kem16/Encrypt
  • Proof/MlKem/AArch64/Noise/{LayoutAll,LayoutPair,ReadonlyLayoutTables}
  • Proof/MlKem/AArch64/Ntt16/{Pass1,Readonly/At,Readonly/Pre}
  • Proof/MlKem/AArch64/NttR/{VerifiedF,VerifiedFI}
  • Proof/MlKem/AArch64/Optimized/{Contracts,Depth,KemNoise,KeyGenNoise,Taints,TransformTablesExec}
  • Proof/MlKem/{KpkeKgRowsContract,Ntt16Contract}
  • Proof/MlKem/X86_64/{Sample16,YNttLay42}

Declarations: 962 more from 284 modules that remain. Among them:

  • the default-callee abbreviations of AArch64 SampleNTT (sampleFull, sampleFast, sampleSqueeze{,N}, sampleNTT; the …With forms stay);
  • x86-64 AVX2 NTT layer code that ML-KEM no longer uses (ylay*, yzeta*, vibflyL, ypack and their proofs; ML-DSA has its own);
  • the ML-KEM-768 abbreviations and the …_mono lemmas of Proof/MlKem/KPke.lean, ntt_eq_ops/nttInv_eq_ops;
  • unused helpers, *_ct, *_wp and frame lemmas.

109 top-level Verified proofs (and _of helpers) of routines that no registration exports. No registration file exports any of them on any target: AArch64's ML-KEM registration exports only checkEk, MlKem16/AArch64's artifact list is empty, and on the other targets they are reached only as internal callees, whose correctness and constant-time proofs stay. They are:

  • AArch64: Decaps.decaps_verified, Encaps.encaps_verified, KeyGen.keyGen_verified, CE.compressEncode_verified, DD.decodeDecompress_verified, Cbd16.verified, Cbd16W.verified, Cbd2.cbd2_verified, Codec16.{dec,enc}_verified, Decode12.decode12_verified, Encode12.encode12_verified, Mul.mul_verified, Ntt16.{ntt,ntt_inv}_verified, NttR.{fast,fastInv}_verified, Sample.sample_verified{,With}, add_verified, sub_verified; ML-KEM-1024's Decaps.decaps_verified, Encaps.encaps_verified, KeyGen.keyGen_verified, CE.compressEncode_verified, DD.decodeDecompress_verified;
  • ARMv7, PPC64LE, RISC-V: each target's Add.{add,sub}_verified, Cbd2, CompressEncode, Decode12, Encode12, Mul, Ntt, NttInv, Sample and Decompress/DecodeDecompress .verified; ML-KEM-1024's CompressEncode.verified and Decompress.verified;
  • x86-64: add, sub, cbd2, cbd2_16Y, compressEncode, decodeDecompress, decode12, encode12, mul, ntt, nttInv, sample, sample16, sample4_16, sample4_scalar, {dec,enc,kg}Mul{3,4}, {dec,enc,kg}MulSse{3,4}, kgNtt768, kgRow768, kpke{Dec,Enc,Kg}768Y _verified, with kpke{Dec,Enc,Kg}768_of and sample4_16_of_correct; ML-KEM-1024's compressEncode1024, decodeDecompress1024, kpke{Dec,Enc,Kg}1024Y _verified and kpke{Dec,Enc,Kg}1024_of.

Outside the ML-KEM directories:

  • Artifacts/MlKem/X86_64.lean and Artifacts/MlKem16/AArch64.lean only drop imports of deleted modules (check_registrations passes).
  • Proof/MlDsa/X86_64/KeyGen/Call.lean only drops an import of a deleted module.

Edits that come with the removal:

  • Impl/MlKem/AArch64/{DotW,OptimizedUsing} no longer open the deleted Dot namespace; Optimized/KemUContext, Kem16/KgRows, Kem16/URow and Kem16P/URow import Noise.Layout (and KemUContext Impl…Noise) directly, which deleted modules used to pass on.
  • Dangling omit … in / set_option … in lines, empty sections and section headers are removed.
  • Doc comments that named removed declarations are reworded, including the module docs of modules that are now much smaller (Impl/MlKem/X86_64/NttAvx2, Proof/MlKem/AArch64/Ntt16/{Idx,Rows,Mem}, Proof/MlKem/X86_64/{YNtt,YNttLay,YNttPack}).

Kept on purpose

72 declarations the analysis still reports dead in scope, all kept for a stated reason:

  • Named in tactic, macro or elaborator bodies (no .ilean reference):
    • offsetNames (lom_unfold);
    • Decaps.offs, Encaps.offs (dek, enk);
    • X86.Enc.{ok_sc,okW_sc,sep_sc,ptrTo_sc} (sc_decide, sc_taint);
    • X86.ea_at, used by ML-DSA's x86 tactics;
    • AArch64.reduced_zero, coeffAt_zero, X86_64.reduced_zero (mlkem_implies and ML-DSA's);
    • the {Arm,PPC64LE,RISCV64}.{KeyGen,Encaps,Decaps}.lay{,M}_sizes;
    • x86-64's setReg_*/setFlags_*/arithFlags_eq/sx* simp-set macros;
    • xdLe_*, ctlOk_{call,ite}, all_{call,ite}, Codecs.{ce,dd}_{ctl,sp};
    • ArithOk.{dm,em,km}_{ctl,sp}, which s4_ctl reaches as ($v).arith.dm_ctl.
  • The auxiliary declarations of macro_rules/elab_rules in AArch64/Lay, X86/TopKem, X86_64/{KgH16Sel,Sample4Impl,Top16Ctl} and the +++ notation of the x86 Impl modules.

Dead Spec/ definitions noticed (not changed here)

  • VG.Spec.MlKem.keyGenInternal_h (Spec/MlKem.lean): the only dead one of Spec/MlKem (1 of 103). For the separate Spec PR.

Checks

  • Lean:
    • the full lake build --log-level=warning passes, before and after rebasing onto main (e7072b2);
    • Emit.lean --check passes with the standard axiom audit, both times;
    • check_lean_public_imports --base origin/main passes on the 312 modified modules.
  • Static checks: every step of the Static checks job passes, with check_lean_single_importer --base origin/main; ci/run_unit_tests.py passes (641 tests).
  • Rust: cargo fmt --check and cargo clippy --all-targets -- -D warnings pass. No Rust changed.
  • No escape hatches: nothing adds sorry, native_decide, bv_decide or maxHeartbeats.
  • Analysis re-run: nothing dead is left in scope beyond the 72 kept above.
  • main has since moved 4 commits (1,414 Lean files, none under ML-KEM): no added line there imports a deleted module or names a removed declaration. The CI Lean build on the merge commit is the final check.

No Spec/ or TCB/ file and no generated crate changes. No benchmark: the emitted code is unchanged.


Generated by Claude Code

@reaperhulk
reaperhulk force-pushed the claude/unify-random-bytes-crypto-xqmg0z-deadcode-mlkem branch from 31a3086 to 1784e87 Compare November 6, 2026 19:33
@reaperhulk
reaperhulk enabled auto-merge November 6, 2026 19:39
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 6, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWuV9czH33R5Wq5Tr46
… passed on

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWuV9czH33R5Wq5Tr46
@reaperhulk
reaperhulk force-pushed the claude/unify-random-bytes-crypto-xqmg0z-deadcode-mlkem branch from 1784e87 to fee2d0c Compare November 6, 2026 20:16
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 03573f4 Nov 6, 2026
25 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-mlkem branch November 6, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants