SlideShare a Scribd company logo
1 of 104
Download to read offline
Satisfiability Modulo Theories
Lecture 8 - Introduction to SMT-based
Model-Checking
(slides revision: Saturday 14th
March, 2015, 11:47)
Roberto Bruttomesso
Seminario di Logica Matematica
(Corso Prof. Silvio Ghilardi)
15 Dicembre 2011
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 1 / 44
Outline
1 Basics
Modeling
Checking
Implementing a Model-Checker
2 mcmt
Two simple protocols
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 2 / 44
Introduction
Model-Checking is a set of techniques to approach the verification of a
system (e.g., a hardware circuit, a program, a protocol)
It was proposed by Clarke-Emerson and Sifakis-Quine as a way of
automatically prove properties of a system
The authors received the Turing Award in 2007
The idea of model-checking was in contrast with the established
“philosophy” at that time (∼ 1980) which was suggesting
semi-automatic human-driven approaches: MC is loved by industry
because of this “push-button” characteristic
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 3 / 44
Model-Checking - Modeling
In MC we model the behavior of a system with the notion of state. A
state is a configuration of the system at a particular time instant
The system can change state by means of a transition
We are interested in a property of the system
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 4 / 44
Model-Checking - Modeling
In MC we model the behavior of a system with the notion of state. A
state is a configuration of the system at a particular time instant
The system can change state by means of a transition
We are interested in a property of the system
Example:
System: a washing machine
A state: “the door is open and the engine is off”
A transition: “if the door is open then close the door”
A property: “When the engine is on, the door is closed”
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 4 / 44
System to Model
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 5 / 44
Modeling - States
State variables can be used to describe a particular state
State variable Values
door open, closed
tray empty, filled
engine off, on
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 6 / 44
Modeling - States
State variables can be used to describe a particular state
State variable Values
door open, closed
tray empty, filled
engine off, on
E.g.:
door=open
engine=on
tray=empty
which stands for “the door is open, the engine is on, and the tray is
empty”.
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 6 / 44
Modeling - States
State variables can be used to describe a particular state
State variable Values
door open, closed
tray empty, filled
engine off, on
E.g.:
door=open
engine=on
tray=empty
which stands for “the door is open, the engine is on, and the tray is
empty”.How many different states can we describe with our state
variables ?
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 6 / 44
Modeling - States
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
door=open
engine=off
tray=full
door=closed
engine=off
tray=full
door=closed
engine=on
tray=empty
door=open
engine=on
tray=full
door=open
engine=on
tray=empty
door=closed
engine=on
tray=full
Some states are called initial (green). Initial states are the
configurations of the system at time 0
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 7 / 44
Modeling - Transitions
Transitions describe the evolution of the system. They transform the
“current” state into a “next” state
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 8 / 44
Modeling - Transitions
Transitions describe the evolution of the system. They transform the
“current” state into a “next” state
Transition Name
if door=open then door’=closed [close door]
if tray=empty then tray’=full [fill tray]
if
engine=off
then
engine’=on
[start wash]
door=closed tray’=empty
if door=closed then
door’=open
[open door]
engine’=off
var’ indicates the value of var in the next state
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 8 / 44
Modeling - Transitions
if door=open then door’=closed [close door]
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
close door
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
Modeling - Transitions
if door=open then door’=closed [close door]
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
close door
if tray=empty then tray’=full [fill tray]
door=open
engine=off
tray=empty
door=open
engine=off
tray=full
fill tray
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
Modeling - Transitions
if door=open then door’=closed [close door]
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
close door
if tray=empty then tray’=full [fill tray]
door=open
engine=off
tray=empty
door=open
engine=off
tray=full
fill tray
if door=closed then
door’=open
[open door]
engine’=off
door=closed
engine=on
tray=full
door=open
engine=off
tray=full
open door
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
Modeling - Transitions
if door=open then door’=closed [close door]
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
close door
if tray=empty then tray’=full [fill tray]
door=open
engine=off
tray=empty
door=open
engine=off
tray=full
fill tray
if door=closed then
door’=open
[open door]
engine’=off
door=closed
engine=on
tray=full
door=open
engine=off
tray=full
open door
if
door=closed
then
tray’=empty
[start washing]
engine=off engine’=on
door=closed
engine=off
tray=full
door=closed
engine=on
tray=empty
start washing
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
Modeling - (Safety) Property
Last step, we need to model the property
“when the engine is on the door is closed”
It is a safety property: they are easy to define as they are properties
of the states
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 10 / 44
Modeling - (Safety) Property
Last step, we need to model the property
“when the engine is on the door is closed”
It is a safety property: they are easy to define as they are properties
of the states
We call bad state (or unsafe state) a state that does not satisfy the
property
door=open
engine=on
tray=full
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 10 / 44
Checking (= Reachability)
To establish if a model satisfies a safety property amounts to check if
some bad state is reachable from the set of initial states
This can be done automatically by visiting the set of states that are
reachable from the initial state with the application of a transition
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 11 / 44
Checking (= Reachability)
To establish if a model satisfies a safety property amounts to check if
some bad state is reachable from the set of initial states
This can be done automatically by visiting the set of states that are
reachable from the initial state with the application of a transition
Let S(0) be the set of initial states. Algorithmically, it amounts to
implement the following loop (iteration i)
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
T(S(i)) = states that can be reached from S(i) with a transition
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 11 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(3)
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(3)
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(3)
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(2)
S(1)
S(0)
BAD
S(4)
≡ S(3)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(2)
S(1)
S(0)
BAD
S(4)
≡ S(3)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
Checking - Forward Reachability - Property Not Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(4)S(3)
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 13 / 44
Checking - Forward Reachability - Property Not Verified
Forward-Reachability
Safety Check If S(i) contains a bad state, return unsafe
Next States Compute S(i+1) := S(i) ∪ T(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(4)S(3)
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 13 / 44
Back to the washing machine
Iteration: 0
door=open
engine=off
tray=empty
door=open
engine=on
tray=full
door=open
engine=on
tray=empty
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
Back to the washing machine
Iteration: 1
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
door=open
engine=off
tray=full
door=open
engine=on
tray=full
door=open
engine=on
tray=empty
close door
fill tray
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
Back to the washing machine
Iteration: 2
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
door=open
engine=off
tray=full
door=closed
engine=off
tray=full
door=closed
engine=on
tray=empty
door=open
engine=on
tray=full
door=open
engine=on
tray=empty
close door
fill tray
open door
start washing
fill tray
close door
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
Back to the washing machine
Iteration: 3
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
door=open
engine=off
tray=full
door=closed
engine=off
tray=full
door=closed
engine=on
tray=empty
door=open
engine=on
tray=full
door=closed
engine=on
tray=full
door=open
engine=on
tray=empty
close door
fill tray
open door
start washing
fill tray
close door
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
Back to the washing machine
Iteration: 4 - Fix Point Reached - System is SAFE
door=open
engine=off
tray=empty
door=closed
engine=off
tray=empty
door=open
engine=off
tray=full
door=closed
engine=off
tray=full
door=closed
engine=on
tray=empty
door=open
engine=on
tray=full
door=closed
engine=on
tray=full
door=open
engine=on
tray=empty
close door
fill tray
open door
start washing
fill tray
close door
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
Checking - Backward Reachability
Backward-Reachability (S(0) ≡ “bad states”)
Safety Check If S(i) contains an initial, return unsafe
Next States Compute S(i+1) := S(i) ∪ T−1(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(2)
S(1)
S(0)
BAD
S(4)
≡ S(3)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 15 / 44
Checking - Backward Reachability
Backward-Reachability (S(0) ≡ “bad states”)
Safety Check If S(i) contains an initial, return unsafe
Next States Compute S(i+1) := S(i) ∪ T−1(S(i))
Fix-Point Check If S(i+1) ≡ S(i), return safe
S(4)
S(3)
S(2)
S(1)
S(0)
BAD
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 15 / 44
Implementing a Model-Checker
In order to implement model-checker we need:
1 representing large sets of states
2 computing T(S(i))
3 check if bad states are in S(i)
4 check if S(i) ≡ S(i+1)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 16 / 44
Implementing a Model-Checker
In order to implement model-checker we need:
1 representing large sets of states
2 computing T(S(i))
3 check if bad states are in S(i)
4 check if S(i) ≡ S(i+1)
The naive way would be to represent states explicitly (e.g., with a C
struct containing values for state variables)
Very few model-checkers adopt this method (e.g., SPIN)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 16 / 44
Implementing a Model-Checker
In order to implement model-checker we need:
1 representing large sets of states
2 computing T(S(i))
3 check if bad states are in S(i)
4 check if S(i) ≡ S(i+1)
The naive way would be to represent states explicitly (e.g., with a C
struct containing values for state variables)
Very few model-checkers adopt this method (e.g., SPIN)
A more powerful approach represents states symbolically, by means
of SAT/SMT-formulæ: each set of states S is represented by a formula
φ such that S corresponds to the models of φ
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 16 / 44
Symbolic Model-Checking - Representing States
Examples:
door=open
engine=on
tray=empty
door open ∧ engine on ∧ ¬ tray full
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
Symbolic Model-Checking - Representing States
Examples:
door=open
engine=on
tray=empty
door open ∧ engine on ∧ ¬ tray full
door=closed
engine=on
tray=empty
¬ door open ∧ engine on ∧ ¬ tray full
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
Symbolic Model-Checking - Representing States
Examples:
door=open
engine=on
tray=empty
door open ∧ engine on ∧ ¬ tray full
door=closed
engine=on
tray=empty
¬ door open ∧ engine on ∧ ¬ tray full
door=open
engine=on
tray=empty
door=closed
engine=on
tray=empty
engine on ∧ ¬ tray full
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
Symbolic Model-Checking - Representing States
Examples:
door=open
engine=on
tray=empty
door open ∧ engine on ∧ ¬ tray full
door=closed
engine=on
tray=empty
¬ door open ∧ engine on ∧ ¬ tray full
door=open
engine=on
tray=empty
door=closed
engine=on
tray=empty
engine on ∧ ¬ tray full
Also, it is easy to see that:
S1 ∪ S2 φ1 ∨ φ2
S1 ∩ S2 φ1 ∧ φ2
S1 ⊆ S2 φ1 → φ2
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
Symbolic Model-Checking - Representing Transitions
Transitions are also represented as formulæ between state variables and their primed
versions
if
door=closed
then
tray’=empty
[start washing]
engine=off engine’=on
¬door open ∧ ¬engine on ∧ ¬door open’ ∧ engine on’ ∧ ¬tray full’
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 18 / 44
Symbolic Model-Checking - Representing Transitions
Transitions are also represented as formulæ between state variables and their primed
versions
if
door=closed
then
tray’=empty
[start washing]
engine=off engine’=on
¬door open ∧ ¬engine on ∧ ¬door open’ ∧ engine on’ ∧ ¬tray full’
This formula says that the following pair of states are related
¬door open ∧ ¬engine on ∧ ¬tray full ¬door open’ ∧ engine on’ ∧ ¬tray full’
¬door open ∧ ¬engine on ∧ tray full ¬door open’ ∧ engine on’ ∧ ¬tray full’
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 18 / 44
Symbolic Model-Checking - Computing Next State
From a set of states S(i), represented symbolically by a formula φ(s), and a transition tj,
represented symbolically by a formula ψ(s, s ), the next states tj(S(i)) can be expressed as
∃s. φ(s) ∧ ψ(s, s )
By means of an operation called quantifier elimination, we can remove s. If then we
rename s as s we obtain the symbolic representation of tj(S(i))
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 19 / 44
Symbolic Model-Checking - Computing Next State
From a set of states S(i), represented symbolically by a formula φ(s), and a transition tj,
represented symbolically by a formula ψ(s, s ), the next states tj(S(i)) can be expressed as
∃s. φ(s) ∧ ψ(s, s )
By means of an operation called quantifier elimination, we can remove s. If then we
rename s as s we obtain the symbolic representation of tj(S(i))
Example:
φ ≡ ¬door open ∧ ¬engine on
ψ ≡ ¬door open ∧ ¬engine on ∧ ¬door open’ ∧ engine on’ ∧ ¬tray full’
Quantifier elimination of ∃ door open, engine on. φ ∧ ψ is
¬door open’ ∧ engine on’ ∧ ¬tray full’
and therefore
¬door open ∧ engine on ∧ ¬tray full
is tj(S(i)). The whole set of next states T(S(i)) is j tj(S(i))
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 19 / 44
Symbolic Model-Checking - Bad states in S(i)
Suppose that φ is the symbolic representation of S(i), and that β is the
symbolic representation of the bad states
checking if some bad state is in S(i) can be simply done with
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 20 / 44
Symbolic Model-Checking - Bad states in S(i)
Suppose that φ is the symbolic representation of S(i), and that β is the
symbolic representation of the bad states
checking if some bad state is in S(i) can be simply done with
φ ∧ β is satisfiable ?
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 20 / 44
Symbolic Model-Checking - Fix point test
Suppose that φi is the symbolic representation of S(i) and that φi+1 is
the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ?
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
Symbolic Model-Checking - Fix point test
Suppose that φi is the symbolic representation of S(i) and that φi+1 is
the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ?
First of all, notice that S(i) ≡ S(i+1) if and only if
S(i)
⊆ S(i+1)
and S(i+1)
⊆ S(i)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
Symbolic Model-Checking - Fix point test
Suppose that φi is the symbolic representation of S(i) and that φi+1 is
the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ?
First of all, notice that S(i) ≡ S(i+1) if and only if
S(i)
⊆ S(i+1)
and S(i+1)
⊆ S(i)
S(i) ⊆ S(i+1) always holds (explored states grow monotonically)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
Symbolic Model-Checking - Fix point test
Suppose that φi is the symbolic representation of S(i) and that φi+1 is
the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ?
First of all, notice that S(i) ≡ S(i+1) if and only if
S(i)
⊆ S(i+1)
and S(i+1)
⊆ S(i)
S(i) ⊆ S(i+1) always holds (explored states grow monotonically)
S(i+1) ⊆ S(i) can be perfomed with the following check
φi+1 → φi is a tautology ? or equivalently
φi+1 ∧ ¬φi is unsafisfiable ?
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
Symbolic Model-Checking - Summary
Model-Checking can be implemented by representing states and
transitions symbolically with SAT/SMT-formulæ
Next states T(S(i)) can be computed using quantifier elimination
Presence of bad states can be computed with a satisfiability call of the
form φ ∧ β
Fix-point check can be computed with a satisfiability call of the form
φi+1 ∧ ¬φi
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 22 / 44
Symbolic Model-Checking - Termination
Forward-Reachability
Safety Check If φi ∧ β is satisfiable, return unsafe
Next States Compute φi+1 with quantifier elimination
Fix-Point Check If φi+1 ∧ ¬φi is unsatisfiable, return safe
Model-Checking always terminates if the satisfiability tests above
terminates
If the system under inspection is a finite state machine,
everything can be encoded into Booleans, and so they always
terminate (SAT-solver is enough)
If the system has infinite states (e.g., 0 ≤ x ∧ y ≥ 2), it
terminates if everyting can be encoded into a decidable SMT
theory (e.g., LIA) (SMT-Solver necessary)
If quantifiers are needed to express states, then
Forward-Reachability might not terminate (SMT-Solver plus
clever way of handling quantifiers)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 23 / 44
Outline
1 Basics
Modeling
Checking
Implementing a Model-Checker
2 mcmt
Two simple protocols
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 24 / 44
mcmt: Model-Checking Modulo Theories
mcmt is a Model-Checker invented and developed by S. Ghilardi and
S. Ranise et al. (see http://www.dsi.unimi.it/ ghilardi/mcmt/ for
complete and precise acknowledgements)
It implements a Symbolic Backward-Reachability algorithm (it relies
on yices)
It was invented to handle safety properties for distributed algorithms
(protocols), which are infinite-state systems
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 25 / 44
mcmt demo
The following example is taken from the tutorial
Model Checking Modulo Theories: Theory and Practice
available at http://st.fbk.eu/MCMTtutorial
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 26 / 44
A simple protocol
Description
l = 1start
l = 2
l = 3
l = 4
No data, only locations
All processes start from the 1st location
A process in location 3 is inside the critical
section
We want to check if the protocol ensures the
mutual exclusion, i.e., at most one process is
inside the critical section
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 27 / 44
A simple protocol
Variable
l = 1start
l = 2
l = 3
l = 4
One local variable l
:smt (define-type locations (subrange 1 4))
:local l locations
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 28 / 44
A simple protocol
Initial configuration
l = 1start
l = 2
l = 3
l = 4
All processes start in location 1
∀x.(l[x] = 1)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 29 / 44
A simple protocol
Initial configuration
l = 1start
l = 2
l = 3
l = 4
All processes start in location 1
∀x.(l[x] = 1)
:initial
:var x
:cnj (= l[x] 1)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 29 / 44
A simple protocol
Unsafe configuration
l = 1start
l = 2
l = 3
l = 4
Mutual exclusion: At most one process is in
location 3
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 30 / 44
A simple protocol
Unsafe configuration
l = 1start
l = 2
l = 3
l = 4
Mutual exclusion: At most one process is in
location 3
U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 30 / 44
A simple protocol
Unsafe configuration
l = 1start
l = 2
l = 3
l = 4
Mutual exclusion: At most one process is in
location 3
U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2)
:unsafe
:var z1
:var z2
:cnj (= l[z1] 3) (= l[z2] 3)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 30 / 44
A simple protocol
Transitions
l = 1start
l = 2
l = 3
l = 4
A process in location 1 moves to location 2
τ1 := ∃x.
l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 31 / 44
A simple protocol
Transitions
l = 1start
l = 2
l = 3
l = 4
A process in location 1 moves to location 2
τ1 := ∃x.
l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
:transition
:var x
:var j
:guard (= l[x] 1)
:numcases 2
:case (= x j)
:val 2
:case (not (= x j))
:val l[j]
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 31 / 44
A simple protocol
Transitions
l = 1start
l = 2
l = 3
l = 4
:transition
:var x
:var j
:guard (= l[x] 1)
:numcases 2
:case (= x j)
:val 2
:case (not (= x j))
:val l[j]
:transition
:var x
:var j
:guard (= l[x] 3)
:numcases 2
:case (= x j)
:val 4
:case (not (= x j))
:val l[j]
:transition
:var x
:var j
:guard (= l[x] 2)
:numcases 2
:case (= x j)
:val 3
:case (not (= x j))
:val l[j]
:transition
:var x
:var j
:guard (= l[x] 4)
:numcases 2
:case (= x j)
:val 1
:case (not (= x j))
:val l[j]
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 32 / 44
A simple protocol
Execution
l = 1start
l = 2
l = 3
l = 4
$ ./mcmt simple unsafe.in
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 33 / 44
A simple protocol
Execution - Get informations from counterexample
[...]
Doing state space exploration...
node 1= [t2_1][0]
node 2= [t1_1][t2_1][0]
node 3= [t2_2][t2_1][0]
node 4= [t2_2][t1_1][t2_1][0]
node 5= [t4_1][t1_1][t2_1][0]
node 6= [t1_2][t2_2][t1_1][t2_1][0]
=============================================================================
System is UNSAFE!
[...]
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 34 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ2 := ∃x.
l[x] = 2 ∧
l = λj. (if (x = j) then 3 else l[j])
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ2 := ∃x.
l[x] = 2 ∧
l = λj. (if (x = j) then 3 else l[j])
z1 z2
l = 3 l = 3
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ2 := ∃x.
l[x] = 2 ∧
l = λj. (if (x = j) then 3 else l[j])
z1 z2
l = 3 l = 3
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ2 := ∃x.
l[x] = 2 ∧
l = λj. (if (x = j) then 3 else l[j])
z1 z2
l = 2 l = 3
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ1 := ∃x.
l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
z1 z2
l = 2 l = 3
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ1 := ∃x.
l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
z1 z2
l = 1 l = 3
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
[t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ2 := ∃x.
l[x] = 2 ∧
l = λj. (if (x = j) then 3 else l[j])
z1 z2
l = 1 l = 3
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
[t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ2 := ∃x.
l[x] = 2 ∧
l = λj. (if (x = j) then 3 else l[j])
z1 z2
l = 1 l = 2
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
[t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 )
[t2_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 2 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ1 := ∃x.
l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
z1 z2
l = 1 l = 2
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
[t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 )
[t2_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 2 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
A simple protocol
Counterexample analysis from trace
Initial state: ∀i. ( l[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0]
τ1 := ∃x.
l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
z1 z2
l = 1 l = 1
[0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
[t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 )
[t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 )
[t2_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 2 )
[t1_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 1 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
Another simple protocol
Description
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
Like before, but with a global flag c that
takes care of mutual exclusion
All processes start from the 1st location
A process in location 3 is inside the critical
section
We want to check if the protocol ensures the
mutual exclusion, i.e., at most one process is
inside the critical section
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 36 / 44
Another simple protocol
Variable(s)
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
One local variable l
:smt (define-type locations (subrange 1 4))
:smt (define-type counter (subrange 1 2))
:local l location
:global c counter
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 37 / 44
Another simple protocol
Initial configuration
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
All processes start in location 1, with counter
set to 1
∀x. ( l[x] = 1 ∧ c[x] = 1 )
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 38 / 44
Another simple protocol
Initial configuration
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
All processes start in location 1, with counter
set to 1
∀x. ( l[x] = 1 ∧ c[x] = 1 )
:initial
:var x
:cnj (= l[x] 1) (= c[x] 1)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 38 / 44
Another simple protocol
Unsafe configuration
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
Mutual exclusion: At most one process is in
location 3
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 39 / 44
Another simple protocol
Unsafe configuration
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
Mutual exclusion: At most one process is in
location 3
U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 39 / 44
Another simple protocol
Unsafe configuration
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
Mutual exclusion: At most one process is in
location 3
U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2)
:unsafe
:var z1
:var z2
:cnj (= l[z1] 3) (= l[z2] 3)
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 39 / 44
Another simple protocol
Transitions
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 40 / 44
Another simple protocol
Transitions
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



:transition
:var x
:var j
:guard (= l[x] 2) (= c[x] 1)
:numcases 2
:case (= x j)
:val 3
:val 2
:case (not (= x j))
:val l[j]
:val 2
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 40 / 44
Another simple protocol
Transitions
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
:transition
:var x
:var j
:guard (= l[x] 1)
:numcases 2
:case (= x j)
:val 2
:val c[x]
:case (not (= x j))
:val l[j]
:val c[x]
:transition
:var x
:var j
:guard (= l[x] 3) (= c[x] 2)
:numcases 2
:case (= x j)
:val 4
:val 1
:case (not (= x j))
:val l[j]
:val 1
:transition
:var x
:var j
:guard (= l[x] 2) (= c[x] 1)
:numcases 2
:case (= x j)
:val 3
:val 2
:case (not (= x j))
:val l[j]
:val 2
:transition
:var x
:var j
:guard (= l[x] 4)
:numcases 2
:case (= x j)
:val 1
:val c[j]
:case (not (= x j))
:val l[j]
:val c[j]
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 41 / 44
Another simple protocol
Execution
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
$ ./mcmt simple safe.in
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 42 / 44
Another simple protocol
Execution
[...]
Doing state space exploration...
node 1 = [t2_1][0]
node 2 = [t1_1][t2_1][0]
node 3 = [t4_1][t1_1][t2_1][0]
=============================================================================
Global fixpoint reached!
System is SAFE!
[...]
R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 43 / 44
A simple protocol
Set of (un)reachable states
Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
t1
t2
t3
t4
l = 3 l = 3
τ1 := ∃x.



l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
c = λj.c[j]



τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



τ3 := ∃x.



l[x] = 3 ∧ c[x] = 2 ∧
l = λj. (if (x = j) then 4 else l[j])
c = λj.1



τ4 := ∃x.



l[x] = 4 ∧
l = λj. (if (x = j) then 1 else l[j])
c = λj.c[j]



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
A simple protocol
Set of (un)reachable states
Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
t1
t2
t3
t4
l = 2
c = 1
l = 3
c = 1
l = 3 l = 3
t2 z1
τ1 := ∃x.



l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
c = λj.c[j]



τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



τ3 := ∃x.



l[x] = 3 ∧ c[x] = 2 ∧
l = λj. (if (x = j) then 4 else l[j])
c = λj.1



τ4 := ∃x.



l[x] = 4 ∧
l = λj. (if (x = j) then 1 else l[j])
c = λj.c[j]



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
A simple protocol
Set of (un)reachable states
Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
t1
t2
t3
t4
l = 1
c = 1
l = 3
c = 1
l = 2
c = 1
l = 3
c = 1
l = 3 l = 3
t1 z1
t2 z1
τ1 := ∃x.



l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
c = λj.c[j]



τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



τ3 := ∃x.



l[x] = 3 ∧ c[x] = 2 ∧
l = λj. (if (x = j) then 4 else l[j])
c = λj.1



τ4 := ∃x.



l[x] = 4 ∧
l = λj. (if (x = j) then 1 else l[j])
c = λj.c[j]



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
A simple protocol
Set of (un)reachable states
Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
t1
t2
t3
t4
l = 4
c = 1
l = 3
c = 1
l = 1
c = 1
l = 3
c = 1
l = 2
c = 1
l = 3
c = 1
l = 3 l = 3
t4 z1
t1 z1
t2 z1
τ1 := ∃x.



l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
c = λj.c[j]



τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



τ3 := ∃x.



l[x] = 3 ∧ c[x] = 2 ∧
l = λj. (if (x = j) then 4 else l[j])
c = λj.1



τ4 := ∃x.



l[x] = 4 ∧
l = λj. (if (x = j) then 1 else l[j])
c = λj.c[j]



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
A simple protocol
Set of (un)reachable states
Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
t1
t2
t3
t4
l = 3
c = 2
l = 3
c = 2
l = 4
c = 1
l = 3
c = 1
l = 1
c = 1
l = 3
c = 1
l = 2
c = 1
l = 3
c = 1
l = 3 l = 3
t3 z1
t4 z1
t1 z1
t2 z1
τ1 := ∃x.



l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
c = λj.c[j]



τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



τ3 := ∃x.



l[x] = 3 ∧ c[x] = 2 ∧
l = λj. (if (x = j) then 4 else l[j])
c = λj.1



τ4 := ∃x.



l[x] = 4 ∧
l = λj. (if (x = j) then 1 else l[j])
c = λj.c[j]



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
A simple protocol
Set of (un)reachable states
Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 )
Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 )
l = 1
c = 1start
l = 2
c = 1
l = 3
c = 2
l = 4
c = 1
t1
t2
t3
t4
l = 4
c = 1
l = 3
c = 1
l = 1
c = 1
l = 3
c = 1
l = 2
c = 1
l = 3
c = 1
l = 3 l = 3
t4 z1
t1 z1
t2 z1
τ1 := ∃x.



l[x] = 1 ∧
l = λj. (if (x = j) then 2 else l[j])
c = λj.c[j]



τ2 := ∃x.



l[x] = 2 ∧ c[x] = 1 ∧
l = λj. (if (x = j) then 3 else l[j])
c = λj.2



τ3 := ∃x.



l[x] = 3 ∧ c[x] = 2 ∧
l = λj. (if (x = j) then 4 else l[j])
c = λj.1



τ4 := ∃x.



l[x] = 4 ∧
l = λj. (if (x = j) then 1 else l[j])
c = λj.c[j]



R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44

More Related Content

Viewers also liked (17)

Trabajo de angie.
Trabajo de angie.Trabajo de angie.
Trabajo de angie.
 
Trabajo de angie.
Trabajo de angie.Trabajo de angie.
Trabajo de angie.
 
Mi 2013
Mi 2013Mi 2013
Mi 2013
 
Mi pagina web
Mi pagina webMi pagina web
Mi pagina web
 
Belajarbahasainggris
BelajarbahasainggrisBelajarbahasainggris
Belajarbahasainggris
 
Trabajo de angie.
Trabajo de angie.Trabajo de angie.
Trabajo de angie.
 
Algo se muere en el alma
Algo se muere en el almaAlgo se muere en el alma
Algo se muere en el alma
 
smtlecture.5
smtlecture.5smtlecture.5
smtlecture.5
 
Trabajo de angie.
Trabajo de angie.Trabajo de angie.
Trabajo de angie.
 
Motivasi belajar
Motivasi belajarMotivasi belajar
Motivasi belajar
 
SGS Tekniks - Best Electronic Contract Manufacturing Company in India
SGS Tekniks - Best Electronic Contract Manufacturing Company in IndiaSGS Tekniks - Best Electronic Contract Manufacturing Company in India
SGS Tekniks - Best Electronic Contract Manufacturing Company in India
 
Tidal wave
Tidal waveTidal wave
Tidal wave
 
PCB Assembly Manual insertion line
PCB Assembly Manual insertion linePCB Assembly Manual insertion line
PCB Assembly Manual insertion line
 
Dossier de presse Midest mai 2013
Dossier de presse Midest mai 2013Dossier de presse Midest mai 2013
Dossier de presse Midest mai 2013
 
Component & assembly issues in PCB design
Component & assembly issues in PCB designComponent & assembly issues in PCB design
Component & assembly issues in PCB design
 
Surface Mount Technology
 Surface Mount Technology Surface Mount Technology
Surface Mount Technology
 
Electronic manufacturing v3.0 - Fab Academy 2016
Electronic manufacturing v3.0 - Fab Academy 2016Electronic manufacturing v3.0 - Fab Academy 2016
Electronic manufacturing v3.0 - Fab Academy 2016
 

Similar to smtlecture.8 (13)

C programming slide c03
C programming slide c03C programming slide c03
C programming slide c03
 
19-MooreMealy.ppt
19-MooreMealy.ppt19-MooreMealy.ppt
19-MooreMealy.ppt
 
Ch01-1.ppt
Ch01-1.pptCh01-1.ppt
Ch01-1.ppt
 
Ch01-1.ppt
Ch01-1.pptCh01-1.ppt
Ch01-1.ppt
 
19 moore mealy
19 moore mealy19 moore mealy
19 moore mealy
 
smtlecture.3
smtlecture.3smtlecture.3
smtlecture.3
 
5 csp
5 csp5 csp
5 csp
 
state_machines1.pdf
state_machines1.pdfstate_machines1.pdf
state_machines1.pdf
 
19-MooreMealy.ppt
19-MooreMealy.ppt19-MooreMealy.ppt
19-MooreMealy.ppt
 
Ch01-1.pdf
Ch01-1.pdfCh01-1.pdf
Ch01-1.pdf
 
smtlecture.9
smtlecture.9smtlecture.9
smtlecture.9
 
Anti-Lock Braking System using FUZZY LOGIC
Anti-Lock Braking System using FUZZY LOGICAnti-Lock Braking System using FUZZY LOGIC
Anti-Lock Braking System using FUZZY LOGIC
 
Control system unit(1)
Control system unit(1)Control system unit(1)
Control system unit(1)
 

More from Roberto Bruttomesso (6)

smtlecture.10
smtlecture.10smtlecture.10
smtlecture.10
 
smtlecture.7
smtlecture.7smtlecture.7
smtlecture.7
 
smtlecture.6
smtlecture.6smtlecture.6
smtlecture.6
 
smtlectures.2
smtlectures.2smtlectures.2
smtlectures.2
 
satandsmt.stpetersburg
satandsmt.stpetersburgsatandsmt.stpetersburg
satandsmt.stpetersburg
 
smtlectures.1
smtlectures.1smtlectures.1
smtlectures.1
 

Recently uploaded

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

smtlecture.8

  • 1. Satisfiability Modulo Theories Lecture 8 - Introduction to SMT-based Model-Checking (slides revision: Saturday 14th March, 2015, 11:47) Roberto Bruttomesso Seminario di Logica Matematica (Corso Prof. Silvio Ghilardi) 15 Dicembre 2011 R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 1 / 44
  • 2. Outline 1 Basics Modeling Checking Implementing a Model-Checker 2 mcmt Two simple protocols R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 2 / 44
  • 3. Introduction Model-Checking is a set of techniques to approach the verification of a system (e.g., a hardware circuit, a program, a protocol) It was proposed by Clarke-Emerson and Sifakis-Quine as a way of automatically prove properties of a system The authors received the Turing Award in 2007 The idea of model-checking was in contrast with the established “philosophy” at that time (∼ 1980) which was suggesting semi-automatic human-driven approaches: MC is loved by industry because of this “push-button” characteristic R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 3 / 44
  • 4. Model-Checking - Modeling In MC we model the behavior of a system with the notion of state. A state is a configuration of the system at a particular time instant The system can change state by means of a transition We are interested in a property of the system R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 4 / 44
  • 5. Model-Checking - Modeling In MC we model the behavior of a system with the notion of state. A state is a configuration of the system at a particular time instant The system can change state by means of a transition We are interested in a property of the system Example: System: a washing machine A state: “the door is open and the engine is off” A transition: “if the door is open then close the door” A property: “When the engine is on, the door is closed” R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 4 / 44
  • 6. System to Model R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 5 / 44
  • 7. Modeling - States State variables can be used to describe a particular state State variable Values door open, closed tray empty, filled engine off, on R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 6 / 44
  • 8. Modeling - States State variables can be used to describe a particular state State variable Values door open, closed tray empty, filled engine off, on E.g.: door=open engine=on tray=empty which stands for “the door is open, the engine is on, and the tray is empty”. R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 6 / 44
  • 9. Modeling - States State variables can be used to describe a particular state State variable Values door open, closed tray empty, filled engine off, on E.g.: door=open engine=on tray=empty which stands for “the door is open, the engine is on, and the tray is empty”.How many different states can we describe with our state variables ? R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 6 / 44
  • 11. Modeling - Transitions Transitions describe the evolution of the system. They transform the “current” state into a “next” state R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 8 / 44
  • 12. Modeling - Transitions Transitions describe the evolution of the system. They transform the “current” state into a “next” state Transition Name if door=open then door’=closed [close door] if tray=empty then tray’=full [fill tray] if engine=off then engine’=on [start wash] door=closed tray’=empty if door=closed then door’=open [open door] engine’=off var’ indicates the value of var in the next state R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 8 / 44
  • 13. Modeling - Transitions if door=open then door’=closed [close door] door=open engine=off tray=empty door=closed engine=off tray=empty close door R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
  • 14. Modeling - Transitions if door=open then door’=closed [close door] door=open engine=off tray=empty door=closed engine=off tray=empty close door if tray=empty then tray’=full [fill tray] door=open engine=off tray=empty door=open engine=off tray=full fill tray R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
  • 15. Modeling - Transitions if door=open then door’=closed [close door] door=open engine=off tray=empty door=closed engine=off tray=empty close door if tray=empty then tray’=full [fill tray] door=open engine=off tray=empty door=open engine=off tray=full fill tray if door=closed then door’=open [open door] engine’=off door=closed engine=on tray=full door=open engine=off tray=full open door R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
  • 16. Modeling - Transitions if door=open then door’=closed [close door] door=open engine=off tray=empty door=closed engine=off tray=empty close door if tray=empty then tray’=full [fill tray] door=open engine=off tray=empty door=open engine=off tray=full fill tray if door=closed then door’=open [open door] engine’=off door=closed engine=on tray=full door=open engine=off tray=full open door if door=closed then tray’=empty [start washing] engine=off engine’=on door=closed engine=off tray=full door=closed engine=on tray=empty start washing R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 9 / 44
  • 17. Modeling - (Safety) Property Last step, we need to model the property “when the engine is on the door is closed” It is a safety property: they are easy to define as they are properties of the states R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 10 / 44
  • 18. Modeling - (Safety) Property Last step, we need to model the property “when the engine is on the door is closed” It is a safety property: they are easy to define as they are properties of the states We call bad state (or unsafe state) a state that does not satisfy the property door=open engine=on tray=full R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 10 / 44
  • 19. Checking (= Reachability) To establish if a model satisfies a safety property amounts to check if some bad state is reachable from the set of initial states This can be done automatically by visiting the set of states that are reachable from the initial state with the application of a transition R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 11 / 44
  • 20. Checking (= Reachability) To establish if a model satisfies a safety property amounts to check if some bad state is reachable from the set of initial states This can be done automatically by visiting the set of states that are reachable from the initial state with the application of a transition Let S(0) be the set of initial states. Algorithmically, it amounts to implement the following loop (iteration i) Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe T(S(i)) = states that can be reached from S(i) with a transition R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 11 / 44
  • 21. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 22. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 23. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 24. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 25. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 26. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 27. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 28. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 29. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(3) S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 30. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(3) S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 31. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(3) S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 32. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(2) S(1) S(0) BAD S(4) ≡ S(3) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 33. Checking - Forward Reachability - Property Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(2) S(1) S(0) BAD S(4) ≡ S(3) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 12 / 44
  • 34. Checking - Forward Reachability - Property Not Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(4)S(3) S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 13 / 44
  • 35. Checking - Forward Reachability - Property Not Verified Forward-Reachability Safety Check If S(i) contains a bad state, return unsafe Next States Compute S(i+1) := S(i) ∪ T(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(4)S(3) S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 13 / 44
  • 36. Back to the washing machine Iteration: 0 door=open engine=off tray=empty door=open engine=on tray=full door=open engine=on tray=empty R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
  • 37. Back to the washing machine Iteration: 1 door=open engine=off tray=empty door=closed engine=off tray=empty door=open engine=off tray=full door=open engine=on tray=full door=open engine=on tray=empty close door fill tray R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
  • 38. Back to the washing machine Iteration: 2 door=open engine=off tray=empty door=closed engine=off tray=empty door=open engine=off tray=full door=closed engine=off tray=full door=closed engine=on tray=empty door=open engine=on tray=full door=open engine=on tray=empty close door fill tray open door start washing fill tray close door R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
  • 39. Back to the washing machine Iteration: 3 door=open engine=off tray=empty door=closed engine=off tray=empty door=open engine=off tray=full door=closed engine=off tray=full door=closed engine=on tray=empty door=open engine=on tray=full door=closed engine=on tray=full door=open engine=on tray=empty close door fill tray open door start washing fill tray close door R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
  • 40. Back to the washing machine Iteration: 4 - Fix Point Reached - System is SAFE door=open engine=off tray=empty door=closed engine=off tray=empty door=open engine=off tray=full door=closed engine=off tray=full door=closed engine=on tray=empty door=open engine=on tray=full door=closed engine=on tray=full door=open engine=on tray=empty close door fill tray open door start washing fill tray close door R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 14 / 44
  • 41. Checking - Backward Reachability Backward-Reachability (S(0) ≡ “bad states”) Safety Check If S(i) contains an initial, return unsafe Next States Compute S(i+1) := S(i) ∪ T−1(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(2) S(1) S(0) BAD S(4) ≡ S(3) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 15 / 44
  • 42. Checking - Backward Reachability Backward-Reachability (S(0) ≡ “bad states”) Safety Check If S(i) contains an initial, return unsafe Next States Compute S(i+1) := S(i) ∪ T−1(S(i)) Fix-Point Check If S(i+1) ≡ S(i), return safe S(4) S(3) S(2) S(1) S(0) BAD R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 15 / 44
  • 43. Implementing a Model-Checker In order to implement model-checker we need: 1 representing large sets of states 2 computing T(S(i)) 3 check if bad states are in S(i) 4 check if S(i) ≡ S(i+1) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 16 / 44
  • 44. Implementing a Model-Checker In order to implement model-checker we need: 1 representing large sets of states 2 computing T(S(i)) 3 check if bad states are in S(i) 4 check if S(i) ≡ S(i+1) The naive way would be to represent states explicitly (e.g., with a C struct containing values for state variables) Very few model-checkers adopt this method (e.g., SPIN) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 16 / 44
  • 45. Implementing a Model-Checker In order to implement model-checker we need: 1 representing large sets of states 2 computing T(S(i)) 3 check if bad states are in S(i) 4 check if S(i) ≡ S(i+1) The naive way would be to represent states explicitly (e.g., with a C struct containing values for state variables) Very few model-checkers adopt this method (e.g., SPIN) A more powerful approach represents states symbolically, by means of SAT/SMT-formulæ: each set of states S is represented by a formula φ such that S corresponds to the models of φ R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 16 / 44
  • 46. Symbolic Model-Checking - Representing States Examples: door=open engine=on tray=empty door open ∧ engine on ∧ ¬ tray full R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
  • 47. Symbolic Model-Checking - Representing States Examples: door=open engine=on tray=empty door open ∧ engine on ∧ ¬ tray full door=closed engine=on tray=empty ¬ door open ∧ engine on ∧ ¬ tray full R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
  • 48. Symbolic Model-Checking - Representing States Examples: door=open engine=on tray=empty door open ∧ engine on ∧ ¬ tray full door=closed engine=on tray=empty ¬ door open ∧ engine on ∧ ¬ tray full door=open engine=on tray=empty door=closed engine=on tray=empty engine on ∧ ¬ tray full R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
  • 49. Symbolic Model-Checking - Representing States Examples: door=open engine=on tray=empty door open ∧ engine on ∧ ¬ tray full door=closed engine=on tray=empty ¬ door open ∧ engine on ∧ ¬ tray full door=open engine=on tray=empty door=closed engine=on tray=empty engine on ∧ ¬ tray full Also, it is easy to see that: S1 ∪ S2 φ1 ∨ φ2 S1 ∩ S2 φ1 ∧ φ2 S1 ⊆ S2 φ1 → φ2 R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 17 / 44
  • 50. Symbolic Model-Checking - Representing Transitions Transitions are also represented as formulæ between state variables and their primed versions if door=closed then tray’=empty [start washing] engine=off engine’=on ¬door open ∧ ¬engine on ∧ ¬door open’ ∧ engine on’ ∧ ¬tray full’ R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 18 / 44
  • 51. Symbolic Model-Checking - Representing Transitions Transitions are also represented as formulæ between state variables and their primed versions if door=closed then tray’=empty [start washing] engine=off engine’=on ¬door open ∧ ¬engine on ∧ ¬door open’ ∧ engine on’ ∧ ¬tray full’ This formula says that the following pair of states are related ¬door open ∧ ¬engine on ∧ ¬tray full ¬door open’ ∧ engine on’ ∧ ¬tray full’ ¬door open ∧ ¬engine on ∧ tray full ¬door open’ ∧ engine on’ ∧ ¬tray full’ R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 18 / 44
  • 52. Symbolic Model-Checking - Computing Next State From a set of states S(i), represented symbolically by a formula φ(s), and a transition tj, represented symbolically by a formula ψ(s, s ), the next states tj(S(i)) can be expressed as ∃s. φ(s) ∧ ψ(s, s ) By means of an operation called quantifier elimination, we can remove s. If then we rename s as s we obtain the symbolic representation of tj(S(i)) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 19 / 44
  • 53. Symbolic Model-Checking - Computing Next State From a set of states S(i), represented symbolically by a formula φ(s), and a transition tj, represented symbolically by a formula ψ(s, s ), the next states tj(S(i)) can be expressed as ∃s. φ(s) ∧ ψ(s, s ) By means of an operation called quantifier elimination, we can remove s. If then we rename s as s we obtain the symbolic representation of tj(S(i)) Example: φ ≡ ¬door open ∧ ¬engine on ψ ≡ ¬door open ∧ ¬engine on ∧ ¬door open’ ∧ engine on’ ∧ ¬tray full’ Quantifier elimination of ∃ door open, engine on. φ ∧ ψ is ¬door open’ ∧ engine on’ ∧ ¬tray full’ and therefore ¬door open ∧ engine on ∧ ¬tray full is tj(S(i)). The whole set of next states T(S(i)) is j tj(S(i)) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 19 / 44
  • 54. Symbolic Model-Checking - Bad states in S(i) Suppose that φ is the symbolic representation of S(i), and that β is the symbolic representation of the bad states checking if some bad state is in S(i) can be simply done with R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 20 / 44
  • 55. Symbolic Model-Checking - Bad states in S(i) Suppose that φ is the symbolic representation of S(i), and that β is the symbolic representation of the bad states checking if some bad state is in S(i) can be simply done with φ ∧ β is satisfiable ? R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 20 / 44
  • 56. Symbolic Model-Checking - Fix point test Suppose that φi is the symbolic representation of S(i) and that φi+1 is the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ? R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
  • 57. Symbolic Model-Checking - Fix point test Suppose that φi is the symbolic representation of S(i) and that φi+1 is the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ? First of all, notice that S(i) ≡ S(i+1) if and only if S(i) ⊆ S(i+1) and S(i+1) ⊆ S(i) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
  • 58. Symbolic Model-Checking - Fix point test Suppose that φi is the symbolic representation of S(i) and that φi+1 is the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ? First of all, notice that S(i) ≡ S(i+1) if and only if S(i) ⊆ S(i+1) and S(i+1) ⊆ S(i) S(i) ⊆ S(i+1) always holds (explored states grow monotonically) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
  • 59. Symbolic Model-Checking - Fix point test Suppose that φi is the symbolic representation of S(i) and that φi+1 is the symbolic representation of S(i+1) how do I that S(i) ≡ S(i+1) ? First of all, notice that S(i) ≡ S(i+1) if and only if S(i) ⊆ S(i+1) and S(i+1) ⊆ S(i) S(i) ⊆ S(i+1) always holds (explored states grow monotonically) S(i+1) ⊆ S(i) can be perfomed with the following check φi+1 → φi is a tautology ? or equivalently φi+1 ∧ ¬φi is unsafisfiable ? R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 21 / 44
  • 60. Symbolic Model-Checking - Summary Model-Checking can be implemented by representing states and transitions symbolically with SAT/SMT-formulæ Next states T(S(i)) can be computed using quantifier elimination Presence of bad states can be computed with a satisfiability call of the form φ ∧ β Fix-point check can be computed with a satisfiability call of the form φi+1 ∧ ¬φi R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 22 / 44
  • 61. Symbolic Model-Checking - Termination Forward-Reachability Safety Check If φi ∧ β is satisfiable, return unsafe Next States Compute φi+1 with quantifier elimination Fix-Point Check If φi+1 ∧ ¬φi is unsatisfiable, return safe Model-Checking always terminates if the satisfiability tests above terminates If the system under inspection is a finite state machine, everything can be encoded into Booleans, and so they always terminate (SAT-solver is enough) If the system has infinite states (e.g., 0 ≤ x ∧ y ≥ 2), it terminates if everyting can be encoded into a decidable SMT theory (e.g., LIA) (SMT-Solver necessary) If quantifiers are needed to express states, then Forward-Reachability might not terminate (SMT-Solver plus clever way of handling quantifiers) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 23 / 44
  • 62. Outline 1 Basics Modeling Checking Implementing a Model-Checker 2 mcmt Two simple protocols R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 24 / 44
  • 63. mcmt: Model-Checking Modulo Theories mcmt is a Model-Checker invented and developed by S. Ghilardi and S. Ranise et al. (see http://www.dsi.unimi.it/ ghilardi/mcmt/ for complete and precise acknowledgements) It implements a Symbolic Backward-Reachability algorithm (it relies on yices) It was invented to handle safety properties for distributed algorithms (protocols), which are infinite-state systems R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 25 / 44
  • 64. mcmt demo The following example is taken from the tutorial Model Checking Modulo Theories: Theory and Practice available at http://st.fbk.eu/MCMTtutorial R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 26 / 44
  • 65. A simple protocol Description l = 1start l = 2 l = 3 l = 4 No data, only locations All processes start from the 1st location A process in location 3 is inside the critical section We want to check if the protocol ensures the mutual exclusion, i.e., at most one process is inside the critical section R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 27 / 44
  • 66. A simple protocol Variable l = 1start l = 2 l = 3 l = 4 One local variable l :smt (define-type locations (subrange 1 4)) :local l locations R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 28 / 44
  • 67. A simple protocol Initial configuration l = 1start l = 2 l = 3 l = 4 All processes start in location 1 ∀x.(l[x] = 1) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 29 / 44
  • 68. A simple protocol Initial configuration l = 1start l = 2 l = 3 l = 4 All processes start in location 1 ∀x.(l[x] = 1) :initial :var x :cnj (= l[x] 1) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 29 / 44
  • 69. A simple protocol Unsafe configuration l = 1start l = 2 l = 3 l = 4 Mutual exclusion: At most one process is in location 3 R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 30 / 44
  • 70. A simple protocol Unsafe configuration l = 1start l = 2 l = 3 l = 4 Mutual exclusion: At most one process is in location 3 U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 30 / 44
  • 71. A simple protocol Unsafe configuration l = 1start l = 2 l = 3 l = 4 Mutual exclusion: At most one process is in location 3 U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2) :unsafe :var z1 :var z2 :cnj (= l[z1] 3) (= l[z2] 3) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 30 / 44
  • 72. A simple protocol Transitions l = 1start l = 2 l = 3 l = 4 A process in location 1 moves to location 2 τ1 := ∃x. l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 31 / 44
  • 73. A simple protocol Transitions l = 1start l = 2 l = 3 l = 4 A process in location 1 moves to location 2 τ1 := ∃x. l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) :transition :var x :var j :guard (= l[x] 1) :numcases 2 :case (= x j) :val 2 :case (not (= x j)) :val l[j] R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 31 / 44
  • 74. A simple protocol Transitions l = 1start l = 2 l = 3 l = 4 :transition :var x :var j :guard (= l[x] 1) :numcases 2 :case (= x j) :val 2 :case (not (= x j)) :val l[j] :transition :var x :var j :guard (= l[x] 3) :numcases 2 :case (= x j) :val 4 :case (not (= x j)) :val l[j] :transition :var x :var j :guard (= l[x] 2) :numcases 2 :case (= x j) :val 3 :case (not (= x j)) :val l[j] :transition :var x :var j :guard (= l[x] 4) :numcases 2 :case (= x j) :val 1 :case (not (= x j)) :val l[j] R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 32 / 44
  • 75. A simple protocol Execution l = 1start l = 2 l = 3 l = 4 $ ./mcmt simple unsafe.in R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 33 / 44
  • 76. A simple protocol Execution - Get informations from counterexample [...] Doing state space exploration... node 1= [t2_1][0] node 2= [t1_1][t2_1][0] node 3= [t2_2][t2_1][0] node 4= [t2_2][t1_1][t2_1][0] node 5= [t4_1][t1_1][t2_1][0] node 6= [t1_2][t2_2][t1_1][t2_1][0] ============================================================================= System is UNSAFE! [...] R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 34 / 44
  • 77. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ2 := ∃x. l[x] = 2 ∧ l = λj. (if (x = j) then 3 else l[j]) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 78. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ2 := ∃x. l[x] = 2 ∧ l = λj. (if (x = j) then 3 else l[j]) z1 z2 l = 3 l = 3 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 79. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ2 := ∃x. l[x] = 2 ∧ l = λj. (if (x = j) then 3 else l[j]) z1 z2 l = 3 l = 3 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 80. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ2 := ∃x. l[x] = 2 ∧ l = λj. (if (x = j) then 3 else l[j]) z1 z2 l = 2 l = 3 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 81. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ1 := ∃x. l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) z1 z2 l = 2 l = 3 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 82. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ1 := ∃x. l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) z1 z2 l = 1 l = 3 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) [t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 83. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ2 := ∃x. l[x] = 2 ∧ l = λj. (if (x = j) then 3 else l[j]) z1 z2 l = 1 l = 3 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) [t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 84. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ2 := ∃x. l[x] = 2 ∧ l = λj. (if (x = j) then 3 else l[j]) z1 z2 l = 1 l = 2 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) [t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 ) [t2_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 2 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 85. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ1 := ∃x. l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) z1 z2 l = 1 l = 2 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) [t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 ) [t2_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 2 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 86. A simple protocol Counterexample analysis from trace Initial state: ∀i. ( l[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) Counter-example: node 6 = [t1_2][t2_2][t1_1][t2_1][0] τ1 := ∃x. l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) z1 z2 l = 1 l = 1 [0] ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) [t2_1] ∃z1, z2. ( l[z1] = 2 ∧ l[z2] = 3 ) [t1_1] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 3 ) [t2_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 2 ) [t1_2] ∃z1, z2. ( l[z1] = 1 ∧ l[z2] = 1 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 35 / 44
  • 87. Another simple protocol Description l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 Like before, but with a global flag c that takes care of mutual exclusion All processes start from the 1st location A process in location 3 is inside the critical section We want to check if the protocol ensures the mutual exclusion, i.e., at most one process is inside the critical section R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 36 / 44
  • 88. Another simple protocol Variable(s) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 One local variable l :smt (define-type locations (subrange 1 4)) :smt (define-type counter (subrange 1 2)) :local l location :global c counter R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 37 / 44
  • 89. Another simple protocol Initial configuration l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 All processes start in location 1, with counter set to 1 ∀x. ( l[x] = 1 ∧ c[x] = 1 ) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 38 / 44
  • 90. Another simple protocol Initial configuration l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 All processes start in location 1, with counter set to 1 ∀x. ( l[x] = 1 ∧ c[x] = 1 ) :initial :var x :cnj (= l[x] 1) (= c[x] 1) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 38 / 44
  • 91. Another simple protocol Unsafe configuration l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 Mutual exclusion: At most one process is in location 3 R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 39 / 44
  • 92. Another simple protocol Unsafe configuration l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 Mutual exclusion: At most one process is in location 3 U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 39 / 44
  • 93. Another simple protocol Unsafe configuration l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 Mutual exclusion: At most one process is in location 3 U := ∃z1, z2. (l[z1] = 3 ∧ l[z2] = 3 ∧ z1 = z2) :unsafe :var z1 :var z2 :cnj (= l[z1] 3) (= l[z2] 3) R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 39 / 44
  • 94. Another simple protocol Transitions l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 40 / 44
  • 95. Another simple protocol Transitions l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    :transition :var x :var j :guard (= l[x] 2) (= c[x] 1) :numcases 2 :case (= x j) :val 3 :val 2 :case (not (= x j)) :val l[j] :val 2 R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 40 / 44
  • 96. Another simple protocol Transitions l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 :transition :var x :var j :guard (= l[x] 1) :numcases 2 :case (= x j) :val 2 :val c[x] :case (not (= x j)) :val l[j] :val c[x] :transition :var x :var j :guard (= l[x] 3) (= c[x] 2) :numcases 2 :case (= x j) :val 4 :val 1 :case (not (= x j)) :val l[j] :val 1 :transition :var x :var j :guard (= l[x] 2) (= c[x] 1) :numcases 2 :case (= x j) :val 3 :val 2 :case (not (= x j)) :val l[j] :val 2 :transition :var x :var j :guard (= l[x] 4) :numcases 2 :case (= x j) :val 1 :val c[j] :case (not (= x j)) :val l[j] :val c[j] R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 41 / 44
  • 97. Another simple protocol Execution l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 $ ./mcmt simple safe.in R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 42 / 44
  • 98. Another simple protocol Execution [...] Doing state space exploration... node 1 = [t2_1][0] node 2 = [t1_1][t2_1][0] node 3 = [t4_1][t1_1][t2_1][0] ============================================================================= Global fixpoint reached! System is SAFE! [...] R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 43 / 44
  • 99. A simple protocol Set of (un)reachable states Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 t1 t2 t3 t4 l = 3 l = 3 τ1 := ∃x.    l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) c = λj.c[j]    τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    τ3 := ∃x.    l[x] = 3 ∧ c[x] = 2 ∧ l = λj. (if (x = j) then 4 else l[j]) c = λj.1    τ4 := ∃x.    l[x] = 4 ∧ l = λj. (if (x = j) then 1 else l[j]) c = λj.c[j]    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
  • 100. A simple protocol Set of (un)reachable states Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 t1 t2 t3 t4 l = 2 c = 1 l = 3 c = 1 l = 3 l = 3 t2 z1 τ1 := ∃x.    l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) c = λj.c[j]    τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    τ3 := ∃x.    l[x] = 3 ∧ c[x] = 2 ∧ l = λj. (if (x = j) then 4 else l[j]) c = λj.1    τ4 := ∃x.    l[x] = 4 ∧ l = λj. (if (x = j) then 1 else l[j]) c = λj.c[j]    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
  • 101. A simple protocol Set of (un)reachable states Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 t1 t2 t3 t4 l = 1 c = 1 l = 3 c = 1 l = 2 c = 1 l = 3 c = 1 l = 3 l = 3 t1 z1 t2 z1 τ1 := ∃x.    l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) c = λj.c[j]    τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    τ3 := ∃x.    l[x] = 3 ∧ c[x] = 2 ∧ l = λj. (if (x = j) then 4 else l[j]) c = λj.1    τ4 := ∃x.    l[x] = 4 ∧ l = λj. (if (x = j) then 1 else l[j]) c = λj.c[j]    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
  • 102. A simple protocol Set of (un)reachable states Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 t1 t2 t3 t4 l = 4 c = 1 l = 3 c = 1 l = 1 c = 1 l = 3 c = 1 l = 2 c = 1 l = 3 c = 1 l = 3 l = 3 t4 z1 t1 z1 t2 z1 τ1 := ∃x.    l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) c = λj.c[j]    τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    τ3 := ∃x.    l[x] = 3 ∧ c[x] = 2 ∧ l = λj. (if (x = j) then 4 else l[j]) c = λj.1    τ4 := ∃x.    l[x] = 4 ∧ l = λj. (if (x = j) then 1 else l[j]) c = λj.c[j]    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
  • 103. A simple protocol Set of (un)reachable states Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 t1 t2 t3 t4 l = 3 c = 2 l = 3 c = 2 l = 4 c = 1 l = 3 c = 1 l = 1 c = 1 l = 3 c = 1 l = 2 c = 1 l = 3 c = 1 l = 3 l = 3 t3 z1 t4 z1 t1 z1 t2 z1 τ1 := ∃x.    l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) c = λj.c[j]    τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    τ3 := ∃x.    l[x] = 3 ∧ c[x] = 2 ∧ l = λj. (if (x = j) then 4 else l[j]) c = λj.1    τ4 := ∃x.    l[x] = 4 ∧ l = λj. (if (x = j) then 1 else l[j]) c = λj.c[j]    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44
  • 104. A simple protocol Set of (un)reachable states Initial state: ∀i. ( l[i] = 1 ∧ c[i] = 1 ) Unsafe state: ∃z1, z2. ( l[z1] = 3 ∧ l[z2] = 3 ) l = 1 c = 1start l = 2 c = 1 l = 3 c = 2 l = 4 c = 1 t1 t2 t3 t4 l = 4 c = 1 l = 3 c = 1 l = 1 c = 1 l = 3 c = 1 l = 2 c = 1 l = 3 c = 1 l = 3 l = 3 t4 z1 t1 z1 t2 z1 τ1 := ∃x.    l[x] = 1 ∧ l = λj. (if (x = j) then 2 else l[j]) c = λj.c[j]    τ2 := ∃x.    l[x] = 2 ∧ c[x] = 1 ∧ l = λj. (if (x = j) then 3 else l[j]) c = λj.2    τ3 := ∃x.    l[x] = 3 ∧ c[x] = 2 ∧ l = λj. (if (x = j) then 4 else l[j]) c = λj.1    τ4 := ∃x.    l[x] = 4 ∧ l = λj. (if (x = j) then 1 else l[j]) c = λj.c[j]    R. Bruttomesso (SMT) Intro to MC 15 Dicembre 2011 44 / 44