24
SAT and Model Checking

SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Embed Size (px)

Citation preview

Page 1: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

SAT and Model Checking

Page 2: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Bounded Model Checking (BMC)

• A.I. Planning problems: can we reach a desired state in k steps?

• Verification of safety properties: can we find a bad state in k steps?

• Verification: can we find a counterexample in k steps ?

Biere, Cimatti, Clarke, Zhu, 1999

Page 3: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

What is SAT?

SATisfying assignment!

Given a propositional formula in CNF, find if there exists an assignment to Boolean variables that makes the formula true:

1 = (b c)

2 = (a d)

3 = (b d)

= 1 2 3

A = {a=0, b=1, c=0, d=1}

1 = (b c)

2 = (a d)

3 = (b d)

= 1 2 3

A = {a=0, b=1, c=0, d=1}

clauses

literals

Page 4: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

BMC ideaGiven: transition system M, temporal logic formula f, and user-supplied time bound k

Construct propositional formula (k) that is satisfiable iff f is validalong a path of length k

Path of length k: )()( 1,

1

00

ii

k

issRsI

Say f = EF p and k = 2, then

)(),(),()( (2) 21021100 pppssRssRsI

What if f = AG p ?

Page 5: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

BMC idea (cont’d)

AG p means p must hold in every state along any path of length k

i

k

iii

k

ipssRsIk

01,

1

00 ))()(()(

i

k

iii

k

ipssRsIk

01,

1

00 )()()(

We take

So

That means we look for counterexamples

Page 6: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Safety-checking as BMC

p is preserved up to k-th transition iff (k) is unsatisfiable:

. . .s0 s1 s2 sk-1 sk

p p p p p

pssRsIkk

iii

k

i

01,

1

00 )()()(

If satisfiable, satisfying assignment gives counterexample to the safety property.

Page 7: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Example: a two bit counter

Safety property: AG

00

01 10

11

(2) is unsatisfiable. (3) is satisfiable.

Initial state:

Transition:

)(

)(

)(

)(

)()(:)2(

22

11

00

12112

0100100

rl

rl

rl

rrrll

rrrllrl

:R

rlI :

rr

rll

'

)('

)( rl

Page 8: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Example: another counter

Liveness property: AF00

01 10

11

(2) is satisfiable

:RrlI :

rl

rr

ll

rr

rll'

'

'

)('

)( rl

Check: EG )( rl

looprlssRsI iii

iii

)()()()2(

2

01,

1

00

where)(),( 23130332 ssssssssRloop

Satisfying assignment gives counterexample to the liveness property

Page 9: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

What BMC with SAT Can Do

• All LTL

• ACTL and ECTL

• In principle, all CTL and even mu-calculus– efficient universal quantifier elimination or

fixpoint computation is an active area of research

Page 10: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

How big should k be?

• For every model M and LTL property there exists k s.t.

• The minimal such k is the Completeness Threshold (CT)

Page 11: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

How big should k be?

• Diameter d = longest shortest path from an initial state to any other reachable state.

• Recurrence Diameter rd = longest loop-free path.

• rd ¸ d

d = 2

rd = 3

Page 12: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

How big should k be?

• Theorem: for Gp properties CT = d

s0

p

Arbitrary path

Page 13: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

How big should k be?

• Theorem: for Fp properties CT= rd

s0

ppppp

Open Problem: The value of CT for general Linear Temporal Logic properties is unknown

Page 14: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Given in CNF: (x,y,z),(-x,y),(-y,z),(-x,-y,-z)

Decide()

Deduce()

Resolve_Conflict()

X

X X X X

A basic SAT solver

Page 15: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

While (true){

if (!Decide()) return (SAT);

while (!Deduce())

if (!Resolve_Conflict()) return

(UNSAT);}

Choose the next variable and value.Return False if all

variables are assigned

Apply unit clause rule.Return False if reached

a conflict

Backtrack until no conflict.

Return False if impossible

Basic Algorithm

Page 16: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

A =

empty clause?

yUNSAT

conflict?Obtain conflict

clause andbacktrack

y

n

is Atotal?

ySAT

Branch:add some literal

to A

DPLL-style SAT solversSATO,GRASP,CHAFF,BERKMIN

n

Page 17: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

The Implication Graph

(a b) (b c d)

a

c

Decisions

b

Assignment: a b c d

d

Page 18: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Resolution

a b c a c d

b c d

When a conflict occurs, the implication graph isused to guide the resolution of clauses, so that thesame conflict will not occur again.

Page 19: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Conflict clauses

(a b) (b c d) (b d)

a

c

Decisions

b

Assignment: a b c d

d

Conflict!

(b c )

resolve

Conflict!(a c)

resolve

Conflict!

Page 20: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Conflict Clauses (cont.)

• Conflict clauses:– Are generated by resolution– Are implied by existing clauses– Are in conflict with the current assignment– Are safely added to the clause set

Many heuristics are available for determiningwhen to terminate the resolution process.

Page 21: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Generating refutations• Refutation = a proof of the null clause

– Record a DAG containing all resolution steps performed during conflict clause generation.

– When null clause is generated, we can extract a proof of the null clause as a resolution DAG.

Original clauses

Derived clauses

Null clause

Page 22: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Unbounded Model Checking

• A variety of methods to exploit SAT and BMC for unbounded model checking:– Completeness Threshold– k - induction– Abstraction (refutation proofs useful here)– Exact and over-approximate image

computations (refutation proofs useful here)– Use of Craig interpolation

Page 23: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Conclusions: BDDs vs. SAT

• Many models that cannot be solved by BDD symbolic model checkers, can be solved with an optimized SAT Bounded Model Checker.

• The reverse is true as well.• BMC with SAT is faster at finding shallow

errors and giving short counterexamples. • BDD-based procedures are better at proving

absence of errors.

Page 24: SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:

Acknowledgements

“Exploiting SAT Solvers in Unbounded Model Checking” by K. McMillan, tutorial presented at CAV’03

“Tuning SAT-checkers for Bounded Model Checking” and“Heuristics for Efficient SAT solving” by O. Strichman

Slides originally prepared for 2108 by Mihaela Gheorghiu.