Skip to content

Elliptic curves: remove dead declarations and modules - #4348

Merged
reaperhulk merged 1 commit into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-curves
Nov 6, 2026
Merged

reaperhulk merged 1 commit into
mainfrom
claude/unify-random-bytes-crypto-xqmg0z-deadcode-curves

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 (DSA) and #4314 (ECDSA), this removes the elliptic-curve proof and implementation declarations that nothing reachable uses. The scope is Proof/ and Impl/ of Weierstrass, EcKey, P192, P224, P256, P384, P521, Secp256k1 and BrainpoolP{256,384,512}r1: 1,583 declarations, including 89 whole modules.

  • Nothing in Spec/, TCB/, src/ or the generated crates changes. Emit.lean --check passes, so the emitted code is identical.
  • No registration file (Artifacts/, Generic/, Variants/) changes.

368 files, +195 / −18,463.

How "dead" was decided

The method of tools/deadcode/README.md on the tooling branch, as in #4314:

  • Graph. A declaration-level graph from the .ilean files of a full build of 73a7af173 (main with ECDSA: remove dead declarations and modules #4314).
  • 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 (materialize_*, rw_lit, lit_decide, taint_decide). Module-level commands of imported modules are live, and Lit modules that live code imports stay.
    • Syntax. A module that defines syntax is never deleted.
    • Attributes and instances in imported modules are live.
  • Removal set. Iterated to a fixed point: a declaration goes only if everything that refers to it goes too. Modules that another algorithm's registration imports are only trimmed, never deleted.
  • One stricter rule than the tooling's default. The tooling treats a registration file as in scope when its name contains a scoped name. That would have covered ECDSA's and ECDH's registrations under Generic/<Curve>/. I counted Ecdsa*/Ecdh* registrations as other algorithms', so the modules they import are protected.
  • Final check. The full build is the arbiter. It caught uses the graph misses (see "Kept on purpose").

Removed

  • 89 modules:

    • Proof/Weierstrass/: Arm 23, PPC64LE 21, AArch64 19, x86 8, x86-64 8, RISC-V 1, RootParity.
    • Proof/P384/X86_64/ (4) and Impl/P384/X86_64/PointOps.
    • Proof/Secp256k1/Arm/Comb{CT,Lit} and Proof/Secp256k1/X86_64/PointOpsContract.
    • Mostly per-curve Mont*/Point* proofs and their Verified/Contract modules, the Arm UMAAL variants' proofs, and unused timing and forward-arithmetic pieces.
  • 816 declarations from 258 modules that remain. Mostly unused helpers, *_ct/*_relCT/*_wp lemmas and contract definitions.

  • 308 removed theorems state a Verified. Each proves that an internal routine meets a contract as if it were exported on its own, but no registration exports any of them on any target. They are reached only as internal callees, whose correctness and constant-time proofs stay, so the emitted functions are unchanged. Among them:

    • the per-curve Montgomery add/sub/mul proofs on Arm (with UMAAL), PPC64LE, x86 and RISC-V, and AArch64/x86-64 mul/sqr;
    • the per-curve point add/double proofs on Arm, PPC64LE and x86;
    • the old EcKey pk_verified on Arm and AArch64 (the registrations export the comb combPk_verified);
    • the P-384 and secp256k1 x86-64 point operations;
    • x86-64 Mont.Wide8.verified.
    All 308, by namespace
    • Proof.EcKey.AArch64 (1): pk_verified
    • Proof.EcKey.Arm (1): pk_verified
    • Proof.EcKey.Arm.BrainpoolP256r1 (1): pk_verified
    • Proof.EcKey.Arm.P224 (1): pk_verified
    • Proof.EcKey.Arm.P384 (1): pk_verified
    • Proof.EcKey.Arm.Secp256k1 (1): pk_verified
    • Proof.P384.X86_64.PointOps (2): addAffine_verified, addCached_verified
    • Proof.Secp256k1.X86_64.PointOps (3): addAffine_verified, addCached_verified, double_verified
    • Proof.Weierstrass.AArch64.Mont (10): brainpoolp384r1n_mul_verified, brainpoolp384r1p_mul_verified, brainpoolp512r1n_mul_verified, brainpoolp512r1p_mul_verified, p384n_mul_verified, p384p_mul_verified, p384p_sqr_verified, p521n_mul_verified, p521p_mul_verified, p521p_sqr_verified
    • Proof.Weierstrass.Arm.Mont (72): add_verified, mul_verified, mulU_verified, sub_verified, and for each of p192, p224, p256, p384, p521, secp256k1, brainpoolp256r1, brainpoolp384r1, brainpoolp512r1 and each modulus p/n: <curve><p|n>_add_verified, _sub_verified, _mul_verified, and _mulU_verified (all but p192 and p521)
    • Proof.Weierstrass.Arm.Point (30): pt0_verified, sum_verified; p192_{add,double}_verified; {p224,p256,p384,brainpoolp256r1,brainpoolp384r1}_{add,addU,double,doubleU}_verified; secp256k1_{add,addU,add0m,add0mU,double0,double0U}_verified
    • Proof.Weierstrass.PPC64LE.Mont (57): add_verified, mul_verified, sub_verified, and <curve><p|n>_{add,sub,mul}_verified for p192, p224, p256, p384, p521, secp256k1, brainpoolp256r1, brainpoolp384r1, brainpoolp512r1
    • Proof.Weierstrass.PPC64LE.Point (16): pt0_verified, sum_verified; {p192,p224,p256,p384,brainpoolp256r1,brainpoolp384r1}_{add,double}_verified; secp256k1_add0m_verified, secp256k1_double0_verified
    • Proof.Weierstrass.RISCV64.Gen4, Gen6, P256Field, P256Order, P384Field, P384Order, P521Field, P521Order (3 each): add_verified, mul_verified, sub_verified
    • Proof.Weierstrass.RISCV64.P192Field, P224Field (6 each): add_verified, add_verified_n, mul_verified, mul_verified_n, sub_verified, sub_verified_n
    • Proof.Weierstrass.X86.Mont (54): <curve><p|n>_{add,sub,mul}_verified for p192, p224, p256, p384, p521, secp256k1, brainpoolp256r1, brainpoolp384r1, brainpoolp512r1
    • Proof.Weierstrass.X86.Point (16): pt0_verified, sum_verified; {p192,p224,p256,p384,brainpoolp256r1,brainpoolp384r1}_{add,double}_verified; secp256k1_add0m_verified, secp256k1_double0_verified
    • Proof.Weierstrass.X86_64.Mont (5): p384n_mul_verified, p384p_mul_verified, p521n_mul_verified, p521p_mul_verified, p521p_mulX_verified
    • Proof.Weierstrass.X86_64.Mont.Wide8 (1): verified

Outside the scope:

  • Imports only.
    • 9 ECDSA modules under Proof/Ecdsa/Verify/AArch64/ drop imports of deleted modules. Nothing else changes in them.
    • VerifiedGarbageTest/EcCompressedRoot.lean drops its import of Weierstrass.RootParity. It imported the module but used none of its three lemmas.

Other edits that come with the removal:

  • Direct imports. These modules now import directly what deleted modules used to pass on:
    • Arm Mont{P192,Secp256k1,BrainpoolP256r1,BrainpoolP384r1,BrainpoolP512r1} and AArch64 MontBrainpoolP{384,512}r1 import MontFn/MontFnG;
    • x86-64 PointOpsCT imports PointOpsAdd;
    • AArch64 PubNaf/StepDTiming imports WinJStep.
  • One pass-through import. AArch64 MontBrainpoolP512r1 also public imports Proof.Framework.Lit (-- shake: keep). ECDSA's AArch64/BrainpoolP512r1/Config uses lit_decide and got it through the deleted MontContract. Editing that ECDSA file is out of scope here; it can import Lit itself later, and then this import can go.
  • Cleanup. Empty sections, namespace blocks, and dangling open … in lines and headers are removed.
  • Doc comments. Comments in 71 in-scope files that named removed declarations are reworded.

Kept on purpose

  • Tactics and the lemmas macros name. The analysis marks these dead because syntax quotations and elab bodies leave no .ilean reference. The build showed they are used:

    • list_mem and nd_find (Proof/Weierstrass/Layout);
    • forward_state (AArch64/Forward/Snapshot);
    • def_literal (X86_64/FieldErase);
    • sext2 and zext0 (X86_64/InvStep), which the irun macro names.

    The unused certificate_value command (AArch64/Forward/Literal) is removed.

  • 32 Weierstrass modules imported by ECDSA/ECDH registrations, mostly AArch64 Naf*/JacWindow*/JacTree, x86 WinLoop/WinEntry and x86-64 Words/NafPrepTiming. They are kept whole even where their declarations look dead. Removing them belongs with ECDSA/ECDH.

  • Declarations that other algorithms' code uses, mostly ECDH's, even when that code is dead too.

  • Impl.Secp256k1.point and Impl.Weierstrass.X86.Point.fn0, which the Lit module Weierstrass/X86/PointLit/Secp256k1 materializes.

After the removal, rerunning the analysis finds no further removable declaration in scope except the 8 kept above.

Stale comments outside the scope (not edited)

These comments name removed declarations, in ECDSA files:

  • Impl/Ecdsa/AArch64.lean:191: PointOps.Curve.bAt
  • Proof/Ecdsa/RISCV64/*/MulVerified.lean (9 curves): Impl.Weierstrass.Mul.Curve.mulInRangeContract
  • Proof/Ecdsa/Verify/Arm/Main.lean:27: step_rep (Arm now has only step_rep')
  • Proof/Ecdsa/X86_64/InvFnX.lean:16: PointOps.wrap_gpr
  • Proof/Ecdsa/Verify/AArch64/AllocatedPointsTiming.lean:22: the header `ArithmeticTableChecks`

Dead Spec/ definitions in scope (not removed here)

  • VG.Spec.P521.feAt and VG.Spec.P521.montR (Spec/P521/Field.lean).
  • None in the other scoped Spec/ modules.

Checks

  • Lean:

    • the full lake build passes (28,742 jobs);
    • Emit.lean --check passes with the standard axiom audit, and no crate changes;
    • check_lean_public_imports --base 73a7af173 passes on the modified modules.
  • Static checks: every step of the Static checks job passes, with check_lean_single_importer --base origin/main.

  • 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 (9 commits and 266 Lean files changed upstream since 73a7af173, none of them files this PR touches):

    • no upstream file imports a deleted module;
    • no upstream file names a removed declaration in full.

    The CI build of the merge commit is the final check.

No benchmark: the emitted code is unchanged.


Generated by Claude Code

Remove the proof and implementation declarations of the elliptic-curve
code (Weierstrass, EcKey and the per-curve directories) that nothing
reachable from the registrations, TCB/ or the tests uses: 1,583
declarations, including 89 whole modules. No Spec/, TCB/ or generated
crate changes; Emit.lean --check passes unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWx9jfFdMU8rNKTRmbk
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 7f50e6d Nov 6, 2026
24 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-curves branch November 6, 2026 19:08
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