Skip to content

Spec: remove dead definitions - #4337

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

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

Conversation

@reaperhulk

Copy link
Copy Markdown
Member

This is a trust change limited to deletions in Spec/, plus rewording of the doc comments that named what was deleted. No definition, contract, signature, Api or theorem that stays is changed. No file outside lean/VerifiedGarbage/Spec/ is touched: no Proof/, Impl/, TCB/, registration, Rust or generated-crate file. Emit.lean --check passes with no change to any crate.

10 files, +2 / −388: 37 definitions removed, including one whole module, Spec/P521/Field.lean.

Method

This uses the same analysis as #4305 and #4314: a declaration graph from a full build's .ilean files, with a live set from the roots (Artifacts/, Generic/, Variants/, TCB/, VerifiedGarbageTest/, lakefile-named and top-level-imported modules). It conservatively keeps attributed declarations and module-level commands. At main it finds 121 dead declarations in Spec/.

A declaration was removed only if all of these hold:

  • it is dead;
  • nothing outside Spec/ refers to it at all, live or dead. The parallel Proof//Impl/ cleanups are removing the dead code, and touching it would conflict with them;
  • nothing in Spec/ that stays refers to it;
  • no doc, docs/algorithms/*.toml, README table, ci/ script, test or Rust comment names it;
  • it is not a theorem a reviewer reads. See "Kept on purpose" below.

Removed (37)

DSA: Spec/Dsa/DomainChecked.lean (5)

signDomainCheckedApi, verifyDomainCheckedApi, randomSignDomainCheckedApi, generateKeyDomainCheckedApi, deriveKeyDomainCheckedApi.

No registration emits these Apis. Their *DomainCheckedContracts stay, since proofs use them.

FFDH (5)

  • Spec/Ffdh.lean:
    • parametersFrom, publicComponents, privateComponents: conversion helpers that nothing calls;
  • Spec/Ffdh/KeyGeneration.lean:
    • initialKeyRetries: unused; keyInit states the same initial state;
  • Spec/Ffdh/VettedKeyGenerationContract.lean:
    • vettedKeySearchApi: no registration emits it. vettedKeySearchContract stays.

AES-GCM (22)

  • Spec/Gcm/OutOfPlace.lean, vg_aes_gcm_open_to and vg_aes_gcm_open_to_precomputed, neither emitted by any registration:
    • openToSig, openToPre, openToPost, openToLeak, openToContract, openToSafety, openToApi;
    • openToPrecomputedSig, openToPrecomputedPre, openToPrecomputedContract, openToPrecomputedApi;
  • Spec/Gcm/Prepared.lean, vg_aes_gcm_open_to_prepared, not emitted:
    • openToPreparedSig, openToPreparedPre, openToPreparedContract, openToPreparedApi;
  • Spec/Gcm/Prepared16.lean, vg_aes_gcm_open_to_prepared16, not emitted:
    • openToPrepared16Pre, openToPrepared16Contract, openToPrepared16Api;
  • Spec/Gcm/Powers8.lean:
    • sealStorePowersApi, openStorePowersApi: no registration emits them;
    • storePowersSummary, storePowersSafety: only those two Apis' documentation used them.

P-521: Spec/P521/Field.lean (2, whole module)

feAt, montR. Nothing imports the module, and no contract of vg_p521_mul_mont or vg_p521_sqr_mont was ever stated in it.

RSA-PSS: Spec/RsaPss.lean (3)

SaltLength, SaltLength.sign, SaltLength.verify: unused. The Rust rsa::pss::SaltLength is a separate Rust type that does not refer to it.

Doc rewording

  • Spec/Gcm/OutOfPlace.lean:
    • the module doc drops its vg_aes_gcm_open_to bullet;
    • the empty ## Decryption out of place heading is removed;
    • "a caller encrypting or decrypting in place" becomes "encrypting in place".
  • Spec/RsaPss.lean:
    • the module doc no longer names SaltLength;
    • the empty ## Salt lengths heading is removed.
  • Spec/Gcm/Prepared.lean and Spec/Gcm/Prepared16.lean: a double blank line left before end is collapsed.

Left for a follow-up: used only by dead proofs (17)

Each of these is referenced by dead Proof/ code that the parallel cleanups are deleting. Removing them now would conflict with those PRs. Once those merge, rerun the analysis.

  • FFDH:
    • Ffdh.choose: Proof.Ffdh.chooseContract, Proof.Ffdh.AArch64.*;
    • Ffdh.ParameterSearchResult.available: Proof.Ffdh.Generation.consume_available.
  • AES-GCM, from Spec/Gcm/Powers8.lean, used by Proof.AesGcm.*StorePowers* and Proof.AesGcm.AArch64.Fast.*:
    • openStorePowersSig, openStorePowersPost, openStorePowersContract;
    • sealStorePowersSig, sealStorePowersPost, sealStorePowersContract;
    • storePowersOk.
  • RSA PKCS Implement all algorithms #1 v1.5 encryption: RsaPkcs1Enc.encryptSig, encryptContract, used by Proof.RsaPkcs1Enc.{AArch64,X86_64}.*.
  • RSA PKCS Implement all algorithms #1 v1.5 signatures: RsaPkcs1Sig.recoverSig, recoverContract, verifySig, verifyContract, used by Proof.RsaPkcs1Sig.AArch64.*.
  • RSA-PSS: RsaPss.dropWhile_db, eq_db, used by Proof.RsaOaep.* and Proof.RsaPss.*.

Kept on purpose (67): dead to the graph, but read by people

Named outside Spec/ (5, plus 6 lemmas they need)

  • Ccm.aesCcmEncrypt, Ccm.aesCcmDecrypt, Gcm.aesGcmDecrypt:
    • the known-answer tests' module docs (VerifiedGarbageTest/{Ccm,Gcm}.lean) name them as what the vectors check.
  • MlDsa.keyGenInternal_tr, MlKem.keyGenInternal_h:
    • Rust comments in src/mldsa_common.rs and src/mlkem_common.rs cite them;
    • so do Sha3.Length's six lemmas, which they use.

Theorems relating the spec to its standard, which reviewers read (56)

Spec/ holds theorems for two reasons: proofs use them, or a reviewer reads them instead of checking a definition against the standard by hand. These are the second kind. Their own docs, or those of the files around them, say so: for example, ChaCha20's "a reviewer need not match its definition against the RFC", or GenerationAgrees.lean's "a reviewer reads generatePrime … and the statements here". Removing them would make the spec harder to review, which is not what a dead-code cleanup is for. The kept theorems:

  • Whole modules:
    • MillerRabin.lean: BoringSSL's Miller–Rabin is FIPS 186-5 B.3.1's;
    • RsaKeyGen/GenerationAgrees.lean: the prime search is FIPS 186-5 A.1.3's generatePrime;
    • Ffdh/SievedAccepted.lean: the sieved search accepts only what the plain test accepts.
  • ChaCha20: keystreamOf_eq, encrypt_eq_keystreamOf (RFC 8439 §2.4.1), and their private lemmas.
  • BLAKE2: blake2s_eq_finalHash (its BLAKE2b twin is live).
  • Key-context equivalences: encryptWith_ctx, decryptWith_ctx for GCM, GCM-SIV and OCB.
  • RSA-PSS: verifyEncodingRfc, verifyEncoding_some, eq_db_of_take: verifyEncoding is RFC 8017's EMSA-PSS-VERIFY.
  • GCM context layouts: PreparedPowersRepr.powers8 and .prepared16. The docs of Powers8.lean and Prepared16.lean rest on them, for example "a context vg_aes_gcm_prepare wrote … so these APIs also take it".
  • Hash table: HashTable.index_hashes.

Definitions that live docs use to state meaning (3)

  • Ffdh.generate: generateKeyContract's doc says the contract is "one attempt of generate".
  • Ffdh.generateParameters: SievedAccepted.lean's statements are about it.
  • Entropy.Refill: the entropy protocol's description, and GenerationAgrees.lean, state the host's side with it.

If reviewers would rather these go too, that is a deletion-only follow-up.

Checks

  • Lean:
    • full lake build --log-level=warning passes (28,928 jobs);
    • lake env lean --run Emit.lean --check passes, with no change to any generated crate, and the audits pass;
    • check_lean_public_imports.py --base origin/main -m on the 9 modified modules: "Public imports OK".
  • Static checks: every step of the Static checks job passes:
    • check_lean_imports, check_lean_modules;
    • check_lean_single_importer --base origin/main;
    • check_case_collisions, check_registrations, check_lean_speed;
    • audit_base check, algorithms_table --check;
    • check_arch_gates, check_variants, check_skills;
    • the VG_CPU_FEATURES grep, cpu_tests lint;
    • run_unit_tests (641 tests), check_mcdt, check_vectors.
  • Rust: cargo fmt --check and cargo clippy --all-targets -- -D warnings pass. No Rust changed.
  • Forbidden constructs: no sorry, admit, native_decide, bv_decide, axiom or maxHeartbeats added (this PR adds 2 lines of doc text).
  • Rerun of the analysis on this branch: 84 dead Spec/ declarations remain, exactly the 17 left for the follow-up plus the 67 kept on purpose.

No benchmark is linked: the emitted code is unchanged.


Generated by Claude Code

Delete 37 Spec/ definitions that nothing refers to: unused Api
declarations (DSA's domain-checked APIs, FFDH's vetted key search, the
AES-GCM open_to and store_powers APIs), the contracts of functions no
registration emits (AES-GCM open_to and its precomputed, prepared and
prepared16 forms), P-521's unused field-arithmetic module, FFDH's
component helpers and RSA-PSS's SaltLength. Doc comments that named
them are reworded. No definition that stays changes.

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