Proving Uniformity and Independence by Self-Composition and Coupling - - PowerPoint PPT Presentation

proving uniformity and independence by self composition
SMART_READER_LITE
LIVE PREVIEW

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 }


slide-1
SLIDE 1

Gilles Barthe Thomas Espitau Benjamin Grégoire Justin Hsu* Pierre-Yves Strub

Proving Uniformity and Independence by Self-Composition and Coupling

1

slide-2
SLIDE 2

A puzzle

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

What is the distribution of the returned edge, and how does it depend on the starting position s?

2

slide-3
SLIDE 3

A puzzle

1 2 3 4 5

S 3

slide-4
SLIDE 4

A puzzle

1 2 3 4 5

S 3

slide-5
SLIDE 5

A puzzle

1 2 3 4 5

S 3

slide-6
SLIDE 6

A puzzle

1 2 3 4 5

S 3

slide-7
SLIDE 7

A puzzle

1 2 3 4 5

S 3

slide-8
SLIDE 8

A puzzle

1 2 3 4 5

S 3

slide-9
SLIDE 9

A puzzle

1 2 3 4 5

S 3

slide-10
SLIDE 10

A puzzle

1 2 3 4 5

S 3

slide-11
SLIDE 11

A puzzle

1 2 3 4 5

S

Somewhat surprisingly

Distribution of final edge is uniform: Starting position s doesn’t matter!

3

slide-12
SLIDE 12

Basic properties of probabilistic programs

Uniformity of a variable X

For any two values w, v in the (finite) range of X, we have:

Pr[X = w] = Pr[X = v]

in output distribution.

4

slide-13
SLIDE 13

Basic properties of probabilistic programs

Uniformity of a variable X

For any two values w, v in the (finite) range of X, we have:

Pr[X = w] = Pr[X = v]

in output distribution.

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

4

slide-14
SLIDE 14

Basic properties of probabilistic programs

Uniformity of a variable X

For any two values w, v in the (finite) range of X, we have:

Pr[X = w] = Pr[X = v]

in output distribution.

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

Can be quite subtle to verify!

4

slide-15
SLIDE 15

The idea today

Use logic for relational verification to verify uniformity and independence

5

slide-16
SLIDE 16

A crash course: the relational logic pRHL

6

slide-17
SLIDE 17

A curious program logic: pRHL [Barthe, Grégoire, Zanella-Béguelin]

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

slide-18
SLIDE 18

A curious program logic: pRHL [Barthe, Grégoire, Zanella-Béguelin]

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

slide-19
SLIDE 19

A curious program logic: pRHL [Barthe, Grégoire, Zanella-Béguelin]

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

slide-20
SLIDE 20

Judgments in pRHL {P(in1, in2)} c ∼ c′ {Q(out1, out2)}

8

slide-21
SLIDE 21

Judgments in pRHL {P(in1, in2)} c ∼ c′ {Q(out1, out2)}

Assertions

◮ Non-probabilistic ◮ FO formulas over program variables tagged with 1 or 2 8

slide-22
SLIDE 22

Judgments in pRHL {P(in1, in2)} c ∼ c′ {Q(out1, out2)}

Assertions

◮ Non-probabilistic ◮ FO formulas over program variables tagged with 1 or 2 8

slide-23
SLIDE 23

Judgments in pRHL {P(in1, in2)} c ∼ c′ {Q(out1, out2)}

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

slide-24
SLIDE 24

For our purposes today: equality of distributions

If this is provable:

⊢ {P} c ∼ c′ {e1 = e′2}

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

slide-25
SLIDE 25

In particular: express equality of probabilities

If this is provable for booleans b, b′:

⊢ {P} c ∼ c′ {b1 = b′2}

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

slide-26
SLIDE 26

Random sampling rules in pRHL

Simplified version

FlipEq ⊢ {⊤} x

$

← flip(p) ∼ x′

$

← flip(p) {x1 = x′2}

FlipNeg ⊢ {⊤} x

$

← flip(p) ∼ x′

$

← flip(1 − p) {x1 = ¬x′2}

11

slide-27
SLIDE 27

Random sampling rules in pRHL

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],

  • 1. [FlipEq]: Distributions of flip(p) and flip(p) are equal
  • 2. [FlipNeg]: Distributions of flip(p) and negated flip(1 − p)

are equal

11

slide-28
SLIDE 28

Rest of rules are standard (≈ Hoare logic)

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

slide-29
SLIDE 29

Rest of rules are standard (≈ Hoare logic)

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

slide-30
SLIDE 30

Benefits of pRHL

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

slide-31
SLIDE 31

Benefits of pRHL

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

Apply to non-relational properties, like uniformity and independence.

13

slide-32
SLIDE 32

Verifying uniformity: simulating a fair coin

14

slide-33
SLIDE 33

The algorithm

Goal

Generate one fair coin flip, using only coin flips with a fixed bias p ∈ (0, 1).

Procedure

  • 1. Flip two coins with bias p
  • 2. Re-flip as long as they are equal
  • 3. Return the first coin flip the first time they are different

15

slide-34
SLIDE 34

In code

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

Distribution of return value is uniform

16

slide-35
SLIDE 35

Observation: uniformity can be proved in pRHL

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

slide-36
SLIDE 36

Step 1: rearrange program

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

slide-37
SLIDE 37

Step 1: rearrange program

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

slide-38
SLIDE 38

Step 1: rearrange program

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

slide-39
SLIDE 39

Step 1: rearrange program

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

slide-40
SLIDE 40

Step 2: apply the loop rule

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

slide-41
SLIDE 41

Step 2: apply the loop rule

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

slide-42
SLIDE 42

Step 2: apply the loop rule

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

slide-43
SLIDE 43

Step 2: apply the loop rule

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

slide-44
SLIDE 44

Step 2: apply the loop rule

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

slide-45
SLIDE 45

Step 3: putting it all together

Applying [Assn], [Seq] shows:

⊢ {p1 = p2} fair ∼ fair {(x1 = w) ⇐ ⇒ (x2 = v)} when w = v; can also show same judgment when w = v.

Conclude

fair returns a uniform boolean

20

slide-46
SLIDE 46

Extensions: verifying independence

21

slide-47
SLIDE 47

Verifying independence: the easier way

Observation: reduce independence to uniformity

(x, y) is uniform over pairs

x and y are independent

Limitation

◮ Only can show independence for uniform variables 22

slide-48
SLIDE 48

Verifying independence: the harder way

Use self-composition

◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating

c ∼ c[1]; c[2]

23

slide-49
SLIDE 49

Verifying independence: the harder way

Use self-composition

◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating

c ∼ c[1]; c[2]

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

23

slide-50
SLIDE 50

Verifying independence: the harder way

Use self-composition

◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating

c ∼ c[1]; c[2]

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

23

slide-51
SLIDE 51

Verifying independence: the harder way

Use self-composition

◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating

c ∼ c[1]; c[2]

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

23

slide-52
SLIDE 52

Verifying independence: the harder way

Use self-composition

◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating

c ∼ c[1]; c[2]

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

23

slide-53
SLIDE 53

Verifying independence: the harder way

Use self-composition

◮ Let c[1], c[2] be two copies of c with disjoint variables ◮ Prove a pRHL judgment relating

c ∼ c[1]; c[2]

Independence of two variables X, Y

For any two values w, v, we have:

Pr[X = w ∧ Y = v] = Pr[X = w] · Pr[Y = v]

in output distribution.

Benefits

◮ Can prove independence for non-uniform variables ◮ Similar ideas can cover conditional independence 23

slide-54
SLIDE 54

Summing up

24

slide-55
SLIDE 55

See the paper for

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

slide-56
SLIDE 56

Future directions

  • Automate this approach
  • Explore relational verification

for non-relational properties

  • Integrate with more general

probabilistic verification tools

26

slide-57
SLIDE 57

Gilles Barthe Thomas Espitau Benjamin Grégoire Justin Hsu* Pierre-Yves Strub

Proving Uniformity and Independence by Self-Composition and Coupling

27