Skip to content

Bignum/Mont: remove dead declarations and modules - #4367

Merged
alex merged 7 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-bignum
Nov 6, 2026
Merged

alex merged 7 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-bignum

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 (DSA) and #4314 (ECDSA), this removes the Bignum, Mont and Divstep proof and implementation declarations that nothing reachable uses. That is 1,384 declarations, including 181 whole modules. Words and Words64 had nothing dead.

  • No file under Spec/, TCB/, src/ or crates/ changes. Emit.lean --check passes, so the emitted code is identical.
  • No Spec/ module belongs to this scope, so there are no dead Spec/ definitions to report.

459 files, +262 / −21,133.

How "dead" was decided

The method of tools/deadcode/README.md (on the tooling branch), as for #4305 and #4314.

  • Graph. A declaration-level graph from the .ilean files of a full build of main.
  • 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, kept by the README's rules:
    • Literals found by name. Every module-level command of a module the roots import is live.
    • Tactics, macros and notation. A module that defines syntax is never deleted.
    • Attributes and instances. These are live in modules the roots import.
  • Two more rules, added after the first build failed. Both keep more; neither removes more:
    • Names in macro bodies. A declaration is live when a syntax definition's body names it and the declaration is in that definition's module or one it imports. Macro hygiene resolves names there. For example, brun and its siblings name the exec_*, rd_mem, wr_mem and sp_mem lemmas of Proof/Bignum/{AArch64,PPC64LE,RISCV64}/Run.lean. This keeps 39 declarations.
    • Names in syntax quotations and name literals. A declaration is live when a `(…) quotation or a `name literal in meta code names it. A full name counts wherever the declaration is defined, since it resolves where the syntax is used. This keeps 6 declarations. Example: RSA's and FFDH's rsa_stack_shape tactic applies VG.Proof.Mont.X86.StaticSquare.seq_noSp/ite_noSp.
  • Iteration. The plan was iterated with live4, leaving out deleted modules, to a fixed point.
  • Final check. The full build is the arbiter.
  • Rerun on the result: the analysis finds nothing more to remove in scope but the generated declaration of a local notation (below).

Removed

181 modules (171 under Proof/, 10 under Impl/): 120 Mont, 61 Bignum. 687 of the declarations were in them.

697 declarations from 252 modules that remain:

  • unused helpers and *_ct, *_ok and *_wp lemmas;
  • the operations at constant offsets that nothing calls:
    • mul, add and sub in Impl/Mont/Arm.lean, where the register-based mulR, addR and subR and the shared parts stay;
    • mul and add in Impl/Mont/X86.lean, where sub, row, csub and chain stay;
  • 10 unused lemmas in five Proof/Divstep/ modules.

27 top-level Verified proofs of routines that no registration exports. Each proves that an internal routine meets a contract as if it were exported. No registration file exports any of them on any target: the live roots never reach them, and they are reached only as internal callees, whose correctness and constant-time proofs stay. The emitted functions are unchanged.

  • AArch64:
    • MontFn.fn_verified, MontFn.mul_verified, MontFn.Product.mul_verified;
    • WindowHelper.verified, WindowShared.verified.
  • ARMv7: mont_verified, montCallUmaal_verified, montCallSquareU_verified, umaalRows_verified.
  • PPC64LE: mul_verified, scratch_verified.
  • x86-64:
    • MontFn.{fn,fnLazy,fnAdx,fnAdxLazy}_verified;
    • FoldedPublic.{base,adx,checked}_verified;
    • Ifma.verified, crt_verified, precompute_verified.
  • x86, Mont:
    • Compact.verified, Square.verified, StaticSquare.verified;
    • Rt.rt_verified, Rt.rt_scalar_verified;
    • Sse2.at_verified.

Outside the scope's directories, imports only:

  • Lines that imported deleted modules are dropped from 11 files of RSA, RSA-OAEP, and the DsaArithmetic, MillerRabin and RsaPrivateCrt variant proofs.
  • lean/VerifiedGarbageAuditBase.lean is regenerated with ci/audit_base.py generate. It drops import Init.Data.Bool, which only the deleted Proof/Mont/X86/StaticSquare/CarryMath.lean imported. TCB/AuditBase.lean is byte-identical.

Follow-on edits within the scope:

  • Where a deleted module passed imports on, its importers now import those modules themselves: 32 files. check_lean_public_imports passes on them.
  • opens of namespaces that no longer exist, empty sections and namespace blocks are removed.
  • About 60 doc comments that named removed declarations are reworded. Several module headers now describe what remains (Impl/Mont/{X86,Arm}.lean, Proof/Mont/{X86,Arm}/Ops.lean, Proof/Mont/X86/OutsZ.lean, Proof/Bignum/PPC64LE/Mont{Fn,Save,Verified}.lean).

Kept on purpose

  • 14 modules that other algorithms' registrations import, kept whole, with what they use:
    • Proof/Bignum/{X86/PublicRt/Verified, Arm/PublicVerified, Arm/PublicEntry, Arm/PublicEntryReady, AArch64/SquareHelper, PPC64LE/CrtVerified, RISCV64/CrtVerified}, which Artifacts/Rsa/* and Generic/RsaPrivateCrt/Arm/* import;
    • Proof/Mont/X86/{Exponentiate, ExponentLoop, ExponentStep, DynamicSelect}, which Generic/RsaPrivateCrt/X86/* imports;
    • Proof/Mont/X86/{SparseShift, SparseStep, P256Red}, which Generic/BrainpoolP{256,384}r1/X86/* imports.
  • Declarations that other algorithms' code refers to, even where that code is dead too, for a later pass:
    • 25 used by FFDH (e.g. Bignum.Arm.TwoExp);
    • 13 used by RSA and RSA key generation (e.g. Bignum.AArch64.pubContract, Bignum.X86.storeBE_truncated_ok);
    • 243 more in scope that only those, or the kept modules, reach.
  • 45 declarations that macro bodies or syntax quotations name (above).
  • local notation "CLay" in Proof/Bignum/X86_64/Ifma/CTMain.lean. Its generated macro_rules declaration has no references, so the analysis lists it, but live proofs use the notation.
  • Module names. Some trimmed modules keep names that describe what they used to hold (PPC64LE/MontVerified, Mont/X86/OutsZ), because other algorithms import them. Renaming them is not this PR's change.

Checks

  • Lean:

    • the full lake build --log-level=warning passes on this branch rebased onto c47391f70 (28,454 jobs, on the restored CI cache);
    • Emit.lean --check passes, with the standard axiom audit and no change to any crate;
    • check_lean_public_imports --base origin/main passes on the modified modules.
  • Static checks: every step of the job passes, including check_lean_single_importer --base origin/main, audit_base check and run_unit_tests.

  • Rust: cargo fmt --check and cargo clippy --all-targets -- -D warnings pass. No Rust changed.

  • No escape hatches: nothing adds sorry, admit, native_decide, bv_decide or maxHeartbeats.

  • No trust changes: no Spec/ or TCB/ file changes.

  • After rebasing onto de183ea71 (19 more commits, including the FFDH/Miller-Rabin, RSA and other dead-code removals):

    • no file imports a deleted module;
    • none of the 2,161 Lean files changed upstream names a removed declaration in full;
    • check_registrations and audit_base check pass.

    The CI Lean build on the merge commit is the final check.

No benchmark: the emitted code is unchanged.


Generated by Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvsvcgXj2u5S6o9SeM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvsvcgXj2u5S6o9SeM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvsvcgXj2u5S6o9SeM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvsvcgXj2u5S6o9SeM
No file imports Init.Data.Bool any more; TCB/AuditBase.lean is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvsvcgXj2u5S6o9SeM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvsvcgXj2u5S6o9SeM
@alex
alex enabled auto-merge November 6, 2026 20:46
@alex
alex added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit bc1b10f Nov 6, 2026
25 checks passed
@alex
alex deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-bignum branch November 6, 2026 21:59
alex pushed a commit that referenced this pull request Nov 7, 2026
…SA modules it uses (work in progress)

Main's dead-code removals (#4305, #4336, #4344, #4367) deleted RISC-V
modules and declarations that only this search uses. Restore them as
they were before each removal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHGhkN8REQLPW8yxN5A
alex pushed a commit that referenced this pull request Nov 7, 2026
Main removed declarations only this branch still used (#4336, #4367,
#4514): `fin64_exec_li_lit`, the RISC-V Miller–Rabin search pieces the
sieved parameter candidate calls, and three of `ModExpWin`'s WP lemmas.
They return, unchanged, as FFDH-only modules (`Proof/Ffdh/RISCV64/Li.lean`,
`Impl/Ffdh/RISCV64/Search.lean`, `Proof/Ffdh/RISCV64/Search.lean`) and
local lemmas in `Cached/Rows.lean`. The registrations drop `consts :=`
(#4380). The generated code takes #4514's Montgomery schedule and #4468's
dispatcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHHEKNw8eCDhgbwoFBL
alex pushed a commit that referenced this pull request Nov 15, 2026
Main removed declarations only this branch still used (#4336, #4367,
#4514): `fin64_exec_li_lit`, the RISC-V Miller–Rabin search pieces the
sieved parameter candidate calls, and three of `ModExpWin`'s WP lemmas.
They return, unchanged, as FFDH-only modules (`Proof/Ffdh/RISCV64/Li.lean`,
`Impl/Ffdh/RISCV64/Search.lean`, `Proof/Ffdh/RISCV64/Search.lean`) and
local lemmas in `Cached/Rows.lean`. The registrations drop `consts :=`
(#4380). The generated code takes #4514's Montgomery schedule and #4468's
dispatcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TKUFHHEKNw8eCDhgbwoFBL
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.

3 participants