Compositional Program Analysis using Max-SMT Albert Rubio Cristina - - PowerPoint PPT Presentation

compositional program analysis using max smt
SMART_READER_LITE
LIVE PREVIEW

Compositional Program Analysis using Max-SMT Albert Rubio Cristina - - PowerPoint PPT Presentation

Compositional Program Analysis using Max-SMT Albert Rubio Cristina Borralleras, Marc Brockschmidt, Daniel Larraz, Albert Oliveras, Jos Miguel Rivero and Enric Rodrguez-Carbonell Universitat Politcnica de Catalunya - Barcelona Tech UCM


slide-1
SLIDE 1

Compositional Program Analysis using Max-SMT

Albert Rubio

Cristina Borralleras, Marc Brockschmidt, Daniel Larraz, Albert Oliveras, José Miguel Rivero and Enric Rodríguez-Carbonell Universitat Politècnica de Catalunya - Barcelona Tech

UCM Seminar March 2018

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 1 / 44

slide-2
SLIDE 2

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 2 / 44

slide-3
SLIDE 3

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 3 / 44

slide-4
SLIDE 4

Motivation

Main Goal: Build static analysis tools for programmers.

Fully automatic. Efficient. Scalable.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 4 / 44

slide-5
SLIDE 5

Motivation

Main Goal: Build static analysis tools for programmers.

Fully automatic. Efficient. Scalable.

Strategy: Take advantage of powerful arithmetic constraint solvers. SMT solvers Constraint-based Program Analysis techniques

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 4 / 44

slide-6
SLIDE 6

Motivation

Main Goal: Build static analysis tools for programmers.

Fully automatic. Efficient. Scalable.

Strategy: Take advantage of powerful arithmetic constraint solvers. Max-SMT solvers Constraint-based Program Analysis techniques

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 4 / 44

slide-7
SLIDE 7

Motivation

Main Goal: Build static analysis tools for programmers.

Fully automatic. Efficient. Scalable.

Strategy: Take advantage of powerful arithmetic constraint solvers. Max-SMT solvers Constraint-based Program Analysis techniques Goal: Verify safety and liveness properties of programs

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 4 / 44

slide-8
SLIDE 8

Motivation

Main Goal: Build static analysis tools for programmers.

Fully automatic. Efficient. Scalable.

Strategy: Take advantage of powerful arithmetic constraint solvers. Max-SMT solvers Constraint-based Program Analysis techniques Goal: Verify safety and liveness properties of programs Challenge: discover (loop) invariants. How can we guide the search?

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 4 / 44

slide-9
SLIDE 9

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 5 / 44

slide-10
SLIDE 10

SMT solvers

We make extensive use of SMT solvers inside our program analysis tools. SAT and SMT solvers gain efficiency by: addressing only (expressive enough) decidable fragments of a certain logic incorporate domain-specific reasoning, e.g:

arithmetic reasoning equality data structures (arrays, lists, stacks, ...)

SAT: use propositional logic as the formalization language

+ high degree of efficiency

  • expressive (all NP-complete) but involved encodings

SMT: propositional logic + domain-specific reasoning

+ improves the expressivity

  • certain (but acceptable) loss of efficiency

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 6 / 44

slide-11
SLIDE 11

Need and Applications of SMT

Some problems are more naturally expressed in other logics than propositional logic, e.g:

Software verification needs reasoning about equality, arithmetic, data structures, ...

SMT consists of deciding the satisfiability of a (ground) FO formula with respect to a background theory Example ( Equality with Uninterpreted Functions – EUF ):

g(a)=c ∧ ( f (g(a))=f (c) ∨ g(a)=d ) ∧ c =d

Wide range of applications:

Predicate abstraction Model checking Scheduling Test generation ...

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 7 / 44

slide-12
SLIDE 12

Theories of Interest - Arithmetic

Very useful for obvious reasons Restricted fragments support more efficient methods:

Bounds: x ⊲ ⊳ k with ⊲ ⊳∈ {<, >, ≤, ≥, =} Difference logic: x − y ⊲ ⊳ k, with ⊲ ⊳∈ {<, >, ≤, ≥, =} UTVPI: ±x ± y ⊲ ⊳ k, with ⊲ ⊳∈ {<, >, ≤, ≥, =} Linear arithmetic, e.g: 2x − 3y + 4z ≤ 5 Non-linear arithmetic, e.g: 2xy + 4xz2 − 5y ≤ 10 Variables are either reals or integers

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 8 / 44

slide-13
SLIDE 13

SMT problems

Input: Given a boolean formula ϕ over some theory T. Question: Is there any interpretation (solution) that satisfies the formula? Example: T = linear integer/real arithmetic. (x < 0 ∨ x ≤ y ∨ y < z) ∧ (x ≥ 0) ∧ (x > y ∨ y < z) {x = 1, y = 0, z = 2}

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 9 / 44

slide-14
SLIDE 14

SMT problems

Input: Given a boolean formula ϕ over some theory T. Question: Is there any interpretation (solution) that satisfies the formula? Example: T = linear integer/real arithmetic. (x < 0 ∨ x ≤ y ∨ y < z) ∧ (x ≥ 0) ∧ (x > y ∨ y < z) {x = 1, y = 0, z = 2}

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 9 / 44

slide-15
SLIDE 15

SMT problems

Input: Given a boolean formula ϕ over some theory T. Question: Is there any interpretation (solution) that satisfies the formula? Example: T = linear integer/real arithmetic. (x < 0 ∨ x ≤ y ∨ y < z) ∧ (x ≥ 0) ∧ (x > y ∨ y < z) {x = 1, y = 0, z = 2} There exist very efficient solvers: yices, z3, Barcelogic, ... Can handle large formulas with a complex boolean structure.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 9 / 44

slide-16
SLIDE 16

Optimization problems

(Weighted) Max-SMT problem Input: Given an SMT formula ϕ = C1 ∧ . . . ∧ Cm in CNF, where some of the clauses are hard and the others soft with a weight. Output: An assignment for the hard clauses that minimizes the sum of the weights of the falsified soft clauses. (x2 + y 2 > 2 ∨ x · z ≤ y ∨ y · z < z2) ∧ (x > y ∨ 0 < z ∨ w(5)) ∧ . . .

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 10 / 44

slide-17
SLIDE 17

Non-linear SMT solving

Input: Given a boolean formula ϕ over some theory T. Question: Is there any solution that satisfies the formula? Example: T = non-linear (polynomial) integer/real arithmetic. (x2 + y 2 > 2 ∨ x · z ≤ y ∨ y · z < z2) ∧ (x > y ∨ 0 < z) {x = 0, y = 1, z = 1}

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 11 / 44

slide-18
SLIDE 18

Non-linear SMT solving

Input: Given a boolean formula ϕ over some theory T. Question: Is there any solution that satisfies the formula? Example: T = non-linear (polynomial) integer/real arithmetic. (x2 + y 2 > 2 ∨ x · z ≤ y ∨ y · z < z2) ∧ (x > y ∨ 0 < z) {x = 0, y = 1, z = 1}

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 11 / 44

slide-19
SLIDE 19

Non-linear SMT solving

Input: Given a boolean formula ϕ over some theory T. Question: Is there any solution that satisfies the formula? Example: T = non-linear (polynomial) integer/real arithmetic. (x2 + y 2 > 2 ∨ x · z ≤ y ∨ y · z < z2) ∧ (x > y ∨ 0 < z) {x = 0, y = 1, z = 1} Non-linear arithmetic decidability: Integers: undecidable (Hilbert’s 10th problem). Reals: decidable (Tarski) but algorithms have prohibitive complexity.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 11 / 44

slide-20
SLIDE 20

Non-linear SMT solving

Input: Given a boolean formula ϕ over some theory T. Question: Is there any solution that satisfies the formula? Example: T = non-linear (polynomial) integer/real arithmetic. (x2 + y 2 > 2 ∨ x · z ≤ y ∨ y · z < z2) ∧ (x > y ∨ 0 < z) {x = 0, y = 1, z = 1} Non-linear arithmetic decidability: Integers: undecidable (Hilbert’s 10th problem). Reals: decidable (Tarski) but algorithms have prohibitive complexity. Incomplete solvers focus on either satisfiability or unsatisfiability.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 11 / 44

slide-21
SLIDE 21

Non-linear SMT solving

Input: Given a boolean formula ϕ over some theory T. Question: Is there any solution that satisfies the formula? Example: T = non-linear (polynomial) integer/real arithmetic. (x2 + y 2 > 2 ∨ x · z ≤ y ∨ y · z < z2) ∧ (x > y ∨ 0 < z) {x = 0, y = 1, z = 1} Non-linear arithmetic decidability: Integers: undecidable (Hilbert’s 10th problem). Reals: decidable (Tarski) but algorithms have prohibitive complexity. Incomplete solvers focus on either satisfiability or unsatisfiability.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 11 / 44

slide-22
SLIDE 22

Solving non-linear SMT formulas

Need to handle large formulas with non-linear arithmetic and complex boolean structure. Barcelogic has shown to be the best SMT-solver proving satisfiability

  • f this kind of problems.

Barcelogic can handle Max-SMT formulas (over non-linear arithmetic) as well.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 12 / 44

slide-23
SLIDE 23

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 13 / 44

slide-24
SLIDE 24

Invariant generation

Definition

An invariant of a program at a location is an assertion over the program variables that remains true whenever the location is reached.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 14 / 44

slide-25
SLIDE 25

Invariant generation

Definition

An invariant of a program at a location is an assertion over the program variables that remains true whenever the location is reached.

Definition

An invariant is said to be inductive at a program location if: Initiation condition: It holds the first time the location is reached. Consecution condition: It is preserved under every cycle back to the location.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 14 / 44

slide-26
SLIDE 26

Invariant generation

Definition

An invariant of a program at a location is an assertion over the program variables that remains true whenever the location is reached.

Definition

An invariant is said to be inductive at a program location if: Initiation condition: It holds the first time the location is reached. Consecution condition: It is preserved under every cycle back to the location. We focus on inductive invariants.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 14 / 44

slide-27
SLIDE 27

Constraint-based invariant generation

We inspire ourselves with the constraint-based method [CSS’03]. Assume input programs consist of linear expressions.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 15 / 44

slide-28
SLIDE 28

Constraint-based invariant generation

We inspire ourselves with the constraint-based method [CSS’03]. Assume input programs consist of linear expressions. Keys: Use a template for candidate invariants. c1x1 + . . . + cnxn + d ≤ 0

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 15 / 44

slide-29
SLIDE 29

Constraint-based invariant generation

We inspire ourselves with the constraint-based method [CSS’03]. Assume input programs consist of linear expressions. Keys: Use a template for candidate invariants. c1x1 + . . . + cnxn + d ≤ 0 Impose initiation and consecution conditions obtaining an ∃∀ problem

  • ver non-linear arithmetic.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 15 / 44

slide-30
SLIDE 30

Constraint-based invariant generation

We inspire ourselves with the constraint-based method [CSS’03]. Assume input programs consist of linear expressions. Keys: Use a template for candidate invariants. c1x1 + . . . + cnxn + d ≤ 0 Impose initiation and consecution conditions obtaining an ∃∀ problem

  • ver non-linear arithmetic.

Transform it using Farkas’ Lemma into an ∃ problem over non-linear arithmetic.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 15 / 44

slide-31
SLIDE 31

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: c1a + c2s + c3t + d ≤ 0 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; }

Back Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-32
SLIDE 32

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: c1a + c2s + c3t + d ≤ 0 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; }

∃ c1, c2, c3, d ∀ a, s, t true = ⇒ c1 · 0 + c2 · 1 + c3 · 1 + d ≤ 0

Initiation condition s ≤ N ∧ c1 · a + c2 · s + c3 · t + d ≤ 0 = ⇒ c1 · (a + 1) + c2 · (s + t + 2) + c3 · (t + 2) + d ≤ 0

  • consecution condition

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-33
SLIDE 33

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: c1a + c2s + c3t + d ≤ 0 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; }

∃ c1, c2, c3, d ∀ a, s, t c2 + c3 + d ≤ 0

Initiation condition s ≤ N ∧ c1 · a + c2 · s + c3 · t + d ≤ 0 = ⇒ c1 · a + c2 · s + (c2 + c3) · t + c1 + 2c2 + 2c3 + d ≤ 0

  • consecution condition

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-34
SLIDE 34

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: c1a + c2s + c3t + d ≤ 0 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; } Apply Farkas’ Lemma to remove ∀ a, s, t Use Barcelogic to solve the non-linear SMT problem!

Back Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-35
SLIDE 35

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: c1a + c2s + c3t + d ≤ 0 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; } Apply Farkas’ Lemma to remove ∀ a, s, t Use Barcelogic to solve the non-linear SMT problem! {c1 = −2, c2 = 0, c3 = 1, d = −1}

Back Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-36
SLIDE 36

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: −2a + 0s + 1t − 1 ≤ 0 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; } Apply Farkas’ Lemma to remove ∀ a, s, t Use Barcelogic to solve the non-linear SMT problem! {c1 = −2, c2 = 0, c3 = 1, d = −1}

Back Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-37
SLIDE 37

Scalar invariant generation: Example

Square root of a natural number N: int isqrt(int N) { //integer square root int a = 0, s = 1, t = 1; // Inv: t ≤ 2a + 1 while (s ≤ N) { a = a + 1; s = s + t + 2; t = t + 2; } return a; } Apply Farkas’ Lemma to remove ∀ a, s, t Use Barcelogic to solve the non-linear SMT problem! {c1 = −2, c2 = 0, c3 = 1, d = −1}

Back Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 16 / 44

slide-38
SLIDE 38

Program analysis using SMT and Max-SMT

We have used this approach for: Array invariant generation. [VMCAI2013] Termination analysis using Max-SMT. [FMCAD2013] (inspired by [BMS’05]) Key notion: quasi-ranking functions Non-Termination analysis using Max-SMT. [CAV2014] Key notion: quasi-invariant/conditional invariants

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 17 / 44

slide-39
SLIDE 39

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 18 / 44

slide-40
SLIDE 40

Safety verification

Aim: verify assertions in large programs (several consecutive loops). Our approach: Goal oriented. Starts from the postcondition. Automatically generate intermediate assertions!! Simple example: while (j>0) { j--; i++; } while (i>0) { x=x+5; i--; } assert(x≥0);

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 19 / 44

slide-41
SLIDE 41

Safety verification

Aim: verify assertions in large programs (several consecutive loops). Our approach: Goal oriented. Starts from the postcondition. Automatically generate intermediate assertions!! Simple example: while (j>0) { j--; i++; } assert(x + 5*i >=0); while (i>0) { x=x+5; i--; } assert(x>=0);

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 19 / 44

slide-42
SLIDE 42

Safety verification

Aim: verify assertions in large programs (several consecutive loops). Our approach: Goal oriented. Starts from the postcondition. Automatically generate intermediate assertions!! Simple example: assert(j>=0 and x + 5*(i+j) >=0); while (j>0) { j--; i++; } assert(x + 5*i >=0); while (i>0) { x=x+5; i--; } assert(x≥0);

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 19 / 44

slide-43
SLIDE 43

Conditional invariant generation

Definition

A formula is a conditional (inductive) invariant at a program location if: Consecution condition holds.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 20 / 44

slide-44
SLIDE 44

Conditional invariant generation

Definition

A formula is a conditional (inductive) invariant at a program location if: Consecution condition holds. but Initiation condition may not hold.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 20 / 44

slide-45
SLIDE 45

Conditional invariant generation

Definition

A formula is a conditional (inductive) invariant at a program location if: Consecution condition holds. Hard but Initiation condition may not hold.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 20 / 44

slide-46
SLIDE 46

Conditional invariant generation

Definition

A formula is a conditional (inductive) invariant at a program location if: Consecution condition holds. Hard but Initiation condition may not hold. Soft Key: We prefer invariants but we can live with conditional invariants

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 20 / 44

slide-47
SLIDE 47

Conditional invariant generation

Altogether we have: Initiation condition (soft) Consecution condition (hard)

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 21 / 44

slide-48
SLIDE 48

Conditional invariant generation

Altogether we have: Initiation condition (soft) Consecution condition (hard) Plus implication of the Postcondition (hard)

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 21 / 44

slide-49
SLIDE 49

Conditional invariant generation

Altogether we have: Initiation condition (soft) Consecution condition (hard) Plus implication of the Postcondition (hard) Solve the problem with a Max-SMT solver (we use Barcelogic)

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 21 / 44

slide-50
SLIDE 50

Conditional invariant generation

Altogether we have: Initiation condition (soft) Consecution condition (hard) Plus implication of the Postcondition (hard) Solve the problem with a Max-SMT solver (we use Barcelogic) If initiation condition holds we are done

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 21 / 44

slide-51
SLIDE 51

Conditional invariant generation

Altogether we have: Initiation condition (soft) Consecution condition (hard) Plus implication of the Postcondition (hard) Solve the problem with a Max-SMT solver (we use Barcelogic) If initiation does not hold we have a new Postcondition for previous code

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 21 / 44

slide-52
SLIDE 52

Conditional invariant generation

Altogether we have: Initiation condition (soft) Consecution condition (hard) Plus implication of the Postcondition (hard) Solve the problem with a Max-SMT solver (we use Barcelogic) If initiation does not hold we have a new Postcondition for previous code call recursively to the safety checker

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 21 / 44

slide-53
SLIDE 53

Safety verification: Recovering from failures

In case of failure of the recursive call to the safety checker Add the negation of the conditional invariant in the corresponding locations: Narrow the loop Try to prove the Postcondition again (with more information).

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 22 / 44

slide-54
SLIDE 54

Safety verification

Narrowing loops: Recovering from failures Simple example: int x=-50; int y=nondet(); while (x<0) { x = x + y; y = y + 1; } assert(y>0);

Skip Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 23 / 44

slide-55
SLIDE 55

Safety verification

Narrowing loops: Recovering from failures Simple example: int x=-50; int y=nondet(); assert(y>0); while (x<0) { x = x + y; y = y + 1; } assert(y>0);

Skip Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 23 / 44

slide-56
SLIDE 56

Safety verification

Narrowing loops: Recovering from failures Simple example: int x=-50; int y=nondet(); assert(y>0); // Conditional invariant while (x<0) { x = x + y; y = y + 1; } assert(y>0);

Skip Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 23 / 44

slide-57
SLIDE 57

Safety verification

Narrowing loops: Recovering from failures Simple example: int x=-50; int y=nondet(); assume(!(y>0)); while (x<0) { assume(!(y>0)); x = x + y; y = y + 1; } assert(y>0);

Skip Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 23 / 44

slide-58
SLIDE 58

Safety verification

Narrowing loops: Recovering from failures Simple example: int x=-50; int y=nondet(); assume(y<=0); while (x<0) { assume(y<=0); x = x + y; y = y + 1; } assert(y>0);

Skip Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 23 / 44

slide-59
SLIDE 59

Safety verification

Narrowing loops: Recovering from failures Simple example: int x=-50; int y=nondet(); assume(y<=0); assert(x<0); // Invariant while (x<0) { assume(y<=0); x = x + y; y = y + 1; } assert(y>0); // Unreachable!

Skip Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 23 / 44

slide-60
SLIDE 60

Experiments

Our techniques have been implemented in a tool called VeryMax 217 programs taken from Numerical Recipes in C++ up to 284 lines of code 6452 safety problems 6106 can be proved highly parallelizable FMCAD 2015

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 24 / 44

slide-61
SLIDE 61

Conditional Termination

Given a program (loop), obtain a (pre-)condition ensuring its termination.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 25 / 44

slide-62
SLIDE 62

Conditional Termination

Given a program (loop), obtain a (pre-)condition ensuring its termination. Our approach: Find ranking functions using (linear) templates Find supporting conditional invariants (like before)

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 25 / 44

slide-63
SLIDE 63

Conditional Termination

Given a program (loop), obtain a (pre-)condition ensuring its termination. Our approach: Find ranking functions using (linear) templates Find supporting conditional invariants (like before) Encode the problem with Max-SMT

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 25 / 44

slide-64
SLIDE 64

Conditional Termination

Given a program (loop), obtain a (pre-)condition ensuring its termination. Our approach: Find ranking functions using (linear) templates Find supporting conditional invariants (like before) Encode the problem with Max-SMT Using conditional termination we can prove termination by cases.

Skip

combine termination and non-termination analysis (in parallel). prove termination of consecutive loops in a compositional way.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 25 / 44

slide-65
SLIDE 65

Running example

int main() { int x, y, z; x = nondet(); y = nondet(); z = nondet(); while (y ≥ 0 && z = 0) { if (z < 0) { y = y + z; z = z − 1; } else { x = x − z; y = y + x; z = z + 1; } } }

ℓ0 ℓ1 ℓ2 τ0: true τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1 τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1 τ3: y < 0 ∧ x′ = x ∧ y ′ = y ∧ z′ = z τ4: z = 0 ∧ x′ = x ∧ y ′ = y ∧ z′ = z

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 26 / 44

slide-66
SLIDE 66

Ranking functions and Conditional Invariants

In order to discard a transition τi we need to find a ranking function f over the integers such that:

1 τi =

⇒ f (x1, . . . , xn) ≥ 0 (bounded)

2 τi =

⇒ f (x1, . . . , xn) > f (x′

1, . . . , x′ n)

(strict-decreasing)

3 τj =

⇒ f (x1, . . . , xn) ≥ f (x′

1, . . . , x′ n) for all j

(non-increasing) Use a linear template for the ranking function as well.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 27 / 44

slide-67
SLIDE 67

Ranking functions and Invariants: Combined problem

In order to prove properties of the ranking function we may need to generate invariants. Generation of both conditional invariants and ranking functions should be combined in the same optimization problem.

Back Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 28 / 44

slide-68
SLIDE 68

Ranking functions and Invariants: Combined problem

In order to prove properties of the ranking function we may need to generate invariants. Generation of both conditional invariants and ranking functions should be combined in the same optimization problem.

Back

1 I ∧ τi =

⇒ f (x1, . . . , xn) ≥ 0 (bounded)

2 I ∧ τi =

⇒ f (x1, . . . , xn) > f (x′

1, . . . , x′ n)

(strict-decreasing)

3 I ∧ τj =

⇒ f (x1, . . . , xn) ≥ f (x′

1, . . . , x′ n) for all j

(non-increasing)

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 28 / 44

slide-69
SLIDE 69

Ranking functions and Invariants: Combined problem

In order to prove properties of the ranking function we may need to generate invariants. Generation of both conditional invariants and ranking functions should be combined in the same optimization problem.

Back

1 I ∧ τi =

⇒ f (x1, . . . , xn) ≥ 0 (bounded)

2 I ∧ τi =

⇒ f (x1, . . . , xn) > f (x′

1, . . . , x′ n)

(strict-decreasing)

3 I ∧ τj =

⇒ f (x1, . . . , xn) ≥ f (x′

1, . . . , x′ n) for all j

(non-increasing) Considering conditional invariants give more chances to the solver

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 28 / 44

slide-70
SLIDE 70

Ranking functions and Invariants: Combined problem

In order to prove properties of the ranking function we may need to generate invariants. Generation of both conditional invariants and ranking functions should be combined in the same optimization problem.

Back

1 I ∧ τi =

⇒ f (x1, . . . , xn) ≥ 0 (bounded)

2 I ∧ τi =

⇒ f (x1, . . . , xn) > f (x′

1, . . . , x′ n)

(strict-decreasing)

3 I ∧ τj =

⇒ f (x1, . . . , xn) ≥ f (x′

1, . . . , x′ n) for all j

(non-increasing) Considering conditional invariants give more chances to the solver But we get a conditional termination proof

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 28 / 44

slide-71
SLIDE 71

Running example

ℓ0 ℓ1 ℓ2 τ0: true τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1 τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1 τ3: y < 0 ∧ x′ = x ∧ y ′ = y ∧ z′ = z τ4: z = 0 ∧ x′ = x ∧ y ′ = y ∧ z′ = z

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 29 / 44

slide-72
SLIDE 72

Running example

ℓ0 ℓ1 τ0: true τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1 τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 29 / 44

slide-73
SLIDE 73

Running example

ℓ0 ℓ1 τ0: true τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1 τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1

z < 0 is a conditional invariant at location ℓ1 y is a ranking function

1 τ1 is disabled 2 τ2 is bounded and strictly decreasing

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 29 / 44

slide-74
SLIDE 74

Running example

ℓ0 ℓ1 τ0: true τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1 τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1

We have a conditional proof: The system terminates if the condition z < 0 holds at ℓ0

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 29 / 44

slide-75
SLIDE 75

Running example

ℓ0 ℓ1 τ0: z < 0 τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1 τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

We have a conditional proof: The system terminates if the condition z < 0 holds at ℓ0 (or τ0)

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 30 / 44

slide-76
SLIDE 76

Running example: Narrowing

In order to complete the termination proof we have to consider the complementary problem. Narrow the transitions removing all states that we already know that are terminating. We can do better than just add the negation of the condition in the entry.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 31 / 44

slide-77
SLIDE 77

Running example: Narrowing

ℓ0 ℓ1 τ0: true τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1 τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

We know more!: whenever z < 0 holds at ℓ1 the system terminates

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 32 / 44

slide-78
SLIDE 78

Running example: Narrowing

ℓ0 ℓ1 τ0: true τ2: y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1 τ1: y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

Narrow the transition system according to this: whenever z < 0 holds at ℓ1 the system terminates

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 32 / 44

slide-79
SLIDE 79

Running example: Narrowing

ℓ0 ℓ1 τ0: z ≥0 τ2: z ≥ 0 y ≥ 0 ∧ z < 0 ∧ x′ = x ∧ y ′ = y + z ∧ z′ = z − 1 τ1: z ≥ 0 y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

Narrow the transition system according to this: whenever z < 0 holds at ℓ1 the system terminates

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 33 / 44

slide-80
SLIDE 80

Running example. Narrowing

After simplifying the transition system we get:

ℓ0 ℓ1 τ0: z ≥0 τ1: z ≥ 0 y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 34 / 44

slide-81
SLIDE 81

Running example. Narrowing

After simplifying the transition system we get:

ℓ0 ℓ1 τ0: z ≥0 τ1: z ≥ 0 y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

Conditionally terminates: x < 0 is a conditional invariant at location ℓ1 y is a ranking function

1 τ1 is bounded and strictly decreasing

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 34 / 44

slide-82
SLIDE 82

Running example. Narrowing

Narrowing again with the complement of x < 0 we get:

ℓ0 ℓ1 τ0: z ≥0 x ≥0 τ1: z ≥ 0 x ≥ 0 y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 35 / 44

slide-83
SLIDE 83

Running example. Narrowing

Narrowing again with the complement of x < 0 we get:

ℓ0 ℓ1 τ0: z ≥0 x ≥0 τ1: z ≥ 0 x ≥ 0 y ≥ 0 ∧ z > 0 ∧ x′ = x − z ∧ y ′ = y + x ∧ z′ = z + 1

Which terminates with x as a ranking function

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 35 / 44

slide-84
SLIDE 84

Compositional Termination Analysis

Aim: prove termination of large programs (several consecutive loops). New approach:

1 Obtain a conditional termination proof. 2 Check the condition as a Safety property.

Simple example: assume(x > y && y ≥ 0); while (y > 0) { x = x - 1; y = y - 1; } while (y < 0) { y = y + x; }

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 36 / 44

slide-85
SLIDE 85

Compositional Termination Analysis

Aim: prove termination of large programs (several consecutive loops). New approach:

1 Obtain a conditional termination proof. 2 Check the condition as a Safety property.

Simple example: assume(x > y && y ≥ 0); while (y > 0) { x = x - 1; y = y - 1; } assert(x > 0); Rank: -y while (y < 0) { y = y + x; }

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 36 / 44

slide-86
SLIDE 86

Compositional analysis through Conditional Termination

Aim: verify termination in large programs (several consecutive loops). New approach:

1 Obtain a conditional termination proof. 2 Check the condition as a Safety property.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 37 / 44

slide-87
SLIDE 87

Compositional analysis through Conditional Termination

Aim: verify termination in large programs (several consecutive loops). New approach:

1 Obtain a conditional termination proof. 2 Check the condition as a Safety property. 3 In case of failure of the Safety checker

Narrow the loop and try again!

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 37 / 44

slide-88
SLIDE 88

Compositional analysis through Conditional Termination

Aim: verify termination in large programs (several consecutive loops). New approach:

1 Obtain a conditional termination proof. 2 Check the condition as a Safety property. 3 In case of failure of the Safety checker

Narrow the loop and try again! We can handle every loop independently

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 37 / 44

slide-89
SLIDE 89

Experiments

Our techniques have been implemented in VeryMax Results: won the C Integer programs categories of the Terminaton Competition in 2016 and 2017 Comparison with tools at the Termination category of SVComp. On the 358 benchmarks not involving recursion or pointers (273) Tool Term NTerm Fail TO Total (s) AProVE 222 76 41 19 10235.44 SeaHorn 189 75 22 72 34760.69 UltimateBuchiA 224 103 25 6 7882.13 VeryMax 231 101 26 2444.29 See our paper at TACAS 2017 for more details.

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 38 / 44

slide-90
SLIDE 90

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 39 / 44

slide-91
SLIDE 91

VeryMax global architecture

  • ITS (smt2)

LLVM CODE TRANSFORMATION LLVM CODE C, C++ VERYMAX TRANSITION SYSTEM TERMINATION ANALISYS NON TERMINATION ANALISYS REACHABILITY CHECK CHECK MAX−SMT SOLVER INVARIANT CONDITIONAL GENERATOR RANKING FUNCTION

+

SAFETY

Two phases

1 Front-end. From source programs to VeryMax Transition Systems 2 Static Analysis Tools

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 40 / 44

slide-92
SLIDE 92

VeryMax static analysis tools

  • VERYMAX

TRANSITION SYSTEM TERMINATION ANALISYS NON TERMINATION ANALISYS REACHABILITY CHECK CHECK MAX−SMT SOLVER INVARIANT CONDITIONAL GENERATOR RANKING FUNCTION

+

SAFETY Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 41 / 44

slide-93
SLIDE 93

VeryMax static analysis tools

  • VERYMAX

TRANSITION SYSTEM TERMINATION ANALISYS NON TERMINATION ANALISYS REACHABILITY CHECK CHECK MAX−SMT SOLVER INVARIANT CONDITIONAL GENERATOR RANKING FUNCTION

+

SAFETY

VeryMax can

1 check safety properties 2 check reachability properties 3 prove termination 4 prove non-termination

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 41 / 44

slide-94
SLIDE 94

Overview of the talk

1 Introduction 2 SMT/Max-SMT solving 3 Invariant generation 4 Compositional safety verification 5 VeryMax Tool 6 Conclusions and current work

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 42 / 44

slide-95
SLIDE 95

Conclusions

Two main conclusions: Using SMT and Max-SMT, automatic generation of needed (conditional) invariants can be made efficiently. Scalable program verification becomes feasible Other potential applications of conditional analysis and Max-SMT: Analysis of concurrent/distributed systems. Program synthesis. Program repair (minimize changes). Using Max-SMT we can express preferences among possible solutions

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 43 / 44

slide-96
SLIDE 96

Thank you!

Albert Rubio (UPC) Program Analysis using Max-SMT UCM Seminar 2018 44 / 44