SLIDE 1 Really Naturally Linear Indexed Type Checking
Arthur Azevedo de Amorim1, Marco Gaboardi2, Emilio Jes´ us Gallego Arias1, Justin Hsu1
1University of Pennsylvania 2University of Dundee
October 2, 2014
SLIDE 2
In the beginning...
SLIDE 3
In the beginning...
SLIDE 4 In the beginning...
Check properties via types
- Type safety
- Parametricity
- Non-interference
SLIDE 5 More recently
Properties model quantitative information
how robust?
how likely?
how private?
SLIDE 6 More recently
Properties model quantitative information
how robust?
how likely?
how private?
SLIDE 7 More recently
Properties model quantitative information
how robust?
how likely?
how private?
SLIDE 8 More recently
Properties model quantitative information
how robust?
how likely?
how private?
SLIDE 9 More recently
Properties model quantitative information
how robust?
how likely?
how private?
Properties not just true or false
SLIDE 10 But what about typechecking?
Typechecking quantitative languages is tricky
- May need to solve numeric constraints
- Typechecking may not be decidable
- May need heuristics to make typechecking practical
SLIDE 11 But what about typechecking?
Typechecking quantitative languages is tricky
- May need to solve numeric constraints
- Typechecking may not be decidable
- May need heuristics to make typechecking practical
Our goal
- Design and implement a typechecking algorithm for DFuzz, a
language for verifying differential privacy
SLIDE 12 The plan today
- A DFuzz crash course
- The problem with standard approaches
- Modifying the DFuzz language to ease typechecking
- Decidability and heuristics
SLIDE 13 The quantitative property
Differential privacy [DMNS06]
- Rigorous definition of privacy for randomized programs
- Idea: random noise should “conceal” an individual’s data
- Quantitative: measure how private a program is
- Close connection to sensitivity analysis
SLIDE 14
Sensitivity analysis
R-sensitive function
SLIDE 15
Sensitivity analysis
R-sensitive function
f
SLIDE 16
Sensitivity analysis
R-sensitive function
f
SLIDE 17
Sensitivity analysis
R-sensitive function
f
SLIDE 18
Sensitivity analysis
R-sensitive function
f
d
SLIDE 19
Sensitivity analysis
R-sensitive function
f
d < R d
SLIDE 20 A language for differential privacy
DFuzz [GHHNP13]
- Type system for differentially private programs
- Use linear logic to model sensitivity
- Combine with (lightweight) dependent types
SLIDE 21
In a little more detail...
Types
τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ
SLIDE 22
In a little more detail...
Types
τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ
Contexts
Γ ::= · | Γ, x : [R] τ
SLIDE 23
In a little more detail...
Types
τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ
Contexts
Γ ::= · | Γ, x : [R] τ
Typing judgment
Γ ⊢ e : τ
SLIDE 24 Reading the types
Sensitivity reading
- Functions !Rτ1 ⊸ τ2: R-sensitive functions
- Changing input by d changes output by at most R · d
SLIDE 25
Sensitivity analysis
R-sensitive function
f
d < R d
SLIDE 26 Reading the types
Sensitivity reading
- Functions !Rτ1 ⊸ τ2: R-sensitive functions
- Changing input by d changes output by at most R · d
SLIDE 27 Reading the types
Sensitivity reading
- Functions !Rτ1 ⊸ τ2: R-sensitive functions
- Changing input by d changes output by at most R · d
Subtyping
- “A 1-sensitive function is also a 2-sensitive function”
- Subtyping: weaken sensitivity bound
!Rτ ⊸ τ2 ⊑ !R′τ1 ⊸ τ2 if R ≤ R′ compare polynomials
SLIDE 28
In a little more detail...
Types
τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ
Contexts
Γ ::= · | Γ, x : [R] τ
Typing judgment
Γ ⊢ e : τ
SLIDE 29
In a little more detail...
Types
τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ
Contexts
Γ ::= · | Γ, x : [R] τ
Typing judgment
Γ ⊢ e : τ
SLIDE 30
The sensitivity language
Grammar
R ::= iR | iN | R | R + R | R · R variables over real/naturals
SLIDE 31
The sensitivity language
Grammar
R ::= iR | iN | R | R + R | R · R variables over real/naturals
SLIDE 32 The sensitivity language
Grammar
R ::= iR | iN | R | R + R | R · R variables over real/naturals
Sensitivity not known statically
- DFuzz is dependent!
- Sensitivity may depend on inputs (length of list, number of
iterations, etc.)
SLIDE 33
In a little more detail...
Types
τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ
Contexts
Γ ::= · | Γ, x : [R] τ
Typing judgment
Γ ⊢ e : τ
SLIDE 34 The sensitivity language
Grammar
R ::= iR | iN | R | R + R | R · R variables over real/naturals
Sensitivity not known statically
- DFuzz is dependent!
- Sensitivity may depend on inputs (length of list, number of
iterations, etc.)
SLIDE 35 The sensitivity language
Grammar
R ::= iR | iN | R | R + R | R · R variables over real/naturals
Sensitivity not known statically
- DFuzz is dependent!
- Sensitivity may depend on inputs (length of list, number of
iterations, etc.)
What does this mean for typechecking?
- Sensitivities are polynomials over reals and naturals
- How to check subtyping?
SLIDE 36 Reading the types
Sensitivity reading
- Functions !Rτ1 ⊸ τ2: R-sensitive functions
- Changing input by d changes output by at most R · d
Subtyping
- “A 1-sensitive function is also a 2-sensitive function”
- Subtyping: weaken sensitivity bound
!Rτ ⊸ τ2 ⊑ !R′τ1 ⊸ τ2 if R ≤ R′ compare polynomials
SLIDE 37 Reading the types
Sensitivity reading
- Functions !Rτ1 ⊸ τ2: R-sensitive functions
- Changing input by d changes output by at most R · d
Subtyping
- “A 1-sensitive function is also a 2-sensitive function”
- Subtyping: weaken sensitivity bound
!Rτ ⊸ τ2 ⊑ !R′τ1 ⊸ τ2 if R ≤ R′ compare polynomials
SLIDE 38 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
SLIDE 39 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
SLIDE 40 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
SLIDE 41 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
SLIDE 42 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
SLIDE 43 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
Annotations
- We need: fully annotated argument types of all functions
! ?? τ1 ⊸ τ2 annot. no annot. no annot.
SLIDE 44 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
Annotations
- We need: fully annotated argument types of all functions
! ?? τ1 ⊸ τ2 annot. no annot. no annot.
SLIDE 45 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
Annotations
- We need: fully annotated argument types of all functions
! ?? τ1 ⊸ τ2 annot. no annot. no annot.
SLIDE 46 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
Annotations
- We need: fully annotated argument types of all functions
! ?? τ1 ⊸ τ2 annot. no annot. no annot.
SLIDE 47 The typechecking problem
Assume
skeleton from term
- Given annotated term, compute
best type type without sensitivities w.r.t. subtyping
Annotations
- We need: fully annotated argument types of all functions
! ?? τ1 ⊸ τ2 annot. no annot. no annot.
- Other more minor annotations
SLIDE 48 The typechecking problem
Input
- Annotated term e
- Annotated context skeleton Γ•:
x : ?? τ no annot. annot.
SLIDE 49 The typechecking problem
Input
- Annotated term e
- Annotated context skeleton Γ•:
x : ?? τ no annot. annot.
SLIDE 50 The typechecking problem
Input
- Annotated term e
- Annotated context skeleton Γ•:
x : ?? τ no annot. annot.
SLIDE 51 The typechecking problem
Input
- Annotated term e
- Annotated context skeleton Γ•:
x : ?? τ no annot. annot.
Output
- Type τ ∗ and context Γ with Γ ⊢ e : τ ∗
- Most precise context and type (with respect to subtyping)
SLIDE 52 The typical approach
“Bottom-up” typechecking
- For each premise, compute best context and type
- Combine outputs from premises to get context and type
SLIDE 53 The typical approach
“Bottom-up” typechecking
- For each premise, compute best context and type
- Combine outputs from premises to get context and type
Example: function application
Γ ⊢ e1 : !Rσ ⊸ τ ∆ ⊢ e2 : σ Γ + R · ∆ ⊢ e1 e2 : τ
1 Given (e1 e2, Γ•)
SLIDE 54 The typical approach
“Bottom-up” typechecking
- For each premise, compute best context and type
- Combine outputs from premises to get context and type
Example: function application
Γ ⊢ e1 : !Rσ ⊸ τ ∆ ⊢ e2 : σ Γ + R · ∆ ⊢ e1 e2 : τ
1 Given (e1 e2, Γ•) 2 Call typechecker on (e1, Γ•), get (!Rσ ⊸ τ, Γ)
SLIDE 55 The typical approach
“Bottom-up” typechecking
- For each premise, compute best context and type
- Combine outputs from premises to get context and type
Example: function application
Γ ⊢ e1 : !Rσ ⊸ τ ∆ ⊢ e2 : σ Γ + R · ∆ ⊢ e1 e2 : τ
1 Given (e1 e2, Γ•) 2 Call typechecker on (e1, Γ•), get (!Rσ ⊸ τ, Γ) 3 Call typechecker on (e2, ∆•), get (σ′, ∆)
SLIDE 56 The typical approach
“Bottom-up” typechecking
- For each premise, compute best context and type
- Combine outputs from premises to get context and type
Example: function application
Γ ⊢ e1 : !Rσ ⊸ τ ∆ ⊢ e2 : σ Γ + R · ∆ ⊢ e1 e2 : τ
1 Given (e1 e2, Γ•) 2 Call typechecker on (e1, Γ•), get (!Rσ ⊸ τ, Γ) 3 Call typechecker on (e2, ∆•), get (σ′, ∆) 4 Check σ′ ⊑ σ, output (τ, Γ + R · ∆)
SLIDE 57 “Minimal” types?
A problem with the bottom-up approach
- Some DFuzz rules have form
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
SLIDE 58 “Minimal” types?
A problem with the bottom-up approach
- Some DFuzz rules have form
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
SLIDE 59 “Minimal” types?
A problem with the bottom-up approach
- Some DFuzz rules have form
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
SLIDE 60 “Minimal” types?
A problem with the bottom-up approach
- Some DFuzz rules have form
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
SLIDE 61 “Minimal” types?
A problem with the bottom-up approach
- Some DFuzz rules have form
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
- But what context do we output?
SLIDE 62 “Minimal” context?
First try
- Have x :[R1] σ and x :[R2] σ
- Most precise context should be x :[max(R1,R2)] σ
- But DFuzz doesn’t have max(R1, R2)...
SLIDE 63
The sensitivity language
Grammar
R ::= iR | iN | R | R + R | R · R variables over real/naturals
SLIDE 64 “Minimal” context?
First try
- Have x :[R1] σ and x :[R2] σ
- Most precise context should be x :[max(R1,R2)] σ
- But DFuzz doesn’t have max(R1, R2)...
SLIDE 65 “Minimal” context?
First try
- Have x :[R1] σ and x :[R2] σ
- Most precise context should be x :[max(R1,R2)] σ
- But DFuzz doesn’t have max(R1, R2)...
Max of two polynomials may not be polynomial!
SLIDE 66 The idea: enrich DFuzz
EDFuzz: E(xtended) DFuzz
- Sensitivity language in DFuzz is “incomplete” for typechecking
- Add constructions like max(R1, R2) to sensitivity language
- Typecheck EDFuzz programs instead
SLIDE 67 The idea: enrich DFuzz
EDFuzz: E(xtended) DFuzz
- Sensitivity language in DFuzz is “incomplete” for typechecking
- Add constructions like max(R1, R2) to sensitivity language
- Typecheck EDFuzz programs instead
Relation with DFuzz
- Extension: all DFuzz programs still valid EDFuzz programs
- Preserve metatheory
- Bottom-up typechecking simple, works
SLIDE 68
How does this fix the problem?
Previously problematic rule
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
SLIDE 69 How does this fix the problem?
Previously problematic rule
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
Now: no problem
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
SLIDE 70 How does this fix the problem?
Previously problematic rule
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
Now: no problem
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
SLIDE 71 How does this fix the problem?
Previously problematic rule
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
Now: no problem
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
SLIDE 72 How does this fix the problem?
Previously problematic rule
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
Now: no problem
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
- For
x :[R1] σ ∈ Γ1 and x :[R2] σ ∈ Γ2, put x :[max(R1,R2)] σ in output context
SLIDE 73 How does this fix the problem?
Previously problematic rule
Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·
Now: no problem
- Running algorithm gives (σ1, Γ1) and (σ2, Γ2)
- For
x :[R1] σ ∈ Γ1 and x :[R2] σ ∈ Γ2, put x :[max(R1,R2)] σ in output context
- Return max(R1, R2) as context
SLIDE 74 Decidability?
Bad news
- Must check inequalities over reals and natural polynomials
- Subtype relation is undecidable
- Even checking validity of derivations is undecidable
- Problem for both DFuzz and EDFuzz
SLIDE 75 Decidability?
Bad news
- Must check inequalities over reals and natural polynomials
- Subtype relation is undecidable
- Even checking validity of derivations is undecidable
- Problem for both DFuzz and EDFuzz
Good news
- Constraint solvers are pretty good in practice
- Typical DFuzz programs rely on easy constraints
SLIDE 76 Checking the constraints
Special structure of constraints
- Allow standard (DFuzz) annotations only
- Subtyping only needs to check
R ≥ R∗, where R is a DFuzz sensitivity and R∗ is a EDFuzz sensitivity
- R understood by standard numeric solvers
- R∗ has extended terms like max(R1, R2), . . .
SLIDE 77 Checking the constraints
Idea: eliminate extended terms
1, R∗ 2) to
R ≥ R∗
1 ∧ R ≥ R∗ 2
- Recursively eliminate comparisons R ≥ R∗
- Similar technique for other new sensitivity constructions
SLIDE 78 About the implementation
It works!
- Dispatches numeric constraints to Why3
- Typechecks examples from the DFuzz paper with no problems
- Annotation burden light on these examples
SLIDE 79 Final thoughts
Lessons learned
- Typechecking with quantitative constraints is tricky
- Numeric solvers are quite good, even for undecidable problems
- Minor details in original language can have huge effects on
how easy it is to use standard solvers
- Keep typechecking in mind!
SLIDE 80 Final thoughts
Lessons learned
- Typechecking with quantitative constraints is tricky
- Numeric solvers are quite good, even for undecidable problems
- Minor details in original language can have huge effects on
how easy it is to use standard solvers
- Keep typechecking in mind!
Open questions
- Does this technique of “completing” a language to ease
typechecking apply to other quantitative type systems?
- Can we remove the argument type annotation in functions?
SLIDE 81 Really Naturally Linear Indexed Type Checking
Arthur Azevedo de Amorim1, Marco Gaboardi2, Emilio Jes´ us Gallego Arias1, Justin Hsu1
1University of Pennsylvania 2University of Dundee
October 2, 2014
SLIDE 82 Another example
Problematic rule
Γ ⊢ e : σ i fresh in Γ Γ ⊢ Λi : κ. e : ∀i : κ. σ
Avoidance problem
- Running typechecker on (e, Γ•) yields (σ, Γ)
- For x :[R] σ ∈ Γ, want smallest R∗ bigger than R but
independent of i
- Again: R∗ may lie outside sensitivity language
- Add construction sup(R, i) to EDFuzz