Software Model Checking with Ultimate Jochen Hoenicke - - PowerPoint PPT Presentation

software model checking with ultimate
SMART_READER_LITE
LIVE PREVIEW

Software Model Checking with Ultimate Jochen Hoenicke - - PowerPoint PPT Presentation

Software Model Checking with Ultimate Jochen Hoenicke Albert-Ludwigs-Universit at Freiburg, Germany July 3rd & 5th, 2019 Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 1 / 65 Brief History of Model


slide-1
SLIDE 1

Software Model Checking with Ultimate

Jochen Hoenicke

Albert-Ludwigs-Universit¨ at Freiburg, Germany

July 3rd & 5th, 2019

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 1 / 65

slide-2
SLIDE 2

Brief History of Model Checking

1980: Emerson & Clarke: Explicit state model-checking.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 2 / 65

slide-3
SLIDE 3

Brief History of Model Checking

1980: Emerson & Clarke: Explicit state model-checking. 1992: Burch, Clarke, McMillan, Dill & Hwang. Symbolic model checking.

1020 states and beyond.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 2 / 65

slide-4
SLIDE 4

Brief History of Model Checking

1980: Emerson & Clarke: Explicit state model-checking. 1992: Burch, Clarke, McMillan, Dill & Hwang. Symbolic model checking.

1020 states and beyond.

2001: Ball, Majumdar, Millstein & Rajamani: Predicate Abstraction

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 2 / 65

slide-5
SLIDE 5

Brief History of Model Checking

1980: Emerson & Clarke: Explicit state model-checking. 1992: Burch, Clarke, McMillan, Dill & Hwang. Symbolic model checking.

1020 states and beyond.

2001: Ball, Majumdar, Millstein & Rajamani: Predicate Abstraction 2009: Heizmann, H. & Podelski: Trace Abstraction.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 2 / 65

slide-6
SLIDE 6

Ultimate Ultimate – a software model-checker

https://ultimate.informatik.uni-freiburg.de/

Push button verification Input: C program Output: Correct (plus invariants) or Incorrect (plus counter-example)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 3 / 65

slide-7
SLIDE 7

The Ultimate Team

J¨ urgen Christ Daniel Dietsch Marius Greitschus Mathias Heizmann Jochen Hoenicke Alexander Nutz Martin Sch¨ af Tanja Schindler . . . and 36 more contributers. You can contribute too: https://github.com/ultimate-pa/ultimate

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 4 / 65

slide-8
SLIDE 8

Ultimate is a Framework

Ultimate Automizer: Trace Abstraction for Safety Ultimate B¨ uchi Automizer: Trace Abstraction for Termination Ultimate Kojak: Predicate Abstraction Ultimate Taipan: Abstract Interpretation + Trace Abstraction

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 5 / 65

slide-9
SLIDE 9

Ultimate is a Framework

Ultimate Automizer: Trace Abstraction for Safety Ultimate B¨ uchi Automizer: Trace Abstraction for Termination Ultimate Kojak: Predicate Abstraction Ultimate Taipan: Abstract Interpretation + Trace Abstraction Ultimate LTL Automizer: Checking LTL properties Ultimate Petri Automizer: Concurrent Programs

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 5 / 65

slide-10
SLIDE 10

Demo

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 6 / 65

slide-11
SLIDE 11

Example Program

int f(int i) { int j = 0; if (i > 0) { int *p = malloc(sizeof(int)); // allocate pointer *p = 0; while (i > 0) { *p += i; // use pointer if (i == 1) { // if in the last iteration: j = *p; free(p); // free the pointer } i--; // decrement i } } return j; }

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 7 / 65

slide-12
SLIDE 12

Example Program

int f(int i) { int j = 0; if (i > 0) { int *p = malloc(sizeof(int)); // allocate pointer *p = 0; while (i > 0) { *p += i; // use pointer if (i == 1) { // if in the last iteration: j = *p; free(p); // free the pointer } i--; // decrement i } } return j; }

Is every allocated memory eventually freed? Is every pointer dereference valid?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 8 / 65

slide-13
SLIDE 13

Adding Automatic Annotations

int f(int i) { int j = 0; if (i > 0) { int *p = malloc(sizeof(int)); // allocate pointer *p = 0; while (i > 0) { *p += i; // use pointer if (i == 1) { // if in the last iteration: j = *p; free(p); // free the pointer } i--; // decrement i } } return j; }

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 9 / 65

slide-14
SLIDE 14

Adding Automatic Annotations

int f(int i) { int j = 0; if (i > 0) { int *p = malloc(sizeof(int)); // allocate pointer palloc = 1; *p = 0; while (i > 0) { *p += i; // use pointer assert(palloc == 1); if (i == 1) { // if in the last iteration: j = *p; free(p); // free the pointer palloc = 0; } i--; // decrement i } } assert(palloc == 0); return j; }

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 9 / 65

slide-15
SLIDE 15

Adding Automatic Annotations

int f(int i) { ... if (i > 0) { ... // allocate pointer palloc = 1; ... while (i > 0) { ... // use pointer assert(palloc == 1); if (i == 1) { // if in the last iteration: ... ... // free the pointer palloc = 0; } i--; // decrement i } } assert(palloc == 0); }

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 9 / 65

slide-16
SLIDE 16

Trace Abstraction

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 10 / 65

slide-17
SLIDE 17

Finite Automaton and Program Automaton

A finite automaton A = (Σ, Q, →, q0, F) consists of Σ: a finite alphabet Q: a finite set of locations → ⊆ Q × Σ × Q: a transition relation q0 ∈ Q: the initial location F ⊆ Q: the accepting locations q0 q1 q2 q3 q4 a b b a c

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 11 / 65

slide-18
SLIDE 18

Finite Automaton and Program Automaton

A finite automaton A = (Σ, Q, →, q0, F) consists of Σ: a finite alphabet Q: a finite set of locations → ⊆ Q × Σ × Q: a transition relation q0 ∈ Q: the initial location F ⊆ Q: the accepting locations A program automaton is a finite automaton: Σ is the set of statements occurring in the program Q are the program locations → defines the control flow graph ℓ0 ∈ Q: the initial location F is the set containing the error location ℓerr ℓ0 ℓ1 ℓ2 ℓ3 ℓerr x >= 0 x < 0 y := x y := -x y < 0 A word over Σ is called a trace. The language of the program automaton is the set of error traces.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 11 / 65

slide-19
SLIDE 19

Statements

Σ is the set of statements occuring in the program. Only two kinds of statements: x := expr assigns the value of expr to variable x cond checks if the condition cond is true, blocks otherwise.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 12 / 65

slide-20
SLIDE 20

Statements

Σ is the set of statements occuring in the program. Only two kinds of statements: x := expr assigns the value of expr to variable x cond checks if the condition cond is true, blocks otherwise. Translation of if statement ℓ0: if (cond) ℓ1: ... else ℓ2: ... ℓ3: ℓ0 ℓ1 ℓ2 ℓ3 cond ¬ cond . . . . . .

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 12 / 65

slide-21
SLIDE 21

Statements

Σ is the set of statements occuring in the program. Only two kinds of statements: x := expr assigns the value of expr to variable x cond checks if the condition cond is true, blocks otherwise. Translation of while statement ℓ0: while (cond) ℓ1: ... ℓ2: ℓ0 ℓ1 ℓ2 cond . . . ¬ cond

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 12 / 65

slide-22
SLIDE 22

Statements

Σ is the set of statements occuring in the program. Only two kinds of statements: x := expr assigns the value of expr to variable x cond checks if the condition cond is true, blocks otherwise. Translation of assert statement ℓ0: assert(cond) ℓ1: ℓ0 ℓerr ℓ1 ¬ cond cond

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 12 / 65

slide-23
SLIDE 23

Statements

Σ is the set of statements occuring in the program. Only two kinds of statements: x := expr assigns the value of expr to variable x cond checks if the condition cond is true, blocks otherwise. Translation of assume statement ℓ0: assume(cond) ℓ1: ℓ0 ℓ1 cond

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 12 / 65

slide-24
SLIDE 24

Example – Program and Program Automaton

ℓ0: assume i > 0 ℓ1: p := 1 ℓ2: while (i > 0) { ℓ3: assert p == 1 ℓ4: if (i == 1) ℓ5: p := 0 ℓ6: i := i - 1 } ℓ7: assert p == 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 13 / 65

slide-25
SLIDE 25

Example – Program and Program Automaton

ℓ0: assume i > 0 ℓ1: p := 1 ℓ2: while (i > 0) { ℓ3: assert p == 1 ℓ4: if (i == 1) ℓ5: p := 0 ℓ6: i := i - 1 } ℓ7: assert p == 0 AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 13 / 65

slide-26
SLIDE 26

Example – Program and Program Automaton

Σ =

  • i > 0 , i <= 0 , i := i-1 ,

i == 1 , i != 1 , p := 1 , p != 0 , p != 1 , p := 0

  • AP :

ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 13 / 65

slide-27
SLIDE 27

Example – Program and Program Automaton

Σ =

  • i > 0 , i <= 0 , i := i-1 ,

i == 1 , i != 1 , p := 1 , p != 0 , p != 1 , p := 0

  • Trace

Word over the alphabet of statements. Example: π = i == 1 i := i-1 i == 1 AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 13 / 65

slide-28
SLIDE 28

Example – Program and Program Automaton

Σ =

  • i > 0 , i <= 0 , i := i-1 ,

i == 1 , i != 1 , p := 1 , p != 0 , p != 1 , p := 0

  • Error Trace

Word accepted by the program automaton. Example: π = i > 0 p := 1 i > 0 p != 1 AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 13 / 65

slide-29
SLIDE 29

Example – Program and Program Automaton

Σ =

  • i > 0 , i <= 0 , i := i-1 ,

i == 1 , i != 1 , p := 1 , p != 0 , p != 1 , p := 0

  • Error Trace

Word accepted by the program automaton. Example: π = i > 0 p := 1 i > 0 p != 1 Does π refute correctness of P ? AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 13 / 65

slide-30
SLIDE 30

Valuations

A valuation ν : Var → Value maps variables to some value domain. ν0 = i → 1 p → 0

  • Valuation are extended to expressions in a natural way.

ν0(i − 1) = ν0(i) − 1 = 0 The update of a valuation ν[x := c] is a copy of valuation ν that maps x to c. ν0[i := 0] = i → 0 p → 0

  • Jochen Hoenicke (Uni Freiburg)

Software Model Checking with Ultimate 3 Jul 2019 14 / 65

slide-31
SLIDE 31

Semantics of Statements

The meaning of the statements is given by a transition system. Valuations are the states of the transition system. Transitions are labelled with statements.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 15 / 65

slide-32
SLIDE 32

Semantics of Statements

The meaning of the statements is given by a transition system. Valuations are the states of the transition system. Transitions are labelled with statements. ν ν[x := ν(expr)]

x := expr

ν ν

cond

iff ν(cond) = true.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 15 / 65

slide-33
SLIDE 33

Semantics of Statements

The meaning of the statements is given by a transition system. Valuations are the states of the transition system. Transitions are labelled with statements. ν ν[x := ν(expr)]

x := expr

ν ν

cond

iff ν(cond) = true. Example: π = i > 0 p := 1 i > 0 p != 1 i → 1 p → 0 i → 1 p → 0 i → 1 p → 1 i → 1 p → 1 i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 15 / 65

slide-34
SLIDE 34

Transition System

The transition system is infinite and has infinitely many initial states. i → −1 p → 0 i → 0 p → 0 i → 1 p → 0 i → −1 p → 1 i → 0 p → 1 i → 1 p → 1

i := i-1 i := i-1 i := i-1 i := i-1 i := i-1 i := i-1 i := i-1 i := i-1 p := 1 p := 0 p := 0 p := 1 i != 1 i <= 0 p != 0 p := 1 i != 1 i <= 0 p != 0 p := 1 i == 1 i > 0 p != 0 p := 1 i != 1 i <= 0 p != 1 p := 0 i != 1 i <= 0 p != 1 p := 0 i == 1 i > 0 p != 1 p := 0

· · · · · ·

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 16 / 65

slide-35
SLIDE 35

Feasibility of Traces

Intuitively, there is no sequence of valuations for the trace: π = i > 0 p := 1 i > 0 p != 1 . How can we show this?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 17 / 65

slide-36
SLIDE 36

Feasibility of Traces

Intuitively, there is no sequence of valuations for the trace: π = i > 0 p := 1 i > 0 p != 1 . How can we show this?

SMT Solver!

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 17 / 65

slide-37
SLIDE 37

Feasibility of Traces

Intuitively, there is no sequence of valuations for the trace: π = i > 0 p := 1 i > 0 p != 1 . How can we show this?

SMT Solver!

SSA (Single Static Assignment): copy the variable each time it is assigned. i0 > 0 p1 := 1 i0 > 0 p1 != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 17 / 65

slide-38
SLIDE 38

Feasibility of Traces

Intuitively, there is no sequence of valuations for the trace: π = i > 0 p := 1 i > 0 p != 1 . How can we show this?

SMT Solver!

SSA (Single Static Assignment): copy the variable each time it is assigned. i0 > 0 p1 := 1 i0 > 0 p1 != 1 Replace := by logical equality and conjunct all statements. SSA(π) : i0 > 0 ∧ p1 = 1 ∧ i0 > 0 ∧ p1 = 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 17 / 65

slide-39
SLIDE 39

Feasibility of Traces

Intuitively, there is no sequence of valuations for the trace: π = i > 0 p := 1 i > 0 p != 1 . How can we show this?

SMT Solver!

SSA (Single Static Assignment): copy the variable each time it is assigned. i0 > 0 p1 := 1 i0 > 0 p1 != 1 Replace := by logical equality and conjunct all statements. SSA(π) : i0 > 0 ∧ p1 = 1 ∧ i0 > 0 ∧ p1 = 1 Ask SMT solver, if there is a solution for the formula: unsat

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 17 / 65

slide-40
SLIDE 40

Excursion: SMT Solvers

SMT solvers are programs that decide satisfiability. Ultimate uses z3, CVC4, mathsat and our own SMT solver SMTInterpol. Input a formula, for example: i0 > 0 ∧ p1 = 1 ∧ i1 = i0 − 1 ∧ i1 ≤ 0 Either sat (satisfiable) and optionally a model: i0 = 1, p1 = 1, i1 = 0

  • r unsat.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 18 / 65

slide-41
SLIDE 41

Demo: SMT Solvers

https://ultimate.informatik.uni-freiburg.de/smtinterpol/ (set-option :produce-models true) (set-logic QF_LIA) (declare-const i0 Int) (declare-const p0 Int) (declare-const i1 Int) (declare-const p1 Int) (assert (and (> i0 0) (= p1 1) (= i1 (- i0 1)) (<= i1 0))) (check-sat) (get-model)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 19 / 65

slide-42
SLIDE 42

Na¨ ıve Model Checking Algorithm

Build program automaton. Collect error traces. For each error trace ask SMT solver.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 20 / 65

slide-43
SLIDE 43

Na¨ ıve Model Checking Algorithm

Build program automaton. Collect error traces. For each error trace ask SMT solver. Problem: There are infinitely many error traces.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 20 / 65

slide-44
SLIDE 44

Example: Error Traces

AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Some error traces:

i > 0 p := 1 i > 0 p != 1 i > 0 p := 1 i > 0 i != 1 i := i-1 i > 0 p != 1 i > 0 p := 1 i > 0 i != 1 i := i-1 i > 0 i != 1 i := i-1 i > 0 p != 1

. . .

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 21 / 65

slide-45
SLIDE 45

Example: Error Traces

AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Some error traces:

i > 0 p := 1 i > 0 p != 1 i > 0 p := 1 i > 0 i != 1 i := i-1 i > 0 p != 1 i > 0 p := 1 i > 0 i != 1 i := i-1 i > 0 i != 1 i := i-1 i > 0 p != 1

. . . All infeasible for the same reason.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 21 / 65

slide-46
SLIDE 46

Trace Abstraction

AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Observation

Every trace . . . p := 1 . . . p != 1 . . . is infeasible, as long as there is no statement

p := 0 in the middle

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 22 / 65

slide-47
SLIDE 47

Trace Abstraction

AP : ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓerr

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 1 p != 0

Observation

Every trace . . . p := 1 . . . p != 1 . . . is infeasible, as long as there is no statement

p := 0 in the middle

Traces can be described by a finite automaton: A1 :

p := 1 p != 1

Σ Σ \ { p := 0 } Σ

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 22 / 65

slide-48
SLIDE 48

Subtracting Finite Automata from Each Other

There are algorithm to complement and intersect finite automata. AP ∩ A1 :

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 0 i > 0 i == 1 i != 1 p := 0 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 23 / 65

slide-49
SLIDE 49

Model Checking with Trace Abstraction

1 Build program automaton. 2 Pick an error traces. If none, program is safe. 3 Ask SMT solver. If sat, program is unsafe. 4 Generalize error trace to an automaton. 5 Subtract from program automaton. 6 Go to step 2. Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 24 / 65

slide-50
SLIDE 50

Set Theoretic View of Trace Abstraction

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 25 / 65

slide-51
SLIDE 51

Set Theoretic View of Trace Abstraction

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 . p := 1 . p != 0 i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 25 / 65

slide-52
SLIDE 52

Set Theoretic View of Trace Abstraction

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 . p := 1 . p != 0 i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 25 / 65

slide-53
SLIDE 53

Set Theoretic View of Trace Abstraction

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 . p := 1 . p != 0 i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 25 / 65

slide-54
SLIDE 54

Set Theoretic View of Trace Abstraction

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 . p := 1 . p != 0 i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 25 / 65

slide-55
SLIDE 55

Set Theoretic View of Trace Abstraction

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 . p := 1 . p != 0 i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 25 / 65

slide-56
SLIDE 56

Trace Abstraction

Definition (Trace Abstraction)

A trace abstraction is given by a tuple of automata (A1, . . . , An) such that each Ai recognizes a subset of infeasible traces, for i = 1, . . . , n. We say that the trace abstraction (A1, . . . , An) does not admit an error trace if AP ∩ A1 ∩ . . . ∩ An is empty.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 26 / 65

slide-57
SLIDE 57

Trace Abstraction

Definition (Trace Abstraction)

A trace abstraction is given by a tuple of automata (A1, . . . , An) such that each Ai recognizes a subset of infeasible traces, for i = 1, . . . , n. We say that the trace abstraction (A1, . . . , An) does not admit an error trace if AP ∩ A1 ∩ . . . ∩ An is empty.

Theorem (Soundness)

L(AP ∩ A1 ∩ . . . ∩ An) = ∅ ⇒ P is correct

Theorem (Completeness)

If P is correct, there is a trace abstraction (A1, . . . , An) such that L(AP ∩ A1 ∩ . . . ∩ An) = ∅

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 26 / 65

slide-58
SLIDE 58

How to Get a Trace Abstraction? Na¨ ıve Approach: Exclude infeasible error traces. . . . but there are infinitely many. Interpolant Based Approach: Generalize infeasible error traces. Exclude classes of infeasible traces.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 27 / 65

slide-59
SLIDE 59

How to Get a Trace Abstraction? Na¨ ıve Approach: Exclude infeasible error traces. . . . but there are infinitely many. Interpolant Based Approach: Generalize infeasible error traces. Exclude classes of infeasible traces.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 27 / 65

slide-60
SLIDE 60

Interpolants

Interpolants for Infeasible Traces

Let st1 ∧ · · · ∧ stn be an infeasible trace. There exists a sequence of predicates I0, . . . , In such that I0 = true Ii ∧ sti+1 ⇒ Ii+1 In = false In particular: st1 ∧ · · · ∧ sti ⇒ Ii ⇒ ¬(sti+1 ∧ · · · ∧ stn) Example: i0 > 0 p1 = 1 i0 > 0 p1 = 1 true true p1 = 1 p1 = 1 false

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 28 / 65

slide-61
SLIDE 61

Interpolants

Interpolants for Infeasible Traces

Let st1 ∧ · · · ∧ stn be an infeasible trace. There exists a sequence of predicates I0, . . . , In such that I0 = true Ii ∧ sti+1 ⇒ Ii+1 In = false In particular: st1 ∧ · · · ∧ sti ⇒ Ii ⇒ ¬(sti+1 ∧ · · · ∧ stn) Example: i0 > 0 p1 = 1 i0 > 0 p1 = 1 true true p1 = 1 p1 = 1 false Interpolants are intermediate assertions in a Hoare proof.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 28 / 65

slide-62
SLIDE 62

Interpolants as Hoare Proofs

i0 > 0 p1 = 1 i0 > 0 p1 = 1 true true p1 = 1 p1 = 1 false

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 29 / 65

slide-63
SLIDE 63

Interpolants as Hoare Proofs

i0 > 0 p1 = 1 i0 > 0 p1 = 1 true true p1 = 1 p1 = 1 false {true} i > 0 {true} {true} p := 1 {p = 1} {p = 1} i > 0 {p = 1} {p = 1} p != 1 {false} This proves that the trace is infeasible: {true} i > 0 p := 1 i > 0 p != 1 {false}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 29 / 65

slide-64
SLIDE 64

Demo: Computing Interpolants with SMTInterpol

(set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const i0 Int) (declare-const p0 Int) (declare-const i1 Int) (declare-const p1 Int) (assert (! (> i0 0) :name st1)) (assert (! (= p1 1) :name st2)) (assert (! (> i0 0) :name st3)) (assert (! (not (= p1 1)) :name st4)) (check-sat) (get-interpolants st1 st2 st3 st4)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 30 / 65

slide-65
SLIDE 65

Example – Use Interpolants to Generalize Infeasible Traces

p := 1 p != 1 i > 0 i > 0 true p = 1 false ℓ0 ℓ1 ℓerr

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 31 / 65

slide-66
SLIDE 66

Example – Use Interpolants to Generalize Infeasible Traces

p := 1 p != 1 i > 0 i > 0 i <= 0 true p = 1 false ℓ0 ℓ1 ℓerr {p = 1} i <= 0 {p = 1}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 31 / 65

slide-67
SLIDE 67

Example – Use Interpolants to Generalize Infeasible Traces

p := 1 p != 1 i > 0 i > 0 i <= 0 i := i-1 true p = 1 false ℓ0 ℓ1 ℓerr {p = 1} i <= 0 {p = 1} {p = 1} i := i-1 {p = 1}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 31 / 65

slide-68
SLIDE 68

Example – Use Interpolants to Generalize Infeasible Traces

p := 1 p != 1 i > 0 i > 0 i <= 0 i := i-1 p != 0 true p = 1 false ℓ0 ℓ1 ℓerr {p = 1} i <= 0 {p = 1} {p = 1} i := i-1 {p = 1} {p = 1} p != 0 {p = 1}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 31 / 65

slide-69
SLIDE 69

Example – Use Interpolants to Generalize Infeasible Traces

p := 1 p != 1 i > 0 i > 0 i <= 0 i := i-1 p != 0 p := 1 true p = 1 false ℓ0 ℓ1 ℓerr {p = 1} i <= 0 {p = 1} {p = 1} i := i-1 {p = 1} {p = 1} p != 0 {p = 1} {p = 1} p := 1 {p = 1}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 31 / 65

slide-70
SLIDE 70

Example – Use Interpolants to Generalize Infeasible Traces

p := 1 p != 1 Σ Σ i > 0 i <= 0 i := i-1 p != 0 p := 1 true p = 1 false ℓ0 ℓ1 ℓerr {p = 1} i <= 0 {p = 1} {p = 1} i := i-1 {p = 1} {p = 1} p != 0 {p = 1} {p = 1} p := 1 {p = 1}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 31 / 65

slide-71
SLIDE 71

Interpolant Automata

Given: Sequence of interpolants I = I0, I1, . . . , In

Definition (Interpolant Automaton AI)

AI = QI, δI, Qinit

I , Qfin I

QI = I (Ii, st, Ij) ∈ δI iff {Ii} st {Ij} holds q0 := true ∈ QI Qfin := {false} ⊆ QI

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 32 / 65

slide-72
SLIDE 72

Interpolant Automata

Given: Sequence of interpolants I = I0, I1, . . . , In

Definition (Interpolant Automaton AI)

AI = QI, δI, Qinit

I , Qfin I

QI = I (Ii, st, Ij) ∈ δI iff {Ii} st {Ij} holds q0 := true ∈ QI Qfin := {false} ⊆ QI

Theorem

An interpolant automaton AI recognizes a subset of infeasible traces. L(AI) ⊆ Infeasible

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 32 / 65

slide-73
SLIDE 73

Example – Refinement Using Interpolant Automata

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 p := 1 i > 0 p != 1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 33 / 65

slide-74
SLIDE 74

Example – Refinement Using Interpolant Automata

set of all traces Σ∗ traces respecting the control flow of P L(AP) Error Traces Feasible Traces i > 0 p := 1 i > 0 p != 1

A1

q0 q1 q2 p := 1 Σ Σ \ p := 0 Σ p != 1

L(A1)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 33 / 65

slide-75
SLIDE 75

Remaining Program Automaton

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 0 i > 0 i == 1 i != 1 p := 0 i := i-1 i <= 0 p != 1 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 34 / 65

slide-76
SLIDE 76

Demo: SMTInterpol

i > 0 p := 1 i > 0 i == 1 p := 0 i := i-1 i > 0 p != 1 (set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const i0 Int) (declare-const i1 Int) (declare-const p0 Int) (declare-const p1 Int) (declare-const p2 Int) (assert (! (...) :named st1)) ... (check-sat) (get-interpolants st1 st2 st3 ...)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 35 / 65

slide-77
SLIDE 77

Interpolant Automaton for Second Trace

i == 1 i := i-1 i > 0 i > 0 p := 1 p := 0 p != 1 true i ≤ 1 i ≤ 0 false

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 36 / 65

slide-78
SLIDE 78

Interpolant Automaton for Second Trace

i == 1 i := i-1 i > 0 i == 1 Σ Σ Σ Σ true i ≤ 1 i ≤ 0 false

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 36 / 65

slide-79
SLIDE 79

Remaining Program Automaton

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 0 i > 0 i == 1 i != 1 p := 0 p != 1 i := i-1 i <= 0 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 37 / 65

slide-80
SLIDE 80

Remaining Program Automaton

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 0 i := i-1 i <= 0 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 37 / 65

slide-81
SLIDE 81

Remaining Program Automaton

i > 0 p := 1 i > 0 i == 1 p := 0 i != 1 i := i-1 i <= 0 p != 0 i := i-1 i <= 0 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 37 / 65

slide-82
SLIDE 82

Demo: SMTInterpol

i > 0 p := 1 i > 0 i == 1 p := 0 i := i-1 i <= 0 p != 0 (set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const i0 Int) (declare-const i1 Int) (declare-const p0 Int) (declare-const p1 Int) (declare-const p2 Int) (assert (! (...) :named st1)) ... (check-sat) (get-interpolants st1 st2 st3 ...)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 38 / 65

slide-83
SLIDE 83

Demo: SMTInterpol

i > 0 p := 1 i > 0 i == 1 p := 0 i := i-1 i <= 0 p != 0 (set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const i0 Int) (declare-const i1 Int) (declare-const p0 Int) (declare-const p1 Int) (declare-const p2 Int) (assert (! (...) :named st1)) ... (check-sat) (get-interpolants st1 st2 st3 ...) ;;(true true true true (= p2 0) (= p2 0) (= p2 0))

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 38 / 65

slide-84
SLIDE 84

Remaining Program Automaton

i > 0 p := 1 i > 0 i != 1 i := i-1 i <= 0 p != 0 i == 1 p := 0 i := i-1 i <= 0 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 39 / 65

slide-85
SLIDE 85

Remaining Program Automaton

i > 0 p := 1 i > 0 i != 1 i := i-1 i <= 0 p != 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 39 / 65

slide-86
SLIDE 86

CEGAR for Trace Abstraction

annotated program P P is correct P is incorrect L(AP ∩ A1 ∩ . . . ∩ An) = ∅ ? π ∈ INFEASIBLE ? no return error trace π such that π ∈ L(AP ∩ A1 ∩ . . . ∩ An) yes return trace automaton An+1 such that π ∈ L(An+1) and L(An+1) ⊆ INFEASIBLE n := n + 1 yes no n := 0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 40 / 65

slide-87
SLIDE 87

Recursive Function

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 41 / 65

slide-88
SLIDE 88

Example: McCarthy 91 Function

int f91(int x) { if (x > 100) return x - 10; else return f91(f91(x + 11)); }

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 42 / 65

slide-89
SLIDE 89

Example: McCarthy 91 Function

int f91(int x) { if (x > 100) return x - 10; else return f91(f91(x + 11)); } int main(int x) { int res; if (x <= 101) { res = f91(x); //@assert(res == 91); } }

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 42 / 65

slide-90
SLIDE 90

McCarthy91 as Automaton

f(x) { ℓ3: if (x > 100) { ℓ4: res := x - 11 } else { ℓ5: x↑:= x + 10 ℓ6: call f ℓ7: x↑:= res ℓ8: call f } ℓ9: return res } main() { ℓ1: if (x↑ <= 101) { ℓ2: call f ℓ10: assert(res == 91) } } ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 ℓ10 ℓerr

x↑<=101 call f x>100 res:=x-10 x<=100 x↑:=x+11 x↑:=res res!=91 return

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 43 / 65

slide-91
SLIDE 91

McCarthy91 as Automaton

f(x) { ℓ3: if (x > 100) { ℓ4: res := x - 11 } else { ℓ5: x↑:= x + 10 ℓ6: call f ℓ7: x↑:= res ℓ8: call f } ℓ9: return res } main() { ℓ1: if (x↑ <= 101) { ℓ2: call f ℓ10: assert(res == 91) } } ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 ℓ10 ℓerr

x↑<=101 call f x>100 res:=x-10 x<=100 x↑:=x+11 x↑:=res res!=91 return ? call f call f return ? return ?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 43 / 65

slide-92
SLIDE 92

Reminder Push-down Automaton

A push-down automaton A = (Σ, Γ, Q, →, q0, F) consists of Σ: a finite alphabet Γ: a stack alphabet Q: a finite set of locations → ⊆ Q × Σ × Op × Q: a transition relation, where Op is a stack operation: ↓γ (push), ↑γ (pop), or none. q0 ∈ Q: the initial location F ⊆ Q: the accepting locations Example: a ↓x b ↑y b ↑x a ↓y b ↑y

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 44 / 65

slide-93
SLIDE 93

Reminder Push-down Automaton

A push-down automaton A = (Σ, Γ, Q, →, q0, F) consists of Σ: a finite alphabet Γ: a stack alphabet Q: a finite set of locations → ⊆ Q × Σ × Op × Q: a transition relation, where Op is a stack operation: ↓γ (push), ↑γ (pop), or none. q0 ∈ Q: the initial location F ⊆ Q: the accepting locations Example: a ↓x b ↑y b ↑x a ↓y b ↑y b, ↑x

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 44 / 65

slide-94
SLIDE 94

McCarthy as Push-down Automaton

f(x) { ℓ3: if (x > 100) { ℓ4: res := x - 11 } else { ℓ5: x↑:= x + 10 ℓ6: call f ℓ7: x↑:= res ℓ8: call f } ℓ9: return res } main() { ℓ1: if (x↑ <= 101) { ℓ2: call f ℓ10: assert(res == 91) } } ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 ℓ10 ℓerr

x↑<=101 call f ↓ℓ2 x>100 res:=x-10 x<=100 x↑:=x+11 x↑:=res res!=91 return ↑ℓ2 call f ↓ℓ6 call f ↓ℓ8 return ↑ℓ6 return ↑ℓ8

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 45 / 65

slide-95
SLIDE 95

Trace Abstraction with Push-down Automaton?

Problem

Push-down Automata can’t be subtracted/complemented/intersected.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 46 / 65

slide-96
SLIDE 96

Trace Abstraction with Push-down Automaton?

Problem

Push-down Automata can’t be subtracted/complemented/intersected. Solution: Alur & Madhusudan: Visibly Push-down Languages, 2004 Closed under complementation, intersection The symbol decides whether to push, pop, or do nothing Suitable for call/return statements.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 46 / 65

slide-97
SLIDE 97

Visibly Push-down Automaton

A visibly push-down automaton A = (Σi, Σc, ΣrΓ, Q, →, q0, F) consists of Σi, Σc, Σr: three distinct finite alphabet for internal, call, and return statements. Γ: a stack alphabet Q: a finite set of locations → ⊆   Q × Σi × Q ∪ Q × Σc× ↓ Γ × Q ∪ Q × Σr× ↑ Γ × Q  . Call statements always push a value, return statements always pop a value, and internal statements do not change stack. q0 ∈ Q: the initial location F ⊆ Q: the accepting locations

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 47 / 65

slide-98
SLIDE 98

Visibly Push-down Automaton

A visibly push-down automaton A = (Σi, Σc, ΣrΓ, Q, →, q0, F) consists of Σi, Σc, Σr: three distinct finite alphabet for internal, call, and return statements. Γ: a stack alphabet Q: a finite set of locations → ⊆   Q × Σi × Q ∪ Q × Σc× ↓ Γ × Q ∪ Q × Σr× ↑ Γ × Q  . Call statements always push a value, return statements always pop a value, and internal statements do not change stack. q0 ∈ Q: the initial location F ⊆ Q: the accepting locations

Remark

Nested word automata have equivalent power, differ only in details.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 47 / 65

slide-99
SLIDE 99

Error Traces

ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 ℓ10 ℓerr x↑<=101 call f ↓ℓ2 x>100 res:=x-10 x<=100 x↑:=x+11 x↑:=res res!=91 return ↑ℓ2 call f ↓ℓ6 call f ↓ℓ8 return ↑ℓ6 return ↑ℓ8

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 48 / 65

slide-100
SLIDE 100

Error Traces

ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 ℓ10 ℓerr x↑<=101 call f ↓ℓ2 x>100 res:=x-10 x<=100 x↑:=x+11 x↑:=res res!=91 return ↑ℓ2 call f ↓ℓ6 call f ↓ℓ8 return ↑ℓ6 return ↑ℓ8

Error Trace:

x↑<=101 call f x>100 res:=x-10 return res!=91

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 48 / 65

slide-101
SLIDE 101

SSA for Recursive Traces

Call statements copy parameters, e.g. call f − → x1 = x↑ Return statements do nothing. return − → true SSA numbering must obey scoping rules, e.g., x↑:=x call f(x) x:=x+1 res:=x return z:=x+res ↓ x↑

1 = x0 ∧ x1 = x↑ 1 ∧ x2 = x1 + 1 ∧ res1 = x2 ∧ z1 = x? + res?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 49 / 65

slide-102
SLIDE 102

SSA for Recursive Traces

Call statements copy parameters, e.g. call f − → x1 = x↑ Return statements do nothing. return − → true SSA numbering must obey scoping rules, e.g., x↑:=x call f(x) x:=x+1 res:=x return z:=x+res ↓ x↑

1 = x0 ∧ x1 = x↑ 1 ∧ x2 = x1 + 1 ∧ res1 = x2 ∧ z1 = x0 + res1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 49 / 65

slide-103
SLIDE 103

Error Trace to SSA

Error Trace: π = x↑<=101 call f x>100 res:=x-10 return res!=91 SSA: SSA(π) = x↑

0 ≤ 101 ∧ x1 = x↑ 0 ∧ x1 > 100 ∧ res1 = x1 − 10nn ∧ res1 = 91

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 50 / 65

slide-104
SLIDE 104

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

x↑:=3x call double res := x+x return res != 6x

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-105
SLIDE 105

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

x↑

1 = 3x0

x1 = x↑

1

res1 = x1 + x1 res1 = 6x0

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-106
SLIDE 106

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

x↑

1 = 3x0

x1 = x↑

1

res1 = x1 + x1 res1 = 6x0 true x↑

1 = 3x0

x1 = 3x0 res1 = 6x0 res1 = 6x0 false Problem: Interpolants use differently scoped variables

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-107
SLIDE 107

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

x↑

1 = 3x0

res1 = x1 + x1 res1 = 6x0 x1 = x↑

1

Problem: Interpolants use differently scoped variables Solution: Tree Interpolants

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-108
SLIDE 108

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

x↑

1 = 3x0

res1 = x1 + x1 res1 = 6x0 x1 = x↑

1

true x↑

1 = 3x0

x1 = x↑

1

res1 = 2x↑

1

res1 = 6x0 false Problem: Interpolants use differently scoped variables Solution: Tree Interpolants

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-109
SLIDE 109

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

x↑

1 = 3x0

res1 = x1 + x1 res1 = 6x0 x1 = x↑

1

true x↑

1 = 3x0

x1 = x↑

1

res1 = 2x↑

1

res1 = 6x0 false function summary Problem: Interpolants use differently scoped variables Solution: Tree Interpolants

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-110
SLIDE 110

Interpolation for Recursive Traces

int main(x) { assert double(3*x) == 6*x; } int double(x) { return x+x; }

true x↑ = 3x x = x↑ res = 2x↑ res = 6x false x↑:=3x call double ↑ x↑ = 3x res := x+x return ↓ x↑ = 3x res != 6x Problem: Interpolants use differently scoped variables Solution: Tree Interpolants

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 51 / 65

slide-111
SLIDE 111

Interpolant Automata

Given: Sequence of interpolants I = I0, I1, . . . , In

Definition (Interpolant Automaton AI)

AI = QI, δI, Qinit

I , Qfin I

QI = I (Ii, st, Ij) ∈ δI iff {Ii} st {Ij} holds (Ii, call f ↑ Ii, Ij) iff x↑ = x ⇒ Ij (Ii, return ↓ Ik, Ij) iff Ii ∧ Ik ⇒ Ij q0 := true ∈ QI Qfin := {false} ⊆ QI

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 52 / 65

slide-112
SLIDE 112

Interpolant Automata

Given: Sequence of interpolants I = I0, I1, . . . , In

Definition (Interpolant Automaton AI)

AI = QI, δI, Qinit

I , Qfin I

QI = I (Ii, st, Ij) ∈ δI iff {Ii} st {Ij} holds (Ii, call f ↑ Ii, Ij) iff x↑ = x ⇒ Ij (Ii, return ↓ Ik, Ij) iff Ii ∧ Ik ⇒ Ij q0 := true ∈ QI Qfin := {false} ⊆ QI

Theorem

An interpolant automaton AI recognizes a subset of infeasible traces. L(AI) ⊆ Infeasible

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 52 / 65

slide-113
SLIDE 113

Computing Tree Interpolants with SMTInterpol

x↑:=3x call double res := x+x return res != 6x (set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const x0 Int) (declare-const x1 Int) (declare-const x^1 Int) (declare-const res1 Int) (assert (! (= x^1 (* 3 x0)) :named st1)) (assert (! (= x1 x^1) :named st2)) (assert (! (= res1 (+ x1 x1)) :named st3)) (assert (! true :named st4)) (assert (! (not (= res1 (* 6 x0))) :named st5)) (check-sat) (set-option :print-terms-cse false) (get-interpolants st1 (st2 st3) st4 st5)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 53 / 65

slide-114
SLIDE 114

Running Example: McCarthy 91

π = x↑<=101 call f x<=100 x↑:=x+11 call f x>100 res:=x-10 return x↑:=res call f x>100 res:=x-10 return return tmp!=91

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 54 / 65

slide-115
SLIDE 115

Running Example: McCarthy 91

π = x↑<=101 call f x<=100 x↑:=x+11 call f x>100 res:=x-10 return x↑:=res call f x>100 res:=x-10 return return tmp!=91 SSA(π) = x↑

0 ≤ 101 ∧

x1 = x↑

0 ∧ x1 ≤ 100 ∧ x↑ 1 = x1 + 11 ∧

x2 = x↑

1 ∧ x2 > 100 ∧ res1 = x2 − 10 ∧ true ∧

x↑

2 = res1 ∧

x3 = x↑

2 ∧ x3 > 100 ∧ res2 = x3 − 10 ∧ true ∧

true ∧ res2 = 91

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 54 / 65

slide-116
SLIDE 116

Computing Interpolants

(set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const x0 Int) (declare-const x1 Int) (declare-const x2 Int) (declare-const x3 Int) (declare-const x^0 Int) ... (assert (! (...) :named st1)) ... (check-sat) (get-interpolants st1 (st2 ...) st12)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 55 / 65

slide-117
SLIDE 117

Computing Interpolants

(set-option :produce-interpolants true) (set-logic QF_LIA) (declare-const x0 Int) (declare-const x1 Int) (declare-const x2 Int) (declare-const x3 Int) (declare-const x^0 Int) ... (assert (! (...) :named st1)) ... (check-sat) (get-interpolants st1 (st2 ...) st12) ;;(true true (<= x1 100) (<= x^1 111) (<= x2 x^1) (<= x2 x^1) ;;(<= res1 (- x^1 10)) (<= x^2 101) (<= x3 x^2) (<= 101 x3 x^2)) ;;(or (<= 91 res2 (- x^2 10)) (= res2 91)) (= res2 91))

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 55 / 65

slide-118
SLIDE 118

Interpolant Automaton

true x ≤ 100 x↑ ≤ 111 x ≤ x↑ res ≤ x↑ − 10 res ≤ 101 x↑ ≤ 101 101 ≤ x ≤ x↑ 91 ≤ res ≤ x↑ − 10 res = 91 false

x↑<=101 call f ↑ true x<=100 x↑:=x+11 call f ↑ x↑ ≤ 111 x↑:=res call f ↑ x↑ ≤ 101 return ↑ x↑ ≤ 101 res!=91 return ↑ true x>100 res:=x-10 return ↓ x↑ ≤ 111 x>100 res:=x-10

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 56 / 65

slide-119
SLIDE 119

Interpolant Automaton

true x ≤ 100 x↑ ≤ 111 x ≤ x↑ res ≤ 101 x↑ ≤ 101 101 ≤ x ≤ x↑ 91 ≤ res ≤ x↑ − 10 res = 91 false

x↑<=101 call f ↑ true x<=100 x↑:=x+11 call f ↑ x↑ ≤ 111 x↑:=res call f ↑ x↑ ≤ 101 return ↑ x↑ ≤ 101 res!=91 return ↑ true x>100 return ↑ x↑ ≤ 111 res:=x-10

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 56 / 65

slide-120
SLIDE 120

Interpolant Automaton

true x ≤ 100 x↑ ≤ 111 x ≤ x↑ res ≤ 101 x↑ ≤ 101 101 ≤ x ≤ x↑ 91 ≤ res ≤ x↑ − 10 res = 91 false

x↑<=101 call f ↑ true x<=100 x↑:=x+11 call f ↑ x↑ ≤ 111 x↑:=res call f ↑ x↑ ≤ 101 return ↑ x↑ ≤ 101 res!=91 x>100 return ↑ x↑ ≤ 111 res:=x-10 x<=100 return ↑ true return ↑ x ≤ 111 return ↑ x ≤ 101 x↑:=res

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 56 / 65

slide-121
SLIDE 121

Subtracting from Program Automaton

ℓ1 ℓ2 ℓ3 ℓ4 ℓ5 ℓ6 ℓ7 ℓ8 ℓ9 ℓ10 ℓerr x↑<=101 call f ↓ℓ2 x>100 res:=x-10 return ↑ ℓ2 res!=91 x<=100 x↑:=x+11 x↑:=res call f ↓ℓ6 call f ↓ℓ8 return ↑ ℓ6 return ↑ ℓ8

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 57 / 65

slide-122
SLIDE 122

Subtracting from Program Automaton

ℓ1 ℓ2 ℓ3 ℓ4 ℓ9 ℓ10 ℓerr x↑<=101 call f ↓ℓ2 x>100 res:=x-10 return ↑ ℓ2 res!=91

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 57 / 65

slide-123
SLIDE 123

Termination

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 58 / 65

slide-124
SLIDE 124

Example: Termination Problem

void main() { while (x > 0 && y > 0) { if (*) { x := x - 1; } else { x := *; y := y - 1; } } } Does this program terminate?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 59 / 65

slide-125
SLIDE 125

Example: Termination Problem

void main() { while (x > 0 && y > 0) { if (*) { x := x - 1; } else { x := *; y := y - 1; } } } Does this program terminate? How can we prove it?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 59 / 65

slide-126
SLIDE 126

Program B¨ uchi Automata

void main() { while (x > 0 && y > 0) { if (*) { x := x - 1; } else { x := *; y := y - 1; } } } ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 x>0 && y>0 x:=x-1 x:=* y:=y-1 A B¨ uchi automaton accepts infinite words that infinitely

  • ften visit accepting states.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 60 / 65

slide-127
SLIDE 127

B¨ uchi Automata

A1: ℓ0 ℓ1 a b b a

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 61 / 65

slide-128
SLIDE 128

B¨ uchi Automata

A1: ℓ0 ℓ1 a b b a L(A1) = {(a + b)ω | infinitely many a}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 61 / 65

slide-129
SLIDE 129

B¨ uchi Automata

A1: ℓ0 ℓ1 a b b a L(A1) = {(a + b)ω | infinitely many a} A2: ℓ0 ℓ1 b a, b b L(A2) = {(a + b)ω | finitely many a}

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 61 / 65

slide-130
SLIDE 130

Traces and Lassos

ℓ0 ℓ1 a, b b b How to represent infinite words?

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 62 / 65

slide-131
SLIDE 131

Traces and Lassos

ℓ0 ℓ1 a, b b b How to represent infinite words?

Fact

Every non-empty B¨ uchi-Automaton accepts an ultimately periodic word.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 62 / 65

slide-132
SLIDE 132

Traces and Lassos

ℓ0 ℓ1 a, b b b How to represent infinite words?

Fact

Every non-empty B¨ uchi-Automaton accepts an ultimately periodic word. b(b)ω ∈ L(A2)

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 62 / 65

slide-133
SLIDE 133

Program B¨ uchi Automata

ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 x>0 && y>0 x:=x-1 x:=* y:=y-1 Error Trace: x>0 && y>0 ( x:=* y:=y-1 x>0 && y>0 )ω

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 63 / 65

slide-134
SLIDE 134

Program B¨ uchi Automata

ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 x>0 && y>0 x:=x-1 x:=* y:=y-1 Error Trace: x>0 && y>0 ( x:=* y:=y-1 x>0 && y>0 )ω Infeasible: Ranking function y.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 63 / 65

slide-135
SLIDE 135

Program B¨ uchi Automata

ℓ0 ℓ1 ℓ2 ℓ3 ℓ4 x>0 && y>0 x:=x-1 x:=* y:=y-1 Error Trace: x>0 && y>0 ( x:=* y:=y-1 x>0 && y>0 )ω Infeasible: Ranking function y. Generalization:

y:=y-1 x>0 && y>0

Σ

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 63 / 65

slide-136
SLIDE 136

Remaining Program B¨ uchi Automata

∃ algorithms for intersection/complementation of B¨ uchi Automata! x>0 && y>0 x:=x-1 x:=* y:=y-1

x>0 && y>0

x:=x-1

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 64 / 65

slide-137
SLIDE 137

Remaining Program B¨ uchi Automata

∃ algorithms for intersection/complementation of B¨ uchi Automata! x>0 && y>0 x:=x-1 x:=* y:=y-1

x>0 && y>0

x:=x-1 Error Trace: x>0 && y>0 x:=x-1

  • x>0 && y>0 x:=x-1

ω

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 64 / 65

slide-138
SLIDE 138

Remaining Program B¨ uchi Automata

∃ algorithms for intersection/complementation of B¨ uchi Automata! x>0 && y>0 x:=x-1 x:=* y:=y-1

x>0 && y>0

x:=x-1 Error Trace: x>0 && y>0 x:=x-1

  • x>0 && y>0 x:=x-1

ω Infeasible: Ranking function x.

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 64 / 65

slide-139
SLIDE 139

Remaining Program B¨ uchi Automata

∃ algorithms for intersection/complementation of B¨ uchi Automata! x>0 && y>0 x:=x-1 x:=* y:=y-1

x>0 && y>0

x:=x-1 Error Trace: x>0 && y>0 x:=x-1

  • x>0 && y>0 x:=x-1

ω Infeasible: Ranking function x. Generalization:

x:=x-1 x>0 && y>0 x:=x-1

Σ

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 64 / 65

slide-140
SLIDE 140

How to find Ranking Functions?

We have a tool Ultimate Rankfinder. General pattern rank := c1x1 + · · · + cnxn where x1, . . . , xn are the variables, c1 . . . cn ∈ Z. For a lasso stem(loop)ω, encode an SMT problem: ∀x1 . . . xn, x′

1, . . . , x′ n.loop ⇒ rank ≥ 0 ∧ rank′ ≤ rank − 1

Quantifiers can be eliminated with Farkas’ Lemma. Ask SMT solver for solution for c1, . . . , cn (non-linear arithmetic required).

Jochen Hoenicke (Uni Freiburg) Software Model Checking with Ultimate 3 Jul 2019 65 / 65