Skip to content

refactor(Crypto/Encryption): generic public-key replacement for validated challenge pairs (readability E2b) - #5096

Queued
SamuelSchlesinger wants to merge 12 commits into
mainfrom
readability/enc-e2b-keyrepl
Queued

SamuelSchlesinger wants to merge 12 commits into
mainfrom
readability/enc-e2b-keyrepl

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

Readability plan E2b (enc lane), part of #4817. Follows #4887 (typed PKE), which has landed.

Encryption/PublicKeyReplacement.lean now covers restricted challenge pairs. publicKeyGameOn valid, keyDistinguisherOn valid and their lemmas (isPPT_keyDistinguisherOn, distinguishingGame_keyDistinguisherOn, probability_keyDistinguisherOn, advantage_publicKeyGameOn_le) are generic over the message type and a challenge-pair validity predicate. eval_gameOn_eq_publicKeyGameOn connects the replacement game to Encryption.gameOn. The unrestricted publicKeyGame / keyDistinguisher are now Msg-generic abbrevs with valid := fun _ _ _ _ => true. isPPT_keyDistinguisherOn is now a short ppt proof from the validity certificate; the old hand-built proof was about 60 lines. Every changed statement generalizes the old one and reduces to it at Msg := Bool and valid := true.

Representative caller. Goldwasser–Micali's word scheme had its own copy of the argument: wordKeyDistinguisher, isPPT_wordKeyDistinguisher, a private swap lemma and a private advantage bound. All four are deleted. publicKeyWordGame is now an abbrev for publicKeyGameOn (validBoundedWords maxLen), with the same body as before. qrWordDistinguisher calls keyDistinguisherOn, and advantage_publicKeyWordGame_le_qr uses advantage_publicKeyGameOn_le. The only GM-specific fact left is the new public computableInPolyTime_validBoundedWords, which the generic PPT lemma consumes. GSW, Regev and Dual Regev keep their proofs; their simp sets now also unfold publicKeyGameOn. The GM theorem statements are unchanged.

Removed public names (none has a remaining user):

  • PublicKeyReplacement: distinguishingGame_keyDistinguisher and probability_keyDistinguisher. Use the …On forms with valid := fun _ _ _ _ => true.
  • GoldwasserMicali: wordKeyDistinguisher and isPPT_wordKeyDistinguisher. Use Encryption.keyDistinguisherOn (validBoundedWords maxLen) encryptWord and Encryption.isPPT_keyDistinguisherOn.

A proof that unfolds publicKeyGame or keyDistinguisher now also unfolds the …On form, plus ↓reduceIte under simp only.

Manuals. The Operator's Manual (security-games-and-primitives.md) gets a new paragraph covering the replacement module, its clients, the unfold note and the test link. The Agent Operator's Manual needs no edit, since no workflow changed. No ROADMAP or results change: this is infrastructure only and adds no new mathematics.

Validation at 4de23de (adc3e8f plus a main merge after #4887 landed; the merge resolves only the manual hunk next to E2a's paragraph). Done locally on targeted modules; CI on the PR does the full run.

  • lake build --wfail --iofail is green on all 14 changed modules and their transitive importers (8306 jobs).
  • The chain and encoding ratchets pass with --base origin/main, and mk_all --check and git diff --check are clean.
  • CslibFrontierTests/Crypto/GSWSecurity.lean exercises the generic distinguisher, including an example with a restricted valid.

Review. Agent review by dhrev-2 approved 4de23de locally (board #1196). The #1003 rendered check follows on the PR.

AI disclosure: prepared by a Jetski agent (enc, session 245e58fa). The review above is by an agent, not a human.

…1, WIP)

Experiment := ProbComp Bool with succProbability/advantage (+ Pr bridges),
distAdvantage, Game.withSetup; TwoStage + TwoStage.IsPPT (family over n),
MessagePair + encMessagePair, lrExperiment on a drawn public input.
SSP.advantage restated through Experiment.advantage.

Part of #4817. Session: Jetski de72c51e (swarm worker infra).
…aragraph (I1)

encMessagePair is encOfEquiv MessagePair.equivProd (encPair encM encM), so the encoded
words equal the word adversary's encChoiceOut (checked by rfl in the test). The SSP tests
unfold Experiment.advantage before rewriting the evaluated runs.
Adds Encryption/Scheme.lean (PKE, PKE.Correct, PKE.cpaExperiment, eval_cpaExperiment) on top of
I1's lrExperiment, and the word bridge AdversaryOf.toTwoStage, isPPT_toTwoStage and
gameOn_eq_cpaExperiment in Encryption/Basic.lean. The I1 test's ofWord copy now uses the library
API. Tests in CslibFrontierTests/Crypto/PKEScheme.lean; manual paragraph in
security-games-and-primitives.md.
Experiment.advantage_bind_le_of_support and succProbability_bind_le_of_support lift a bound at
every output of a setup program (key generation) to setup >>= exp, through
Experiment.eval_bind_eq_withSetup. The TwoStage.IsPPT test now uses a typed saved state, and
the module doc notes that the word-to-typed converse needs a stage-2 simulation.
…age bridge corollary

- Scheme.lean cites Definition 11.1 in Section 11.2; drop the unused Norm import.
- Add Encryption.advantage_gameOn_eq_cpaExperiment (Encryption.advantage applies gameOn
  partially, so rw with gameOn_eq_cpaExperiment does not reach it), with a test client.
- Manual and module doc name the corollary.
…ve GM word copy (E2b)

publicKeyGameOn/keyDistinguisherOn and their PPT, swap and advantage lemmas are
generic over the message type and the gameOn admissibility predicate; the
unrestricted names are the valid := true abbrevs. The distinguisher's PPT
certificate is now the ppt tactic. Goldwasser-Micali's wordKeyDistinguisher,
its PPT proof and private swap/advantage lemmas are deleted in favour of the
generic ones; computableInPolyTime_validBoundedWords is the only GM-specific
fact left. GSW/Regev/DualRegev simp sets also unfold publicKeyGameOn.
# Conflicts:
#	CslibFrontierTests/Crypto/Experiment.lean
#	manual/programs-crypto-and-probability/security-games-and-primitives.md
# Conflicts:
#	CslibFrontier/Crypto/Computational/Encryption/PublicKeyReplacement.lean
#	CslibFrontier/Crypto/Computational/GoldwasserMicali.lean
#	CslibFrontier/Crypto/Computational/LWE/DualRegev/Security.lean
…eyrepl

# Conflicts:
#	manual/programs-crypto-and-probability/security-games-and-primitives.md
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review claim: coordinator agy-634bba4c (session 634bba4c-9d3c-4f80-8d5b-6097f495b913) is reviewing head 4de23de089c41a40d0c12fe049de36ce22a3a2cc. This is agent review, not human review.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review by dhrev-2 (swarm reviewer) of head 4de23de089c41a40d0c12fe049de36ce22a3a2cc. This is agent review, not human review. Per the queue freeze, I reviewed the branch locally first (git diff cd4dc4279 4de23de08) and approved it on the swarm board before the PR was opened at this head.

Verdict: APPROVE.

  • Statements: every changed public statement in PublicKeyReplacement strictly generalizes the old one. At Msg := Bool and valid := fun _ _ _ _ => true each matches the old form by definition:
    • encKeyedInput encBool is the old encPair encUnary (encPair encBits encBool).
    • AdversaryOf.IsPPT encBool is Adversary.IsPPT.
    • The unrestricted abbrevs equal the old bodies once if true reduces.
    • In GM, publicKeyWordGame is the old body verbatim, as an abbrev of publicKeyGameOn (validBoundedWords maxLen). The GM theorem statements are unchanged.
  • Removed public names, all listed in the body, with no remaining users at head: distinguishingGame_keyDistinguisher, probability_keyDistinguisher, wordKeyDistinguisher, isPPT_wordKeyDistinguisher.
  • Duplication removed: GM's word copy of the reduction is deleted rather than kept privately: the def, its PPT proof, the swap lemma and the advantage bound. isPPT_keyDistinguisherOn replaces a ~60-line hand-built PPT proof with ppt from the hvalid certificate. computableInPolyTime_validBoundedWords is the right shared fact, and its encoding (encChallengePairInput encBits) matches INDCPAOn.
  • Representative caller: indcpaOn_goldwasserMicali_bits now gets the replacement step from eval_gameOn_eq_publicKeyGameOn plus advantage_publicKeyGameOn_le, with no word-specific reduction left. DualRegev's lweDistinguisher reads the ciphertext out of the LWE word rather than encrypting under pk, so keeping it separate is correct.
  • Other checks:
  • Heads-up: lattice reports that L4a conflicts with this PR in Regev's publicKeyGame_uniformEnsemble simp list. Whichever lands second adds Encryption.publicKeyGameOn to it.
  • Optional, no change requested: a future client wanting the affine identity for the unrestricted keyDistinguisher has to go through probability_keyDistinguisherOn.

Rendered: inspected PDF p.451 (printed 443) of cslib-frontier-operators-manual.pdf from manual run 43396147208 at 4de23de: OK.

  • Manifest: source_revision equals the head, source_checkout_dirty is False, and the sha256 matches (6931131b…).
  • The new paragraph has no raw markdown and no overflow (x ∈ [71.7, 543.4] of 612 pt).
  • The links resolve to blob/4de23de08…/CslibFrontier/Crypto/Computational/Encryption/PublicKeyReplacement.lean and …/CslibFrontierTests/Crypto/GSWSecurity.lean.

Agent Operator's Manual: no edit needed. The change adds no workflow, tooling or agent procedure.

I'll queue this exact head once ci-checks and guide are green and the CI notices are clean.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review (coordinator agy-634bba4c, session 634bba4c-9d3c-4f80-8d5b-6097f495b913) of head 4de23de089c41a40d0c12fe049de36ce22a3a2cc: APPROVE (pending ci-checks, guide, and check-title completion + advisory check before queueing). This is agent review, not human review.

What was checked

  • Generic validated public-key replacement (CslibFrontier/Crypto/Computational/Encryption/PublicKeyReplacement.lean):
    • publicKeyGameOn and keyDistinguisherOn generalize over {Msg : Type} and valid : ℕ → List Bool → Msg → Msg → Bool, returning pure false and false ^^ bit on inadmissible challenge pairs so distinguishingGame_keyDistinguisherOn, probability_keyDistinguisherOn, and advantage_publicKeyGameOn_le hold with exact factor-2 loss and no restrictions on saved state.
    • publicKeyGame and keyDistinguisher become abbrev specializations at valid := fun _ _ _ _ => true (eval_gameOn_eq_publicKeyGameOn, eval_game_eq_publicKeyGame, advantage_publicKeyGame_le).
    • isPPT_keyDistinguisherOn collapses ~60 lines of manual tuple-encoding plumbing to a 4-line ppt proof from ComputableInPolyTime ... (encChallengePairInput encMsg) encBool.
  • Representative client deduplication & callers (GoldwasserMicali.lean, GSW/Security.lean, Regev/Security.lean, DualRegev/Security.lean):
    • Deletes GoldwasserMicali's bespoke wordKeyDistinguisher, isPPT_wordKeyDistinguisher, distinguishingGame_wordKeyDistinguisher, and advantage_publicKeyWordGame_le (~80 lines), replacing them with computableInPolyTime_validBoundedWords + Encryption.publicKeyGameOn/keyDistinguisherOn while keeping isPPTOn_qrWordDistinguisher, advantage_publicKeyWordGame_le_qr, and indcpaOn_goldwasserMicali_bits unchanged.
    • Verified git grep finds zero remaining callers of the four removed declarations across the repository, and CslibFrontierTests/Crypto/GSWSecurity.lean checks the inadmissible-pair case (valid := fun _ _ _ _ => false).
  • Checks & Operator's Manual PDF:
    • check_hygiene.py --check-simp, check_projection_chains.py --base cd4dc4279, check_changed_files.py --source-only --base cd4dc4279, and check_operator_manual.py (0 errors) all pass; git show --remerge-diff 4de23de08 resolves only the adjacent security-games-and-primitives.md hunk cleanly after #4887, and git merge-tree --write-tree is clean against origin/main (e4f39124c) as well as #5050, #5081, #5008, and #5013.
    • Visually inspected rendered cslib-frontier-operators-manual.pdf from Operator's Manual PDFs (run 43396147208), PDF p. 451 (printed p. 443, §14.8.3): the new Encryption/PublicKeyReplacement.lean paragraph, hyperlinks, inline Lean identifiers (↓reduceIte), and margins all render cleanly.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

CI notices at 4de23de08 (agent review by dhrev-2; not human review): 0 repeated proof blocks in 114 proofs, 0 parallel-definition candidates among 6, 0 duplicate statements among 17. The 4 PR-name flags are the removed public names, which the body's migration list cites on purpose. 0 unresolved threads, CLEAN. Queueing this head.

@SamuelSchlesinger
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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant