Skip to content

AEADs: remove dead declarations and modules - #4345

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

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

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

Like #4305 (DSA) and #4314 (ECDSA), this removes the AEADs' proof and implementation declarations that nothing reachable uses. The scope is the directories AesGcm, Gcm, GcmSiv, AesGcmSiv, Sm4Gcm, Poly1305, ChaCha20 and ChaCha20Poly1305 under Proof/ and Impl/. In total it removes 1,198 declarations, 248 of them in 24 whole modules.

  • Nothing in Spec/, TCB/, src/ or the generated crates changes. Emit.lean --check passes, so the emitted code is identical.
  • Spec/ files are untouched. Dead Spec/ definitions in scope are listed at the end for the separate Spec pass.

395 files, +222 / −12,689.

How "dead" was decided

This follows tools/deadcode/README.md, the method used for #4305 and #4314.

  • Graph. A declaration-level graph built from the .ilean files of a full build.
  • 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 of a module the roots import is live, along with what it references.
    • Tactics, macros and notation. A module that defines syntax is never deleted.
    • Attributes and instances. A declaration with a simp-set or instance attribute is live in modules the roots import.
  • Iteration. The plan was iterated to a fixed point.
  • Final check. The full build is the arbiter. It found two more kinds of use the graph misses (see "Kept on purpose").

Removed

Modules (24)

  • Impl/AesGcm/AArch64/Prepared
  • Proof/AesGcm/AArch64/Fast/{OpenPrepared,OpenStore,Prepared,SealStore}
  • Proof/AesGcm/AArch64/Gather/Prepared
  • Proof/AesGcm/AArch64/Prepared/{Derive,Powers,Verified}
  • Proof/AesGcm/ScratchPrepared8
  • Proof/AesGcm/X86_64/{Prepared,Prepared16}/BlocksTo
  • Proof/ChaCha20/AArch64/Mixed5/Loop
  • Proof/ChaCha20/AArch64/Rows6/{Chunk,Loop,Tail}
  • Proof/ChaCha20/Contract
  • Proof/ChaCha20/{PPC64LE,RISCV64}/Shared
  • Proof/Gcm/{Powers8Contract,PrecomputedContract}
  • Proof/Gcm/X86_64/StitchAvx/{Aes,Dec,Gh}

Declarations

950 further declarations come from 362 modules that remain. All 1,198 by directory:

Directory Declarations
AesGcm 407
Poly1305 216
Gcm 208
ChaCha20 161
ChaCha20Poly1305 83
AesGcmSiv 68
Sm4Gcm 53
GcmSiv 2

Most are unused helpers, *_ct/*_wp lemmas and contracts.

70 top-level Verified proofs of routines no registration exports

Each proves that a routine would satisfy a public contract if it were exported on its own. No registration file exports any of them on any target.

The routines are now reached only as internal callees: through the generic …Impl/variant interfaces (BlocksImpl, XorImpl, GcmImpl, …) or the stitched and prepared paths. Their correctness and constant-time proofs stay, and the emitted functions are unchanged.

  • GHASH (12): ghash_verified on x86, x86-64 (+ Pclmul, Vpclmul), AArch64 (+ Pmull.ghash{,P,W}_verified), ARMv7, PPC64LE (Vpmsum) and RISC-V.
  • Poly1305 (10): blocks_verified on x86, x86-64, AArch64, ARMv7 and RISC-V; Radix64.blocks_verified; blocksAvx2/blocksAvx512/blocksIfma_verified; RISC-V finalizeScratch_verified.
  • ChaCha20 (20):
    • block_verified on x86, x86-64, AArch64 and ARMv7;
    • xor_verified on every target and variant: Xor, Avx2 (+ xorVL), Avx512, Avx512VL, Avx512Split.xorSplit, Mixed8, Neon4, Rows6, x86 xorSsse3;
    • AArch64 XorImpl.verified.
  • ChaCha20-Poly1305 (2): x86-64 Gather.sealGather_verified and Gather.Whole.sealGather_verified.
  • AES-GCM (26):
    • x86-64 {encrypt,decrypt}Blocks{,P,Prepared,Prepared16}_verified, encryptBlocksTo{,P,Prepared,Prepared16}_verified, open{Prepared,Prepared16}_verified;
    • AArch64 Fast.{seal,open}{Prepared,St,StS}_verified, Gather.sealGatherPrepared_verified, derive_verified;
    • PPC64LE seal_verified, Blocks.encrypt_verified, SplitBlocks.encrypt_verified, Gather.sealGather_verified.

Outside the scope's directories

  • 3 of the scope's own registration files (Artifacts/ChaCha20/{PPC64LE,RISCV64}, Generic/AesGcm/X86_64/AesGcm) only drop the import of a deleted module. check_registrations passes.
  • ci/lean_speed_allowed.py lowers two decide := true allowances (ChaCha20/AArch64/Rows6/Save: 1 → 0, Poly1305/AArch64/Blocks: 20 → 2), as check_lean_speed requires.

Other edits that come with the removal

  • Passed-on imports. Modules that imported a deleted module now import what it passed on and they use (check_lean_public_imports --base origin/main passes).
  • Leftovers removed:
    • omit … in, set_option … in and open … in that belonged to removed declarations;
    • emptied sections, namespace blocks and section headings.
  • Docs. Doc comments that named removed declarations are reworded. The Proof/Gcm/Prepared8Contract module doc now describes only the format it still defines.

Kept on purpose

  • Used by another algorithm. Proof.Gcm.ctr32Sig and ctr32Contract stay: AES's ctr32_verified proofs use them.

  • local notations (vdword, ofVDwords, dw) in 12 Gcm/AesGcm/AesGcmSiv modules. Their uses leave no reference in the .ilean files, and removing them broke the build.

  • 19 declarations named inside tactic macros (tactic_template, macro) of their own algorithm's modules. A quotation's names are not recorded either, so the build failed without them:

    • Sm4Gcm.Arm.{store32_eq, store8_eq, encodable_of_decide} (arun, Sm4Gcm/Arm/Run);
    • Gcm.RISCV64.{readW_wr_ne0, readW_wr_ne0', splitStore_eq} (Gcm/RISCV64/Law);
    • AesGcmSiv.X86.readW_writeB_off, AesGcmSiv.{AArch64.Lay.a_w', AArch64.Lay.n_w', Arm.Lay.n_w'};
    • ChaCha20-Poly1305 X86.APre.{a_sub, ret_stk, t_sub}, X86_64.APre.{a_d, stk_a', stk_d', stk_t'}, X86_64.ret_stk, and Region.Disjoint.dsymm, which X86_64.ret_stk uses.

    Rerunning the analysis now reports only these and the notations' auxiliary declarations as dead in scope.

Checks

  • Lean:
    • the full lake build --log-level=warning passes, after rebasing onto current main;
    • Emit.lean --check passes with the standard axiom audit, and no generated crate changes;
    • check_lean_public_imports --base origin/main passes on the modified modules.
  • Static checks: every step passes (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.
  • After rebasing onto current main (426 Lean files changed upstream):
    • no file imports a deleted module;
    • no upstream-changed file names a removed declaration by a qualified name.

No benchmark: the emitted code is unchanged.

Not changed, for follow-ups

Out-of-scope stale doc reference: Proof/AesSiv/RISCV64/Env.lean:24 names Lay.cal, which is removed here from Proof/AesGcm/RISCV64/Env. It is AES-SIV's file, so it is left for that algorithm's pass.

Dead Spec/ definitions in scope. These are only listed here; the separate Spec PR removes them.

  • Spec/Gcm (34):

    • aesGcmDecrypt, encryptWith_ctx, decryptWith_ctx;
    • PreparedPowersRepr.powers8, PreparedPowersRepr.prepared16;
    • Spec/Gcm/OutOfPlace: openTo{Api,Contract,Leak,Post,Pre,Safety,Sig}, openToPrecomputed{Api,Contract,Pre,Sig};
    • Spec/Gcm/Prepared: openToPrepared{Api,Contract,Pre,Sig};
    • Spec/Gcm/Prepared16: openToPrepared16{Api,Contract,Pre};
    • Spec/Gcm/Powers8: {seal,open}StorePowers{Api,Contract,Post,Sig}, storePowers{Ok,Safety,Summary}.

    Note: Spec/Gcm/Powers8's vg_aes_gcm_store_powers (Spec: vg_aes_gcm_store_powers, GCM's eight powers of H from a key context #4317) just landed and awaits its implementation. It is not in this list.

  • Spec/GcmSiv (2): encryptWith_ctx, decryptWith_ctx.

  • Spec/ChaCha20 (5): encrypt_eq_keystreamOf, keystreamOf_eq, and the private length_chacha20Block, length_flatMap_const, zipWith_append_of_le.



Generated by Claude Code

Remove the AES-GCM, GHASH, GCM-SIV, AES-GCM-SIV, SM4-GCM, Poly1305,
ChaCha20 and ChaCha20-Poly1305 proof and implementation declarations that
nothing reachable from the registrations, the TCB or the tests uses:
1,198 declarations, 24 of them whole modules. Nothing in Spec/, TCB/ or
the generated crates changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWwM7EdmaMkyjpzzob6
@reaperhulk
reaperhulk added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 0cabe94 Nov 6, 2026
19 checks passed
@reaperhulk
reaperhulk deleted the claude/unify-random-bytes-crypto-xqmg0z-deadcode-aead branch November 6, 2026 18:25
alex pushed a commit that referenced this pull request Nov 6, 2026
reaperhulk pushed a commit that referenced this pull request Nov 6, 2026
Resolve the import list of Proof/AesGcm/X86_64/Instances.lean (both
sides' imports), and restore preparedPowersRepr(16)_zeroMem and
preparedPowersRepr(16)_of_zeroMem, which #4345 removed as unused and
open_to's satisfiability proofs use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ajQWvqXkQxFyWZxghqxBG
reaperhulk pushed a commit that referenced this pull request Nov 6, 2026
Resolve the import list of Proof/AesGcm/X86_64/Instances.lean, and state
saved_crFrame, which #4345 removed from Proof/AesGcm/X86_64/Fn.lean as
unused, in OpenSplit/Run.lean, its only user.

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