Skip to content

FFDH/Miller-Rabin: remove dead declarations and modules - #4336

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

reaperhulk merged 2 commits into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-ffdh

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 (DSA) and #4314 (ECDSA), this removes the FFDH and Miller–Rabin proof and implementation declarations that nothing reachable uses: 964 declarations, including 63 whole modules.

  • Nothing in Spec/, TCB/, src/ or the generated crates changes. Emit.lean --check passes, so the emitted code is identical.
  • Every changed file is under Proof/Ffdh/, Impl/Ffdh/, Proof/MillerRabin/ or Impl/MillerRabin/. No registration file changes.

287 files, +88 / −14,490.

How "dead" was decided

This follows the method in tools/deadcode/README.md on the tooling branch.

  • Graph. A declaration-level graph built from the .ilean files of a full build at the base (880b9378c).
  • Live roots. The live set starts from:
    • 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. Every module-level command in a module the roots import is live, along with what it references, and Lit modules that live code imports stay.
    • Tactics, macros and notation. A module that defines syntax is never deleted.
    • Attributes and instances. Anything carrying an attribute such as simp or instance, in a module the roots import, is live.
  • Iteration. The analysis was iterated to a fixed point.
  • Final check. The full build is the arbiter. It found two blind spots in the scripts, covered under "Kept on purpose" below.

Removed

Modules: 63 whole modules.

  • 52 under Proof/Ffdh/, 3 under Impl/Ffdh/:
    • Impl/Ffdh/AArch64, Impl/Ffdh/Arm/KeyPower, Impl/Ffdh/Arm/KeyPowerDetect;
    • the Arm non-cached key generation and domain-check proofs: KeyBody, KeyFirst*, KeyGenerate*, KeyVerified, DomainVerified, DomainContractCT, VettedKeyGenerate*, ParameterCandidate/{CandidateScreenQ,SieveStep,…};
    • Proof/Ffdh/{Choose,KeyGeneration}, Proof/Ffdh/AArch64, AArch64/GenerateKey/Contract;
    • PPC64LE/GenerateKey/Fn;
    • X86/KeySearch/{ABI,Data,Entry};
    • X86_64/ParameterCandidate/{Backend,LoadCT}.
  • 7 under Proof/MillerRabin/ and 1 under Impl/MillerRabin/: the RISC-V blinded loop (Impl/MillerRabin/RISCV64/Blinded and Proof/MillerRabin/RISCV64/Blinded/{Ctx,Load,LoadCT,LoopCT,Round,RoundCT,WitnessCT}).

Declarations: 642 more, from the 218 modules that remain. Some examples:

  • the non-cached PPC64LE GenerateKey.generateKey and its proof pieces (gkFront, smear, scalar, gkBody), whose shared pieces the cached form still uses;
  • the AArch64 key-generation stage chain (CR, G1…G3, Pa.bound, the *.out lemmas);
  • in the RISC-V Miller–Rabin search, smallMod, sieve, oddPrimes256, montPrep, r2Any and millerRabin, with their proofs. Only RSA key generation's pieces (montPrepWith, montPrepHi, roundCall, loadDraw, …) remain;
  • unused *_ct and *_ok lemmas.

13 top-level Verified proofs of routines that no registration exports. No registration file (Artifacts/, Generic/, Variants/) exports any of them, on any target. Where the routine is still emitted, it is reached through another export or as an internal callee, whose correctness and constant-time proofs stay:

  • Proof.Ffdh.AArch64.verified: choose against chooseContract;
  • Proof.Ffdh.AArch64.CheckDomain.cd_verified: the generic AArch64 vg_ffdh_check_domain against checkDomainContract;
  • Proof.Ffdh.AArch64.ParameterCandidate.pc_verified, against sievedParameterCandidateContract;
  • Proof.Ffdh.X86_64.ParameterCandidate.candidateCode_verified, against sievedParameterCandidateContract;
  • Proof.Ffdh.Arm.domain_verified, key_verified, keyGenerate_verified: Arm CheckDomain.code, GenerateKey.code and KeyGenerate.code against checkDomainContract and generateKeyContract;
  • Proof.Ffdh.Arm.VettedKeyGenerate.verified and the private vettedKeyGenerate_verified, against vettedGenerateKeyContract;
  • Proof.MillerRabin.AArch64.RoundImpl.verified and Proof.MillerRabin.X86_64.RoundImpl.verified: the generic round against roundContract;
  • Proof.MillerRabin.Arm.round_verified and RoundImpl.verifiedSpec: the ARMv7 round against the 56-byte roundContract. Its own-contract proof (round_verified_lite) and round_implies stay.

Other edits that come with the removal:

  • Nine blocks of former merged modules (-- Formerly … sections) were left with no declarations and are removed.
  • Imports. Modules that got names through a deleted module now import what they use directly:
    • Proof/Ffdh/Arm/KeyFn: KeyOutputs, KeyTail;
    • Proof/Ffdh/X86/KeySearch/Steps: TCB.X86.Target;
    • Proof/MillerRabin/RISCV64/Blinded/Witness: Proof.MillerRabin.RISCV64.Prep, Impl.MillerRabin.RISCV64.Search.
  • opens. Dangling opens of deleted namespaces or constants are dropped in PPC64LE/GenerateKey/Front, RISCV64/Blinded/{CTBase,Witness,Loop} and X86/KeySearch/Steps.
  • Doc comments. About 30 in-scope doc comments that named removed declarations are reworded.

Kept on purpose

  • Modules imported by other registrations. Proof/Ffdh/Arm/{SharedDeriveInstances,SharedExchangeInstances,SharedCheckPublicInstances,KeySearch/*,KeyBackend,…} and Impl/Ffdh/Arm/{KeySearch,CombPrecompute,VettedGroups}, which Generic/RsaMont/Arm/{CachedFfdh,DerivePublic,Exchange,Domain} import. They are only trimmed.
  • Lemmas a tactic names. The 31 lemmas of Proof/Ffdh/Arm/Block.lean that the ffrun tactic template names (mov_exec, cmp_exec, gpr_putMem, z_subFlags, …). The .ilean files record no use for them, but live proofs run ffrun. The first build caught this.
  • Local notations. sl and n1 in Impl/Ffdh/X86/{Cached,Candidate,Derive,Domain,KeyGen}, and sv in Proof/Ffdh/PPC64LE/ParameterCandidate/Exit. Their macro rules look unreferenced in the graph. The first build caught this too.

Rerunning the analysis on this branch finds exactly these 42 declarations dead in scope, and nothing else. FFDH has 42 dead declarations and 0 dead modules; Miller–Rabin has 0 and 0.

Not changed, outside scope

  • Two RsaKeyGen RISC-V doc comments still name declarations this removes. They are another algorithm's files, so they are left as they are:
    • Impl/RsaKeyGen/RISCV64/Witness.lean names montPrep;
    • Proof/RsaKeyGen/RISCV64/Cand/CTMr.lean names check_ok and LInv.
  • Proof/Ffdh/X86/Cached/PreTop.lean already named a nonexistent body_ok (the theorem is pcBody_ok). This PR doesn't touch it.

Dead Spec/ definitions in scope (listed only)

A separate session removes dead Spec definitions in one PR.

  • Spec/Ffdh (19):
    • choose, generate, generateParameters, parametersFrom, privateComponents, publicComponents;
    • initialKeyRetries, ParameterSearchResult.available, vettedKeySearchApi;
    • sievedParameterCandidate_accepted, sievedParameterSearch_accepted;
    • SievedAccepted's private lemmas: candidate_suffix, consume_accepted, drawWitness_suffix, drawWitnesses_suffix, draw_suffix, loop_suffix, screened_suffix, search_accepted.
  • Spec/MillerRabin (all 11): mrIteration_eq_mrRound, mrSquarings_iff, mrSquarings_true, obviouslyComposite_dvd, powMod_double, powMod_two_pow, splitTwos_spec, sqIter, sqIter_one, sqIter_succ', witness_range.

Checks

  • Lean:
    • the full lake build --log-level=warning passes;
    • Emit.lean --check passes, with the standard axiom audit, and no file under crates/ changes;
    • check_lean_public_imports.py --base origin/main passes on the 224 modified modules.
  • Static checks: every step of the lean-imports job passes, with check_lean_single_importer.py --base origin/main. This includes check_registrations, check_lean_speed, check_variants, run_unit_tests (641 tests) and check_mcdt.
  • 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.
  • Against current main: 18 Lean files changed upstream since the base, none under FFDH or Miller–Rabin. None of them imports a deleted module or names a removed declaration in full. The CI Lean build on the merge commit is the final check.

No benchmark: the emitted code is unchanged.


Generated by Claude Code

Remove the declarations and modules under Proof/Ffdh, Impl/Ffdh,
Proof/MillerRabin and Impl/MillerRabin that nothing reachable from the
registrations, the TCB, the tests or the lakefile's roots uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvCMMw8GyH4m7pdZWZ
Keep the lemmas the ffrun tactic names and the local notations, which
the .ilean files do not record as uses; import directly what deleted
modules passed on; remove the unused St.at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvCMMw8GyH4m7pdZWZ
@github-actions github-actions Bot added the untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified. label Nov 6, 2026
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 8781344 Nov 6, 2026
21 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-ffdh branch November 6, 2026 19:16
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

untrusted-only This changes exclusively implementations and proofs, and thus is entirely formally verified.

Development

Successfully merging this pull request may close these issues.

2 participants