satisfiability modulo theory
play

Satisfiability modulo theory David Monniaux CNRS / VERIMAG October - PowerPoint PPT Presentation

Satisfiability modulo theory David Monniaux CNRS / VERIMAG October 2017 1 / 182 Schedule Introduction Propositional logic First-order logic Applications Beyond DPLL(T) Qvantifier elimination Interpolants 2 / 182 Who I am David


  1. Tseitin encoding c c c b turned into clauses 36 / 182 d c e ≡ a ∧ ¯ f ≡ b ∧ c ∧ ¯ b ∧ ¯ g ≡ e ∨ f h ≡ ¯ b ∨ ¯ ϕ ≡ g ∧ h ; e ∨ ¯ e ∨ a e ∨ ¯ a ∨ b ∨ c ∨ e ¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯ f ∨ b f ∨ c f ∨ d b ∨ ¯ c ∨ d ∨ f ¯ ¯ ¯ e ∨ g f ∨ g g ∨ e ∨ f ¯ h ∨ ¯ b ∨ h c ∨ h b ∨ ¯ ¯ ¯ g ∨ ¯ ¯ ϕ ∨ g ϕ ∨ h h ∨ ϕ ϕ

  2. DIMACS format c start with comments p cnf 5 3 1 -5 4 0 -1 5 3 4 0 -3 -4 0 5 = number of variables 3 = number of clauses each clause: -1 is variable 1 negated, 5 is variable 5, 0 is end of clause 37 / 182

  3. DPLL Each clause acts as propagator e.g. Boolean constraint propagation aka unit propagation : propagate as much as possible once the value of a variable is known, use it elsewhere 38 / 182 assuming a and ¯ b , clause ¯ a ∨ b ∨ c yields c

  4. DPLL: Branching If unit propagation insufgicient to false) Then: 39 / 182 ▶ either find a satisfying assignment ▶ either find an unsatisfiable clause (all literals forced to ▶ pick a variable ▶ do a search subtree for both polarities of the variable

  5. Example c c Now g and h are t , c 40 / 182 b e ∨ ¯ ¯ e ∨ a ¯ ¯ e ∨ ¯ ¯ a ∨ b ∨ c ∨ e ¯ ¯ ¯ ¯ f ∨ b f ∨ c f ∨ d b ∨ ¯ c ∨ d ∨ f ¯ ¯ ¯ e ∨ g f ∨ g g ∨ e ∨ f ¯ h ∨ ¯ b ∨ h c ∨ h b ∨ ¯ ¯ ¯ g ∨ ¯ ¯ ϕ ∨ g ϕ ∨ h h ∨ ϕ ϕ From unit clause ϕ ¯ ¯ g ∨ ¯ ¯ ϕ ∨ g → g ϕ ∨ h → h h ∨ ϕ removed ¯ ¯ e ∨ g removed f ∨ g removed b ∨ h removed ¯ h ∨ ¯ c → ¯ ¯ c ∨ h removed g ∨ e ∨ f → e ∨ f b ∨ ¯ b ∨ ¯

  6. CDCL: clause learning A DPLL branch gets closed by contradiction : a literal gets Used by unit propagation Add this clause (maybe garbage-collected later) to H d Learn clause = negation of bad hypotheses, implied by H : 41 / 182 Trace back to a subset of hypotheses, sufgicient for contradiction. Both t and f inferred from hypotheses H by unit propagation. forced to both t and f . e.g. a ∧ ¯ b ∧ ¯ c ∧ d ∧ H = ⇒ f a ∨ b ∨ c ∨ ¯ ¯

  7. Resolution . C . . . . H n a . . . H n Propositional resolution rule: a 42 / 182 Proved C 1 from H 1 , . . . , H n and hypothesis a + proved C 2 from H 1 , . . . , H n and hypothesis ¯ ≡ Proved C 1 ∨ ¯ a from H 1 , . . . , H n + proved C 2 ∨ a from H 1 , . . . , H n . . . . . . H 1 H 1 C 1 ∨ ¯ C 2 ∨ a

  8. Resolution proofs a DPLL “unsat” run = a resolution tree proof obtain it by instrumenting the solver = logging the proof steps used for deriving clauses a CDCL “unsat” run = a resolution DAG proof shared subtrees for learned lemmas 43 / 182

  9. CDCL betuer than DPLL Some problems: Resolution independent of search strategy! Almost all current solvers do CDCL, not DPLL. 44 / 182 ▶ short DAG resolution proofs ▶ only exponential tree resolution proofs.

  10. Insights Difgicult to prove results on solvers full of heuristics 45 / 182 Can sometimes prove properties of their proof systems

  11. Pigeons n pigeons, m pigeon holes Each pigeon in a hole: for all i , …but any DAG resolution proof has exponential size in 46 / 182 a i , j j means pigeon i in hole j a i , 1 ∨ · · · ∨ a 1 , m Each hole has at most one pigeon: for all j , for all i , i ′ , ¯ a i , j ∨ · · · ∨ ¯ a i ′ , j If n > m “trivially” unsatisfiable n = m + 1

  12. Implementation wise Clause simplification etc. implemented as two watched literals per clause Pointers to clauses used for deduction Highly optimized proof engines //www.labri.fr/perso/lsimon/glucose/ http://fmv.jku.at/software/index.html Preprocessing 47 / 182 ▶ Minisat http://minisat.se/ ▶ Glucose http: ▶ Armin Biere’s solvers

  13. Unit propagation Textbook propagation assigned t ) d 48 / 182 ▶ look for a variable in each clause, “remove it” ▶ how do we backtrack? Remark: a clause acts when 1 unassigned literal (and none a ∨ ¯ b ∨ c ∨ ¯ in context a = f , b = t , d = t , deduce c = t .

  14. Two watched literals per clause assigned to false clause 49 / 182 ▶ for each literal: a linked list of clauses ▶ each clause has two watched literals ▶ invariant: in each clause the two watched literals are not When l := f , scan associated list ▶ For each clause with one literal assigned t , ignore the ▶ For each clause with > 1 unassigned literal l ′ , move clause to the list for l ′ ▶ For each clause with 1 unassigned literal l ′ , l ′ := t ▶ 0 unassigned literal, CONFLICT (analyze and backtrack)

  15. Variable and polarity selection Heuristics for picking variable to branch on Polarity ( t vs f ) Restart once in a while (keep polarities and learned clauses) 50 / 182 ▶ heuristics for picking first polarity choice ▶ keep last polarity used in next choices

  16. Schedule Introduction Propositional logic Generalities Binary decision diagrams Satisfiability checking Applications First-order logic Applications Beyond DPLL(T) Qvantifier elimination Interpolants 51 / 182

  17. a n output from A b n output from B (same inputs) Equivalence checking Two combinatorial circuits How to check they compute the same? a b assert a b a n b n 52 / 182

  18. Equivalence checking Two combinatorial circuits How to check they compute the same? 52 / 182 ( a 1 , . . . , a n ) output from A ( b 1 , . . . , b n ) output from B (same inputs) assert ( a 1 ⊕ b 1 ) ∨ · · · ∨ ( a n ⊕ b n )

  19. Schedule Introduction Propositional logic First-order logic Applications Beyond DPLL(T) Qvantifier elimination Interpolants 53 / 182

  20. Schedule Introduction Propositional logic First-order logic Basics Decision in fixed theories DPLL(T) Applications Beyond DPLL(T) Qvantifier elimination Interpolants 54 / 182

  21. Qvantifier-free first order formulas arguments) 55 / 182 e.g. ( P ( f ( x , z ) , y ) ∧ R ( y ) ∧ T ) ∨ S ( y , g ( z , x )) Ordinary connectives ∧ , ∨ , ¬ … Predicate symbols P , Q , . . . , each with an arity (number of ▶ 0 -ary predicates = propositional variables ▶ 1 -ary predicates (monadic) ▶ other predicates Function symbols f , g , . . . , each with an arity 0 -ary function symbols are known as constants

  22. Common notations Predicate and function symbols form a signature these symbols. 56 / 182 Some predicate symbols may be noted as infix: < , ≤ , > , ≥ … = denotes equality (more on that later) Some function symbols may be noted as infix: + , − Some constants may be noted as 0 , 1 etc. 1 may a notation for S (0) , 2 as S ( S (0)) where S is successor These so far implies nothing regarding the interpretation of

  23. Qvantifiers Beware of variable capture! in prenex form 57 / 182 ∀ , ∃ Can be moved to the front = prenex form. ∀ x (( ∀ yP ( x , y )) ∨ ( ∃ yQ ( x , y ))) ∀ x ∀ y 1 ∃ y 2 ( P ( x , y 1 ) ∨ Q ( x , y 2 ))

  24. 58 / 182 Interpretation Let M be a set. To any predicate symbol P of arity n associate P M ⊆ M n Note: a 0 -ary predicate associates to t or f To any function symbol f of arity n associate P M : M n → M To any term t (e.g. g ( z , f ( x , y )) ) associate an interpretation t M . To any formula F associate an interpretation F M .

  25. Interpretation with equality In most cases: 59 / 182 The predicate = must be interpreted as equality.

  26. Models of a set of formulas 60 / 182 Let F be a set of formulas (or “system of axioms”). A model M is an interpretation that makes true all formulas in F .

  27. Schedule Introduction Propositional logic First-order logic Basics Decision in fixed theories DPLL(T) Applications Beyond DPLL(T) Qvantifier elimination Interpolants 61 / 182

  28. Models with fixed interpretation of certain predicates 62 / 182 ∀ x ∃ y y > x ∧ y < x + z E.g. M is the set Z , + is addition, − subtraction, 0 is zero, S is “successor” x �→ x + 1 . E.g. M is the set Q , + is addition, − subtraction, 0 is zero, S is x �→ x + 1 . The remaining part of the model, to fix, is then z .

  29. Example (declare-const x Int) (declare-const y Int) (declare-const z Int) ( assert (<= x y)) ( assert (<= y z)) (check-sat) (get-model) ( push ) ( assert (< z x)) (check-sat) ( pop ) ( assert (<= z x)) (check-sat) (get-model) 63 / 182

  30. Output cvc4 --incremental example.smt2 sat ( error "Cannot ␣ get ␣ model ␣ when ␣ produce-models ␣ options ␣ is ␣ off.") 64 / 182

  31. Schedule Introduction Propositional logic First-order logic Basics Decision in fixed theories DPLL(T) Applications Beyond DPLL(T) Qvantifier elimination Interpolants 65 / 182

  32. DPLL(T) (Improper terminology, should be CDCL(T)) d . d 66 / 182 ( x ≤ 0 ∨ x + y ≤ 0) ∧ y ≥ 1 ∧ x ≥ 1 ↓ dictionary of theory literals ( a ∨ b ) ∧ c ∧ d Solve, get ( a , b , c , d ) = ( t , f , t , t ) . But x ≤ 0 ∧ x ≥ 1 is a contradiction! a ∨ ¯ Add theory lemma ¯ Solve, get ( a , b , c , d ) = ( f , t , t , t ) . But x + y ≤ 0 ∧ ≥ 1 ∧ x ≥ 1 is a contradiction! Add theory lemma ¯ c ∨ ¯ b ∨ ¯ The problem is unsatisfiable .

  33. DPLL(T) In practice, do not wait for the CDCL solver to provide a full assignment. Check partial assignments for theory feasibility. If during theory processing, a literal becomes known to be t or f , propagate it to CDCL. Boolean relaxation of the original problem. Lazy expansion of theory. 67 / 182 e.g. x ≥ 0 , x ≥ 1 assigned, propagate x + y ≥ 0

  34. Linear real arithmetic Usually decided by exact precision simplex . Extract from the tableau the contradictory subset of assignments. 68 / 182

  35. LRA Example (1) 69 / 182  ≤ 2 x + y 2   − 6 ≤ 2 x − 3 y    − 1000 ≤ 2 x + 3 y ≤ 18 − 2 ≤ − 2 x + 5 y     20 ≤ x + y . 

  36. LRA Example x (2) 70 / 182  ≤ a a = 2 x + y 2   b = 2 x − 3 y − 6 ≤ b    − 1000 ≤ c ≤ 18 c = 2 x 3 y d = − 2 x +5 y − 2 ≤ d     e = + y 20 ≤ e . 

  37. LRA Example Gauss-like pivoting until: (3) 71 / 182  e = 7/16 c − 1/16 d   a = 3/4 c − 1/4 d    b = 1/4 c − 3/4 d − 3/16 d x = 5/16 c     y = 1/8 c +1/8 d . 

  38. LRA Example x (4) 72 / 182 Relevant original inequalities can be combined into an e = 7/16 c − 1/16 d But: c ≤ 18 and d ≥ − 2 , so − 7/16 c − 1/16 d ≤ 8 . But we have e ≥ 20 , thus no solution . unsatisfiable one (thus the theory lemma ) 7/16 ( − 2 x − 3 y ) ≥ − 7/16 × 18 1/16 ( − 2 x +5 y ) ≥ − 1/16 × 2 ≥ 1 + y 20 ≥ 0 0 12

  39. Linear integer arithmetic Linear real arithmetic + 73 / 182 ▶ branching: if LRA model x = 4 . 3 , then x ≤ 4 ∨ x ≥ 5 ▶ (sometimes) Gomory cuts

  40. 74 / 182 Uninterpreted functions f ( x ) ̸ = f ( y ) ∧ x = z + 1 ∧ z = y − 1 ↓ f x ̸ = f y ∧ x = z + 1 ∧ z = y − 1 Get ( x , y , z , f x , f y ) = (1 , 1 , 0 , 0 , 1) . But if x = y then f x = f y ! Add x = y = ⇒ f x = f y . The problem over ( x , y , z , f x , f y ) becomes unsatisfiable .

  41. Arrays 75 / 182 update ( f , x 0 , y 0 ) the function mapping ▶ x ̸ = x 0 to f [ x ] ▶ x 0 to y 0 .

  42. Qvantifiers Show this formula is true: (5) Equivalently, unsatisfiable: 76 / 182 ( ∀ i 0 ≤ i < j = ⇒ t [ i ] = 42) = ⇒ ( ∀ i 0 ≤ i ≤ j = ⇒ update ( t , j , 0)[ i ] = 42) 0 ≤ i 0 ≤ j ∧ update ( t , j , 0)[ i 0 ] = 0 ∧ ( ∀ i 0 ≤ i < j = ⇒ t [ i ] = 0)

  43. Instantiation Prove unsatisfiable: Unsatisfiable 77 / 182 0 ≤ i 0 ≤ j ∧ update ( t , j , 0)[ i 0 ] = 0 ∧ ( ∀ i 0 ≤ i < j = ⇒ t [ i ] = 0) By instantiation i = i 0 : 0 ≤ i 0 ≤ j ∧ update ( t , j , 0)[ i 0 ] = 0 ∧ (0 ≤ i 0 < j = ⇒ t [ i 0 ] = 0)

  44. Schedule Introduction Propositional logic First-order logic Applications Beyond DPLL(T) Qvantifier elimination Interpolants 78 / 182

  45. Inductiveness checking Floyd-Hoare proof methods Prove a property holds at every loop iteration: Proving A = 79 / 182 ▶ prove it holds initially ▶ prove: if it holds then it holds at next iteration ⇒ B universally ≡ proving A ∧ ¬ B unsatisfiable

  46. Example: binary search 0 <= l && u <= n-1 } return -1; } else return m; else if (t[m] > v) u = m - 1; if (t[m] < v) l = m + 1; //@ assert l <= m <= u; int m = l + (u-l) / 2; while (l <= u ) { @*/ @ loop variant u-l ; @ loop assigns l,u ; && (\forall int k; 0 <= k < n ==> t[k] == v ==> l <= k <= u) ; @ @ /*@ requires /*@ loop invariant int l = 0, u = n-1; int binary_search( int * t, int n, int v) { @*/ (\result == -1 && \forall int k; 0 <= k < n ==> t[k] != v); @ (0 <= \result < n && t[\result] == v) || @ @ ensures @ assigns \nothing; \forall int k1, k2; 0 <= k1 <= k2 <= n-1 ==> t[k1] <= t[k2]; @ n >= 0 && \valid(t+(0..n-1)) && @ 80 / 182

  47. Symbolic / concolic execution Explore the program: tests) code…), concretize (find actual values) for some variables 81 / 182 ▶ Follow paths inside the program ▶ On each path collect constraints on variables (guards in ▶ Check feasibility using SMT-solving ▶ If symbolic execution becomes impossible (calls to native

  48. Example #include <klee/klee.h> int get_sign( int x) { if (x == 0) return 0; if (x < 0) return -1; else return 1; } int main() { int a; klee_make_symbolic(&a, sizeof (a), "a"); return get_sign(a); } 82 / 182

  49. Running Klee $ clang-3.4 -I $KLEE/include -emit-llvm -c -g get_sign.c $KLEE/bin/klee get_sign.bc KLEE: output directory is "klee-out-0" KLEE: Using STP solver backend KLEE: done: total instructions = 31 KLEE: done: completed paths = 3 KLEE: done: generated tests = 3 83 / 182

  50. Examining one test input $ ktest-tool klee-last/test000002.ktest ktest file : 'klee-last/test000002.ktest' args : ['get_sign.bc'] num objects: 1 object 0: name: 'a' object 0: size: 4 object 0: data: '\x01\x01\x01\x01' 84 / 182

  51. Checking an assertion failure #include <klee/klee.h> int main() { int t = 0, x; for ( int i=0; i<3; i++) { klee_make_symbolic(&x, sizeof (x), "xboucle"); klee_assume((x >= 0) & (x < 100)); t += x; } klee_assert(t < 290); return 0; } 85 / 182

  52. Crash trace object 2: data: 99 object 2: size: 4 object 2: name: 'xboucle' object 1: data: 93 object 1: size: 4 1: name: 'xboucle' ktest file : 'klee-last/test000001.ktest' object 0: data: 98 object 0: size: 4 object 0: name: 'xboucle' object num objects: 3 : ['klee_boucle.bc'] args 86 / 182

  53. Bounded model checking Convert a loop-free program into one big formula One Boolean per control location = “the execution went through it” Close to SSA form in compilers. (Can be extended to arrays, structures, objects, pointers, pointer arithmetic. Becomes messy.) If loops, unroll them to finite depth 87 / 182

  54. BMC example extern int choice(void); int main() { int t = 0, x; for(int i=0; i<3; i++) { x = choice(); if (x > 100 || x < 0) x=0; t += x; } assert(t < 290); return 0; } 88 / 182

  55. BMC results State 36 file cbmc_boucle.c line 6 function main thread 0 assertion t < 290 file cbmc_boucle.c line 10 function main Violated property: i=3 (00000000000000000000000000000011) State 48 file cbmc_boucle.c line 5 function main thread 0 t=290 (00000000000000000000000100100010) State 47 file cbmc_boucle.c line 8 function main thread 0 x=98 (00000000000000000000000001100010) State 45 file cbmc_boucle.c line 6 function main thread 0 i=2 (00000000000000000000000000000010) State 39 file cbmc_boucle.c line 5 function main thread 0 t=192 (00000000000000000000000011000000) State 38 file cbmc_boucle.c line 8 function main thread 0 x=97 (00000000000000000000000001100001) i=1 (00000000000000000000000000000001) $ cbmc --trace cbmc_boucle.c State 21 file cbmc_boucle.c line 5 function main thread 0 State 18 file cbmc_boucle.c line 4 function main thread 0 t=0 (00000000000000000000000000000000) State 19 file cbmc_boucle.c line 4 function main thread 0 t=0 (00000000000000000000000000000000) State 20 file cbmc_boucle.c line 4 function main thread 0 x=0 (00000000000000000000000000000000) i=0 (00000000000000000000000000000000) State 30 file cbmc_boucle.c line 5 function main thread 0 State 22 file cbmc_boucle.c line 5 function main thread 0 i=0 (00000000000000000000000000000000) State 27 file cbmc_boucle.c line 6 function main thread 0 x=95 (00000000000000000000000001011111) State 29 file cbmc_boucle.c line 8 function main thread 0 t=95 (00000000000000000000000001011111) 89 / 182

  56. Schedule Introduction Propositional logic First-order logic Applications Beyond DPLL(T) Qvantifier elimination Interpolants 90 / 182

  57. Schedule Introduction Propositional logic First-order logic Applications Beyond DPLL(T) WCET example CDCL explosion Abstract CDCL (ACDCL) Model-construction satisfiability calculus (MCSAT) Qvantifier elimination Interpolants 91 / 182

  58. Motivating example As in bounded model checking: Formula extracted from controller): through that block” intermediate value 92 / 182 loop-free sofuware (e.g. step function of a fly-by-wire ▶ one Boolean per program basic block “the execution goes ▶ constraints expressing program operations and tests (e.g. instruction x = x+1; translated to x 2 = x 1 + 1 Solution of the formula ≡ execution trace with all

  59. WCET Worst-case execution time = time for the longest execution of the program Enrich the formula with timing information for basic blocks (In real life, this is more complicated) Maximize the solution 93 / 182

  60. SMT Encoding by Example add = x_old.0 + 10 LLVM Control Flow Graph x_old.1 = phi [x.3,if.then4], [x.2,if.end] if.end6: x.3 = x_old.0 - 10 if.then4: cmp3 ? cmp3 = x.2 < sub sub = x_old.0 - 10 x.2 = phi [x.1,if.then], [x.0,entry] if.end: x.1 = x_old.0 + 10 if.then: cmp ? cmp = x.0 > add x.0 = input(-10000,10000) void rate_limiter_step() { x = x_old-10; assume (x_old <= 10000); assume (x_old >= -10000); x = input(-10000,10000); if (x > x_old+10) x = x_old+10; if (x < x_old-10) x_old = x; assume -10000 < x_old.0 <10000 } void main() { while (1) rate_limiter_step(); } entry: 94 / 182

  61. The SMT formula encodes cmp ? x_old.1 = phi [x.3,if.then4], [x.2,if.end] if.end6: ; x.3 = x_old.0 - 10 if.then4: ; cmp3 ? cmp3 = x.2 < sub the feasible program traces: x.2 = phi [x.1,if.then], [x.0,entry] if.end: ; x.1 = x_old.0 + 10 if.then: ; sub = x_old.0 - 10 cmp = x.0 > add entry: ; add = x_old.0 + 10 transition through b i Cost for the trace: 95 / 182 x.0 = input(-10000,10000) assume -10000 < x_old.0 <10000 b _ 0 ▶ 1 Boolean per block t _ 0 _ 1 cost = 15 ▶ 1 Boolean per b _ 1 t _ 0 _ 2 t _ 1 _ 2 cost = 6 cost = 14 b _ 2 b i true ↔ trace goes t _ 2 _ 3 cost = 12 b _ 3 t _ 2 _ 4 t _ 3 _ 4 cost = 6 cost = 11 ∑ b i ∗ cost i b _ 4

  62. Step 1: encode instructions if.end: ; x.0 = input(-10000,10000) add = x_old.0 + 10 cmp = x.0 > add cmp ? (Linear Integer Arithmetic) x.1 = x_old.0 + 10 x.2 = phi [x.1,if.then], [x.0,entry] entry: ; sub = x_old.0 - 10 cmp3 = x.2 < sub cmp3 ? if.then4: ; x.3 = x_old.0 - 10 if.end6: ; x_old.1 = phi [x.3,if.then4], [x.2,if.end] assume -10000 < x_old.0 <10000 if.then: ; 95 / 182 form: Static Single Assignment b _ 0 t _ 0 _ 1 cost = 15 b _ 1 t _ 0 _ 2 t _ 1 _ 2 cost = 6 cost = 14 1 SMT variable ↔ 1 SSA variable b _ 2 − 10000 ≤ x _ old . 0 ≤ 10000 ∧ − 10000 ≤ x . 0 ≤ 10000 ∧ add = ( x _ old . 0 + 10) t _ 2 _ 3 cost = 12 ∧ x . 1 = ( x _ old . 0 + 10) ∧ sub = ( x _ old . 0 − 10) b _ 3 ∧ x . 3 = ( x _ old . 0 − 10) t _ 2 _ 4 ∧ b _ 2 ⇒ ( x . 2 = ite ( t _ 1 _ 2 , x . 1 , x . 0)) t _ 3 _ 4 cost = 6 cost = 11 ∧ b _ 4 ⇒ ( x . 1 = ite ( t _ 3 _ 4 , x . 3 , x . 2)) b _ 4

Recommend


More recommend