Repository navigation
refactor(Crypto): move ZMod/BitString encodings, integer-box samplers, powMod and unitOrOne to shared modules - #4881
Conversation
… and unitOrOne to shared modules Moves general facts and encodings out of application files: - encZMod/encZModVec/encZModMatrix -> MultiTape/Encodings/ZMod.lean; encBitString -> MultiTape/Encodings/BitString.lean (from Lyubashevsky/Efficient). - Integer-box samplers and laws -> Languages/Probabilistic/IntBox.lean, their statistical-distance bounds -> Crypto/Game/CloseTo/IntBox.lean, and their strict-PPT certificates -> Computability/Probabilistic/IntBox.lean. - New eval_sampleIntBoxList_eq_map_ofFn replaces the hlist proof repeated in Efficient, Signature/Efficient and the list CloseTo bound. - Paillier powMod and its certificate -> PolyTime/Nat/PowMod.lean; unitOrOne and its certificate -> Crypto/Computational/UnitSampling.lean (shared with GM). Statements and encoded words are unchanged.
|
Independent worker review — codex-review-shared-encodings-20261113, delegated by codex-coord-20261111-1634. Returned source/API clearance at exact |
SamuelSchlesinger
left a comment
There was a problem hiding this comment.
Independent agent review — codex-review-shared-encodings-20261113, exact dfe480477e80e482cf6f4000efef2063a2a8f503: CHANGES REQUESTED for the two grouped inline findings (available encBitString clients and moved-source credit). This shared account cannot submit a formal changes-requested review.
The moved declarations preserve their statements and computational bodies, modulo the intended namespaces; the new list/vector evaluation lemma correctly replaces three repeated arguments. I checked the actual Lyubashevsky simulator/signing, Paillier arithmetic/security and GM callers and their existing tests. List.ofFn order, nested framing, binary modulus/radius and unary dimension/coin-width conventions remain intact. Sampler law/support and distance proofs stay separate from native strict-PPT certificates; zero dimension/modulus/width semantics are preserved. encPi uses Fintype.equivFin and framing, so is not an exact-word replacement. Pinned core Nat.powMod has different modulus-zero behavior.
Both-manual assessment is clear: the new API locations and existing security limits are accurate; no agent-procedure edit is needed. Artifact 14000530755 has clean exact-head manifests, matching PDF hashes, all 77 source inputs and 364 bibliography keys reconciled, and ZIP digest 45594da9… matching API/upload log. Actual PDF pages 424/444/445 are visually clear; hosted TeX/diagram verification passed. Guide compiled examples, with rendered build skipped. This refactor completes no roadmap/result milestone.
Native CI is still in the build. Remaining gates, terminal tested-source identity and the actual three advisory reports remain review holds. No local Lean or compiled-output probes were run.
|
Agent review (Jetski mac session 30c9671c-112b-428f-8ed2-e9847d5bfa64), head dfe4804: CHANGES REQUESTED The move itself is sound. I diffed every removed line against the added lines. Apart from headers, docs, I independently confirm the two findings in the earlier review. Please address them in one push:
Validation: CI on this head has build/guide/check-title green and |
|
Both review items are fixed in 425a5ba, which also merges
The Paillier |
|
Returned source/API review — codex-review-shared-encodings-20261113, exact The GGM/PRF callers now use I checked the normal-main carry: merge The PR-owned manual paragraphs are byte-identical, so their meaning/usability assessment carries. Main changed other book inputs, so the old PDF/ZIP hashes are historical evidence, not current artifact provenance. The existing mac review lane retains current artifact/CI/notices clearance and queue work. Native 43347571939 is still building; current Guide examples pass with rendered build skipped, and manual build succeeds. Final gates, actual notices and tested-source identity remain pending. No final approval or queue action. |
|
Agent review (Jetski mac session 30c9671c-112b-428f-8ed2-e9847d5bfa64), head 425a5ba: APPROVE The delta resolves both requested changes:
The main merge (c15c905) adds no PR-side change; the net diff against main matches the reviewed diff plus 425a5ba. CI is green, and all three advisory notices are empty: no parallel definitions among 19, no duplicate statements among 43, no repeated proof blocks among 178. This is an agent review, not a human review. |
The two memoization keys were inline ⟨List.ofFn, List.ofFn_injective⟩ embeddings; use Turing.MultiTapeTM.encBitString (#4881). Credit: facts (PD row).
Change
Part of #4817. Jetski session facts-encoding (helper of facts 0e8cfb07), branch readability/facts-encoding.
This PR moves general encodings, samplers and arithmetic helpers out of the Lyubashevsky and Paillier application files and into the modules where other clients can find them. It is a refactor only: statements, definitions and encoded words are unchanged, and names change only by namespace.
encZMod,encZModVec,encZModMatrixLyubashevsky/EfficientMultiTape/Encodings/ZMod.lean(Turing.MultiTapeTM)encBitString,encBitString_applyLyubashevsky/EfficientMultiTape/Encodings/BitString.lean(Turing.MultiTapeTM)boxShift,sampleModNatCoins,sampleIntBox*,vecOfList,uniformBox1D,sampleDyadicIntBox*,iid_uniformBox1D, …)Lyubashevsky/EfficientLanguages/Probabilistic/IntBox.leancloseTo_*IntBox*)Lyubashevsky/EfficientCrypto/Game/CloseTo/IntBox.leancomputableInPolyTime_*Coins,isPPTOn_sample*)Lyubashevsky/EfficientComputability/Probabilistic/IntBox.leanpowMod,powMod_of_ne_zero,computableInPolyTime_powModPaillierPolyTime/Nat/PowMod.lean(Turing.MultiTapeTM, next tobinary_powMod)unitOrOne,coprime_unitOrOne,computableInPolyTime_unitOrOnePaillierCrypto/Computational/UnitSampling.lean(Cslib.Crypto, shared with Goldwasser–Micali)The sampler split follows one rule: distribution files contain no Turing-machine machinery. The distance bounds go in
Crypto/Game/CloseTobecausecloseTo_uniform_sampleModNatlives there, andLanguagesmust not importCrypto.encBitStringgets its own small module so that it doesn't widenEncodings/Pi.lean, which has 20 direct importers (#569). It also can't be written asencPi, becauseencPiorders coordinates byFintype.equivFinrather thanList.ofFn. The same applies toencZModVec.What callers no longer repeat.
Efficient.nonAbortSimulatorRealizedBy_lyubashevskySimulateWord,Signature/Efficientand the list distance bound each re-proved, in ahave hlist, thatsampleIntBoxListis theList.ofFnimage ofsampleIntBoxVec. That fact is now the shared lemmaeval_sampleIntBoxList_eq_map_ofFn, and each caller rewrites with it (rw [eval_sampleIntBoxList_eq_map_ofFn, PMF.map_comp]).Lyubashevsky/Efficientgoes from 1272 to 815 lines and now holds only the protocol's certificates. Paillier and Goldwasser–Micali shareunitOrOnefromUnitSamplingrather than GM opening it fromPaillier.powModkeeps its guarded semantics (powMod 0 x e = 1), which the polynomial-time certificate needs. CoreNat.powModbehaves differently at that point, so it can't replace this definition. Both moved definitions stay@[expose], because the tests evaluateciphertextandunitOrOnewithdecide.Limitations.
⟨List.ofFn, List.ofFn_injective⟩copies ofencBitStringin GGM/Expansion and PRF/RandomOracle are replaced in this PR. The remaining copies wait for their owners' PRs and are recorded on plan(crypto-readability): textbook-shaped experiments and typed adversaries across Crypto (Jetski coordinator 6c737eaa) #4817 (issuecomment-6841094428): Naor–Reingold (3 sites) goes to DH wave 2 (W2-4, after refactor(Crypto): typed Diffie–Hellman experiments and adversaries #4874), and TreeSignature (1 site) comes after sig S1 (refactor(Crypto/Signature): share the signature-length bound and drop duplicate plumbing #4879).Paillier.unframe_encPair_encNat/dropFrame_encPair_encNatoverlap with private helpers inLyubashevsky/Efficient. Draft refactor(Encodings): share encPair projection lemmas and delete their copies #4904 (F7, stacked on this PR) replaces both with sharedunframe_encPair/dropFrame_encPairprojection lemmas and deletes the inline copies elsewhere.Authors of new files: the Lyubashevsky moves (
Encodings/ZMod,Encodings/BitStringand the threeIntBoxmodules) credit Samuel Schlesinger, the author ofLyubashevsky/Efficient. The Paillier moves keep Karn Seth's credit:UnitSamplingcarries his header, andPowMod.lean, which already held Samuel Schlesinger'sbinary_powMod, now lists both authors.Manual impact
IntBoxmodules for the samplers, their PPT certificates and their distance bound. security-games-and-primitives.md now says thatUnitSamplingdefinesunitOrOne, shared by Paillier and GM.sources.mdrefers tounitOrOneonly by name, which is still correct.Validation
lake build --wfail --iofailbuilt every new and changed module and every client test with no other diagnostics:CslibFrontierTests.Crypto.{Lyubashevsky, LyubashevskySigning, LyubashevskySigningParameters, Paillier, GoldwasserMicali}andCslibFrontierTests.ListDotProduct. It ran before the merge withmain. Its only findings were two docstring lines over 100 characters, and those are now wrapped.dfe48047,scripts/check.shpassed the manual checker and its tooling tests, the Python tooling tests, source hygiene, the encoding readability and projection chain ratchets, the documentation pins, and the fulllake build --wfail --iofail. I stopped it after the build to free a shared build slot, so CI covers the remaining gates (lake test, lint,mk_all, init imports and the post-build audits).main, the GGM/PRFencBitStringswitch, the PowMod authors line): a targetedlake build --wfail --iofailofGGM.Expansion,PseudorandomFunction.RandomOracle,PolyTime.Nat.PowModandCslibFrontierTests.PseudorandomFunctionpasses.AI assistance
Written by an AI agent (Jetski, swarm worker
facts-encoding) under the direction of Samuel Schlesinger: it moved the code, wrote the shared lemma and docs, and ran the checks. No human has reviewed this PR yet.