Private information retrieval (EasyCrypt examples/PIR.ec) #
Two-server PIR: to read entry i of a database a replicated on two servers without either
server learning i, the client sends the first server a random subset s of the indices
[0, N) and the second server s with i flipped; each server returns the xor of the entries
it was asked for, and the two answers xor to a i.
EC's file, declaration by declaration and script line by line: correctness (PIR_correct),
security by a coupling (PIR_secure1, PIR_secure2 and the two byequiv lemmas), the
probability of each query computed in pHL (Pr_PIR_s, Pr_PIR_s' and the two bypr lemmas),
and the uniformity equivalences (PIR_s_uniform, PIR_s'_uniform). All of EC's lemmas are
proven.
Translation:
clone import BitWord as BS,op N,op a,axiom N_posare the classParams(nthe length ofBS.word);clone import Bigop as BBSis a clone ofLib/EC/Bigop.lean.var s, s' : int listofmodule PIRareglobal_var PIR.s,PIR.s'before the module.var j <- 0is the declaration and the assignmentj <- 0.- pHL's bounds are reals, as EC's:
1 / 2 ^ (N - §j)is1%r/2%r^(N-j)(an integer power). int fsetisFSet ℤ(Finset),`|`and`&`are∪and∩,oflistand the membership lemmas areLib/EC/FSetOflist.lean;b ^^ (j \in x1)isb ^^ decide (j ∈ x1).
Gap list (what keeps the file from reading as EC's):
- GAP 1 (closed 2026-11-16):
PIR_correct'sconseq (_: _ ==> sxor2 PIR.s PIR.s' i)and itswhileare EC's:hoare_conseqandhoare_whilekeep what the precondition says of the variables the code does not modify (i = i0), as EC's do. - GAP 2:
PIR_correct's loop body is onesmt_close [sxor2_cons, sxor_cons]where EC takes the cases apart first (case: (j{m} <= i{m}), …); EC'sringon the two answers is the lemmaxorw_cancel. - GAP 3:
while (={j,PIR.s});autoisequiv_while (={j, PIR.s}) <;> equiv_auto, thenauto_progress; EC'srnd (fun x => !x)isequiv_rnd (fun x => !x) (fun x => !x). - The variant of pHL's
while (true) (N-j)is a natural number:(N - §j).toNat. - GAP 4: the
restrlemmas are proven frommem_restr(membership inrestr s n) where EC rewrites withFSetlemmas and callssmt. InPIR_s_uniform,PIR_s'_uniformthe conditions ofrndare split by hand as in EC (EC's tworingare a case analysis on the booleans), and EC'srewrite !oflist_cons !restrS //goes into the hints ofsmt_close. - GAP 5 (closed 2026-11-16):
(s, s') <- ([], [])is EC's tuple assignment (the conditionspleaves on the pair is taken apart by the closer). - GAP 6 (
Pr_PIR_s,Pr_PIR_s'):byphoare (: True ==> _)for EC'sbyphoare=> //(the default precondition fixes the argument and the memory);case: (is_restr x N)isby_cases; the rule forwhile I V k εhas two goals more than EC's (bound_le_one,sat:Logic/PHoareWhileRev.lean);exists * j, PIR.s; elim * => j0 s0is twostmt_exists *; EC'ssmt (…)on therestrlemmas aresmt_close […]with EC's hints, the rewrites that precede them (rewrite oflist_cons,rewrite -set0E) added to the hints; one hint list differs (the¬ Ebound of the secondseq: EC's membership lemmasin_fsetU in_fset1 nin_is_restrareis_restr_diff is_restr_Ueq is_restr_restr), andENNReal.ofReal_zerois a hint where the bound is0. By hand: the two goals of the loop rule that EC does not have,pre_bound(EC:have ->>: j = N by smt()), thevariantgoal (EC:smt (dbool_ll)), and the final equation on powers of two (EC:rewrite -exprS,ring).
EC's pred sxor2.
Equations
- GaudisCrypt.Examples.PIR.sxor2 s s' i = (GaudisCrypt.Examples.PIR.sxor s s' i ∨ GaudisCrypt.Examples.PIR.sxor s' s i)
Instances For
Equations
- GaudisCrypt.Examples.PIR.PIR.s = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.Examples.PIR.PIR.s" (List ℤ))
Instances For
Equations
- GaudisCrypt.Examples.PIR.PIR.s' = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.Examples.PIR.PIR.s'" (List ℤ))
Instances For
Instantiating the holes of PIR.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [PIR.main.procedure.apply_simp]).
@[simp]: PIR.query = Module.proc PIR.query.procedure — true by definition, proc query using no module parameter and so having no holes to fill.
The body of proc query of module PIR, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see PIR.query.procedure.apply_simp) rather than run. Use PIR.query for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
proc query of module PIR as a module: Module.proc PIR.query.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — PIR.query.apply_simp says exactly that.
Equations
Instances For
The body of proc main of module PIR, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see PIR.main.procedure.apply_simp) rather than run. Use PIR.main for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instantiating the holes of PIR.query.procedure with a tuple holeArgs of procedures: the body of proc query as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [PIR.query.procedure.apply_simp]).
proc main of module PIR as a module: Module.proc PIR.main.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — PIR.main.apply_simp says exactly that.
Equations
Instances For
@[simp]: PIR.main = Module.proc PIR.main.procedure — true by definition, proc main using no module parameter and so having no holes to fill.
The module declared by module PIR: the record of its procedures PIR.query, PIR.main.
The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no PIR.apply_simp to apply it with.
Equations
Instances For
Alternative proof: we show that the distribution of PIR.s and PIR.s' is uniform. First
version: we use phoare.
Equations
Other version without explicit computation of the probability: we first show that the probability is uniform. (EC: "unfortunately this does not allow to conclude in EasyCrypt. We need to be able to do the projection of memories.")