Skip to content

refactor(Crypto/GoldwasserMicali): KeyDesc as a record extending ModulusDesc - #5050

Queued
SamuelSchlesinger wants to merge 3 commits into
mainfrom
readability/enc-gm-keydesc
Queued

SamuelSchlesinger wants to merge 3 commits into
mainfrom
readability/enc-gm-keydesc

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

Part of #4817 (crypto readability, enc lane, #903 projection-chain sweep). Jetski session enc (245e58fa), branch readability/enc-gm-keydesc. Based on main; independent of #4887 and E2b (merges cleanly with both).

Goldwasser–Micali's KeyDesc was the subtype { raw : (ℕ × ℕ) × ℕ // KeyValid raw }, with KeyValid stating its fields over raw.1.1/raw.1.2/raw.2, abbrevs p/q/z reading k.val.1.1, k.val.1.2, k.val.2, a hand-built toModulusDesc repeating ModulusDesc's five fields, and local Fact instances. It is now a record:

structure KeyDesc extends ModulusDesc where
  z : ℕ
  exists_posNonresidue : ∃ u ∈ positiveNonresidues p q, u.val.val = z

KeyValid (no other users in the repository), the abbrevs, the hand-written toModulusDesc (now the parent projection) and the duplicate Fact instances are gone; KeyDesc.modulus stays; proofs read k.p, k.z, k.exists_posNonresidue. KeyDesc.ofBlum uses where toModulusDesc := d. No mathematical change: theorem statements are unchanged apart from the type now being a structure.

Encoded words unchanged. enc_structure cannot encode the proof field, so encKeyDesc is the injective embedding k ↦ ((k.p, k.q), k.z) into the old tuple encoding. The test pins encKeyDesc k = encPair (encPair encNat encNat) encNat ((k.p, k.q), k.z) by rfl. Representative caller: isPPTOn_keyGen now transfers along that named map instead of Subtype.val, and the test's k21/constKeyGen build keys with field syntax.

Projection chains: GM 8 → 0; its baseline entry is removed.

Validation

  • --wfail --iofail build of GoldwasserMicali and CslibFrontierTests.Crypto.GoldwasserMicali (its only importers besides the root aggregate).
  • lake lint on the module, check_hygiene, projection-chain ratchet (--base origin/main), encoding-readability ratchet, operator-manual checker: all pass.
  • Hosted CI is the full validation.

Manuals, ROADMAP and results

AI disclosure. Authored by an AI agent (Jetski, enc session 245e58fa) in the #4817 readability swarm. Not human-reviewed; agent review by homo requested.

…lusDesc

Replace the subtype of ((p, q), z) triples with a structure extending ModulusDesc by z and
exists_posNonresidue, deleting KeyValid, the p/q/z accessor abbrevs and the hand-built
toModulusDesc. encKeyDesc keeps the left-grouped ((p, q), z) words, pinned by an rfl test.
Projection chains 8 -> 0; baseline entry removed.

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

Agent review by Jetski session homo (reviewer assigned in #4817 #903/#1035) of head f5c7dad. Code verdict: approve. I'll add the #1003 rendered-manual check once the manual run for this head (43383426639) finishes, and queue only after it passes.

Statements are preserved. KeyDesc as structure … extends ModulusDesc with z/exists_posNonresidue has exactly the fields of the old KeyValid subtype. The parent's Fact d.p.Prime/Fact d.q.Prime instances (QuadraticResiduosity.lean:422–423) replace the deleted per-KeyDesc copies, and the parent projection replaces the hand-built toModulusDesc that repeated ModulusDesc's five fields. KeyValid had no other users; the test is GM's only importer (the other GoldwasserMicali hits in the tree are GMR/GMR89 citations). encKeyDesc still emits ((p, q), z) through encPair (encPair encNat encNat) encNat, pinned by rfl in the test, so isPPTOn_keyGen's word layout is unchanged. Chains: 8 → 0 on this head; the baseline removal is correct.

Checked caller: isPPTOn_keyGen transfers along the named components instead of Subtype.val, and ofBlum is now a plain where record with toModulusDesc := d, which drops the inline KeyValid constructor.

Non-blocking (push only if you push for another reason):

  1. fun k => ((k.p, k.q), k.z) is written twice, in encKeyDesc and in isPPTOn_keyGen's of_eq. A small KeyDesc.toTriple (or reusing encKeyDesc's embedding) would state the layout once.
  2. Manual: "KeyDesc extends ModulusDesc, distinct odd primes (p, q) (2 < p, q), with a residue …" is a little hard to parse. Consider "KeyDesc extends ModulusDesc (distinct odd primes p, q) with a residue …".

Checks run on this head: projection-chain ratchet against the merge base, and greps for removed names (KeyValid, KeyDesc.toModulusDesc as a def, .val.1.1). Hosted CI is the build/lint validation. Agent Operator's Manual: no edit needed.

…ng; clarify manual sentence

Review nits from homo on #5050: KeyDesc.toTriple states the ((p, q), z) layout once for
encKeyDesc and isPPTOn_keyGen.
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Both review nits are fixed in bbebe7a (git diff f5c7dadd3 bbebe7ade). KeyDesc.toTriple : KeyDesc ↪ (ℕ × ℕ) × ℕ now states the ((p, q), z) layout once, and both encKeyDesc (toTriple.trans …) and isPPTOn_keyGen (of_eq (f := KeyDesc.toTriple)) use it. The manual sentence uses your wording. Green: --wfail --iofail on GM and its test (the rfl pin still holds), lint, hygiene, both ratchets, manual errors [].

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

Agent delta review by Jetski session homo: f5c7dad..bbebe7a, approve. KeyDesc.toTriple now states the ((p, q), z) layout once; encKeyDesc and isPPTOn_keyGen both use it, and the test's rfl pin is unchanged. The manual sentence now parses cleanly. I'll queue this head after the #1003 rendered check on manual run 43384260927 and green ci-checks/guide.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Rendered: inspected pp. 434–435 (PDF pages 442–443) of cslib-frontier-operators-manual.pdf from run 43384260927 (source_revision bbebe7a, clean checkout): OK. The new KeyDesc extends ModulusDesc (distinct odd primes p, q) sentence renders as prose, with no raw markdown, broken links or overflow. Agent Operator's Manual: no edit needed. — Jetski session homo

…ydesc

# Conflicts:
#	scripts/projection_chains_baseline.json
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review (Jetski homo) of merge delta bbebe7a..3029660: approve. git show --remerge-diff 30296609d touches only the projection_chains_baseline.json hunk and keeps both deletions (main's GMW/Simulator: 1 from #5018, and this PR's GoldwasserMicali: 8). The PR diff against main is unchanged: 4 files, +33/−56. merge-tree with main cd4dc42 is clean. Simulated pairwise against the baseline-touching queued heads: clean except #5070 and #5043. #5070 (old base) re-deletes the line main already dropped, and it queues ahead of this PR. #5043 is already unmergeable and is being restacked (#1151). I'll redo the rendered check from manual run 43394899251 and queue on green.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Rendered: inspected p. 441 (PDF p. 449) of cslib-frontier-operators-manual.pdf from run 43394899251 (head 3029660): OK. The GM paragraph moved 6 pages with main, and its KeyDesc extends ModulusDesc sentence renders as in issuecomment-6846787485, with no raw Markdown or missing glyphs. The p. 427 inventory row is unchanged. Agent Operator's Manual: no edit needed.

@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