more on verification and model checking · 2015. 10. 7. · software model checking bounded model...

59
1/60 More on Verification and Model Checking Wednesday Oct 07, 2015 Philipp Rümmer Uppsala University [email protected]

Upload: others

Post on 03-Mar-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

1/60

More onVerification and Model Checking

Wednesday Oct 07, 2015

Philipp RümmerUppsala University

[email protected]

Page 2: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

2/60

Course fair!

Page 3: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

3/60

Exam

● October 21st, 8:00 – 13:00● If you want to participate, register

now!

● (You also need to bringID card/passport to the exam)

Page 4: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

4/60

Outline

● Timed automata vs. software

● Four general model checking approaches

● Explicit-state● Symbolic● Bounded● Abstraction-based

Page 5: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

6/60

Verification also here?

Page 6: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

7/60

Software model checking

● Bounded model checking (BMC)● Geared towards bug finding● Tools like: CBMC, LLBMC, …

● Full model checking● Primarily used to show absence of bugs● Tools like: Spin, Blast, CPAChecker,

SatAbs, Eldarica, SeaHorn, …● Similar techniques as in Uppaal

● Annual competition: SV-COMP

Page 7: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

8/60

Some examples

Page 8: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

9/60

Definition of properties

● assert● Check whether condition holds;

otherwise, stop program execution with an error

● Comparable to a post-condition

● assume● Checks whether condition holds;

otherwise, suspend further program execution

● Comparable to a pre-condition

Page 9: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

10/60

Web interfaces

● CBMChttp://logicrunch.it.uu.se:4096/~wv/cbmc/

● Eldaricahttp://logicrunch.it.uu.se:4096/~wv/eldarica/

Page 10: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

11/60

Analysis ofTimed Automata vs. Code

● Representing one using the other?

Page 11: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

12/60

Control-flow graphs (CFGs)int mult(int a, int b){  int z = 0;  while ( a != 0) {    if ( a % 2 != 0) {      z = z+b;    }    a = a /2;    b = b *2;  }  return z;}

Graphical representation of code:

● Nodes are control-flow locations + statements

● Edges denote transitions + guards

Page 12: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

13/60

As automaton

● Represent every node as an automaton state

● Statements are turned into updates

Page 13: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

14/60

Automata as code?

void main() { int i = 0;

wait : goto increase;

increase : if (i < 5) { i = i + 1; goto wait; } else { goto done; }

done : ;}

Page 14: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

15/60

Additional aspects● Communication/synchronisation● Atomicity

● Guards + updates are atomic

● Time● Non-determinism

● Sometimes, multipletransitions might be possible

● Guards/partiality● For analysis, considered

as assume

Ingeneral,notexecutable

Page 15: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

16/60

Additional features of software

● Structure● Functions, classes, modules

● Datatypes/structures● Pointers, heap, arrays

● Large state space● (But normally no time)

Page 16: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

17/60

Global view:Transition systems (TS)

● Tuple● State space● Initial states● State transitions

● Notion capturing various types of systems

● Related concept: Kripke structures

Page 17: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

18/60

Example

Page 18: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

19/60

Finite automaton as TS

● Simply leave out labels to obtain TS

Page 19: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

20/60

Automaton with time/data

Page 20: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

21/60

Software program as TS

Page 21: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

22/60

Safety of transition system

● Identify set of error states● System is safe if there is no

pathwith and

● Safety = (un)reachability in graph

“Is any error state reachable from an initial state?”

Page 22: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

23/60

Example

Page 23: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

24/60

The “state space explosion” problem

● The size of set grows very rapidly● Exponentially in number of variables● Exponentially in number of

threads/processes

● Sometimes, is even considered infinite (e.g., time is unbounded)

● Checking reachability can be challenging (or undecidable)

Page 24: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

25/60

Method 1:Explicit-state model checking

● Explicitly construct graph● Check reachability of error states

● Example tool: Spin, Java Path Finder

● Problem: complexity linear in size of TS, only works for very small TS (millions/billions of states)

Page 25: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

26/60

Side note: CTL properties

● Reachability covers the casesA[], E<>

● How can we check A<>, E[]?(for finite TS)

● For E[] p:● Search for cycles on which p holds in

every state● Determine states from which such cycle

are reachable, only following p states

Page 26: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

27/60

Method 2:Symbolic model checking

● Represent graphsymbolically; normally usingBinary Decision Diagrams (BDDs)

● Check reachability of error states by fixed-point computation

● Example tool: SMV

Page 27: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

28/60

Binary Decision Diagrams

● Data structure to represent Boolean functions

● Often concise in memory● Canonical representation● Boolean operations on BDDs (&&, ||,

etc) can be executed efficiently(usually in polynomial time)

Page 28: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

29/60

Binary Decision Diagrams (2)

Page 29: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

30/60

Binary Decision Diagrams (3)

● Sets can be represented by their characteristic function

● If elements of are encoded as sequences of , then is a Boolean function, can be represented as BDD

Page 30: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

31/60

Binary Decision Diagrams (4)

● For transition systems● Represent using vector of Boolean

variables● can then be represented using

BDDs

● Safety + CTL properties can be checked by fixed-point computation

Page 31: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

32/60

Method 2:Symbolic model checking

● Big success in the 90s:Suddenly able to analyse real hardware implementations (processors, memory, etc.)

● J.R. Burch, E.M. Clarke, K.L. McMillan. D.L. Dill, L.J. Hwang:Symbolic model checking: 10^20 states and beyond.

Page 32: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

33/60

Method 2:Symbolic model checking

● 10^20 states is still way too few …● E.g., software program with ten 32bit

integer variables has states

Page 33: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

34/60

Method 3:Bounded model checking

● Idea: search for bugs in programs/systems up to some depth; but otherwise reason fully precisely

● Tailored to showing reachability, not so much unreachability

● Today, one of the most successful techniques for hardware analysis

BMC ProblemDecide whether an error can be reached within the firstk execution steps of a program/system.

Page 34: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

35/60

Page 35: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

36/60

Monolithic BMC

● Transition system● Finite state space● Initial states● Transition relation

→ E.g., repres. by vectors of Booleans

● Errors

Page 36: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

37/60

Monolithic BMC (2)

● If the formula can be solved, then represent a path visiting an error state

● Various solvers can be applied:● Linear/mixed integer programming● SAT/SMT solving● Convex optimisation

Page 37: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

38/60

Monolithic BMC (3)

● Mainly works well for hardware● For software, formula contains a lot of

redundancy● Better to unwind program guided by

control structure

● Example tool: CBMC

Page 38: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

39/60

BMC: straight-line programs

int x, y;

x = x * x;y = x + 1;

assert(y > 0);

(set-option :pp.bv-literals false)

(declare-const x0 (_ BitVec 32))(declare-const y0 (_ BitVec 32))

(declare-const x1 (_ BitVec 32))(declare-const y1 (_ BitVec 32))

(assert (= x1 (bvmul x0 x0)))(assert (= y1 (bvadd x1 (_ bv1 32))))

(assert (not (bvsgt y1 (_ bv0 32))))

(check-sat)(get-model)

Signed comparison

E.g., check using theconstraint solver Z3:

Page 39: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

40/60

BMC: conditional branching

int x, y;

if (x > 0) y = x;else y = -x;

assert(y >= 0);

(set-option :pp.bv-literals false)

(declare-const x0 (_ BitVec 32))(declare-const y0 (_ BitVec 32))(declare-const y1a (_ BitVec 32))(declare-const y1b (_ BitVec 32))(declare-const y2 (_ BitVec 32))(declare-const b Bool)

(assert (= b (bvsgt x0 (_ bv0 32))))(assert (=> b (= y1a x0)))(assert (=> (not b) (= y1b (bvneg x0))))(assert (= y2 (ite b y1a y1b)))

(assert (not (bvsge y2 (_ bv0 32))))

(check-sat)(get-model)

Page 40: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

41/60

Further features

● Data-structures, heap, pointers● Can be represented using scalar

variables, since only finitely many variables/heap locations can be used in k execution steps

● Concurrency● Systematically explore all possible

interleavings of threads

● Also applicable to timed automata, and other kinds of systems

Page 41: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

42/60

Method 4:Abstraction-based MC

● Idea: instead of analysing full model/code, compute and analyse a small abstraction of it

● Refine if the abstraction is too coarse● In particular successful for software

● Example tools: CPAChecker, SatAbs, SLAM, Eldarica, SeaHorn

Page 42: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

43/60

Example

→ Abstraction has introduced a spurious counterexample

Page 43: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

44/60

Example

→ In this abstraction no error states are reachable!

Page 44: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

45/60

Existential abstraction

A transition systemis an existential abstraction ofwith respect to if

1.2.

( is a homomorphism)

Page 45: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

46/60

Safety through abstraction

If is an existential abstraction of with respect to and in none of the statesis reachable, then is safew.r.t.

(The same does not hold for all CTL properties; but other forms of abstraction exist ...)

Page 46: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

47/60

Abstraction refinement

Page 47: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

48/60

Predicate abstraction● In software, abstraction is usually

defined through a set of predicates

Page 48: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

49/60

“CEGAR”Counterexample-guided abstraction refinement

Page 49: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

50/60

CEGAR (2)

● In each refinement step, one (or multiple) abstract states are split

● The procedure never gives a wrong answer; but might not terminate for infinite-state systems

● Termination guaranteed for finite-state systems

Page 50: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

51/60

Abstraction-based MC

● In many cases, abstraction-based model checking can also analyse infinite-state systems

● Programs with unbounded heap● Infinite datatypes (e.g., true integers)● Unbounded/infinite number of threads

Page 51: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

52/60

What is Uppaal using?

● For automata locations, data variables:Explicit-state model checking

● For time and clocks:Abstraction-based model checking(“regions” and “zones”)

Page 52: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

53/60

Case study: Fischer protocol

● Simple mutual exclusion protocol; only needs one shared variable lock

● Assumptions:● Time bound A known after which writes

to shared variable are visible to all threads

● Every process has an id (> 0), and a timer

● Popular model checking benchmark

Page 53: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

54/60

Fischer protocol as code

loop wait until lock = 0; set lock to process id; // visible after <=A units wait for a delay >= B > A; if lock = process id enter critical sectionend

Every thread executes the following code:

Page 54: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

55/60

Case study: Fischer protocol (2)

Safety property: no two processescan be in cs at the same time

Page 55: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

56/60

Verifiable with any number of processes?

Page 56: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

57/60

Fischer as parameterised system

● Infinite family of transition systems● One instance per number of threads

● Some model checkers can verify correctness for all instances at once

● E.g., Eldarica● Idea: analyse system assuming

infinitely many threads using abstraction; this subsumes all cases with finitely many threads

Page 57: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

58/60

In C/Eldarica syntax

int lock = 0;

thread[tid] Proc { clock C; assume(tid > 0);

while (1) { atomic { assume(lock == 0); C = 0; } within (C <= 1) lock = tid; // within = time inv.

C = 0; // delay >1 time unit assume(C > 1); if (lock == tid) { // critical section assert(lock == tid); lock = 0; } }}

Page 58: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

59/60

Conclusions

● Four model checking approaches● Explicit-state● Symbolic● Bounded● Abstraction-based

Page 59: More on Verification and Model Checking · 2015. 10. 7. · Software model checking Bounded model checking (BMC) Geared towards bug finding Tools like: CBMC, LLBMC, … Full model

60/60

Further reading

● Orna Grumberg: Model Checking: From BDDs to Interpolationwww.cs.technion.ac.il/users/orna/markt-2011.pdf

● Daniel Kroening: Predicate Abstraction, A Tutorialfm.csl.sri.com/SSFT12/predabs-SSFT12.pdf