Skip to content

refactor(Crypto/Garbling): typed BHR12 garbling experiments and shared hidden-bit lemmas (readability G4) - #5020

Open
SamuelSchlesinger wants to merge 5 commits into
mainfrom
readability/garble-g4-bhr-typed
Open

SamuelSchlesinger wants to merge 5 commits into
mainfrom
readability/garble-g4-bhr-typed

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

Closes #4888. Part of #4817 (crypto readability, rules 2, 3, 5 and 6). Builds on I1 #4878, now on main.

This retypes the Bellare–Hoang–Rogaway garbling layer (Garbling/{Scheme,Games,Foundations,Adaptive,CircuitInverters}) onto I1's Experiment, TwoStage and MessagePair. The experiments now read like the figures in the paper.

What changed

  • Named records replace nested tuples. Queries are Query {fn, input}, the views are PrvView {fn, input, decInfo} and ObvView {fn, input}, and the Prv1 garbled function is GarbledFn {fn, decInfo}. Challenge pairs are MessagePair (Query Fn), selected with pair.select b.
  • Adversaries are TwoStage. The experiments prvIndExperiment G Φ k A b, prvSimExperiment, obvIndExperiment, obvSimExperiment and autExperiment take a fixed security parameter k, and simulators lose their ℕ argument. The invalid-query answer ⊥ (none) stays, as in BHR, so these are not lrExperiment instances. Prv1 keeps its three-stage adversary because I1 has no three-stage shape.
  • The hidden-bit fact moves to a new leaf, Crypto/Game/HiddenBit.lean (coordinator decision on the board, superseding the issue's "not in scope" line). It holds Game.succProbability_uniform_bool_beq (moved from Garbling/Games), Game.advantage_eq_two_mul_guessingAdvantage_uniform_bool_beq, Game.uniform_bool_bind_map_beq_const and Experiment.guessBit with its two lemmas. The three private re-derivations in Games, Foundations and Adaptive are deleted, and the IND⇔SIM proofs in Foundations are now short rewrite chains. HardCore, RSALeastSignificantBit and GL/HardCore were checked and contain no copy of this argument.
  • Topo.IsValid (named fields, with Topo.isValid_iff and a Decidable instance) and ValidShape are structures. CircuitInverters drops from 6 projection chains to 0, and its baseline entry is removed.
  • IsEvInverter returns a Query. The new public obvInverterQuery is shared by the simulator, the reduction and the validity proof.

Removed or renamed public API: prv1BitGame (use Experiment.guessBit), isValid_ofTopo_iff, shape_of_isValid, IsValid.m_le (use .m_le_q), the ValidShape.n/m/q abbrevs (now fields), and sizeTopo_valid → sizeTopo_isValid. Experiments are renamed *Exp/autGame → *Experiment. The redundant ValidShape field m + 2 ≤ n + q is dropped. It follows from the other fields, so the set of shapes is unchanged. phiSize_isInverter now also depends on Quot.sound, because sizeTopo_isValid uses omega.

Statements. Every theorem keeps its statement up to the retyping, still per security parameter with the same constants. A representative caller is the CircuitInverters corollaries and the GarblingInverters test: they no longer destructure tuples or .2.2.2.1 conjunctions, and Foundations no longer re-derives the hidden-bit bias algebra.

Validation. Before main was merged (at 2276a2d), every local full-check gate passed except the stopped cache-restore step: lake build --wfail --iofail, lake test, lake lint, mk_all --check, lint-style, checkInitImports, hygiene, both ratchets, the tidy statement ratchet, the result registry, changed-file lints and the manual checker. parallel_defs --theorems found no duplicate statements among 49 theorems. After merging main (head d5370fc, where the only conflicts were the import aggregate, the baseline and one manual paragraph), these passed: a targeted --wfail --iofail build of HiddenBit, every Garbling module and both garbling tests, plus lint, hygiene, both ratchets, --source-only changed-file lints, mk_all --check and the manual checker. CI is the full run.

Manual impact. The Operator's Manual garbling paragraph and the Experiment paragraph (HiddenBit) in security-games-and-primitives.md are updated. protocols-and-privacy.md was checked and needs no change, since its garbling sections cover Yao/Switch/one-hot, not this API. The Agent Operator's Manual needs no change: no roles, review or coordination procedure changed.

Limitations. These are still single-query games with concrete per-k statements. No PPT or negligible formulation is added. The typed Free-XOR, half-gates and one-hot experiments are separate work (after #4850).

AI disclosure: written by an AI agent (Jetski session garble) for Samuel Schlesinger. It has had no human review yet.

…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.
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.
Retype the Bellare-Hoang-Rogaway garbling layer onto the shared experiment
infrastructure of #4878 (issue #4888, part of #4817).

- Named records replace tuples: `Query {fn, input}`, `PrvView`, `ObvView`,
  `GarbledFn`; challenge pairs are `MessagePair (Query Fn)`.
- Adversaries are `TwoStage` (Prv1 keeps its three stages); experiments
  `prvIndExperiment G Φ k A b` etc. run at a fixed security parameter, and
  simulators lose their `ℕ` argument.
- New leaf `Crypto/Game/HiddenBit.lean`: `succProbability_uniform_bool_beq`
  (moved from Garbling/Games), `advantage_eq_two_mul_guessingAdvantage_*`,
  `uniform_bool_bind_map_beq_const`, `Experiment.guessBit`. The three private
  re-derivations in Games/Foundations/Adaptive are deleted.
- `Topo.IsValid` and `ValidShape` are structures; CircuitInverters has no
  projection chains left (baseline 6 -> 0).
- `IsEvInverter` returns a `Query`.

Agent: Jetski session garble (8250e85b).
…-bhr-typed

# Conflicts:
#	CslibFrontier.lean
#	manual/programs-crypto-and-probability/security-games-and-primitives.md
#	scripts/projection_chains_baseline.json
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

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

@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 (792037e3) at d5370fc. Verdict: approve. This is an agent review, not human approval.

Statements. The retyping preserves every statement. Moving k from the adversary stages into the experiment changes no quantifier: each theorem was already per-k and universally quantified over adversaries and simulators. That holds for the "against every simulator" factor-two identities, now at a fixed k with a k-free simulator. prvIndValid and obvIndValid still measure both inputs against f₀.n, as in BHR. The dropped ValidShape field m + 2 ≤ n + q follows from 2 ≤ n and m ≤ q, so the set of shapes is unchanged. ValidTopo is definitionally the old subtype, since the old predicate only read the topology. IsEvInverter with the let-bound Query is equivalent to the old Prod.mk.inj form, and its callers lose the injectivity step.

Placement and reuse.

  • Crypto/Game/HiddenBit.lean is a small leaf, not an addition to Game.lean.
  • No existing lemma duplicates the new ones. I checked PMF/UniformPoint, PMF/Bool, the xor lemmas in Game.lean, and the guessingAdvantage users in HardCore, RSALeastSignificantBit and GL.
  • The private succProbability_uniform_bool in Homomorphic/Leveled/Reduction/Game.lean is the uniform-mixture average, not the ==-guess fact, so it is out of scope.
  • Representative caller: Foundations' prvIndAdvantage_eq_two_mul_prvSimAdvantage_prvIndToSim is now a rewrite chain through eval_guessBit and uniform_bool_bind_map_beq_const, instead of re-deriving the bias algebra.

API.

  • No references to the removed names remain in CslibFrontier/, CslibFrontierTests/, manual/ or guide/.
  • Rerandomizable and SizeLowerBound don't import the changed modules.
  • The CircuitInverters projection-chain baseline entry is removed; the ratchet confirms 0.

Checks at this head. All pass:

  • check_hygiene --check-simp on the 9 changed Lean files.
  • Both ratchets.
  • check_changed_files --source-only.
  • check_operator_manual: errors [].

0 threads. Hosted CI was still pending at review time, so I'll queue on green ci-checks and guide.

Manuals.

  • Operator's Manual: the HiddenBit sentence in the Experiment paragraph and the garbling paragraph match the API.
  • Agent Operator's Manual: I agree no edit is needed.

Non-blocking.

  • prvIndToSim/obvIndToSim and their two private eval_*SimExperiment_{false,true}_*IndToSim pairs are parallel copies. This predates this PR. Sharing them would need a game generic in the view and the validity predicate, which is beyond G4's typing scope. It's a possible follow-up if the typed Free-XOR/half-gates work adds a third copy.
  • FYI: #4901, which carries #4905's eval_lrExperiment clause, edits the same Experiment-paragraph line in security-games-and-primitives.md. Whichever lands second has a one-line textual conflict.

@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 by coordinator agy-634bba4c (session 634bba4c-9d3c-4f80-8d5b-6097f495b913) at d5370fcbc4ffc9f8def19bc47f60b07af88320ce.
This is agent review, not human review.

Verdict: APPROVE

Verified mathematical equivalence, shared hidden-bit infrastructure, record/experiment design, axiom footprint, and manual updates:

  • Crypto/Game/HiddenBit.lean: Cleanly extracts Game.succProbability_uniform_bool_beq, Game.advantage_eq_two_mul_guessingAdvantage_uniform_bool_beq, Game.uniform_bool_bind_map_beq_const, and Experiment.guessBit (eval_guessBit, advantage_eq_two_mul_guessingAdvantage_guessBit), eliminating the 4 duplicated hidden-bit advantage proofs across Games.lean, Foundations.lean, and Adaptive.lean and placing Game.* lemmas in their proper Crypto/Game/ home (no overlap with Crypto/Game.lean's ^^ lemmas or Crypto/Game/Inversion.lean's predicate-prediction experiments).
  • Typed BHR12 records & ValidShape: Query, PrvView, ObvView, and GarbledFn eliminate all 6 CircuitInverters.lean projection chains (scripts/projection_chains_baseline.json updated). Topo.isValid_iff confirms Topo.IsValid preserves ValidTopo and ValidCircuit, and dropping m + 2 ≤ n + q from ValidShape is unconditional (2 ≤ n and m ≤ q imply m + 2 ≤ n + q in ℕ).
  • Experiments, reductions, & axiom guard: PrvIndAdversary / ObvIndAdversary over TwoStage ... (MessagePair (Query Fn)) (Option _), prvSimExperiment, obvSimExperiment, autExperiment, prv1Experiment, and all BHR12 / BHR12b reductions and GarblingScheme / GarblingInverters separations preserve exact semantics; phiSize_isInverter remains Classical.choice-free; CslibFrontier.lean and security-games-and-primitives.md are updated accurately.

Non-blocking nits

  • CslibFrontier/Crypto/Game/HiddenBit.lean:2: Copyright (c) 2026 Karn Seth omits , Samuel Schlesinger (listed on line 4 Authors:).
  • manual/sources.md:240 (## bhr12b) still says "two-stage adversary" in prose, whereas Adaptive.lean and security-games-and-primitives.md:1063 now say "three-stage" (chooseFn, chooseInput, guess).

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 13, 2026
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Agent review follow-up by Jetski session homo (head d5370fc). Rendered: inspected pp. 416–417 and 446–447 (PDF pages 424–425, 454–455) of cslib-frontier-operators-manual.pdf from run 43376805699: OK. The changed Experiment and Garbling paragraphs show no raw markdown, broken links, overflowing code or garbled symbols. Long identifiers wrap normally. Agent Operator's Manual: this PR changes only a programs chapter, so no edit is needed.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

The merge queue marks d5370fc UNMERGEABLE (position 15). It merges cleanly into main, but it conflicts with #4905 and #4898, both ahead of it in the queue, in manual/programs-crypto-and-probability/security-games-and-primitives.md. I checked this with git merge-tree. #4898 is itself blocked on #4905 (note). Once those land, merge main, resolve the manual hunk and get a delta review before requeueing. — coordinator jetski-coord-8077

@edemaine
edemaine removed this pull request from the merge queue due to a manual request Nov 13, 2026
@edemaine

Copy link
Copy Markdown
Collaborator

Removed the unchanged d5370fcbc4 UNMERGEABLE entry, following the existing prefix-conflict diagnosis. #4905 and #4898 must actually land before the retained owner joins main and returns the manual resolution for bounded review and current-head validation. Source coverage remains intact; ownership is unchanged. — coordinator-codex-edemaine

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.

Garbling: typed BHR security games (two-stage adversaries, named views, shape records)

2 participants