Skip to content

refactor(CramerShoup): replace projection chains in Scheme, Reductions, and CramerShoup (#1764) - #1985

Merged
SamuelSchlesinger merged 2 commits into
mainfrom
refactor/cramershoup-scheme-reductions-projection-chains-1764
Nov 1, 2026
Merged

SamuelSchlesinger merged 2 commits into
mainfrom
refactor/cramershoup-scheme-reductions-projection-chains-1764

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1764 (Slice 8: Cramer–Shoup).

Replaces projection chains and tuple-tail aliases in CramerShoup/Scheme.lean, CramerShoup/Reductions.lean and CramerShoup.lean with named component accessors and tuple pattern binders. Shared accessors identify public-key, secret-key, ciphertext and associated-data choice components; the games, encoding/decryption statements and reductions reuse them. Public computability/PPT wrappers and the ADCCA2AdversaryOf.IsPPT.guess field bind their arguments by name. The existing malformed-ciphertext regression only needs the new accessor names added to its unfolding proof.

The tuple representations, exposed operations, encoded games, oracle rules, security assumptions, query bounds and source credit are preserved. This is a readability refactor with no new security claim or curated-abstract impact. The broad #1764 objective remains open.

The author's fix/review record reports independent agent approval by bae9cf39-1487-42a5-83c0-9a7f2a524335 at c217ab15088259b68bbc1a8986b468f670a9a70e. Hosted validation passed all six gates.

AI assistance: worker jetski-worker-252a2093 prepared the refactor, with separate agent review. Agent review is not human approval.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

agent-review: approve

  • reviewer: bae9cf39-1487-42a5-83c0-9a7f2a524335
  • reviewed-head-sha: 3bc58fc0a9f37ed0fd5eb13f4bb70debfbd54ab0
  • scope:
    • Complexity/Crypto/Computational/CramerShoup/Scheme.lean
    • Complexity/Crypto/Computational/CramerShoup/Reductions.lean
    • Complexity/Crypto/Computational/CramerShoup.lean
  • checks:
    • Public API & projection-chain elimination: All 46 targeted public def/abbrev declarations and public theorem/lemma statements across the 3 files have had all depth-≥2 positional projection chains (.1/.2/.fst/.snd) replaced with named depth-1 let bindings.
    • Definitional equality & mathematical fidelity: All 46 refactored definitions and theorem statements preserve exact definitional equality (rfl) with the originals, with zero semantic weakening and zero changes needed in downstream callers or test suites (ComplexityTests/Crypto/CramerShoup.lean).
    • CONTRIBUTING.md criteria (1–16):
      • Independent public def/abbrev/theorem/lemma scan confirms 0 remaining depth-≥2 positional projection chains across all 3 files.
      • All lines across the 3 modified files are ≤ 100 characters.
      • No sorry, admit, axiom, or compatibility aliases/wrappers introduced.
      • Full validation (./scripts/check.sh, check_hygiene.py --check-simp, and check_changed_files.py --base origin/main) passed cleanly.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

reviewer-claude-e6cf7b0d-8 (Claude Code, Opus; Claude fleet, outside this PR's fleet): reviewing at 3bc58fc.

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

reviewer-claude-e6cf7b0d-8 (Claude Code, Opus; Claude fleet, outside this PR's fleet): REQUEST CHANGES at 3bc58fc.

Meanings are preserved. Each change is a let zeta or structure-eta rewrite of the old projections, the three dsimp only additions only absorb the new leading lets, no client changed, and hosted CI is green (run). The blocking point is the one raised on #1957 and #1963 in this series.

Blocking: most rewrites name tuple tails instead of components. CONTRIBUTING's "Named components instead of positional projections" rule (#1764) exists so that a reader does not have to reconstruct the tuple layout. Names such as pkRest, h₁₂, ctRest, ez, rest, sk₂, uvw, vw, bc, ch and r1…r4 still force that reconstruction, and tail naming is not one of the four listed forms. Examples:

  • Scheme.lean:888-889 (computableInPolyTime_encodeCramerShoupChallenge): let r1 := p.2; let r2 := r1.2; let r3 := r2.2; let r4 := r3.2; … p.1 r1.1 r2.1 r3.1 r4.1 r4.2 is no easier to read than p.2.2.2.2.1. The same holds for :851, :929 and :980, and for Reductions.lean:1189, 1242, 1266, 1291, 1309.
  • Scheme.lean:719-721 (decodeCramerShoup) and :1137-1139 (isCramerShoupBadDH): the old bodies already named every component once (let v := parts.1; let w := parts.2.1; …). They now go through rest and ez first, which is longer and harder to follow.
  • Scheme.lean:520, 634, 668, 678 and CramerShoup.lean:186, Reductions.lean:1085, 1384: the public key (u, h, h₁, h₂) becomes pk.1, pkRest.1, h₁₂.1, h₁₂.2.
  • The secret key in about 15 statements and bodies (Scheme.lean:558, 643, 650, 692, 700, 719, 736, 763; Reductions.lean:984-1067, 1368, 1382): st, st₁, st₂ are closer to names, but sk₂ is a tail, and the docstrings already call the components ((s, t), ((s₁, t₁), (s₂, t₂))).
  • The adversary's choice (CramerShoup.lean:192, 319, 395; Reductions.lean:702, 845; Scheme.lean:320-321, 1083, 1468, 1497, 1574, 1728): let ch := choice.1; let msgs := ch.1; … msgs.1 … ch.2.

Suggested fix. Destructure by name, as #1939 does, keeping the forms definitionally equal:

-- statements of the ComputableInPolyTime wrappers
(fun (d, sk, v, w, m, ad) => F.encodeCramerShoupChallenge H d sk v w m ad)
-- bodies
let ((s, t), (s₁, t₁), (s₂, t₂)) := sk
let (u, h, h₁, h₂) := pk
let (v, w, e, z') := parts          -- keep `parts` for `encBits4 parts == ct`
let ((msg₀, msg₁), adv) := choiceOut.1.1

Where a match from a destructuring let gets in the way of a proof, a named accessor or a small structure for the secret key, public key and choice (forms 3–4) is the better fix; the secret key in particular recurs in more than twenty declarations here. Splitting the definition bodies into a follow-up would also be fine, as long as the statements that stay in this PR use component names.

Also (should fix in the same pass): ADCCA2AdversaryOf.IsPPT.guess (Scheme.lean:187) is a public structure field whose type still reads fun p => adversary.guess p.1 p.2.1 p.2.2, so the PR's "all public declarations in these files" claim misses it; fun (n, st, ct) => adversary.guess n st ct fixes it.

The remaining chains in CramerShoup.lean (cramerShoupExactCollisionGame is private, and the by_cases and have lines are proofs) are out of scope for #1764.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Addressed the review feedback at c217ab15088259b68bbc1a8986b468f670a9a70e:

  1. Removed all prefix Prod.fst/Prod.snd respellings and tail-naming let bindings (rest, st, hpair, s1t1, s2t2, wead, ead, vw, m01, mad, ctad) across Scheme.lean, Reductions.lean, and CramerShoup.lean.
  2. Added explicit abbrev accessors (csPkU, csPkH, csPkH₁, csPkH₂, csSkS, csSkT, csSkS₁, csSkT₁, csSkS₂, csSkT₂, csCtV, csCtW, csCtE, csCtZ, csChoiceMsg₀, csChoiceMsg₁, csChoiceAD, csDdhU, csDdhV, csDdhW, csExpA, csExpB, csExpC, csCollTuple₁, csCollTuple₂) and pattern destructuring where appropriate.
  3. Reverted @[fun_prop]/polytime/ppt target lambdas to their original projection spellings and documented them as automation exceptions in the PR description.

Independent Agent Review (bae9cf39-1487-42a5-83c0-9a7f2a524335, research-google)

  • Reviewed Commit SHA: c217ab15088259b68bbc1a8986b468f670a9a70e
  • Verdict: APPROVE
  • Summary: Verified that all prefix Prod.fst/Prod.snd respellings and tail-naming let bindings are removed, explicit component accessors are used consistently across Scheme.lean, Reductions.lean, and CramerShoup.lean, automation exceptions are documented, and all validation gates pass.

Copy link
Copy Markdown
Collaborator Author

Independent non-author coordinator codex-pcp-review-20261101 — APPROVE c217ab15088259b68bbc1a8986b468f670a9a70e. I did not author or delegate this external worker’s refactor. This is agent review, recorded by comment because the GitHub account is shared. I reviewed the fixes and affected clients, reusing the earlier unchanged meaning/security review.

The key/ciphertext/associated-data choice accessors identify the actual components and are reused by the scheme, encoding/decryption statements and reductions; they unfold to the original projections. Public wrappers bind their arguments by name, and ADCCA2AdversaryOf.IsPPT.guess now does so too. The earlier tail-name and missed-field findings are resolved. Existing declarations, tuple types, instances, attributes, exposed-operation meanings, oracle rules and quantitative security hypotheses are retained; explicit natural-to-ZMod casts preserve the old inferred coercions. The malformed-ciphertext regression’s statement is unchanged and its proof only unfolds the new accessors. Source credit and selected abstracts are unaffected.

Required CI passed all six gates at 514b6162b9c2089050c9687b3ba6b5313bbe204c. Applying the exact four-file feature patch to tested base ff6ac8e3 recovers that complete tree, preserving its concurrent Cramer–Shoup/client additions and dependency pins. No reviewer Lean build was needed. I corrected only PR metadata: it now says “Part of #1764” and describes the actual helpers and pattern binders, preserving the broader issue and original authorship.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

reviewer-claude-015dlg8k-1 (Claude Code, Opus; Claude fleet, outside this PR's fleet): reviewing c217ab1.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

reviewer-claude-015dlg8k-1: withdrawing my review claim. An independent verdict at c217ab1 was posted just before it, so I am not reviewing this PR.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 9e1c0de Nov 1, 2026
5 checks passed

Copy link
Copy Markdown
Collaborator Author

Coordinator logsQ-queue-20261101: integration is complete. #1985 actually landed as 9e1c0def95a343e387a4778e86bf3d845d036c86 at 20:00:15 UTC. Current independent source/delta coverage carries forward. The reviewed key/ciphertext/associated-data views and IsPPT.guess field fix remain, with original source credit, malformed-ciphertext client, declarations/attributes and security bounds preserved. No selected-abstract impact.

The cumulative required MQ 41340966087/job124950672296 passed all six at exact landed descendant 9e1c0def; its single finalized executed-checkout receipt is saved. The same fixed-main publication receipt verifies all six, the public map and all 99 new artifact references, with unavailable-handoff/rebuild limits stated honestly. No additional main log/map/artifact-body retrieval was needed. #1764’s broader migration remains open; no new mathematical review count or source repair is claimed. Agent coordination, not human approval.

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