An Introduction To Formal Verification: Sandeep K. Shukla
An Introduction To Formal Verification: Sandeep K. Shukla
An Introduction To Formal Verification: Sandeep K. Shukla
Verification
Sandeep K. Shukla
CECS/ICS/UCI
Acknowledgement
1
Overview
• Introduction
– What is verification (validation)
– Why do we need it
– Formal vs. simulation-based methods
• Math background
– BDD’s
– Symbolic FSM traversal
• Model checking
– Problem statement
– Explicit algorithms (on graphs)
– Symbolic algorithms (using BDDs)
• Theorem proving
– Deductive reasoning
2
Overview – Functional Testing
• Simulation-based methods
– Functional test generation
– SAT-based methods, Boolean verification
• Boolean satisfiability
– RTL verification
• Arithmetic/Boolean satisfiability
– ATPG-based methods
• Emulation-based methods
– Hardware-assisted simulation
– System prototyping
Part I
INTRODUCTION
3
Verification
• Design verification = ensuring correctness of the design
– against its implementation (at different levels)
-- against alternative design (at the same level)
Why Verification
• Verification crisis
– system complexity, difficult to manage
– more time, effort devoted to verification than to design
– need automated verification methods, integration
4
Verification Methods
• Simulation - performed on the model
• Deductive verification
• Model checking Formal Verification
• Equivalence checking
• Testing - performed on the actual product
(manufacturing test)
• Emulation, prototyping
Formal Verification
• Deductive reasoning (theorem proving)
– uses axioms, rules to prove system correctness
– no guarantee that it will terminate
– difficult, time consuming: for critical applications only
• Model checking
– automatic technique to prove correctness of concurrent systems: digital
circuits, communication protocols, etc.
• Equivalence checking
– check if two circuits are equivalent
5
Why Formal Verification
Part II
BACKGROUND
6
Binary Decision Diagrams
• Binary Decision Diagram (BDD)
– compact data structure for Boolean logic
– can represent sets of objects (states) encoded as Boolean
functions
– reduced ordered BDDs (ROBDD) are canonical
– canonicity - essential for verification
• Construction of ROBDD
– remove duplicate terminals
– remove duplicate nodes (isomorphic subgraphs)
– remove internal nodes with identical children
BDD - Construction
7
BDD Construction – cont’d
f f f = (a+b)c
a a a
b b b b b
c c c c c c c
0 1 0 1 0 1
Application to Verification
• Equivalence of combinational circuits
• Canonicity property of BDDs:
– if F and G are equivalent, their BDDs are
identical (for the same ordering of variables)
b ≡ b
c c
0 1 0 1
8
Application to Verification,
cont’d
H
• Functional test generation
– SAT, Boolean satisfiability a
analysis
– to test for H = 1 (0), find a b ab
path in the BDD to terminal 1
c
(0)
– the path, expressed in ab’c
function variables, gives a 0 1
satisfying solution (test
vector)
• Useful operators F F’
¬
– Complement ¬ F = F’
0 1 1 0
(switch the terminal nodes)
F(x,y) F(y)
Restrict
– Restrict: F|x=b = F(x=b)
where b = const
0 1 x=b 0 1
9
Useful BDD Operators - cont’d
• Apply: F • G
where • stands for any Boolean operator (AND, OR,
XOR, →)
F G F • G
• =
0 1 0 1
0 1
R
– Inputs: X
– Outputs: O
– States: S
– Next state function, δ(s,x) : S × X → S
– Output function, λ(s,x) : S × X → O
10
FSM Traversal
1/0 s2 0/1
Existential Quantification
11
Existential Quantification -
cont’d
• Function can be existentially quantified w.r.to a
vector: X = x 1x2…
Image Computation
S(u) Img(v)
12
Image Computation - example
Compute a set of next states from state s1
Example - cont’d
• Compute Image from s1 under R
Img( s1,R ) = ∃a ∃xy s1(x,y) • R(a,x,y,X,Y)
s2
a 01
s1 s4 Result: a set of next
00 a’
11 states for all inputs
10 s1 → {s2, s3}
s3
13
Pre-Image Computation
• Computing a set of present states from a given
next state (or set of states)
Pre-Img( S’,R) = ∃v R(u,v) )• S’(v)
R(u,v)
Pre-Img(u) S’(v)
Part III
EQUIVALENCE CHECKING
14
Equivalence Checking
• Two circuits are functionally
equivalent if they exhibit the same
behavior
In CL Out
• Combinational circuits
– for all possible input values PI Po
• Sequential circuits
CL
– for all possible input sequences
Ps Ns
R
• Structural
– identify structurally similar internal points
– prove internal points (cut-points) equivalent
– find implications
15
Functional Equivalence
• If BDD can be constructed for each circuit
– represent each circuit as shared (multi-output)
BDD
• use the same variable ordering !
– BDDs of both circuits must be identical
Functional Decomposition
16
Cut-Points Resolution Problem
• If all pairs of cut-points (z 1,z2) are equivalent
– so are the two functions, F,G
• If intermediate functions (f 2,g2) are not equivalent
– the functions (F,G) may still be equivalent
– this is called false negative F G
• Why do we have false negative ? g2
f 2
– functions are represented in terms of
intermediate variables z1 z2
– to prove/disprove equivalence must
represent the functions in terms of f1 g1
primary inputs (BDD composition)
x y x y
f1 g1
x y x y
17
Cut-Point Resolution – cont’d
• Procedure 2: create a BDD for F ⊕ G
– perform satisfiability analysis (SAT) of the BDD
• if BDD for F ⊕G = ∅, problem is not satisfiable, false negative
• BDD for F ⊕G ≠ ∅, problem is satisfiable, true negative
F G F ⊕G = ∅, F ≡ G (false negative)
= Non-empty, F ≠ G
⊕
18
Sequential Verification
• Approach 2: based on isomorphism of state
transition graphs
– two machines M1, M2 are equivalent if their state
transition graphs (STGs) are isomorphic
– perform state minimization of each machine
– check if STG(M1) and STG(M2) are isomorphic
1/0
1/0 0/0 0/1
0/0 0/1 State min. 0 1.2
0 1/1 1
M1 min 1/1 ≡
1/0 2 0/1 M1
1/0
0/0 0/1
0 1
M2
1/1
Sequential Verification
• Approach 3: symbolic FSM traversal of the
product machine
• Given two FSMs: M1(X,S1, δ 1, λ1,O1), O(M)
M2(X,S2, δ 2, λ2,O2)
• Create a product FSM: M = M1× M 2
– traverse the states of M and check its O1 O2
output for each transition
– the output O(M) =1, if outputs O1= O2
M1 M2
– if all outputs of M are 1, M1 and M2 are S1 S2
equivalent
– otherwise, an error state is reached X
– error trace is produced to show: M1 ≠ M2
19
Product Machine - Construction
20
Construction of the Product FSM
1/0 0/0
0/0 0/1 2
M1 0 1 M2 1/1 1/0
0/1
0/0
1/1 0 1
• For each pair of states, s1 ∈ M1 , s 2∈ M 2 1/1
– create a combined state s = (s1. s2) of M
– create transitions out of this state to other states of M
– label the transitions (input/output) accordingly
1⊗ 1
0/1 1/0 0/1 Output = { 10 error
OK
0⊗ 0
M1 1 0 1/1
0/1 1.1 0.2
M2 1/0
1 2
21
Part IV
MODEL CHECKING
Model Checking
• Algorithmic method of verifying correctness of (finite state)
concurrent systems against temporal logic specifications
– A practical approach to formal verification
• Basic idea
– System is described in a formal model
• derived from high level design (HDL, C), circuit structure,
etc.
– The desired behavior is expressed as a set of properties
• expressed as temporal logic specification
– The specification is checked agains the model
22
Model Checking
• How does it work
Model Checking
• Characteristics
– searches the entire solution space
– always terminates with YES or NO
– relatively easy, can be done by experienced designers
– widely used in industry
– can be automated
• Challenges
– state space explosion – use symbolic methods, BDDs
• History
– Clark, Emerson [1981] USA
– Quielle, Sifakis [1980’s] France
23
Model Checking - Tasks
• Modeling
– converts a design into a formalism: state transition system
• Specification
– state the properties that the design must satisfy
– use logical formalism: temporal logic
• asserts how system behavior evolves over time
• Verification
– automated procedure (algorithm)
• Negative results
– incorrect model
– incorrect specification (false negative)
– failure to complete the check (too large)
24
Model Checking - Basics
• State transition structure
M(S,R,L) (Kripke structure)
s1
S = finite set of states {s1, s 2, … sn }
R = transition relation a
L = set of labels assigned to states, so that s3
s2
L(s) = f if state s has property f b ac
Temporal Logic
• Formalism describing sequences of transitions
• Time is not mentioned explicitly
• The temporal operators used to express temporal properties
– eventually
– never
– always
• Temporal logic formulas are evaluated w.r.to a state in the
model
• Temporal operators can be combined with Boolean
expressions
25
Computation Trees
s1
a
s1
a
b ac
s2 s3
b ac
a ac ac
26
CTL Formulas
• State formulas
– apply to a specific state
• Path formulas
– apply to all states along a specific path
27
Basic CTL Formulas - cont ’d
• E F (g)
– there exists a path which eventually contains a state in
which g is true
• A F (g)
– for all paths, eventually there is state in which g holds
• E F, A F are special case of E [f U g], A [f U g]
– E F (g) = E [ true U g ], A F (g) = A [ true U g ]
• f U g (f until g)
– true if there is a state in the path where g holds, and at
every previous state f holds
g
g g g
so |= E F g so |= A F g
so g g so
g g g
g g g g
so |= E G g so |= A G g
28
Basic CTL Formulas - cont ’d
• Full set of operators
– Boolean: ¬, ∧, ∨, ⊕, →
– temporal: E, A, X, F, G, U, R
• Examples:
f ∧ g = ¬(¬f ∨ ¬g), F f = true U f , A (f ) = ¬E(¬f )
• E F ( start ∧ ¬ ready )
– eventually a state is reached where start holds and
ready does not hold
• A G ( req → A F ack )
– any time request occurs, it will be eventually
acknowledged
• A G ( E F restart )
– from any state it is possible to get to the restart
state
29
Model Checking – Explicit Algorithm
Problem: given a structure M(S,R,L) and a temporal
logic formula f, find a set of states that satisfy f
{s ∈ S: M,s |= f }
• Explicit algorithm: label each state s with the set
label(s) of sub-formulas of f which are true in s.
• i = 0; label(s) = L(s)
• i = i + 1; Process formulas with (i -1) nested CTL operators.
Add the processed formulas to the labeling of each state in
which it is true.
• Example: E F ¬ (g ∧ h )
T1 = states in which g and h are true
T2 = complement of T1
T3 = predecessor states to T2
30
Model Checking Example
Traffic light controller
(simplified) sensor
C Timer
C = car sensor Road 2
T = timer C ’+ T ’ TC G1 R2
Road 1
G1 R2 G1 R2
Y1 R2
CT
G1 R2 Y1 R2 R1 G2
R1 Y2 Y1 R2
G1 G2
Y1 R2 R1 G2 R1 Y2 R1 G2
Y1 Y2
R1 R2
C ’+ T
R1 Y2 R1 G2 G1 R2
R1 G2
CT ’
R1 Y2
CT
A G ¬ (G1 ∧ G2 )
C ’+T
E F (G1 ∨ G2)
31
Checking the Safety Condition
A G ¬ (G1 ∧ G2) = ¬ E F
(G1∧G2) G1 R2 1
2
• S(G1 ∧ G2 ) = S(G1) ∩ S(G2) = R1 Y2 Y1 R2
{1}∩{3} = ∅
4
• S(EF (G1 ∧ G2 )) = ∅
S(¬ EF (G1 ∧ G2 )) = ¬∅
R1 G2
• 3
= {1, 2, 3, 4}
Each state is included in {1,2,3,4} ⇒
the safety condition is true (for each state)
1 4 3 3 2 1
32
Another Check
E X 2 (Y1) = E X (E X (Y1)) G1 R2 1
(starting at S1=G1R2, is
there a path s.t. Y1 is true in 2 2
steps ?)
R1 Y2 Y1 R2
4
• S (Y1) = {2}
R1 G2
• S (EX (Y1)) = {1} 3
(predecessor of 2)
• S (EX (EX(Y1)) = {1,4}
(predecessors of 1)
Property E X 2 (Y1) is true for states {1,4}, hence true
• Quantification operators
– Existential: ∃ x f = f |x=0 + f |x=1 (smoothing)
– Universal: ∀x f = f |x=0 • f |x=1 (consensus)
33
Symbolic Model Checking - example
Traffic Light Controller
G1 R2 s1
abcd
11 10
G1 11 -- s2
10 01
Y1 01 --
R1 1 0 -- R1 Y2 Y1 R2
G2 --11 01 10
s4
Y2 --01 10 11
R2 -- 10
R1 G2
s3
Example - cont’d
• Represent the set of states as Boolean formula
Q: Q = abcd’ + a’bcd’ + ab’cd + ab’c’d
• Store Q in a BDD
G1 R2 s1
(It will be used to perform logic
operations, such as S(G1) ∨ S(G2) 11 10
10 01 s2
R1 Y2 Y1 R2
01 10
s4
10 11
R1 G2
s3
34
Example - cont’d
• Write a characteristic function R for the transition
relation R =abcd’vxyz’ + abcd’v’xyz’ + … +
ab’c’dvxyz’
abcd vxyz R s1
(6 terms) G1 R2
1110 1110 1 11 10
1110 0110 1
10 01 s2
0110 1011 1
1011 1011 1 R1 Y2 Y1 R2
1011 1001 1
1001 1110 1 01 10
s4
10 11
R1 G2
• Store R in a BDD. It will be used for s3
Pre-Image computation for EF.
35
Example – cont’d
• Step 3: compute S(EF (G1 ∨ G2 )) using Pre-Image
computation (quanitfy w.r.to next state variables)
Example – Interpretation
• Pre-Img(s1’,s3’,R) eliminates those
transitions which do not reach {s1,s3}
G1 R2 s1
abcd vxyz R
11 10
1110 1110 1 s2
X 1110 0110 1 10 01
0110 1011 1 R1 Y2 Y1 R2
1011 1011 1
X 1011 1001 1 01 10
s4
1001 1110 1 10 11
R1 G2
s3
• Quantification w.r.to next state variables
(v,x,y,z) gives the encoded present states
{s1,s2,s3,s4}
36