Download LTL and CTL Semantics with Model Checking Algorithms and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!
Model Checking
Foundations and Applications
Tevfik Bultan Department of Computer Science University of California, Santa Barbara [email protected] http://www.cs.ucsb.edu/~bultan/
Outline
- Temporal Logics for Reactive Systems
- Automated Verification of Temporal Properties of Finite State Systems
- Temporal Properties ≡ Fixpoints
- Symbolic Model Checking
- LTL Properties ≡ Büchi automata
- Infinite State Model Checking
- Model Checking Programs
- SLAM project
- Java Path Finder
Temporal Logics for Reactive Systems
[Pnueli FOCS 77, TCS 81] Transformational systems get input; compute something; return result; Reactive systems while (true) { receive some input, send some output }
- Transformational view follows from the initial use of computers as advanced calculators: A component receives some input, does some calculation and then returns a result.
- Nowadays, the reactive system view seems more natural: components which continuously interact with each other and their environment without terminating
Transformational vs. Reactive Systems
Transformational systems get input; {pre-condition} compute something; {post-condition} return result; Reactive systems while (true) { receive some input, send some output }
- Earlier work in verification uses the transformational view: - halting problem - Hoare logic - pre and post-conditions - partial vs. total correctness
- For reactive systems:
- termination is not the main issue
- pre and post-conditions are not enough
Reactive Systems: A Very Simple Model
- We will use a very simple model for reactive systems
- A reactive system generates a set of execution paths
- An execution path is a concatenation of the states (configurations) of the system, starting from some initial state
- There is a transition relation which specifies the next-state relation, i.e., given a state what are the states that can follow that state
- We need an example
A Mutual Exclusion Protocol
Process 1: while (true) { out: a := true; turn := true; wait: await (b = false or turn = false); cs: a := false; } || Process 2: while (true) { out: b := true; turn := false; wait: await (a = false or turn); cs: b := false; } Two concurrently executing processes are trying to enter a critical section without violating mutual exclusion
State Space
- The state space of a program can be captured by the valuations of the variables and the program counters - you have to wait until the next lecture for a discussion about the control stack (and recursion) and the heap (and dynamic memory allocation)
- For our example, we have
- two program counters: pc1, pc domains of the program counters: {out, wait, cs}
- three boolean variables: turn, a, b boolean domain: {True, False}
- Each state of the program is a valuation of all the variables
State Space
- Each state can be written as a tuple (pc1,pc2,turn,a,b)
- Initial states: {(o,o,F,F,F), (o,o,F,F,T), (o,o,F,T,F), (o,o,F,T,T), (o,o,T,F,F), (o,o,T,F,T), (o,o,T,T,F), (o,o,T,T,T)} - initially: pc1=o and pc2=o
- How many states total? 3 * 3 * 2 * 2 * 2 = 72 exponential in the number of variables and the number of concurrent components
Transition Relation
- Transition Relation specifies the next-state relation, i.e., given a state what are the states that can come after that state
- For example, given the initial state (o,o,F,F,F) Process 1 can execute: out: a := true; turn := true; or Process 2 can execute: out: b := true; turn := false;
- If process 1 executes, the next state is (w,o,T,T,F)
- If process 2 executes, the next state is (o,w,F,F,T)
- So the state pairs ((o,o,F,F,F),(w,o,T,T,F)) and ((o,o,F,F,F),(o,w,F,F,T)) are included in the transition relation
Transition Relation
The transition relation is like a graph, edges represent the next-state relation (o,o,F,F,F) (o,w,F,F,T) (w,o,T,T,F) (o,c,F,F,T) (w,w,T,T,T)
Transition System
- A transition system T = (S, I, R) consists of
- a set of states S
- a set of initial states I ⊆ S
- and a transition relation R ⊆ S × S
- A common assumption in model checking
- R is total, i.e., for all s ∈ S, there exists s’ such that (s,s’) ∈ R
Execution Paths
- An execution path is an infinite sequence of states x = s 0 , s 1 , s 2 , ... such that s 0 ∈ I and for all i ≥ 0, (si,si+1) ∈ R Notation: For any path x xi denotes the i’th state on the path (i.e., si) xi^ denotes the i’th suffix of the path (i.e., si, si+1, si+2, ... )
Example Properties
mutual exclusion: G ( ¬ (pc1=c ∧ pc2=c)) starvation freedom: G(pc1=w ⇒ F(pc1=c)) ∧ G(pc2=w ⇒ F(pc2=c)) Given the execution path: x =((o,o,F,F,F), (o,w,F,F,T), (o,c,F,F,T))ω x |= pc1=o x |= X (pc2=w) x |= F (pc2=c) x |= (¬turn) U (pc2=c ∧ b) x |= G ( ¬ (pc1=c ∧ pc2=c)) x |= G(pc1=w ⇒ F(pc1=c)) ∧ G(pc2=w ⇒ F(pc2=c))
LTL Equivalences
- We do not really need all four temporal operators
- X and U are enough (i.e., X, U, AP and boolean connectives form a basis for LTL) F p = true U p G p = ¬ (F¬p) = ¬ (true U ¬p)
LTL Model Checking
- Given a transition system T and an LTL property p T |= p iff for all execution paths x in T, x |= p For example: T |=? G ( ¬ (pc1=c ∧ pc2=c)) T |=? G(pc1=w ⇒ F(pc1=c)) ∧ G(pc2=w ⇒ F(pc2=c)) Model checking problem : Given a transition system T and an LTL property p, determine if T is a model for p (i.e., if T |=p)
Linear Time vs. Branching Time
- In linear time logics given we look at execution paths individually
- In branching time logics we view the computation as a tree
- computation tree: unroll the transition relation s1 s2 s3 s Transition System Execution Paths Computation Tree s s s s s .^ s .. s... s s s s s .. . ... s4 s1^ s ... .. . s4... s...
Computation Tree Logic (CTL)
- In CTL we quantify over the paths in the computation tree
- We use the same four temporal operators: X, G, F, U
- However we attach path quantifiers to these temporal operators: - A : for all paths - E : there exists a path
- We end up with eight temporal operators:
- AX, EX, AG, EG, AF, EF, AU, EU
CTL Semantics
Given a state s and CTL properties p and q s |= p iff L(s, p) =True, where p ∈ AP s |= ¬p iff not x |= p s |= p ∧ q iff s |= p and s |= q s |= p ∨ q iff s |= p or s |= q s 0 |= EX p iff there exists a path s 0 , s 1 , s 2 , ... such that s 1 |= p s 0 |= AX p iff for all paths s 0 , s 1 , s 2 , ..., s 1 |= p
CTL Semantics
s 0 |= EG p iff there exists a path s 0 , s 1 , s 2 , ... such that for all i, si |= p s 0 |= AG p iff for all paths s 0 , s 1 , s 2 , ..., for all i, si |= p s 0 |= EF p iff there exists a path s 0 , s 1 , s 2 , ... such that there exists an i such that si |= p s 0 |= AF p iff for all paths s 0 , s 1 , s 2 , ..., there exists an i, such that, si |= p s 0 |= p EU q iff there exists a path s 0 , s 1 , s 2 , ..., such that, there exists an i such that si |= q and for all j < i, sj |= p s 0 |= p AU q iff for all paths s 0 , s 1 , s 2 , ..., there exists an i such that si |= q and for all j < i, sj |= p
CTL Equivalences
- CTL basis: EX, EU, EG AX p = ¬ EX ¬p AG p = ¬ EF ¬p AF p = ¬ EG ¬p p AU q = ¬( (¬q EU (¬p ∧¬q)) ∨ EG ¬ q) EF p = True EU p
- Another CTL basis: EX, EU, AU
CTL Properties
s1 s2 s3 s Transition System Computation Tree s s s s s
.. . ... s4 s1^ s ... .. . s4... s... p p p p p p s3 |= p s4 |= p s1 |= ¬ p s2 |= ¬ p s3 |= EX p s3 |= EX ¬ p s3 |= ¬ AX p s3 |= ¬ AX ¬ p s3 |= EG p s3 |= ¬ EG ¬ p s3 |= AF p s3 |= EF ¬ p s3 |= ¬ AF ¬ p p p
CTL Model Checking
- Given a transition system T= (S, I, R) and a CTL property p T |= p iff for all initial state s ∈ I, s |= p Model checking problem : Given a transition system T and a CTL property p, determine if T is a model for p (i.e., if T |=p) For example: T |=? AG ( ¬ (pc1=c ∧ pc2=c)) T |=? AG(pc1=w ⇒ AF(pc1=c)) ∧ AG(pc2=w ⇒ AF(pc2=c))
- Question: Are CTL and LTL equivalent?
CTL vs. LTL
- CTL and LTL are not equivalent
- There are properties that can be expressed in LTL but cannot be expressed in CTL - For example: FG p
- There are properties that can be expressed in CTL but cannot be expressed in LTL - For example: AG(EF p)
- Hence, expressive power of CTL and LTL are not comparable
CTL*
- CTL* is a temporal logic which is strictly more powerful than CTL and LTL
- CTL* also uses the temporal operators X, F, G, U and the path quantifiers A and E, but temporal operators can also be used without path quantifiers
- The following CTL* property cannot be expressed in CTL or LTL - A(FG p) ∨ AG(EF p)
Temporal Properties ≡ Fixpoints
[Emerson and Clarke 80] Here are some interesting CTL equivalences: AG p = p ∧ AX AG p EG p = p ∧ EX EG p AF p = p ∨ AX AF p EF p = p ∨ EX EF p p AU q = q ∨ (p ∧ AX (p AU q)) p EU q = q ∨ (p ∧ EX (p EU q)) Note that we wrote the CTL temporal operators in terms of themselves and EX and AX operators
Functionals
- Given a transition system T=(S, I, R), we will define functions from sets of states to sets of states - F : 2S^ → 2 S
- For example, one such function is the EX operator (which computes the precondition of a set of states) - EX : 2 S^ → 2 S which can be defined as: EX(p) = { s | (s,s’) ∈ R and s’ ∈ p } Abuse of notation: I am using p to denote the set of states which satisfy the property p
Functionals
- Now, we can think of all temporal operators also as functions from sets of states to sets of states
- For example: AX p = ¬EX(¬p) or if we use the set notation AX p = (S - EX(S - p)) Abuse of notation: I will use the set and logic notations interchangeably. Logic Set p ∧ q p ∩ q p ∨ q p ∪ q ¬p S – p False ∅ True S
Lattice
The set of states of the transition system forms a lattice:
- lattice 2 S
- partial order ⊆
- bottom element ∅
- top element S
- Least upper bound ∪ (aka join) operator
- Greatest lower bound ∩ (aka meet) operator
Temporal Properties ≡ Fixpoints
Based on the equivalence EF p = p ∨ EX EF p we observe that EF p is a fixpoint of the following function: F y = p ∨ EX y F (EF p) = EF p In fact, EF p is the least fixpoint of F, which is written as: EF p = μ y. p ∨ EX y Based on the equivalence EG p = p ∧ AX EG p we observe that EG p is a fixpoint of the following function: F y = p ∧ EX y F (EG p) = EG p In fact, EG p is the greatest fixpoint of F, which is written as: EG p = ν y. p ∧ EX y
Fixpoint Characterizations
Fixpoint Characterization Equivalences AG p = ν y. p ∧ AX y AG p = p ∧ AX AG p EG p = ν y. p ∧ EX y EG p = p ∧ EX EG p AF p = μ y. p ∨ AX y AF p = p ∨ AX AF p EF p = μ y. p ∨ EX y EF p = p ∨ EX EF p p AU q = μ y. q ∨ (p ∧ AX (y)) p AU q=q ∨ (p ∧ AX (p AU q)) p EU q = μ y. q ∨ (p ∧ EX (y)) p EU q = q ∨ (p ∧ EX (p EU q))
Least and Greatest Fixpoints
The least and greatest fixpoint operators are defined as: μ y. F y = ∩ { y | F y ⊆ y } (glb of all the reductive elements) ν y. F y = ∪ { y | F y ⊇ y } (lub of all the extensive elements) The least fixpoint μ y. F y is the limit of the following sequence (assuming F is ∪-continuous): ∅, F ∅, F^2 ∅, F^3 ∅, ... The greatest fixpoint ν y. F y is the limit of the following sequence (assuming F is ∩-continuous): S, F S, F^2 S, F^3 S, ... If S is finite, then we can compute the least and greatest fixpoints using these sequences
EF and EG computations
Then, EF p = μ y. p ∨ EX y is the limit of the sequence: ∅, p∨EX ∅, p∨EX(p∨EX ∅) , p∨EX(p∨EX(p∨ EX ∅)) , ... which is equivalent to ∅, p, p ∨ EX p , p ∨ EX (p ∨ EX (p) ) , ... Similarly, EG p = ν y. p ∧ EX y is the limit of the sequence: S, p∧EX S, p∧EX(p ∧ EX S) , p∧EX(p ∧ EX (p ∧ EX S)) , ... which is equivalent to S, p, p ∧ EX p , p ∧ EX (p ∧ EX (p) ) , ...
EF Fixpoint Computation
pp • • • • • • EF(EF( pp )) ≡ states that can reachstates that can reach pp ≡ pp ∪ EX(EX( pp )) ∪ EX(EX(EX(EX( pp )))) ∪ (^) ...... EF(EF( pp ))
EG Fixpoint Computation
- • • • • • EG(EG( p)p) EG(EG( pp )) ≡ states that can avoid reachingstates that can avoid reaching ¬¬ pp ≡ pp ∩ EX(EX( pp )) ∩ EX(EX(EX(EX( pp )))) ∩ ......
μ-Calculus
μ-Calculus is a temporal logic which consist of the following:
- Atomic properties AP
- Boolean connectives: ¬ , ∧ , ∨
- Precondition operator: EX
- Least and greatest fixpoint operators: μ y. F y and ν y. F y Any CTL* property can be expressed in μ-calculus
Symbolic Model Checking
[McMillan et al. LICS 90]
- Represent sets of states and the transition relation as Boolean logic formulas
- Fixpoint computation becomes formula manipulation
- pre-condition (EX) computation: Existential variable elimination
- conjunction (intersection), disjunction (union) and negation (set difference), and equivalence check
- Use an efficient data structure for boolean logic formulas
- Binary Decision Diagrams (BDDs)
Symbolic Pre-condition Computation
- Remember the function EX : 2 S^ → 2 S which is defined as: EX(p) = { s | (s,s’) ∈ R and s’ ∈ p }
- We can symbolically compute pre as follows EX(p) ≡ ∃V’ R ∧ p[V’ / V]
- V : current-state boolean variables
- V’ : next-state boolean variables
- p[V’ / V] : rename variables in p by replacing current- state variables with the corresponding next-state variables
- ∃V’ f : existentially quantify out all the variables in V’ from f
Renaming
- Assume that we have two variables x, y.
- Then, V = {x, y} and V’={x’, y’}
- Renaming example: Given p ≡ x ∧ y : p[V’ / V] ≡ x ∧ y [V’ / V] ≡ x’ ∧ y’
Existential Quantifier Elimination
- Given a boolean formula f and a single variable v ∃v f ≡ f[True/v] ∨ f[False/v] i.e., to existentially quantify out a variable, first set it to true then set it to false and then take the disjunction of the two results
- Example: f ≡ ¬x ∧ y ∧ x’ ∧ y’ ∃V’ f ≡ ∃x’ ( ∃y’ (¬x ∧ y ∧ x’ ∧ y’) ) ≡ ∃x’ ((¬x ∧ y ∧ x’ ∧ y’ )[T/y’] ∨ (¬x ∧ y ∧ x’ ∧ y’ )[F/y’]) ≡ ∃x’ (¬x ∧ y ∧ x’ ∧T ∨ ¬x ∧ y ∧ x’ ∧ F ) ≡ ∃x’ ¬x ∧ y ∧ x’ ≡ (¬x ∧ y ∧ x’)[T/x’] ∨ (¬x ∧ y ∧ x’)[F/x’]) ≡ ¬x ∧ y ∧ T ∨ ¬x ∧ y ∧ F ≡ ¬x ∧ y
An Extremely Simple Example
Variables: x, y: boolean Set of states: S = {(F,F), (F,T), (T,F), (T,T)} S ≡ True Initial condition: I ≡ ¬ x ∧ ¬ y Transition relation (negates one variable at a time): R ≡ x’=¬x ∧ y’=y ∨ x’=x ∧ y’=¬y (= means ↔) F,T F,F T,T T,F
An Extremely Simple Example
Given p ≡ x ∧ y, compute EX(p) EX(p) ≡ ∃V’ R ∧ p[V’ / V] ≡ ∃V’ R ∧ x’ ∧ y’ ≡ ∃V’ (x’=¬x ∧ y’=y ∨ x’=x ∧ y’=¬y ) ∧ x’ ∧ y’ ≡ ∃V’ (x’=¬x ∧ y’=y) ∧ x’ ∧ y’ ∨ (x’=x ∧ y’=¬y) ∧ x’ ∧ y’ ≡ ∃V’ ¬x ∧ y ∧ x’ ∧ y’ ∨ x ∧ ¬y ∧ x’ ∧ y’ ≡ ¬x ∧ y ∨ x ∧ ¬y EX(x ∧ y) ≡ ¬x ∧ y ∨ x ∧ ¬y In other words EX({(T,T)}) ≡ {(F,T), (T,F)} F,T F,F T,T T,F
An Extremely Simple Example
Let’s compute compute EF(x ∧ y) The fixpoint sequence is False, x∧y , x∧y ∨ EX(x∧y) , x∧y ∨ EX (x∧y ∨ EX(x∧y) ) , ... If we do the EX computations, we get: False, x ∧ y , x ∧ y ∨ ¬x ∧ y ∨ x ∧ ¬y, True EF(x ∧ y) ≡ True In other words EF({(T,T)}) ≡ {(F,F),(F,T), (T,F),(T,T)} F,T F,F T,T T,F 0 1 2 3 1 2 3
An Extremely Simple Example
- Based on our results, for our extremely simple transition system T=(S,I,R) we have I ⊆ EF(x ∧ y) (⊆ corresponds to implication) hence: T |= EF(x ∧ y) (i.e., there exists a path from each initial state where eventually x and y both become true at the same time) I ⊆ EX(x ∧ y) hence: T |= EX(x ∧ y) (i.e., there does not exist a path from each initial state where in the next state x and y both become true)
An Extremely Simple Example
- Let’s try one more property AF(x ∧ y)
- To check this property we first convert it to a formula which uses only the temporal operators in our basis: AF(x ∧ y) ≡ ¬ EG(¬(x ∧ y)) If we can find an initial state which satisfies EG(¬(x ∧ y)), then we know that the transition system T, does not satisfy the property AF(x ∧ y)
An Extremely Simple Example
Let’s compute compute EG(¬(x ∧ y)) The fixpoint sequence is True, ¬x ∨ ¬y, (¬x ∨ ¬y) ∧ EX(¬x ∨ ¬y) , … If we do the EX computations, we get: True, ¬x ∨ ¬y, ¬x ∨ ¬y, EG(¬(x ∧ y)) ≡ ¬x ∨ ¬y Since I ∩ EG(¬(x ∧ y)) ≠ ∅ we conclude that T |= AF(x ∧ y) F,T F,F T,T T,F 0 1 2 0 1
Symbolic CTL Model Checking Algorithm
- Translate the formula to a formula which uses the basis
- Atomic formulas can be interpreted directly on the state representation
- For EX p compute the precondition using existential variable elimination as we discussed
- For EG and EU compute the fixpoints iteratively
Symbolic Model Checking Algorithm
Check(f : CTL formula) : boolean logic formula case: f ∈ AP return f; case: f ≡ ¬p return ¬Check(p); case: f ≡ p ∧q return Check(p) ∧ Check(q); case: f ≡ p ∨ q return Check(p) ∨ Check(q); case: f ≡ EX p return ∃V’ R ∧ Check(p) [V’ / V];
Symbolic Model Checking Algorithm
Check(f) … case: f ≡ EG p Y := True; P := Check(p); Y’ := P ∧ Check(EX(Y)); while (Y ≠ Y’) { Y := Y’; Y’ := P ∧ Check(EX(Y)); } return Y;
Bad News About BDDs
- The size of a BDD can be exponential in the number of boolean variables
- The sizes of the BDDs are very sensitive to the variable ordering. Bad variable ordering can cause exponential increase in the size of the BDD
- There are functions which have BDDs that are exponential for any variable ordering (for example binary multiplication)
- Pre condition computation requires existential variable elimination - Existential variable elimination can cause an exponential blow-up in the size of the BDD
BDDs are Sensitive to Variable Ordering
Identity relation for two variables: (x’ ↔ x) ∧ (y' ↔ y) T F F F T F y y’ F F T T x x’ x’ y’ T T F T Variable order: x, x’, y, y' For n variables, 3n+2 nodes T F F F T F x’ y’ F F T T x y y y’ T T T F Variable order: x, y, x’, y' For n variables, 3 × 2 n^ – 1 nodes x’ x’ x’ T F F T F T
SMV [McMillan 93]
- BDD-based symbolic model checker
- Finite state
- Temporal logic: CTL
- Focus: hardware verification
- Later applied to software specifications, protocols, etc.
- SMV has its own input specification language
- concurrency: synchronous, asynchronous
- shared variables
- boolean and enumerated variables
- bounded integer variables (binary encoding)
- SMV is not efficient for integers, but it can be fixed
- fixed size arrays
Example Mutual Exclusion Protocol
Process 1: while (true) { out: a := true; turn := true; wait: await (b = false or turn = false); cs: a := false; } || Process 2: while (true) { out: b := true; turn := false; wait: await (a = false or turn); cs: b := false; } Two concurrently executing processes are trying to enter a critical section without violating mutual exclusion
Example Mutual Exclusion Protocol in SMV
MODULE VAR process1(a,b,turn) ASSIGN^ pc:^ {out,^ wait,^ cs}; init(pc) next(pc) :=:= out; case pc=out : wait; pc=wait pc=cs : &out; (!b | !turn) : cs; esac;^1 :^ pc; next(turn) case := pc=out 1 : turn; : 1; next(a)^ esac; := case pc=out : 1; pc=cs 1 : a; : 0; next(b)^ esac; := b; FAIRNESS running MODULE VAR process2(a,b,turn) ASSIGN^ pc:^ {out,^ wait,^ cs}; init(pc) next(pc) :=:= out; case pc=out : wait; pc=wait pc=cs : &out; (!a | turn) : cs; esac;^1 :^ pc; next(turn) case := pc=out 1 : turn; : 0; next(b)^ esac; := case pc=out : 1; pc=cs 1 : b; : 0; next(a)^ esac; := a; FAIRNESS running
Example Mutual Exclusion Protocol in SMV
MODULE VAR main a b :: boolean;boolean; turn p1 : :process boolean; process1(a,b,turn); SPEC^ p2^ :^ process^ process2(a,b,turn); AG(!(p1.pc=cs -- AG(p1.pc=wait & p2.pc=cs)) -> AF(p1.pc=cs)) & AG(p2.pc=wait -> AF(p2.pc=cs)) Here is the output when I run SMV on this example to check the mutual exclusion property % smv mutex.smv -- specification AG (!(p1.pc = cs & p2.pc = cs)) is true resources user time: used: 0.01 s, system time: 0 s BDD Bytes nodes allocated: allocated: 1245184 692 BDD nodes representing transition relation: 143 + 6
Example Mutual Exclusion Protocol in SMV
The output for the starvation freedom property: % -- smv specification mutex.smv AG (p1.pc = wait -> AF p1.pc = cs) & AG ... is true resources user time: used: 0 s, system time: 0 s BDD Bytes nodes allocated: allocated: 1245184 1251 BDD nodes representing transition relation: 143 + 6
Example Mutual Exclusion Protocol in SMV
Let’s insert an error change pc=wait & (!b | !turn) : cs; to pc=wait & (!b | turn) : cs; % -- smv specification mutex.smv AG (!(p1.pc = cs & p2.pc = cs)) is false -- state as demonstrated1.1: by the following execution sequence a b == (^00) turn p1.pc = = (^0) out p2.pc [stuttering] = out state [executing 1.2: process p2] state b = 1 1.3: p2.pc [executing = wait process p2] state p2.pc 1.4:= cs [executing process p1] state a = 1 1.5: turn p1.pc = = (^1) wait [executing process p1] state p1.pc 1.6:= cs [stuttering] resources user time: used: 0.01 s, system time: 0 s BDD Bytes nodes allocated: allocated: 1245184 1878 BDD nodes representing transition relation: 143 + 6