Safety Proofs using Appearance and Behaviours Sumanth Prabhu S, - - PowerPoint PPT Presentation

safety proofs using appearance and behaviours
SMART_READER_LITE
LIVE PREVIEW

Safety Proofs using Appearance and Behaviours Sumanth Prabhu S, - - PowerPoint PPT Presentation

Safety Proofs using Appearance and Behaviours Sumanth Prabhu S, Kumar Madhukar, R Venkatesh TRDDC, Pune July 20, 2018 Safe Inductive Invariants: x y x y x int x = y = 0 while (*) { x = x + 1 y = y + x } assert(y >= 0) Inductive


slide-1
SLIDE 1

Safety Proofs using Appearance and Behaviours

Sumanth Prabhu S, Kumar Madhukar, R Venkatesh

TRDDC, Pune July 20, 2018

slide-2
SLIDE 2

Inductive Invariants

int x = y = 0 while (*) { x = x + 1 y = y + x } assert(y >= 0)

Program Reference: Understanding IC3

Safe Inductive Invariants: x y x y x

2

slide-3
SLIDE 3

Inductive Invariants

int x = y = 0 while (*) { x = x + 1 y = y + x } assert(y >= 0)

Program Reference: Understanding IC3

Safe Inductive Invariants: (x ≥ 0 ∧ y ≥ 0) (x ≥ 0 ∧ y − x ≥ 0)

2

slide-4
SLIDE 4

Inductive Invariants

Given ⟨V ∪ V′, Init, Tr⟩ and Bad x y x y x y , x x y y x and y Initiation: Init(V) ⇒ Inv(V) x y x y Consecution: Inv(V) ∧ Tr(V, V′) ⇒ Inv(V′) x y x x y y x x y Safety: Inv(V) ∧ Bad(V) ⇒ false x y y false

How to synthesize Inv?

3

slide-5
SLIDE 5

Inductive Invariants

Given ⟨V ∪ V′, Init, Tr⟩ and Bad {x, y, x′, y′}, x = 0 ∧ y = 0, x′ = x + 1 ∧ y′ = y + x and ¬(y ≥ 0) Initiation: Init(V) ⇒ Inv(V) (x = 0 ∧ y = 0) ⇒ (x ≥ 0 ∧ y ≥ 0) Consecution: Inv(V) ∧ Tr(V, V′) ⇒ Inv(V′) (x ≥ 0 ∧ y ≥ 0) ∧ x′ = x + 1 ∧ y′ = y + x ⇒ (x′ ≥ 0 ∧ y′ ≥ 0) Safety: Inv(V) ∧ Bad(V) ⇒ false (x ≥ 0 ∧ y ≥ 0) ∧ ¬(y ≥ 0) ⇒ false

How to synthesize Inv?

3

slide-6
SLIDE 6

Inductive Invariants

Given ⟨V ∪ V′, Init, Tr⟩ and Bad {x, y, x′, y′}, x = 0 ∧ y = 0, x′ = x + 1 ∧ y′ = y + x and ¬(y ≥ 0) Initiation: Init(V) ⇒ Inv(V) (x = 0 ∧ y = 0) ⇒ (x ≥ 0 ∧ y ≥ 0) Consecution: Inv(V) ∧ Tr(V, V′) ⇒ Inv(V′) (x ≥ 0 ∧ y ≥ 0) ∧ x′ = x + 1 ∧ y′ = y + x ⇒ (x′ ≥ 0 ∧ y′ ≥ 0) Safety: Inv(V) ∧ Bad(V) ⇒ false (x ≥ 0 ∧ y ≥ 0) ∧ ¬(y ≥ 0) ⇒ false

How to synthesize Inv?

3

slide-7
SLIDE 7

Guess and Check

Iterative learning: Inv ⇔ l0 ∧ l1 ∧ · · · ∧ ln

4

slide-8
SLIDE 8

Appearance Guided Synthesis

int x = y = 0 while (*) x = x + 1 y = y + x assert(y >= 0)

Probability distribution: (x ≥ 0) → 0.4 (−x ≥ 0) → 0.0 (y ≥ 0) → 0.3 (−y ≥ 0) → 0.0 (x + y ≥ 0) → 0.2 (y − x ≥ 0) → 0.1

How often does a disjunctive formula have the arity i p How often does an operator

  • p

appear among the inequalities p How often does a variable v have a coefficient k p

x 5

slide-9
SLIDE 9

Appearance Guided Synthesis

int x = y = 0 while (*) x = x + 1 y = y + x assert(y >= 0)

Fedyukovich, Kaufman, and Bodík, FMCAD 2017 Sampling Grammar c ::= 0 | 1 | −1 k ::= 0 | 1 | −1 v ::= x | y lincom ::= k · v + . . . k · v ineq ::= lincom ≥ c | lincom > c cand ::= ineq∨ineq∨. . . ineq

How often does a disjunctive formula have the arity i p How often does an operator

  • p

appear among the inequalities p How often does a variable v have a coefficient k p

x 5

slide-10
SLIDE 10

Appearance Guided Synthesis

int x = y = 0 while (*) x = x + 1 y = y + x assert(y >= 0)

How often does a disjunctive formula have the arity i p How often does an operator

  • p ∈ {>, ≥} appear among the

inequalities p How often does a variable v have a coefficient k p

x 5

slide-11
SLIDE 11

Appearance Guided Synthesis

int x = y = 0 while (*) x = x + 1 y = y + x assert(y >= 0)

How often does a disjunctive formula have the arity i p∨(2) = 0 How often does an operator

  • p ∈ {>, ≥} appear among the

inequalities p> = 1/5 How often does a variable v have a coefficient k p{1,x}(1) = 1/2 Detective Auguste Dupin gave them a ’stong acceptance’ as they found what was hidden in plain sight.

5

slide-12
SLIDE 12

Relearning Probabilities

Avoid candidates that are: Already checked Stronger than failures (x > 5 ∨ x + y ≥ 0) ⊃ (x > 10 ∨ x + y > 5) Weaker than learned lemmas (y ≥ 0 ∨ y − x ≥ 10) ⊂ (y ≥ −1 ∨ y − x > 8) Increase probability of candidates that are unrelated

6

slide-13
SLIDE 13

Experimental Evaluation

On 76 loopy programs, this technique outperformed ▷ µZ on 37 benchmarks (including 32 for which µZ crashed

  • r timed out after 10 minutes)

▷ ICE-DT on 53 benchmarks (including 30 . . .) ▷ MCMC on 67 benchmarks (including 49 . . .)

7

slide-14
SLIDE 14

Downsides

Equal treatment of all syntactic expressions Ignorance to whether the candidates have a semantic value Inability to predict an appropriate order of candidates to be sampled and checked

8

slide-15
SLIDE 15

Downsides

int x = k = c = 0; int N = *; while (c < N) int M = *; if (k mod 2 == 0) x = x + M; c = c + M; k = x + c; assert(x >= N);

Inductive Invariant1: k mod 2 = 0 ∧ x = c Inductive Invariant2: k = x + c ∧ x = c

9

slide-16
SLIDE 16

Accelerating Synthesis

Fedyukovich, and Bodík, TACAS 2017 Usage of Interpolation Safety Proofs from Bounded Model Checking Batch-wise candidate check for each cand ∈ candidates ∧

c∈candidates

c(V) ∧ Tr(V, V′) ⇒ cand(V′)

10

slide-17
SLIDE 17

Accelerating Synthesis

int x = k = c = 0; int N = *; while (c < N) int M = *; if (k mod 2 == 0) x = x + M; c = c + M; k = x + c; assert(x >= N);

BMC: x = 0 ∧ k = 0 ∧ c = 0 ∧ ¬(c < N) ∧ ¬(x ≥ N) Interpolants: x c x c x c Candidates: k x c k mod

11

slide-18
SLIDE 18

Accelerating Synthesis

int x = k = c = 0; int N = *; while (c < N) int M = *; if (k mod 2 == 0) x = x + M; c = c + M; k = x + c; assert(x >= N);

BMC: x = 0 ∧ k = 0 ∧ c = 0 ∧ ¬(c < N) ∧ ¬(x ≥ N) Interpolants: {x ≥ 0, c ≤ 0}, {x = c}, {x ≥ c} Candidates: k x c k mod

11

slide-19
SLIDE 19

Accelerating Synthesis

int x = k = c = 0; int N = *; while (c < N) int M = *; if (k mod 2 == 0) x = x + M; c = c + M; k = x + c; assert(x >= N);

BMC: x = 0 ∧ k = 0 ∧ c = 0 ∧ ¬(c < N) ∧ ¬(x ≥ N) Interpolants: {x ≥ 0, c ≤ 0}, {x = c}, {x ≥ c} Candidates: k = x + c ∧ k mod 2 = 0

11

slide-20
SLIDE 20

Behaviour as Data

Prabhu, Madhukar, Venkatesh, SAS 2018, to appear assume(1 <= n <= 1000); sum = 0, i = 1; while(i<=n) { sum = sum + i; i = i + 1; } assert(2*sum == n*(n+1));

12

slide-21
SLIDE 21

Behaviour as Data

assume(1 <= n <= 1000); sum = 0, i = 1; while(i<=n) { sum = sum + i; i = i + 1; } assert(2*sum == n*(n+1)); Safe Inductive invariant: 2 ∗ sum = i ∗ (i − 1) ∧ i ≤ n + 1

12

slide-22
SLIDE 22

Behaviour as Data

assume(1 <= n <= 1000); sum = 0, i = 1; if(i<=n) { <0 , 1> sum = sum + i; i = i + 1; } if(i<=n) { <1, 2> sum = sum + i; i = i + 1; } if(i<=n) { <3, 3> sum = sum + i; i = i + 1; } if(i<=n) { <6, 4> sum = sum + i; i = i + 1; } if(i<=n) { <10, 5> sum = sum + i; i = i + 1; }

13

slide-23
SLIDE 23

Behaviour as Data

assume(1 <= n <= 1000); sum = 0, i = 1; if(i<=n) { <0 , 1> sum = sum + i; i = i + 1; } if(i<=n) { <1, 2> sum = sum + i; i = i + 1; } if(i<=n) { <3, 3> sum = sum + i; i = i + 1; } if(i<=n) { <6, 4> sum = sum + i; i = i + 1; } if(i<=n) { <10, 5> sum = sum + i; i = i + 1; } If an invariant is a conjunction of k polynomial equations each of degree d and nullity

  • f A is k, where A is

a data matrix, then any basis for nullspace of A forms an invariant. Sharma et al, ESOP, 2013

13

slide-24
SLIDE 24

Behaviour as Data

assume(1 <= n <= 1000); sum = 0, i = 1; if(i<=n) { <0 , 1> sum = sum + i; i = i + 1; } if(i<=n) { <1, 2> sum = sum + i; i = i + 1; } if(i<=n) { <3, 3> sum = sum + i; i = i + 1; } if(i<=n) { <6, 4> sum = sum + i; i = i + 1; } if(i<=n) { <10, 5> sum = sum + i; i = i + 1; } Inductive invariant: a ∗ sum2 + b ∗ i2 + c ∗ sum ∗ i + d ∗ sum + e ∗ i + f = 0

13

slide-25
SLIDE 25

Algebraic Invariants

1 sum i sum2 sum ∗ i i2 1 1 1 1 1 2 1 2 4 1 3 3 9 9 9 1 6 4 36 24 16 1 10 5 100 50 25

14

slide-26
SLIDE 26

Algebraic Invariants

      1 1 1 1 1 2 1 2 4 1 3 3 9 9 9 1 6 4 36 24 16 1 10 5 100 50 25       ∗         a b c d e f         = 0

14

slide-27
SLIDE 27

Algebraic Invariants

basis(Nullspace(M)) =         −2 −1 1         0∗1−2∗sum−1∗i+0∗sum2 +0∗sum∗i+1∗i2 2 ∗ sum = i ∗ (i − 1)

14

slide-28
SLIDE 28

Conditional Invariants

int LRG = nondet(); assume(LRG > 0); int x = 0, y = LRG; while(x < 2*LRG) { if (x < LRG) { y = y; } else { y = y + 1; } x = x + 1; } assert(y == 2*LRG); Disjunctive: x LRG y x x LRG Conditional Invariants: x LRG y LRG x LRG y x x LRG CTIs: sk = Inv and sk sk = Tr, but sk = Inv

15

slide-29
SLIDE 29

Conditional Invariants

int LRG = nondet(); assume(LRG > 0); int x = 0, y = LRG; while(x < 2*LRG) { if (x < LRG) { y = y; } else { y = y + 1; } x = x + 1; } assert(y == 2*LRG); Disjunctive: ((x ≥ LRG)∨ (y = x)∧ (x ≤ 2 ∗ LRG)) Conditional Invariants: x LRG y LRG x LRG y x x LRG CTIs: sk = Inv and sk sk = Tr, but sk = Inv

15

slide-30
SLIDE 30

Conditional Invariants

int LRG = nondet(); assume(LRG > 0); int x = 0, y = LRG; while(x < 2*LRG) { if (x < LRG) { y = y; } else { y = y + 1; } x = x + 1; } assert(y == 2*LRG); Disjunctive: ((x ≥ LRG)∨ (y = x)∧ (x ≤ 2 ∗ LRG)) Conditional Invariants: (((x < LRG) ⇒ (y = LRG))∧ ((x ≥ LRG) ⇒ (y = x)))∧ (x ≤ 2 ∗ LRG) CTIs: sk | = Inv and (sk, s′

k+1) |

= Tr, but s′

k+1 ̸|

= Inv′

15

slide-31
SLIDE 31

Results

ELABor solved 16/24 new programs when compared to FreqHorn-2 2x speedup and 100s time difference for 31 programs

16

slide-32
SLIDE 32

Future Directions

Usage in solving nested loops (In Review) Neural nets to refine sampling Deciding between behaviour or appearance

17

slide-33
SLIDE 33

Conclusion

Appearance guided synthesis Behaviours to obtain candidates Conditional invariants for disjunctions

18

slide-34
SLIDE 34

References

Grigory Fedyukovich and Rastislav Bodı ́

  • k. “Accelerating Syntax-Guided Invariant Synthesis”. In:

2018 Tools and Algorithms for the Construction and Analysis of Systems, TACAS 2018, Thessaloniki, Greece, April 14-20, 2018. To appear. Grigory Fedyukovich, Samuel J. Kaufman, and Rastislav Bodı ́

  • k. “Sampling invariants from

frequency distributions”. In: 2017 Formal Methods in Computer Aided Design, FMCAD 2017, Vienna, Austria, October 2-6, 2017. 2017, pp. 100–107. Sumanth Prabhu S, Kumar Madhukar, and R Venkatesh. “Efficiently Learning Safety Proofs from Appearance as well as Behaviours”. In: Static Analysis Symposium. 2018, to appear. Rahul Sharma et al. “A Data Driven Approach for Algebraic Loop Invariants”. In: Programming Languages and Systems - 22nd European Symposium on Programming, ESOP 2013, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2013, Rome, Italy, March 16-24,

  • 2013. Proceedings. 2013, pp. 574–592.

19

slide-35
SLIDE 35

20

slide-36
SLIDE 36

Conditional Invariants

Polynomial relation: x′

i ∈ V′,

f(x′

i) =

c1 ∗ m1 + c2 ∗ m2 + · · · + cn ∗ mn CTIs: sk = Inv and sk sk = Tr, but sk = Inv M matrix of monomials from sk fxi

T

xi xil from sk rank M rank M fxi no solution over c cn

21

slide-37
SLIDE 37

Conditional Invariants

Polynomial relation: x′

i ∈ V′,

f(x′

i) =

c1 ∗ m1 + c2 ∗ m2 + · · · + cn ∗ mn CTIs: sk | = Inv and (sk, s′

k+1) |

= Tr, but s′

k+1 ̸|

= Inv′ M matrix of monomials from sk fxi

T

xi xil from sk rank M rank M fxi no solution over c cn

21

slide-38
SLIDE 38

Conditional Invariants

Polynomial relation: x′

i ∈ V′,

f(x′

i) =

c1 ∗ m1 + c2 ∗ m2 + · · · + cn ∗ mn CTIs: sk | = Inv and (sk, s′

k+1) |

= Tr, but s′

k+1 ̸|

= Inv′ M matrix of monomials from sk ⃗ fx′

i

T

= (x′

i1

. . . x′

il

) from s′

k+1

rank M rank M fxi no solution over c cn

21

slide-39
SLIDE 39

Conditional Invariants

Polynomial relation: x′

i ∈ V′,

f(x′

i) =

c1 ∗ m1 + c2 ∗ m2 + · · · + cn ∗ mn CTIs: sk | = Inv and (sk, s′

k+1) |

= Tr, but s′

k+1 ̸|

= Inv′ M matrix of monomials from sk ⃗ fx′

i

T

= (x′

i1

. . . x′

il

) from s′

k+1

rank(M) ̸= rank((M| ⃗ fx′

i )) no

solution over c1 . . . cn

21

slide-40
SLIDE 40

Conditional Invariants

int LRG = nondet(); assume(LRG > 0); int x = 0, y = LRG; while(x < 2*LRG) { if (x < LRG) { y = y; } else { y = y + 1; } x = x + 1; } assert(y == 2*LRG); y = LRG sk(LRG) = 100, sk(x) = 100, sk(y) = 100 s′

k+1(LRG′) = 100,

sk+1(x′) = 101, sk+1(y′) = 101 y x sk LRG , sk x , sk y sk LRG , sk x , sk y

22

slide-41
SLIDE 41

Conditional Invariants

int LRG = nondet(); assume(LRG > 0); int x = 0, y = LRG; while(x < 2*LRG) { if (x < LRG) { y = y; } else { y = y + 1; } x = x + 1; } assert(y == 2*LRG); y = LRG sk(LRG) = 100, sk(x) = 100, sk(y) = 100 s′

k+1(LRG′) = 100,

sk+1(x′) = 101, sk+1(y′) = 101 y = x sk(LRG) = 100, sk(x) = 10, sk(y) = 100 s′

k+1(LRG′) = 100,

sk+1(x′) = 11, sk+1(y′) = 100

22

slide-42
SLIDE 42

Conditional Invariants

int LRG = nondet(); assume(LRG > 0); int x = 0, y = LRG; while(x < 2*LRG) { if (x < LRG) { y = y; } else { y = y + 1; } x = x + 1; } assert(y == 2*LRG); Rank     const LRG x y 1 100 100 100 1 100 10 100 . . .     ̸= Rank     const LRG x y y′ 1 100 100 100 101 1 100 10 100 100 . . .    

23

slide-43
SLIDE 43

The cardinality of B is called dimension of V. For a matrix A, the dimension of the vector space generated by its columns is called its

  • rank. The nullspace of a matrix A is a set of all

vectors v such that Av = 0. The dimension of a matrix’s nullspace is also called its nullity.

24