67
Model Checking Clark Barrett Stanford University Model Checking – p. 1/45

Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Model Checking

Clark Barrett

Stanford University

Model Checking – p. 1/45

Page 2: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

What is Formal Verification?

1. Modeling: Create a mathematical model of the system

• An inaccurate model can introduce false bugs or maskreal bugs

• For many systems, this step can be done automatically

2. Specification: The properties which the system shouldsatisfy must be stated in a formal language

• Challenge: translate informal into formal specifications

• Challenge: requires manual effort and expertise

3. Proof: Prove that the model satisfies the specification• Better than testing: covers all cases• ...when it succeeds:• Challenge: Can the proof be automated? Does it

scale?

Model Checking – p. 2/45

Page 3: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Modeling

Let us consider again the circuit example we saw before.

Model Checking – p. 3/45

Page 4: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

��������

��

����

����

=

+1

+2

1

0

1

0

1

0

test

x

y

z

a

a

a

Model Checking – p. 4/45

Page 5: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Modeling

How do we model this circuit as a mathematical object?

Model Checking – p. 5/45

Page 6: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Modeling

One formal model for systems is a Kripke structure, which is aspecific kind of transition system.

Let a∗ be a set of atomic propositions. In this context, anatomic proposition is anything that describes a property whichmay be true about the system being modeled (depending onwhat state the system is in). For our purposes, we willconsider a∗ to be a set of propositional symbols.

Model Checking – p. 6/45

Page 7: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Modeling

A Kripke structure M over a∗ is a four-tuple M = (S, S0, R, L)where

1. S is a finite set of states.

2. S0 ⊆ S is the set of initial states.

3. R ⊆ S × S is a transition relation that must be total (thatis, for every state s ∈ S, there is a state s′ ∈ S such thatR(s, s′)).

4. L : S → P(a∗) is a labeling function that labels each statewith the set of atomic propositions true in that state.

A path in the structure M from a state s is an infinitesequence of states π = s0s1s2 such that s0 = s and R(si, si+1)holds for all i ≥ 0.

Model Checking – p. 7/45

Page 8: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

State Graphs and Computation Trees

A state transition graph for a structure M = (S, S0, R, L) has avertex for each state in S. If s, t ∈ S, then there is a directededge from the vertex for s to the vertex for t iff R(s, t).

The image Image (X) of a set X ⊆ S is the set

{y | ∃x ∈ X. R(x, y)}. For a single state x, Image (x) denotes

{y | R(x, y)}.

A computation tree from a state s is an infinite tree in whicheach vertex is labeled by a state of M . The tree is built asfollows.

• The root of the tree is labeled by the state s.

• For each vertex v in the tree, if v is labeled by t, then therefor each t′ ∈ Image (t), there is a child of t labeled by t′.

Model Checking – p. 8/45

Page 9: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Example

Consider a Kripke structure M = (S, S0, R, L) over a∗ where

• a∗ = {A,B,C}, S = {r, g, b}, S0 = {r}

• R = {(r, b), (r, g), (g, g), (b, r), (b, g)}

• L(r) = {A,B}, L(g) = {C}, L(b) = {B,C}

The state transition graph and computation tree from r areshown below.

A B

B C C

A B

B C C

CCA B

Model Checking – p. 9/45

Page 10: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

SAT encoding of Kripke structures

A Kripke structure contains a finite set S of states, a set S0 ofinitial states, and a transition relation R.

Since S is finite, we can find an m such that 2m ≥ |Q|. We can

then use m variables: x = [x1, . . . , xm] to represent the states.These are called state variables.

To represent R, we need m additional variables,y = [y1, . . . , ym], which we call next-state variables.

We can write formulas FS0(x) and FR(y) such that the

solutions of FS0(x) correspond to initial states in S0 and the

solutions of FR(x,y) correspond to valid transitions in R.

Model Checking – p. 10/45

Page 11: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Proof by Induction

Induction can be used to show that a property P holds for allstates:

• Base case: FS0(x0) → FSP

(x0)

• Induction case: (FSP(x) ∧ FR(x,y)) → FSP

(y)

k-induction is a more general version that often works better:

• Base case: (FS0(x0) ∧ FR(x0,x1) ∧ · · · ∧ FR(xk−1,xk)) →

(FSP(x0) ∧ FSP

(x1) ∧ · · · ∧ FSP(xk))

• Induction case:(FSP

(x0) ∧ FR(x0,x1) ∧ · · · ∧ FSP(xk) ∧ FR(xk,xk+1)) →

FSP(xk+1)

Model Checking – p. 11/45

Page 12: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

��������

��

����

����

=

+1

+2

1

0

1

0

1

0

test

x

y

z

a

a

a

Model Checking – p. 12/45

Page 13: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Assume every register is 1-bit.

What is the property?

Model Checking – p. 13/45

Page 14: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Assume every register is 1-bit.

What is the property?FSP

(x, y, z) = (z ↔ ¬y) ∧ (y ↔ ¬x)

Model Checking – p. 13/45

Page 15: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Assume every register is 1-bit.

What is the property?FSP

(x, y, z) = (z ↔ ¬y) ∧ (y ↔ ¬x)

What is the base case?

Model Checking – p. 13/45

Page 16: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Assume every register is 1-bit.

What is the property?FSP

(x, y, z) = (z ↔ ¬y) ∧ (y ↔ ¬x)

What is the base case?FS0

(x, y, z) → FSP(x, y, z) =

((x ↔ x0) ∧ (y ↔ y0) ∧ (z ↔ z0)) → ((z ↔ ¬y) ∧ (y ↔ ¬x))

Model Checking – p. 13/45

Page 17: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Assume every register is 1-bit.

What is the property?FSP

(x, y, z) = (z ↔ ¬y) ∧ (y ↔ ¬x)

What is the base case?FS0

(x, y, z) → FSP(x, y, z) =

((x ↔ x0) ∧ (y ↔ y0) ∧ (z ↔ z0)) → ((z ↔ ¬y) ∧ (y ↔ ¬x))

What is the transition relation?

Model Checking – p. 13/45

Page 18: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Assume every register is 1-bit.

What is the property?FSP

(x, y, z) = (z ↔ ¬y) ∧ (y ↔ ¬x)

What is the base case?FS0

(x, y, z) → FSP(x, y, z) =

((x ↔ x0) ∧ (y ↔ y0) ∧ (z ↔ z0)) → ((z ↔ ¬y) ∧ (y ↔ ¬x))

What is the transition relation?FR(x, y, z, x

′, y′, z′) =((z′ ↔ z)∧(y′ ↔ y)∧(x′ ↔ x))∨((x′ ↔ y)∧(y′ ↔ z)∧(z′ ↔ y))

Model Checking – p. 13/45

Page 19: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

SMT solvers: Motivation

SAT solvers are automatic and efficient.

As a result, they are frequently used as the “engine” behindverification applications.

However, systems are usually designed and modeled at ahigher level than the Boolean level and the translation toBoolean logic can be expensive and confusing.

A primary goal of research in Satisfiability Modulo Theories(SMT) [BT18] is to create verification engines that can reasonnatively at a higher level of abstraction, while still retaining thespeed and automation of today’s Boolean engines.

Model Checking – p. 14/45

Page 20: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Modeling

The language of SMT allows us to model at a higher level ofabstraction.

Consider again the circuit example.

Model Checking – p. 15/45

Page 21: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Running Example

��������

��

����

����

=

+1

+2

1

0

1

0

1

0

test

x

y

z

a

a

a

Model Checking – p. 16/45

Page 22: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Suppose now that every register is modeled as an integerand we are allowed to use arithmetic operators and equality.

What is the property?

Model Checking – p. 17/45

Page 23: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Suppose now that every register is modeled as an integerand we are allowed to use arithmetic operators and equality.

What is the property?FSP

(x, y, z) = (z = y + 1) ∧ (y = x+ 1)

Model Checking – p. 17/45

Page 24: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Suppose now that every register is modeled as an integerand we are allowed to use arithmetic operators and equality.

What is the property?FSP

(x, y, z) = (z = y + 1) ∧ (y = x+ 1)

What is the base case?

Model Checking – p. 17/45

Page 25: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Suppose now that every register is modeled as an integerand we are allowed to use arithmetic operators and equality.

What is the property?FSP

(x, y, z) = (z = y + 1) ∧ (y = x+ 1)

What is the base case?FS0

(x, y, z) → FSP(x, y, z) =

((x = x0) ∧ (y = y0) ∧ (z = z0)) → ((z = y + 1) ∧ (y = x+ 1))

Model Checking – p. 17/45

Page 26: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Suppose now that every register is modeled as an integerand we are allowed to use arithmetic operators and equality.

What is the property?FSP

(x, y, z) = (z = y + 1) ∧ (y = x+ 1)

What is the base case?FS0

(x, y, z) → FSP(x, y, z) =

((x = x0) ∧ (y = y0) ∧ (z = z0)) → ((z = y + 1) ∧ (y = x+ 1))

What is the transition relation?

Model Checking – p. 17/45

Page 27: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Circuit Example

Suppose now that every register is modeled as an integerand we are allowed to use arithmetic operators and equality.

What is the property?FSP

(x, y, z) = (z = y + 1) ∧ (y = x+ 1)

What is the base case?FS0

(x, y, z) → FSP(x, y, z) =

((x = x0) ∧ (y = y0) ∧ (z = z0)) → ((z = y + 1) ∧ (y = x+ 1))

What is the transition relation?FR(x, y, z, x

′, y′, z′) =((z′ = z)∧(y′ = y)∧(x′ = x))∨((x′ = y)∧(y′ = z)∧(z′ = y+2))

Model Checking – p. 17/45

Page 28: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Modeling

Notice that at this level of abstraction, we can prove theformula is true for arbitrary integers, eliminating the need toconsider the size of the registers

Alternatively, if we are concerned about overflow, we can usethe theory of bitvectors, which still has the advantage that thesize of the formula does not increase with increasingbit-width.

Model Checking – p. 18/45

Page 29: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Model Checking

Model Checking is a verification technique whichautomatically checks whether a model satisfies a givenproperty [CGP02].

This is done by enumerating (either explicitly or symbolically)a set of states of the model, and checking that each statesatisfies the property.

Model Checking – p. 19/45

Page 30: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Specifying Properties

Typically, properties of the model are specified using the logicCTL∗ . CTL stands for Computation Tree Logic since itssemantics are best understood in terms of computation trees.

There are two types of formulas in CTL∗ : state formulas andpath formulas. Let a∗ be a set of atomic propositions. Thesyntax of CTL∗ formulas is given by the following rules:

Model Checking – p. 20/45

Page 31: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Syntax of CTL∗

• If p ∈ a∗, then p is a state formula.

• If f and g are state formulas, then ¬f , f ∨ g, and f ∧ g arestate formulas.

• If f is a state formula, then f is also a path formula.

• If f and g are path formulas, then ¬f , f ∨ g, f ∧ g, Xf , Ff ,Gf , f Ug, and f Rg are path formulas.

• If f is a path formula, then Ef and Af are state formulas.

Notice that CTL∗ includes propositional logic, but there arealso seven new operators: X , F , G , U , R , A , and E .

Model Checking – p. 21/45

Page 32: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Semantics of CTL∗

State formulas describe properties associated with a singlestate. For example, any propositional formula over thepropositional symbols in a∗ is a state formula.

We write M, s |= f to mean that a state formula f is true instate s of the Kripke structure M .

Model Checking – p. 22/45

Page 33: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Semantics of CTL∗

For the initial state of our example, A ∧ B and ¬A → C aretrue state formulas, but A → C is not.

A B

B C C

Model Checking – p. 23/45

Page 34: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Semantics of CTL∗

Path formulas describe properties associated with a path.Recall that a path is a sequence of states π = s0s1s2 such thatR(si, si+1) holds for all i ≥ 0.

We write M,π |= g to mean that a path formula g is true forpath π of the Kripke structure M .

Any state formula is also a path formula and is interpreted asbeing true if and only if it is true in the first state of the path.

The operators X , F , G , U , and R are called temporaloperators. They can be used to create path formulas fromstate formulas.

Model Checking – p. 24/45

Page 35: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

X operator

The X (“next time”) operator specifies that a property holds inthe second state of the path.

By repeatedly appplying this operator, we can specify that a

property holds in the nth state of the path.

Model Checking – p. 25/45

Page 36: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

X operator

Which of the following formulas are true for the path below?

Note that a state formula is true for a path if it is true in thefirst state of the path.

• A ∧B

• X (A ∧B)

• X (C)

• X X (C)

A B B C C C

Model Checking – p. 26/45

Page 37: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

X operator

Which of the following formulas are true for the path below?

Note that a state formula is true for a path if it is true in thefirst state of the path.

• A ∧B True

• X (A ∧B)

• X (C)

• X X (C)

A B B C C C

Model Checking – p. 26/45

Page 38: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

X operator

Which of the following formulas are true for the path below?

Note that a state formula is true for a path if it is true in thefirst state of the path.

• A ∧B True

• X (A ∧B) False

• X (C)

• X X (C)

A B B C C C

Model Checking – p. 26/45

Page 39: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

X operator

Which of the following formulas are true for the path below?

Note that a state formula is true for a path if it is true in thefirst state of the path.

• A ∧B True

• X (A ∧B) False

• X (C) True

• X X (C)

A B B C C C

Model Checking – p. 26/45

Page 40: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

X operator

Which of the following formulas are true for the path below?

Note that a state formula is true for a path if it is true in thefirst state of the path.

• A ∧B True

• X (A ∧B) False

• X (C) True

• X X (C) True

A B B C C C

Model Checking – p. 26/45

Page 41: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

U operator

U (“until”) is a binary operator which asserts that the firstproperty holds for every state on a path up to but notnecessarily including a state in which the second propertyholds.

Furthermore, there must exist a state on the path for whichthe second property holds.

Model Checking – p. 27/45

Page 42: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

U operator

Which of the following formulas are true for the path below?

• AU¬B

• B UC

• X (¬AU¬B)

• X (C UA)

A B B C C C

Model Checking – p. 28/45

Page 43: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

U operator

Which of the following formulas are true for the path below?

• AU¬B False

• B UC

• X (¬AU¬B)

• X (C UA)

A B B C C C

Model Checking – p. 28/45

Page 44: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

U operator

Which of the following formulas are true for the path below?

• AU¬B False

• B UC True

• X (¬AU¬B)

• X (C UA)

A B B C C C

Model Checking – p. 28/45

Page 45: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

U operator

Which of the following formulas are true for the path below?

• AU¬B False

• B UC True

• X (¬AU¬B) True

• X (C UA)

A B B C C C

Model Checking – p. 28/45

Page 46: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

U operator

Which of the following formulas are true for the path below?

• AU¬B False

• B UC True

• X (¬AU¬B) True

• X (C UA) False

A B B C C C

Model Checking – p. 28/45

Page 47: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Other Temporal Operators

The other temporal operators can be defined in terms of theothers:

• Ff = True Uf (“eventually” or “in the future”) asserts that fholds at some state on the path.

• Gf = ¬F¬f (“always” or “globally”) specifies that f holdsat every state on the path.

• f Rg = ¬(¬f U¬g) (“release”) requires that g holds up toand including the first state where the f holds. Unlike U ,the “release” property is true even if such a state does notexist.

Model Checking – p. 29/45

Page 48: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Path Quantifiers

The path quantifiers A (“for all paths”) and E (“there exists apath”) are used to convert path formulas to state formulas.

To interpret these formulas relative to a given state s, weconsider the computation tree rooted at s.

• A (f) specifies that the path formula f is true for everypath through the tree starting at s.

• E (f) specifies that the path formula f is true for somepath through the tree starting s.

Model Checking – p. 30/45

Page 49: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Path Quantifiers Example

Which of the following formulas are true for the initial state?• E G (C)• A F (C)• A G (C ∨ X (C))• E X (A G (C))

A B

B C C

A B

B C C

CCA B

Model Checking – p. 31/45

Page 50: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Path Quantifiers Example

Which of the following formulas are true for the initial state?• E G (C) False

• A F (C)• A G (C ∨ X (C))• E X (A G (C))

A B

B C C

A B

B C C

CCA B

Model Checking – p. 31/45

Page 51: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Path Quantifiers Example

Which of the following formulas are true for the initial state?• E G (C) False

• A F (C) True

• A G (C ∨ X (C))• E X (A G (C))

A B

B C C

A B

B C C

CCA B

Model Checking – p. 31/45

Page 52: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Path Quantifiers Example

Which of the following formulas are true for the initial state?• E G (C) False

• A F (C) True

• A G (C ∨ X (C)) True

• E X (A G (C))

A B

B C C

A B

B C C

CCA B

Model Checking – p. 31/45

Page 53: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Path Quantifiers Example

Which of the following formulas are true for the initial state?• E G (C) False

• A F (C) True

• A G (C ∨ X (C)) True

• E X (A G (C)) True

A B

B C C

A B

B C C

CCA B

Model Checking – p. 31/45

Page 54: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

CTL and LTL

There are two well-known sublogics of CTL∗ : CTL and LTL .They differ only in the allowed syntax.

Model Checking – p. 32/45

Page 55: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

CTL and LTL

Syntax of CTL∗ :

• State formula α: p ∈ a∗ | ¬α | α ∨ α | α ∧ α | E (β) | A (β)

• Path formula β: α | ¬β | β ∨ β | β ∧ β | X (β) | F (β) | G (β) |β Uβ | β Rβ

Syntax of CTL :

• State formula α: p ∈ a∗ | ¬α | α ∨ α | α ∧ α | E (β) | A (β)

• Path formula β: X (α) | F (α) | G (α) | αUα | αRα

Syntax of LTL :

• State formula α: A (β)

• Path formula β: p ∈ a∗ | ¬β | β ∨ β | β ∧ β | X (β) | F (β) |G (β) | β Uβ | β Rβ

Model Checking – p. 33/45

Page 56: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Typical Formulas

Here are some examples of the kinds of formulas that mightarrise in specifying properties of an actual system.

• E F (Start ∧ ¬Ready ): It is possible to get to a state whereStart holds but Ready does not hold.

• A G (Req → A F Ack ): If a request occurs, then it willeventually be acknowledged.

• A G (A F DeviceEnabled ): The device is enabled(DeviceEnabled is true) infinitely often on every computationpath.

• A G (E F Restart ): From any state it is possible to get to theRestart state.

Model Checking – p. 34/45

Page 57: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Model Checking

The first algorithms for model checking used an explicitrepresentation of the state transition graph for the Kripkestructure.The basic model checking problem is the following.

Given a Kripke structure M and a formula f expressing somedesired property of M , find the set of states {s ∈ S|M, s |= f}.

The system satisfies its specification if this set includes theset of initial states S0.

Model Checking – p. 35/45

Page 58: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Explicit State CTL Model Checking

First, the formula f is expressed using only the operators ¬,∨, X , U , G , and E .

We inductively define a procedure Check (f) which labels each

state s in the state transition graph with the set label (s) ofsubformulas of f which are true in that state.

For atomic propositions p, Check (p) just labels each state s

such that p ∈ L(s).

For nontrivial formulas, there are five possible operators toconsider: ¬, ∨, E X , E U , and E G .

Model Checking – p. 36/45

Page 59: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Explicit State CTL Model Checking

• Check (¬g) simply calls Check (g) and then labels with ¬gevery state not labeled with g.

• Check (g1 ∨ g2) calls Check (g1) and Check (g2) and thenlabels with g1 ∨ g2 every state labeled with either g1 or g2.

• Check (E Xg) calls Check (g) and then labels with E Xg

every state that has some successor labeled by g.

• Check (E (g1 Ug2)) = CheckEU (g1, g2)

• Check (E G (g)) = CheckEG (g)

Model Checking – p. 37/45

Page 60: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Explicit State Model Checking: E U

procedure CheckEU(f1, f2)

Check(f1); Check(f2);

T := {s|f2 ∈ label (s)};for each s ∈ T do label (s) := label (s) ∪ {E (f1 Uf2)};while T 6= ∅ do

choose s ∈ T; T := T − {s};for each t such that R(t, s) do

if E (f1 Uf2) 6∈ label (t) and f1 ∈ label (t) then

label (t) := label (t) ∪ {E (f1 Uf2)};T := T ∪ {t};

end if

end for

end while

Model Checking – p. 38/45

Page 61: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Explicit State Model Checking: E G

procedure CheckEG(f1)

Check(f1);

S′ := {s|f1 ∈ label (s)};SCC := {C|C is a nontrivial SCC of S′};T :=

⋃C∈ SCC {s|s ∈ C};

for each s ∈ T do label (s) := label (s) ∪ {E G (f1)};while T 6= ∅ do

choose s ∈ T; T := T − {s};for each t such that t ∈ S′ and R(t, s) do

if E G (f1) 6∈ label (t) then

label (t) := label (t) ∪ {E G (f1)};T := T ∪ {t};

end if

end for

end while

Model Checking – p. 39/45

Page 62: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Symbolic Model Checking

We can represent a Kripke structure M = (S, S0, R, L) usingBDD’s.

Suppose for simplicity that |S| = 2m. Let φ be a 1-1 mapping

from {0, 1}m to S. We can construct the Boolean function fS0

over the variables x such that fS0(x1, . . . , xm) = 1 iff

φ(x1, . . . , xm) ∈ S0.

To represent R, we use the additional next-state variables y.The BDD for R corresponds to the function fR:

fR(x1, . . . , xm, y1, . . . , ym) = 1 iff

(φ(x1, . . . , xm), φ(y1, . . . , ym)) ∈ R.

To represent L, we create a BDD Lp for each atomic

proposition p which represents the set of all states s ∈ S suchthat p ∈ L(s).

Model Checking – p. 40/45

Page 63: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Symbolic Model Checking

In explicit state model checking, we labeled each state of aKripke structure with the CTL formulas true in that state.

In symbolic model checking, BDD’s are used to represent theKripke structure as well as the sets of states for which a givenCTL formula holds.

Symbolic model checking can scale many orders ofmagnitude beyond explicit state model checking.

Model Checking – p. 41/45

Page 64: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Counterexamples and Witnesses

One of the most important features of CTL model-checkingalgorithms is the ability to find counterexamples andwitnesses.

A counterexample is produced when a formula with auniversal path quantifier is false.

A witness is produced when a formula with an existential pathquantifier is true.

Model Checking – p. 42/45

Page 65: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

Bounded Model Checking

Suppose we are checking A G (P ). P is called a safetyproperty.

Bounded Model Checking [BCCZ99, CBRZ01] can be used todetermine whether P holds after some bounded number oftransitions.

To perform bounded model checking to a depth of k usingSAT or SMT, we need k extra copies of the state variables.

Let x0, . . . ,xk be k + 1 copies of the state variables. And letFSP

(x) be a formula that is true iff the property P holds.

Then P holds after k steps iff the following formula is valid:

(FS0(x0) ∧ FR(x0,x1) ∧ · · · ∧ FR(xn−1,x)) → FSP

(xn).

Model Checking – p. 43/45

Page 66: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

CoSA Model Checker

The CoSA model checker [MMB+18] is an open-sourcemodel-checker for hardware

It reads in verilog with properties and can then use a varietyof model checking techniques to try to prove the properties.

In particular, CoSA can do bounded and k-induction basedmodel checking using SMT formulas and solvers

Model Checking – p. 44/45

Page 67: Model Checking - Stanford Universityweb.stanford.edu/class/cs237b/pdfs/lecture/lecture_7.pdfState Graphs and Computation Trees A state transition graph for a structure M =(S,S0,R,L)has

References

[BCCZ99] A. Biere, A. Cimatti, E. Clarke, and Y. Zhu. Symbolic model checking without

BDDs. In Proceedings of the 5th Workshop on Tools and Algorithms for the

Construction and Analysis of Systems (TACAS ’99), volume 1573 of LNCS, pages

193–207. Springer-Verlag, 1999

[BT18] Clark Barrett and Cesare Tinelli. Satisfiability modulo theories. In Edmund M. Clarke,

Thomas A. Henzinger, Helmut Veith, and Roderick Bloem, editors, Handbook of Model

Checking, pages 305–343. Springer International Publishing, 2018

[CBRZ01] E. Clarke, A. Biere, R. Raimi, and Y. Zhu. Solving SAT and SAT Modulo Theories:

from an Abstract Davis-Putnam-Logemann-Loveland Procedure to DPLL(T). Formal

Methods in System Design, 19(1):7–34, 2001

[CGP02] Edmund M. Clarke, Orna Grumberg, and Doron A. Peled. Model Checking. MIT

Press, 2002

[MMB+18] Cristian Mattarei, Makai Mann, Clark Barrett, Ross G. Daly, Dillon Huff, and Pat

Hanrahan. CoSA: Integrated verification for agile hardware design. In Nikolaj Bjørner

and Arie Gurfinkel, editors, Proceedings of the 18th International Conference on

Formal Methods In Computer-Aided Design (FMCAD ’18), pages 7–11. FMCAD Inc.,

October 2018. Austin, Texas

Model Checking – p. 45/45