Gilles Barthe Thomas Espitau Benjamin Grégoire Justin Hsu* Pierre-Yves Strub
Proving Uniformity and Independence by Self-Composition and Coupling
1
Proving Uniformity and Independence by Self-Composition and Coupling - - PowerPoint PPT Presentation
Proving Uniformity and Independence by Self-Composition and Coupling Gilles Barthe Thomas Espitau Benjamin Grgoire Justin Hsu* Pierre-Yves Strub 1 A puzzle A random walk on a cycle Start at position s { 0 , 1 , . . . , n 1 }
Gilles Barthe Thomas Espitau Benjamin Grégoire Justin Hsu* Pierre-Yves Strub
1
A random walk on a cycle
◮ Start at position s ∈ {0, 1, . . . , n − 1} ◮ Each iteration, flip a fair coin
– Heads: increment position (modulo n) – Tails decrement position (modulo n)
◮ Return: last edge (r, r + 1) to be traversed
A question
2
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S 3
1 2 3 4 5
S
Somewhat surprisingly
3
Uniformity of a variable X
For any two values w, v in the (finite) range of X, we have:
in output distribution.
4
Uniformity of a variable X
For any two values w, v in the (finite) range of X, we have:
in output distribution.
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
4
Uniformity of a variable X
For any two values w, v in the (finite) range of X, we have:
in output distribution.
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
4
5
6
pWhile: An imperative language with random sampling
c ::= x ← e | x
$
← flip(p) | if e then c else c | while e do c | skip | c; c
7
pWhile: An imperative language with random sampling
c ::= x ← e | x
$
← flip(p) | if e then c else c | while e do c | skip | c; c
pRHL is a program logic that is:
◮ Probabilistic: Programs can draw samples 7
pWhile: An imperative language with random sampling
c ::= x ← e | x
$
← flip(p) | if e then c else c | while e do c | skip | c; c
pRHL is a program logic that is:
◮ Probabilistic: Programs can draw samples ◮ Relational: Describe executions of two programs 7
8
Assertions
◮ Non-probabilistic ◮ FO formulas over program variables tagged with 1 or 2 8
Assertions
◮ Non-probabilistic ◮ FO formulas over program variables tagged with 1 or 2 8
Assertions
◮ Non-probabilistic ◮ FO formulas over program variables tagged with 1 or 2
Deep connection to probabilistic couplings
◮ Proofs specify how to correlate random samplings in runs ◮ Reduce sources of randomness, simplify verification 8
If this is provable:
Then:
On any two input memories related by P, the distribution of e in the first output is equal to the distribution of e′ in the second output.
9
If this is provable for booleans b, b′:
Then:
On any two input memories related by P, the probability of b in the first output is equal to the probability of b′ in the second output.
10
Simplified version
FlipEq ⊢ {⊤} x
$
← flip(p) ∼ x′
$
← flip(p) {x1 = x′2}
FlipNeg ⊢ {⊤} x
$
← flip(p) ∼ x′
$
← flip(1 − p) {x1 = ¬x′2}
11
Simplified version
FlipEq ⊢ {⊤} x
$
← flip(p) ∼ x′
$
← flip(p) {x1 = x′2}
FlipNeg ⊢ {⊤} x
$
← flip(p) ∼ x′
$
← flip(1 − p) {x1 = ¬x′2}
Reading: for any p ∈ [0, 1],
are equal
11
Assignments
Assn ⊢ {Q[e1, e′2/x1, x′2]} x ← e1 ∼ x′ ← e2 {Q}
Sequencing
Seq ⊢ {P} c1 ∼ c′
1 {Q}
⊢ {Q} c2 ∼ c′
2 {R}
⊢ {P} c1; c2 ∼ c′
1; c′ 2 {R}
Loops
While ⊢ {P ∧ b1} c ∼ c′ {P}
| = P = ⇒ b1 = b′2 ⊢ {P} while b do c ∼ while b′ do c′ {P ∧ ¬b1}
12
Assignments
Assn ⊢ {Q[e1, e′2/x1, x′2]} x ← e1 ∼ x′ ← e2 {Q}
Sequencing
Seq ⊢ {P} c1 ∼ c′
1 {Q}
⊢ {Q} c2 ∼ c′
2 {R}
⊢ {P} c1; c2 ∼ c′
1; c′ 2 {R}
Loops
While ⊢ {P ∧ b1} c ∼ c′ {P}
| = P = ⇒ b1 = b′2 ⊢ {P} while b do c ∼ while b′ do c′ {P ∧ ¬b1}
12
Probabilistic properties without probabilistic reasoning
◮ Abstract away all probabilities ◮ All reasoning is about relation between samples
Highly similar to Hoare logic
◮ Most things “just work” ◮ Compositional reasoning 13
Probabilistic properties without probabilistic reasoning
◮ Abstract away all probabilities ◮ All reasoning is about relation between samples
Highly similar to Hoare logic
◮ Most things “just work” ◮ Compositional reasoning
13
14
Goal
Generate one fair coin flip, using only coin flips with a fixed bias p ∈ (0, 1).
Procedure
15
Consider the program fair:
x ← tt; y ← tt; while x = y do x
$
← flip(p); y
$
← flip(p); return(x)
To show: generates fair coin flip
16
For every two booleans w, v, show:
⊢ {p1 = p2} fair ∼ fair {(x1 = w) ⇐ ⇒ (x2 = v)}
Reading: for every two booleans w, v,
Pr[x = w] = Pr[x = v] in the output of fair.
Four choices in all for w, v
◮ We show the cases with w = v 17
Two equivalent programs: fair and fair′
x ← tt; x ← tt; y ← tt; y ← tt; while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
18
Two equivalent programs: fair and fair′
x ← tt; x ← tt; y ← tt; y ← tt; while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
18
Two equivalent programs: fair and fair′
x ← tt; x ← tt; y ← tt; y ← tt; while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
18
Two equivalent programs: fair and fair′
x ← tt; x ← tt; y ← tt; y ← tt; while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
For the cases w = v, suffices to show:
⊢ {p1 = p2} fair ∼ fair′ {x1 = ¬x2}
18
while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
19
while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
In the body: apply [FlipEq] for both pairs of samples
19
while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
In the body: apply [FlipEq] for both pairs of samples
◮ We have: x1 = y2 19
while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
In the body: apply [FlipEq] for both pairs of samples
◮ We have: x1 = y2 ◮ And: x2 = y1 19
while x = y do while x = y do x
$
← flip(p); y
$
← flip(p); y
$
← flip(p); x
$
← flip(p); return(x) return(x)
In the body: apply [FlipEq] for both pairs of samples
◮ We have: x1 = y2 ◮ And: x2 = y1
Establishes main invariant:
x2 = (if x1 = y1 then y2 else ¬x1)
19
Applying [Assn], [Seq] shows:
⊢ {p1 = p2} fair ∼ fair {(x1 = w) ⇐ ⇒ (x2 = v)} when w = v; can also show same judgment when w = v.
Conclude
20
21
Observation: reduce independence to uniformity
Limitation
◮ Only can show independence for uniform variables 22
Use self-composition
◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating
23
Use self-composition
◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
23
Use self-composition
◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
23
Use self-composition
◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
23
Use self-composition
◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
23
Use self-composition
◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating
Independence of two variables X, Y
For any two values w, v, we have:
in output distribution.
Benefits
◮ Can prove independence for non-uniform variables ◮ Similar ideas can cover conditional independence 23
24
Lots more examples
◮ Cycle random walk ◮ Pairwise and k-wise independence ◮ Bayesian network ◮ Ballot theorem
Details about the implementation
◮ Most examples formalized in EasyCrypt framework 25
26
Gilles Barthe Thomas Espitau Benjamin Grégoire Justin Hsu* Pierre-Yves Strub
27