37
Computation Tree Logic (CTL) & Basic Model Checking Algorithms Martin Fr ¨ anzle Carl von Ossietzky Universit ¨ at Dpt. of Computing Science Res. Grp. Hybride Systeme Oldenburg, Germany 02917: CTL & Model Checking – p.1/37

Computation Tree Logic (CTL) & Basic Model Checking Algorithms

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Computation Tree Logic (CTL) &Basic Model Checking Algorithms

Martin Franzle

Carl von Ossietzky Universitat

Dpt. of Computing Science

Res. Grp. Hybride Systeme

Oldenburg, Germany

02917: CTL & Model Checking – p.1/37

Page 2: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

What you’ll learn

1. Rationale behind declarative specifications:• Why operational style is insufficient

2. Computation Tree Logic CTL:• Syntax• Semantics: Kripke models

3. Explicit-state model checking of CTL:• Recursive coloring

02917: CTL & Model Checking – p.2/37

Page 3: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Operational modelsNowadays, a lot of ES design is based on executable behavioralmodels of the system under design, e.g. using• Statecharts (a syntactically sugared variant of Moore automata)• VHDL.

Such operational models are good at• supporting system analysis• simulation / virtual prototyping

• supporting incremental design• executable models

• supporting system deployment• executable model as “golden device”• code generation for rapid prototyping or final product• hardware synthesis

02917: CTL & Model Checking – p.3/37

Page 4: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Operational models

...are bad at• supporting non-operational descriptions:• What instead of how.• E.g.: Every request is eventually answered.

• supporting negative requirements:• “Thou shalt not...”• E.g.: The train ought not move, unless it is manned.

• providing a structural match for requirement lists:• System has to satisfy R1 and R2 and ...• If system fails to satisfy R1 then R2 should be satisfied.

02917: CTL & Model Checking – p.4/37

Page 5: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Multiple viewpoints

Requirementsanalysis

Programming

"How?"

Algorithmics"What?"

Aspects

Requirementsanalysis

Programming

"How?"

Algorithmics"What?"

Aspects

Consistent?

Requirementsanalysis

Programming

"How?"

Algorithmics"What?"

Aspects

Consistent?

"Consistent?"

Tests & proofs

Validation / verification

02917: CTL & Model Checking – p.5/37

Page 6: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model checking

Device Specification

Device Descript.architecture behaviourof processor is

process fetch if halt=0 then if mem_wait=0 then nextins <= dport ...

Model Checker

♦(π ⇐ φ)

Hello world

This is DeDuCe V 1.4

Give me your design

Approval/Counterexample

02917: CTL & Model Checking – p.6/37

Page 7: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Exhaustive state-space search

Automatic verification/falsification of invariants

02917: CTL & Model Checking – p.7/37

Page 8: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

InApproach EmptyEmpty

ente

r!

leav

e!

Safety requirement: Gate has to be closed whenever a train is in “In”.

02917: CTL & Model Checking – p.8/37

Page 9: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

The gate model

Open

Opening

~enter?

enter?

~leave?

leave?

Closing

Closed

Track model— safe abstraction —

leave!

enter!Empty Appr. In

02917: CTL & Model Checking – p.9/37

Page 10: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Automatic check

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open~enter

~leave

~enter

~leave

~enter

~leave

enter

enter ~enter

~leave ~leave

leave

leave

Empty Appr. In

Appr. InEmpty

Empty

Empty

Appr.

Appr. In

In

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In0

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In0

1

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In0

1

2 2

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In0

1

2 2

3

4

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In0

1

2 2

3

4 5

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In0

1

2 2

3

4 5

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In

02917: CTL & Model Checking – p.10/37

Page 11: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Verification result

0

1

2 2

3

4 5

Closed

Opening

Closed

Closing

Opening

Open

Closed

Closing

Opening

Open

Closing

Open

Empty

Empty

Empty

Empty App.

App.

App.

App.

In

In

In

In

Stimuli: Empty, Approach, In , Empty , Approach, In.Gate reaction: Open , Closing , Closed, Opening, Open , Open.

02917: CTL & Model Checking – p.11/37

Page 12: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Computation Tree Logic

02917: CTL & Model Checking – p.12/37

Page 13: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Syntax of CTL

We start from a countable set AP of atomic propositions.The CTL formulae are then defined inductively:• Any proposition p ∈ AP is a CTL formula.• The symbols ⊥ and > are CTL formulae.• If φ and ψ are CTL formulae, so are

¬φ, φ∧ψ, φ∨ ψ, φ→ ψ

EXφ, AXφEFφ, AFφEGφ, AGφφEUψ, φAUψ

02917: CTL & Model Checking – p.13/37

Page 14: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Semantics (informal)

• E and A are path quantifiers:• A: for all paths in the computation tree . . .• E: for some path in the computation tree . . .

• X, F, G und U are temporal operators which refer to the pathunder investigation, as known from LTL:• Xφ (Next) : evaluate φ in the next state on the path• Fφ (Finally) : φ holds for some state on the path• Gφ (Globally) : φ holds for all states on the path• φUψ (Until) : φ holds on the path at least until ψ holds

N.B. Path quantifiers and temporal operators are compound inCTL: there never is an isolated path quantifier or an isolated tem-poral operator. There is a lot of things you can’t express in CTLbecause of this...

02917: CTL & Model Checking – p.14/37

Page 15: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Semantics (formal)

CTL formulae are interpreted over Kripke structures.:A Kripke structure K is a quadruple K = (V, E, L, I) with• V a set of vertices (interpreted as system states),• E ⊆ V × V a set of edges (interpreted as possible transitions),• L ∈ V → P(AP) labels the vertices with atomic propositions that

apply in the individual vertices,• I ⊆ V is a set of initial states.

q1

qq3 q4

pq2

p,q

p,r

02917: CTL & Model Checking – p.15/37

Page 16: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Paths in Kripke structures

A path π in a Kripke structure K = (V, E, L, I) is an edge-consistentinfinite sequence of vertices:• π ∈ Vω,• (πi, πi+1) ∈ E for each i ∈ IN.

Note that a path need not start in an initial state!

The labelling L assigns to each path π a propositional trace

trπ = L(π)def= 〈L(π0), L(π1), L(π2), . . .〉

that path formulae (Xφ,Fφ,Gφ,φUψ) can be interpreted on.

02917: CTL & Model Checking – p.16/37

Page 17: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Semantics (formal)

Let K = (V, E, L, I) be a Kripke structure and v ∈ V a vertex of K.• v, K |= >• v, K 6|= ⊥• v, K |= p for p ∈ AP iff p ∈ L(v)• v, K |= ¬φ iff v, K 6|= φ,• v, K |= φ∧ψ iff v, K |= φ and v, K |= ψ,• v, K |= φ∨ψ iff v, K |= φ or v, K |= ψ,• v, K |= φ⇒ ψ iff v, K 6|= φ or v, K |= ψ.

02917: CTL & Model Checking – p.17/37

Page 18: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Semantics (contd.)

• v, K |= EXφ iff there is a path π in K s.t. v = π1 and π2, K |= φ,• v, K |= AXφ iff all paths π in K with v = π1 satisfy π2, K |= φ,

• v, K |= EFφ iff there is a path π in K s.t. v = π1 and πi, K |= φ for some i,• v, K |= AFφ iff all paths π in K with v = π1 satisfy πi, K |= φ for some i (that

may depend on the path),

• v, K |= EGφ iff there is a path π in K s.t. v = π1 and πi, K |= φ for all i,• v, K |= AGφ iff all paths π in K with v = π1 satisfy πi, K |= φ for all i,

• v, K |= φEUψ , iff there is a path π in K s.t. v = π1 and some k ∈ IN s.t.πi, K |= φ for each i < k and πk, K |= ψ,

• v, K |= φAUψ , iff all paths π in K with v = π1 have some k ∈ IN s.t.πi, K |= φ for each i < k and πk, K |= ψ.

A Kripke structure K = (V, E, L, I) satisfies φ iff all its initial states satisfy φ,

i.e. iff is, K |= φ for all is ∈ I.

02917: CTL & Model Checking – p.18/37

Page 19: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

CTL Model Checking

Explicit-state algorithm

02917: CTL & Model Checking – p.19/37

Page 20: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Rationale

We will extend the idea of verification/falsification by exhaustivestate-space exploration to full CTL.• Main technique will again be breadth-first search, i.e. graph

coloring.• Need to extend this to other modalities than AG ..• Need to deal with nested modalities.

02917: CTL & Model Checking – p.20/37

Page 21: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: General layout

Given: a Kripke structure K = (V, E, L, I) and a CTL formula φ

Core algorithm: find the set Vφ ⊆ V of vertices in K satisfying φ by1. for each atomic subformula p of φ, mark the set Vp ⊆ V of

vertices in K satisfying φ2. for increasingly larger subformulae ψ of φ, synthesize the

marking Vψ ⊆ V of nodes satisfying ψ from the markings forψ’s immediate subformulae

until all subformulae of φ have been processed(including φ itself)

Result: report “K |= φ” iff Vφ ⊇ I

02917: CTL & Model Checking – p.21/37

Page 22: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Reduction

The tautologies

φ∨ψ ⇔ ¬(¬φ∧ ¬ψ)

AXφ ⇔ ¬EX¬φ

AGφ ⇔ ¬EF¬φ

EFφ ⇔ >EUφEGφ ⇔ ¬AF¬φ

φAUψ ⇔ ¬((¬ψ)EU¬(φ∨ψ)) ∧ AFψ

indicate that we can rewrite each formula to one only containingatomic propositions, ¬,∧,EX , EU ,AF .

After preprocessing, our algorithm need only tackle these!

02917: CTL & Model Checking – p.22/37

Page 23: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: Atomic propositions

Given: A finite Kripke structure with vertices V and edges E and alabelling function L assigning atomic propositions to vertices.

Furthermore an atomic proposition p to be checked.

Algorithm: Mark all vertices that have p as a label.

Complexity: O(|V |)

02917: CTL & Model Checking – p.23/37

Page 24: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: ¬φ

Given: A set Vφ of vertices satisfying formula φ.

Algorithm: Mark all vertices not belonging to Vφ.

Complexity: O(|V |)

02917: CTL & Model Checking – p.24/37

Page 25: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: φ∧ψ

Given: Sets Vφ and Vψ of vertices satisfying formulae φ or ψ, resp.

Algorithm: Mark all vertices belonging to Vφ ∩ Vψ.

Complexity: O(|V |)

02917: CTL & Model Checking – p.25/37

Page 26: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: EXφ

Given: Set Vφ of vertices satisfying formulae φ.

Algorithm: Mark all vertices that have a successor state in Vφ.

Complexity: O(|V | + |E|)

02917: CTL & Model Checking – p.26/37

Page 27: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: φEUψ

Given: Sets Vφ and Vψ of vertices satisfying formulae φ or ψ, resp.

Algorithm: Incremental marking by1. Mark all vertices belonging to Vψ.2. Repeat

if there is a state in Vφ that has some successor statemarked then mark it also

until no new state is found.

Termination: Guaranteed due to finiteness of Vφ ⊂ V .

Complexity: O(|V | + |E|) if breadth-first search is used.

02917: CTL & Model Checking – p.27/37

Page 28: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: AFφ

Given: Set Vφ of vertices satisfying formula φ.

Algorithm: Incremental marking by1. Mark all vertices belonging to Vφ.2. Repeat

if there is a state in V that has all successor states markedthen mark it also

until no new state is found.

Termination: Guaranteed due to finiteness of V .

Complexity: O(|V | · (|V | + |E|)).

02917: CTL & Model Checking – p.28/37

Page 29: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: EGφ, for efficiency

Given: Set Vφ of vertices satisfying formula φ.

Algorithm: Incremental marking by1. Strip Kripke structure to Vφ-states:

(V, E) (Vφ, E ∩ (Vφ × Vφ)). Complexity: O(|V | + |E|)

2. Mark all states belonging to loops in the reduced graph. Complexity: O(|Vφ| + |Eφ|) by identifying strongly connected

components.3. Repeat

if there is a state in Vφ that has some successor statesmarked then mark it also

until no new state is found. Complexity: O(|Vφ| + |Eφ|)

Complexity: O(|V | + |E|).

02917: CTL & Model Checking – p.29/37

Page 30: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: Main result

Theorem: It is decidable whether a finite Kripke structure (V, E, L, I)satisfies a CTL formula φ.The complexity of the decision procedure is O(|φ| · (|V | + |E|)),i.e.• linear in the size of the formula, given a fixed Kripke structure,• linear in the size of the Kripke structure, given a fixed formula.

However, size of Kripke structure is exponential innumber of parallel components in the system model.

02917: CTL & Model Checking – p.30/37

Page 31: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Appendix

Fair Kripke Structures &

Fair CTL Model Checking

02917: CTL & Model Checking – p.31/37

Page 32: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Fair Kripke Structures

A fair Kripke structure is a pair (K,F), where• K = (V, E, L, I) is a Kripke structure• F ⊆ P(V) is set of vertice sets, called a fairness condition.

A fair path π in a fair Kripke structure ((V, E, L, I),F) is anedge-consistent infinite sequence of vertices which visits each setF ∈ F infinitely often:• π ∈ Vω,• (πi, πi+1) ∈ E for each i ∈ IN,• ∀ F ∈ F .∃∞i ∈ IN. πi ∈ F.

Note the similarity to (generalized) Büchi acceptance!

02917: CTL & Model Checking – p.32/37

Page 33: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Fair CTL: Semantics• v, K,F |=F EXφ iff there is a fair path π in K s.t. v = π0 and π1, K,F |=F φ,• v, K,F |=F AXφ iff all fair paths π in K with v = π0 satisfy π1, K,F |=F φ,

• v, K,F |=F EFφ iff there is a fair path π in K s.t. v = π0 and πi, K,F |=F φ forsome i,

• v, K,F |=F AFφ iff all fair paths π in K with v = π0 satisfy πi, K,F |=F φ forsome i (that may depend on the fair path),

• v, K,F |=F EGφ iff there is a fair path π in K s.t. v = π0 and πi, K,F |=F φ forall i,

• v, K,F |=F AGφ iff all fair paths π in K with v = π0 satisfy πi, K,F |=F φ forall i,

• v, K,F |=F φEUψ , iff there is a fair path π in K s.t. v = π0 and some k ∈ INs.t. πi, K,F |=F φ for each i < k and πk, K,F |=F ψ,

• v, K,F |=F φAUψ , iff all fair paths π in K with v = π0 have some k ∈ IN s.t.πi, K,F |=F φ for each i < k and πk, K,F |=F ψ.

A fair Kripke structure ((V, E, L, I),F) satisfies φ, denoted ((V, E, L, I),F) |=F φ,iff all its initial states satisfy φ, i.e. iff is, K,F |=F φ for all is ∈ I.

02917: CTL & Model Checking – p.33/37

Page 34: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking CTL: Fair states

Lemma: Given a fair Kripke structure (((V, E, L, I),F), the setFair ⊆ V of states from which a fair path originates can bedetermined algorithmically.

Alg.: This is a problem of finding adequate SCCs:1. Find all SCCs in K.2. Select those SCCs that do contain at least one state from

each fairness set F ∈ F .3. Find all states from which at least one of the selected SCCs

is reachable.

02917: CTL & Model Checking – p.34/37

Page 35: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking fair CTL: EXφ

Given: Set Vφ of vertices fairly satisfying formulae φ.

Algorithm: Mark all vertices that have a successor state in Vφ∩Fair .

Note that the intersection with Fair is necessary even though the states in Vφfairly satisfy φ:• φ may be an atomic proposition, in which case fairness is irrelevant;• φ may start with an A path quantifier that is trivially satisfied by non-

existence of a fair path.

02917: CTL & Model Checking – p.35/37

Page 36: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking fair CTL: φEUψ

Given: Sets Vφ and Vψ of vertices fairly satisfying formulae φ or ψ,resp.

Algorithm: Incremental marking by1. Mark all vertices belonging to Vψ∩Fair .2. Repeat

if there is a state in Vφ that has some successor statemarked then mark it also

until no new state is found.

02917: CTL & Model Checking – p.36/37

Page 37: Computation Tree Logic (CTL) & Basic Model Checking Algorithms

Model-checking fair CTL: EGφ

Given: Set Vφ of vertices fairly satisfying formula φ.

Algorithm: Incremental marking by1. Strip Kripke structure to Vφ-states:

(V, E) (Vφ, E ∩ (Vφ × Vφ)).2. Mark all states that can reach a fair SCC in the reduced

graph.(Same algorithm as for finding the set Fair , yet applied to the reducedgraph.)

02917: CTL & Model Checking – p.37/37