Repository navigation
refactor(Crypto/LWE): typed Module-LWE games; ML-KEM and ML-DSA share them - #5097
Queued
SamuelSchlesinger wants to merge 83 commits into
Queued
SamuelSchlesinger wants to merge 83 commits into
SamuelSchlesinger wants to merge 83 commits into
Conversation
Refs #4678. Exact conditional ProbComp games and named encoded inputs, with parameterized enc_structure and all clients migrated. Authored with Codex assistance for Samuel Schlesinger.
Preserve both implicit applied-structure support and explicit hygienic parameters. Retain both regression sets and manual guidance. All files outside the 18-file PR scope are identical to main.
Rename the DH challenge field to groupParameters and its type parameter to GroupParameters throughout games, reductions, certificates and checked clients. Explain F.Desc and Schnorr parameters (p, q, g) in source and the manual. Preserve challenge encodings, sampling laws and resource contracts. Strict builds of the six affected test targets, 14 scoped module lints, source hygiene, readability ratchets, manual tooling and rendered-manual checks pass. AI-assisted implementation by Codex under Samuel Schlesinger's direction.
State Boneh–Shoup Attack Games 10.4, 10.5 and 10.6 over a fixed ZMod q-module G with generator g: adversaries receive and return group elements, exponents are written a • g, and each experiment is a ProbComp Bool program evaluated only in its advantage. Add the elementary reductions dlToCDH and cdhToDDH. The superseded DDH.realGame/randomGame/advantage stay until DDH-OT migrates (#4678). Co-authored-by: Karn Seth <karn@google.com>
dlAdvantage_le_cdhAdvantage_dlToCDH holds in every group. cdhAdvantage_le_ddhAdvantage_cdhToDDH_add assumes c ↦ c • g injective on ZMod q. Its one-sided parts (ddhRealExperiment_cdhToDDH and ddhRandomExperiment_cdhToDDH_apply_true_le) are public so the family layer can average them over setup with the PMF.bind_apply_* lemmas (#4678).
DDH-OT now uses a • g with [Module (ZMod q) G] throughout, in place of a.val • g with the hypothesis ∀ y, q • y = 0. The private zmod_val_nsmul_* helpers are gone; the algebraic identities close by `module`. ddhOTReduction takes the DDH triple as three group elements. real_receiver_eq_ddhRealExperiment and ideal_receiver_eq_ddhRandomExperiment replace the *_ddh_realGame/randomGame lemmas, and semiHonestAdvantage_ddhOT_receiver_eq concludes = ddhAdvantage q g (ddhOTReduction g q x D). The sender-privacy theorems no longer need hq. The superseded Cslib.Crypto.DDH tuple games are removed, with no wrappers. New CslibFrontierTests/Crypto/DiffieHellmanFinite.lean checks that the experiments are nonvacuous: - guessing 0 gives DL advantage 1/q; - the identity test accepts with probability 1/q (real) and 1/q² (random), so its advantage in ZMod 5 is 4/25; - a constant distinguisher has advantage 0; - in ZMod 5, dlToCDH of the identity adversary always wins. Refs #4678. Co-authored-by: Karn Seth <karn@google.com>
Stage 1b of the typed Diffie–Hellman redesign. Family games now run core's fixed-group experiments in `F.Carrier d` after an arbitrary setup draw, and adversaries receive and return group elements: - `CDHInput`/`DDHInput` records with `words` views; `encCDHInput`/`encDDHInput` are byte-identical to the previous layout (`encCDHInput_apply`, `encDDHInput_apply`). - `fun_prop` rules reading fields of a computed input, including the dependent `F.encode x.groupParameters x.leftPublic`. - `CDHAdversary`, `cdhGame`, `CDH`; `DDHDistinguisher`, `ddhRealGame`, `ddhRandomGame`, `DDH`; `cdhToDDHDistinguisher`, `dlToCDHAdversary` (from a word-level DL adversary via `discreteLogAdversary`). - `CDH.discreteLog`, `DDH.cdh`, `DDH.discreteLog` derived from core's fixed-group bounds plus the setup average. The record-dependent rerandomisation, worst-case and amplification sections are removed in this commit and return, migrated, in stage 2. Clients do not compile until stage 3. AI-assisted (spike worker, Jetski swarm).
…oup masks Add `Probability/PMF/UniformPoint.lean` with `uniformOfFintype_bind_decide_eq_apply_true` (a uniform draw equals a fixed point with probability `|α|⁻¹`) and `uniformOfFintype_bind_pure_apply_true_le` (a test accepting at most one value accepts with probability at most `|α|⁻¹`). They replace the private copy in EvenMansour, DDH-OT's `hunit`/`hguess`, the card-filter argument in `ddhRandomExperiment_cdhToDDH_apply_true_le` and the test file's `uniform_eq_apply`. Make the fixed-group masks public in `DiffieHellman/Finite.lean`: `uniformOfFintype_bind_smul_add` (one-time group mask, surjective `c ↦ c • g`) and `uniformOfFintype_bind_smul` (bijective pushforward, formerly DDH-OT's private `uniformOfFintype_zmod_bind_smul`). `PrimeOrderGroupFamily.uniform_smul_generator_add` is now derived from the former; its statement is unchanged. Refs #4678
…teLog Move the encoding-based `DecidableEq (F.Carrier d)` instance from SchnorrProtocol.lean into DiscreteLog.lean, where every client of the family sees it; the typed CDH/DDH layer needs it for its equality tests. Refs #4678
Typed family-level CDH/DDH games (spike). The duplicate encoding-based DecidableEq (F.Carrier d) instance is dropped; it now lives in DiscreteLog.lean. Refs #4678
The key-exchange reduction now builds an F.DDHDistinguisher that encodes the group elements at the call site. Its certificate is hA.preprocess with the DDHInput field rules (fun_prop). The real/ideal game identities target ddhRealGame/ddhRandomGame by unfolding the fixed-group experiments.
…istinguishers Order.lean's identity test is now a typed F.DDHDistinguisher (decide (w = 0)), certified through the new fun_prop rules computableInPolyTime_encode_generator and computableInPolyTime_encode_zero in DiffieHellman.lean. Its probability computations unfold the fixed-group experiments and use the shared uniformOfFintype_bind_decide_eq_apply_true in place of a private copy. AI-assisted (spike worker, Jetski swarm).
Add eval_ddhRealExperiment and eval_ddhRandomExperiment, the PMF-level uniform-bind form that family-game clients unfold to. Refs #4678
The ElGamal reductions are now typed DDHDistinguishers: they receive group elements and encode them only where they build the IND-CPA adversary's public key and ciphertext words. The IND-CPA games keep their encodings. Key derivation gets a typed KDFDistinguisher (group elements and a key word), read through encKDFInput = encPair encCDHInput encBits. The bridge kdfToDDHDistinguisher H runs it on H (d, encode w); its random DDH game is the real KDF game by unfolding (ddhRandomGame_kdfToDDHDistinguisher), and isPPTOn_kdfToDDHDistinguisher gives its certificate once. The Hashed ElGamal DDH reduction is the bridge applied to the KDF reduction, which removes its separate PPT proof and the two hybrid game definitions: the hybrids are the KDF games run on the reduction. KDF.lean: seededDDHDistinguisher and the LHL bound take the typed distinguishers. Refs #4678
… KEM kemToKDFDistinguisher is a typed KDFDistinguisher and kemToDDHDistinguisher runs it through kdfToDDHDistinguisher, so the random-DDH/real-KDF bridge and the DDH PPT proof come from the shared Hashed ElGamal lemmas. Refs #4678
…hed ElGamal The per-bit and hidden-bit KDF reductions are typed KDFDistinguishers and the DDH reductions run them through kdfToDDHDistinguisher, so each DDH PPT proof and random-DDH bridge comes from the shared lemmas. Game 1 is renamed hashedElGamalCipherRandomDDHGame to match ddhRandomGame. Refs #4678
…esc-level construction The two Naor–Reingold DDH distinguishers repeated one body. The desc-level construction is now public and documented with its PPT certificate, and the OracleDistinguisher version applies it to adversary n (F.encDesc d).
Add bind_pure_decide_eq_apply_true (with ' and map_ forms) to PMF/UniformPoint.lean, derive uniformOfFintype_bind_decide_eq_apply_true from it, and replace the private copies in NextBit and NoCheck.
…tage LWE.realGame and LWE.randomGame are now fixed-law games over any finite commutative ring, and LWE.advantage is their distance. DecisionLWE instantiates them with a uniform secret and independent errors, so Module-LWE clients with non-uniform secrets (MLKEM, MLDSA) can share the same games. Part of #4817.
# Conflicts: # CslibFrontier/Crypto/Computational/SIS/Module.lean
…adability/lattice-L3m # Conflicts: # CslibFrontier/Crypto/Computational/SIS/Module.lean # CslibFrontierTests/Crypto/ModuleSIS.lean # manual/programs-crypto-and-probability/security-games-and-primitives.md
Addresses review thread r4558456561 on #4878: the word-specialized distinguishing game had its own copy of `Game.withSetup`'s body. - `distinguishingGame distribution adversary := Game.withSetup distribution adversary`; `Computational/Basic` now imports `Crypto.Game.Experiment` (which imports only `Crypto.Game` and `Probabilistic.Notation`). - `eval_bind_eq_distinguishingGame` is `Experiment.eval_bind_eq_withSetup`. - `distinguishingGame_eq_bind` (rfl) states the sampling form. Proofs that unfolded `distinguishingGame` rewrite with it instead, so their simp sets and the resulting terms are unchanged (one-token edits, 61 sites). Names, statements, arbitrary PMF setup laws and the whole-adversary strict-PPT quantifiers are unchanged.
…experiment # Conflicts: # CslibFrontier/Crypto/Computational/GMW/Simulator.lean
…l for typed Module-LWE Part of #4817
…experiment # Conflicts: # manual/programs-crypto-and-probability/security-games-and-primitives.md
# Conflicts: # manual/programs-crypto-and-probability/protocols-and-privacy.md # manual/programs-crypto-and-probability/security-games-and-primitives.md
# Conflicts: # manual/programs-crypto-and-probability/security-games-and-primitives.md
# Conflicts: # CslibFrontier/Crypto/Computational/MLDSA/KeyOnly.lean # CslibFrontier/Crypto/Computational/SIS/Module.lean # CslibFrontier/Crypto/Computational/SIS/Polynomial.lean # CslibFrontier/Foundations/Algebra/Negacyclic.lean # CslibFrontierTests/Foundations/Algebra/Negacyclic.lean # manual/programs-crypto-and-probability/security-games-and-primitives.md
…only the sample part
# Conflicts: # manual/programs-crypto-and-probability/security-games-and-primitives.md
Collaborator
Author
|
Agent review claim: coordinator |
Collaborator
Author
|
Agent review (negacyclic, AI; not human review): APPROVE at 1dec3c3. Local review of
I'll queue it on green ci-checks/guide once I've checked the notices. |
SamuelSchlesinger
left a comment
Collaborator
Author
There was a problem hiding this comment.
Coordinator review (coordinator agy-634bba4c, session 634bba4c-9d3c-4f80-8d5b-6097f495b913) of head 1dec3c39d15a39bb6286a55fbcd4c76df084c8ce: APPROVE.
This is agent review, not human review.
What I checked
- Typed Module-LWE experiments, ring-LWE bridge & word-level equivalence (
LWE/Module.lean,SIS/Module.lean,SIS/Module/ApproximateSampling.lean,SIS/ModuleEncryption.lean,CslibFrontierTests/Crypto/DecisionModuleLWE.lean):LWE/Module.leanextractssample,flattenPolyVec_sample,encodeSample,sampleLaw,realEnsemble, anduniformEnsemblecleanly fromSIS/Module.lean(leavingSIS/Module.leandedicated to Module-SIS) and introducesModuleLWE.realExperiment,randomExperiment,realGame,randomGame, andadvantage, matching the architecture ofLWE/Basic.lean.ModuleLWE.advantage_eq_lweAdvantagecleanly identifiesModuleLWE.advantagewithLWE.advantageoverNegacyclic (ZMod q) nviaNegacyclic.coeffsEquiv.DecisionModuleLWEis nowGame.Indistinguishableover typedModuleLWE.Distinguishers (ModuleLWE.Input,encInput,Distinguisher.IsPPT), withencInput_applypreserving the exact framed(1^κ, encodeSample (A, b))layout (rfl) anddecisionModuleLWE_iff_encoded/DecisionModuleLWE.encodedproving equivalence with the word-level ensemble definition.- Regression client
CslibFrontierTests/Crypto/DecisionModuleLWE.leanexercises a concreteℤ_5[X]/(X^2+1)evaluation,rflinput layout, zero-advantage sanity check,advantage_eq_lweAdvantage, and both directions ofdecisionModuleLWE_iff_encoded.
- Client consolidation (
SIS/MLKEM/Security.lean,MLDSA/KeyOnly.lean):MLKEM: deletes bespokemlweRealGame,mlweIdealGame, andmlweAdvantage, curriesmlweKeyReductionandmlweReduction, and statesadvantage_indCpa_uniform_leandindCpaAdvantage_ledirectly in terms ofModuleLWE.advantagefor the centered-binomial secret/error laws.MLDSA: deletes bespokekeyDistinguishGameandkoaGame_eq_keyDistinguishGame, curriesforgeryDistinguisher, proveskoaGame_keyLawandkoaGame_uniformKeyLaw, and statessuccProbability_koaGame_leviaModuleLWE.advantage. Both modules and the manual explicitly state that uniform-secretDecisionModuleLWEdoes not bound short-secretModuleLWE.advantage.- Verified zero remaining references to the removed names across
CslibFrontier/,CslibFrontierTests/,CslibFrontierResults/, andmanual/, andCslibFrontier.leanaddsLWE.Modulein sorted order.
- Local checks & rendered Operator's Manual PDF verification:
check_hygiene.py --check-simp,check_projection_chains.py --base e4f39124c,check_changed_files.py --source-only --base e4f39124c, andcheck_operator_manual.pyall pass (0errors).- Visually inspected rendered
cslib-frontier-operators-manual.pdf(Operator's Manual PDFsrun43397000789) PDF pp. 436, 442, 443, and 456 (printed pp. 428, 434, 435, and 448) by eye: the lattice table row, ML-DSA paragraph, LWE/Module-LWE paragraph, and ML-KEM paragraph all render cleanly with no overfull boxes or broken links.
This was referenced Nov 13, 2026
Open
SamuelSchlesinger
added this pull request to the merge queue
Nov 13, 2026
Any commits made after this event will not be merged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4817 (lattice slice, L3m). It builds on #4889 (negacyclic ring, L3a) and #5017 (L3, typed decision LWE), both on
main.Module-LWE now has the same shape as
DecisionLWE. It has one set of games, and the ML-KEM and ML-DSA bounds are stated with them instead of their own copies.LWE/Module.lean. The Module-LWE part ofSIS/Module.lean(sample,flattenPolyVec_sample,encodeSample,sampleLaw, the encoded ensembles) moves here unchanged. The file adds:ModuleLWE.realExperiment s e DandrandomExperiment D, with@[simp]eval_*lemmas;ModuleLWE.realGame secretLaw errorLaw DandrandomGame D, andModuleLWE.advantage, the distance between them;realGame_eq_uniform_bind(matrix drawn first) andrandomGame_eq(one uniform pair), the orders the scheme proofs use.ModuleLWE.advantage_eq_lweAdvantage: the Module-LWE advantage is the LWE advantage over the ringNegacyclic (ZMod q) nfor the coefficientwise images of the laws.DecisionModuleLWEisGame.Indistinguishableover typed distinguishers, withModuleLWE.Input,encInputandDistinguisher.IsPPT.decisionModuleLWE_iff_encodedproves it equivalent to the previous word-level statement, so its strength is unchanged; the encoded words are the same (encInput_apply, checked byrfl). Word-level clients useDecisionModuleLWE.encoded. In-tree that is one site,publicKey_indistinguishable_of_decisionModuleLWE, plus the ModuleSIS nonvacuity test.SIS/MLKEM/Security.lean).mlweRealGame,mlweIdealGameandmlweAdvantageare deleted.advantage_indCpa_uniform_leandindCpaAdvantage_lebound the same quantities byModuleLWE.advantagewith centered-binomial laws.mlweKeyReductionandmlweReductionare now curried typed distinguishersA b ↦ ….MLDSA/KeyOnly.lean).keyDistinguishGameandkoaGame_eq_keyDistinguishGameare deleted.koaGame_keyLawandkoaGame_uniformKeyLawidentify the key-only game withModuleLWE.realGamefor the short laws and withrandomGame.succProbability_koaGame_leis stated withModuleLWE.advantage.SIS/Module.leanis now Module-SIS only, and its header points toLWE/Module.lean.SIS/Module/ApproximateSampling.leannow importsProbability.Productdirectly; it had been gettingPMF.pithroughSIS/Module'sLWE.Basicimport.Removed or changed public names.
MLKEM.mlweRealGame,mlweIdealGame,mlweAdvantage. UseModuleLWE.realGame,randomGameandadvantageinstead; they give the same games by definition.MLKEM.eval_mlweIdealGame_mlweKeyReductionandeval_mlweIdealGame_mlweReductionare nowrandomGame_mlweKeyReductionandrandomGame_mlweReduction.MLDSA.keyDistinguishGameandkoaGame_eq_keyDistinguishGame. UsekoaGame_keyLawandkoaGame_uniformKeyLawinstead.MLKEM.mlweKeyReduction,MLKEM.mlweReductionandMLDSA.forgeryDistinguishernow take the sample componentsA b(respectivelyM w,A t) instead of a pair or public key.DecisionModuleLWEis now typed. The word-level form isDecisionModuleLWE.encoded, equivalent bydecisionModuleLWE_iff_encoded.ModuleLWE.sample,flattenPolyVec_sample,encodeSample,sampleLaw,realEnsembleanduniformEnsemblekeep their names and statements. They move fromSIS/Module.leantoLWE/Module.lean, so importers ofSIS/Modulethat use them need the new import.Tests. New
CslibFrontierTests/Crypto/DecisionModuleLWE.leancontains:ℤ_5[X]/(X^2+1);rflword layout;ModuleSIS.leanusesh.encoded.Manuals. I updated the Operator's Manual (security-games-and-primitives):
DecisionModuleLWEmoved);mlweAdvantage.The Agent Operator's Manual needs no edit, because this PR adds no workflow or tooling.
results/andROADMAP.mdhave no entries for these declarations.Limitations.
DecisionModuleLWEfixes a uniform secret, so it still does not bound the ML-KEM and ML-DSA terms, whose secrets are short. This was already true; the docs now say it at each bound.advantage_realEncryptionView_uniform_le,…_msg_le) boundsGame-valued distinguishers oversampleLaw. Moving it ontoModuleLWE.advantagewould change those statements, so it is left as is.DecisionModuleLWEandDecisionLWEat modulus2 ^ wis proved. The bridge relates the games over the negacyclic ring, not the assumptions.Validation.
lake build --wfail --iofailpassed on the 78 affected targets: every importer ofSIS/Module,LWE/Module,ModuleEncryption, ML-KEM and ML-DSA, theLWE/Basicclosure (Regev, DualRegev, GSW) and their tests. Also clean:mk_all --check,lake linton the changed modules, the changed-file source lints, hygiene, the ratchets and the manual checker. CI provides the full run.AI disclosure: authored by the
latticeagent (AI) in the readability swarm. Agent review:negacyclicapproved 1dec3c3 locally (swarm board #1205); this is not human review.