Really Naturally Linear Indexed Type Checking Arthur Azevedo de - - PowerPoint PPT Presentation

really naturally linear indexed type checking
SMART_READER_LITE
LIVE PREVIEW

Really Naturally Linear Indexed Type Checking Arthur Azevedo de - - PowerPoint PPT Presentation

Really Naturally Linear Indexed Type Checking Arthur Azevedo de Amorim 1 , Marco Gaboardi 2 , us Gallego Arias 1 , Justin Hsu 1 Emilio Jes 1 University of Pennsylvania 2 University of Dundee October 2, 2014 In the beginning... In the


slide-1
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
SLIDE 2

In the beginning...

slide-3
SLIDE 3

In the beginning...

slide-4
SLIDE 4

In the beginning...

Check properties via types

  • Type safety
  • Parametricity
  • Non-interference
slide-5
SLIDE 5

More recently

Properties model quantitative information

  • Numerical robustness

how robust?

  • Probabilistic assertions

how likely?

  • Differential privacy

how private?

slide-6
SLIDE 6

More recently

Properties model quantitative information

  • Numerical robustness

how robust?

  • Probabilistic assertions

how likely?

  • Differential privacy

how private?

slide-7
SLIDE 7

More recently

Properties model quantitative information

  • Numerical robustness

how robust?

  • Probabilistic assertions

how likely?

  • Differential privacy

how private?

slide-8
SLIDE 8

More recently

Properties model quantitative information

  • Numerical robustness

how robust?

  • Probabilistic assertions

how likely?

  • Differential privacy

how private?

slide-9
SLIDE 9

More recently

Properties model quantitative information

  • Numerical robustness

how robust?

  • Probabilistic assertions

how likely?

  • Differential privacy

how private?

Properties not just true or false

slide-10
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
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
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
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
SLIDE 14

Sensitivity analysis

R-sensitive function

slide-15
SLIDE 15

Sensitivity analysis

R-sensitive function

f

slide-16
SLIDE 16

Sensitivity analysis

R-sensitive function

f

slide-17
SLIDE 17

Sensitivity analysis

R-sensitive function

f

slide-18
SLIDE 18

Sensitivity analysis

R-sensitive function

f

d

slide-19
SLIDE 19

Sensitivity analysis

R-sensitive function

f

d < R d

slide-20
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
SLIDE 21

In a little more detail...

Types

τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ

slide-22
SLIDE 22

In a little more detail...

Types

τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ

Contexts

Γ ::= · | Γ, x : [R] τ

slide-23
SLIDE 23

In a little more detail...

Types

τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ

Contexts

Γ ::= · | Γ, x : [R] τ

Typing judgment

Γ ⊢ e : τ

slide-24
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
SLIDE 25

Sensitivity analysis

R-sensitive function

f

d < R d

slide-26
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
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
SLIDE 28

In a little more detail...

Types

τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ

Contexts

Γ ::= · | Γ, x : [R] τ

Typing judgment

Γ ⊢ e : τ

slide-29
SLIDE 29

In a little more detail...

Types

τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ

Contexts

Γ ::= · | Γ, x : [R] τ

Typing judgment

Γ ⊢ e : τ

slide-30
SLIDE 30

The sensitivity language

Grammar

R ::= iR | iN | R | R + R | R · R variables over real/naturals

slide-31
SLIDE 31

The sensitivity language

Grammar

R ::= iR | iN | R | R + R | R · R variables over real/naturals

slide-32
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
SLIDE 33

In a little more detail...

Types

τ ::= N [R] | τ ⊕ τ | τ ⊗ τ | ! R τ ⊸ τ | ∀i. τ

Contexts

Γ ::= · | Γ, x : [R] τ

Typing judgment

Γ ⊢ e : τ

slide-34
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
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
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
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
SLIDE 38

The typechecking problem

Assume

  • Can extract type

skeleton from term

  • Given annotated term, compute

best type type without sensitivities w.r.t. subtyping

slide-39
SLIDE 39

The typechecking problem

Assume

  • Can extract type

skeleton from term

  • Given annotated term, compute

best type type without sensitivities w.r.t. subtyping

slide-40
SLIDE 40

The typechecking problem

Assume

  • Can extract type

skeleton from term

  • Given annotated term, compute

best type type without sensitivities w.r.t. subtyping

slide-41
SLIDE 41

The typechecking problem

Assume

  • Can extract type

skeleton from term

  • Given annotated term, compute

best type type without sensitivities w.r.t. subtyping

slide-42
SLIDE 42

The typechecking problem

Assume

  • Can extract type

skeleton from term

  • Given annotated term, compute

best type type without sensitivities w.r.t. subtyping

slide-43
SLIDE 43

The typechecking problem

Assume

  • Can extract type

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
SLIDE 44

The typechecking problem

Assume

  • Can extract type

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
SLIDE 45

The typechecking problem

Assume

  • Can extract type

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
SLIDE 46

The typechecking problem

Assume

  • Can extract type

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
SLIDE 47

The typechecking problem

Assume

  • Can extract type

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
SLIDE 48

The typechecking problem

Input

  • Annotated term e
  • Annotated context skeleton Γ•:

x : ?? τ no annot. annot.

slide-49
SLIDE 49

The typechecking problem

Input

  • Annotated term e
  • Annotated context skeleton Γ•:

x : ?? τ no annot. annot.

slide-50
SLIDE 50

The typechecking problem

Input

  • Annotated term e
  • Annotated context skeleton Γ•:

x : ?? τ no annot. annot.

slide-51
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
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
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
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
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
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
SLIDE 57

“Minimal” types?

A problem with the bottom-up approach

  • Some DFuzz rules have form

Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·

slide-58
SLIDE 58

“Minimal” types?

A problem with the bottom-up approach

  • Some DFuzz rules have form

Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·

slide-59
SLIDE 59

“Minimal” types?

A problem with the bottom-up approach

  • Some DFuzz rules have form

Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·

slide-60
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
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
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
SLIDE 63

The sensitivity language

Grammar

R ::= iR | iN | R | R + R | R · R variables over real/naturals

slide-64
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
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
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
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
SLIDE 68

How does this fix the problem?

Previously problematic rule

Γ ⊢ e1 : σ1 Γ ⊢ e2 : σ2 Γ ⊢ · · · : · · ·

slide-69
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
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
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
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
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
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
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
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
SLIDE 77

Checking the constraints

Idea: eliminate extended terms

  • Change R ≥ max(R∗

1, R∗ 2) to

R ≥ R∗

1 ∧ R ≥ R∗ 2

  • Recursively eliminate comparisons R ≥ R∗
  • Similar technique for other new sensitivity constructions
slide-78
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
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
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
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
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