970 likes | 1.19k Views
Z3: A Decision Engine for Software. Nikolaj Bjørner and Leonardo de Moura Microsoft Research TCN Programming Languages event, January 31 st. Slides: http ://my/sites/redmond_nbjorner /. RiSE. RiSE – a primer Symbolic Reasoning Engines using Z3 What is SMT? Little Engines of Proof
E N D
Z3: A Decision Engine for Software Nikolaj Bjørner and Leonardo de Moura Microsoft Research TCN Programming Languages event, January 31st Slides: http://my/sites/redmond_nbjorner/
RiSE RiSE – a primer Symbolic Reasoning Engines using Z3 What is SMT? Little Engines of Proof Solver: Interaction Directions Extra: Nuts and Bolts Microsoft Research Redmond
RiSE: Research in Software Engineering http://rise4fun.com/AGL/rise
AGL – Automatic Graph Layout Lev Nachmanson Tim Dwyer Ted Hart Alexander Holroyd • Applications: • Dev10 Progression • Dev11Tuvalu • SpecExplorer • Many others
CCI and ER CCI2: Common Compiler Infrastructure v2 Herman Venter ER: Extended ReflectionNikolai Tillmann HeapDbg uses CCI+AGL Manuel Fändrich Mark Marron SMT@Microsoft
Cuzz: Concurrency Fuzzing Child Parent void* p = 0; CallCuzz(); CreateThd(child); CallCuzz(); p = malloc(…); void* p = 0; CreateThd(child); p = malloc(…); void* p = 0; RandDelay(); CreateThd(child); RandDelay(); p = malloc(…); void* p = 0; RandDelay(); CreateThd(child); • Instrument calls to Cuzz • Insert random delays • Use the Cuzz algorithm to determine when and by how much to delay Init(); RandDelay(); DoMoreWork(); RandDelay(); p->f ++; Init(); RandDelay(); DoMoreWork(); Init(); DoMoreWork(); p->f ++; Init(); CallCuzz(); DoMoreWork(); CallCuzz(); p->f ++; RandDelay(); p = malloc(…); RandDelay(); p->f ++; This is where all the magic (probabilistic analysis) is • Cuzz by MadanMusuvathi, Sebastian Burckhardt- in AppVerifier, used to find bugs in SQL, IE, ACPI, Kernel
Symbolic Reasoning RiSE- a primer Symbolic Reasoning Engines using Z3 What is SMT? Little Engines of Proof Solver: Interaction Directions Extra: Nuts and Bolts
Tools using the Z3 Decision Engine http://research.microsoft.com/projects/z3
Symbolic Reasoning • Verification/Analysis tools need some form of Symbolic Reasoning
What is logic? • Logic is the science of effective symbolic reasoning. • How can we draw general and reliable conclusions from a collection of facts? • Formal logic: Precise, syntactic characterizations of well-formed expressions and valid deductions. • Formal logic makes it possible to calculate consequences at the symbolic level. • Computers can be used to automate such symbolic calculations.
Symbolic Reasoning Logic is “The Calculus of Computer Science” (Z. Manna). Succinct: High computational complexity Undecidable (FOL + LA) Semi-decidable (First-order logic) NEXPTime-complete (EPR) PSpace-complete (QBF) NP-complete (Propositional logic) P-time (Equality)
Symbolic Engines: SAT, FTP and SMT • SAT: Propositional Satisfiability. (Tie Shirt) (Tie Shirt) (Tie Shirt) • FTP: First-order Theorem Proving. X,Y,Z [X*(Y*Z) = (X*Y)*Z] X [X*inv(X) = e] X [X*e = e] • SMT: Satisfiability Modulo background Theoriesb + 2 = c A[3]≠ A[c-b+1]
SAT - Milestones Problems impossible 10 years ago are trivial today Concept 2002 2010 Millions of variables from HW designs
FTP - Milestones • Some successstories: • Open Problems (of 25 years):XCB: X ((X Y) (Z Y)) Z)is a single axiom for equivalence • Knowledge Ontologies GBs of formulas Courtesy Andrei Voronkov, Manchester U
SMT - Milestones Z3 (of ’07) Time On BoogieRegression 1sec Simplify (of ’01) time Z3 Time On VCC Regression Includes progress from SAT: 15KLOC + 215KLOC = Z3 Nov 08 March 09
Engines Using Z3 RiSE- a primer Symbolic Reasoning Engines using Z3 What is SMT? Little Engies of Proof Solver: Interaction Directions Extra: Nuts and Bolts
Some Microsoft Engines using Z3 • SDV: The Static Driver Verifier • Pex: Program EXploration for .NET • SAGE: Scalable Automated Guided Execution • Spec#: C# + contracts • VCC: Verifying C Compiler for the Viridian Hyper-Visor • HAVOC: Heap-Aware Verification of C-code • SpecExplorer: Model-based testing of protocol specs • Yogi: Dynamic symbolic execution + abstraction • FORMULA: Model-based Design • PREfix: The Static Analysis Engine for C/C++ • F7: Refinement types for security protocols • Rex: Regular Expressions and formal languages • VS3: Abstract interpretation and Synthesis • VERVE: Verified operating system • FINE: Proof carrying certified code • SLAyer: Separation Logic-based Static Analysis
Test case generation unsigned GCD(x, y) { requires(y > 0); while (true) { unsigned m = x % y; if (m == 0) return y; x = y; y = m; } } (y0 > 0) and (m0 = x0 % y0) and not (m0 = 0) and (x1 = y0) and (y1 = m0) and (m1 = x1 % y1) and (m1 = 0) • x0 = 2 • y0 = 4 • m0 = 2 • x1 = 4 • y1 = 2 • m1 = 0 SSA Solver We want a trace where the loop is executed twice.
FINE: F# with Refinement Types Signature: div : int, { x : int | x 0 } int Subtype Call site: • if a 1 and a b then • return div(a, b) Verification condition • a 1 and a b implies b 0
FORMULA: Design Space Exploration Use Design Space Exploration to identify valid candidate architectures
Extended Static Checking and Verification Hyper-V Boogie VCC HAVOC Verification condition NTFS, SymDiff Bug path F7/FINE
What is SMT? RiSE- a primer Symbolic Reasoning Engines using Z3 What is SMT? Little Engines of Proof Solver: Interaction Solver: Nuts and Bolts Directions
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1) Arithmetic
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1) Array Theory Arithmetic
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1) Uninterpreted Functions Array Theory Arithmetic
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1) • Substituting c by b+2
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), b+2-2)) ≠ f(b+2-b+1) • Simplifying
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), b)) ≠ f(3)
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(read(write(a,b,3), b)) ≠ f(3) • Applying array theory axiom • foralla,i,v: read(write(a,i,v), i) = v
Satisfiability Modulo Theories (SMT) • b + 2 = c and f(3) ≠ f(3) • Inconsistent/Unsatisfiable
SMT by Example: Job Shop Scheduling Machines Tasks Jobs P = NP? Laundry
Job Shop Scheduling Constraints: Precedence: between two tasks of the same job Resource: Machines execute at most one job at a time 3 1 2 4
Job Shop Scheduling Constraints: Encoding: Precedence: - start time of job 2 on mach 3 - duration of job 2 on mach 3 Resource: 3 1 2 4 Notconvex
Little Engines of Proof RiSE- a primer Symbolic Reasoning Engines using Z3 What is SMT? Little Engines of Proof Solver: Interaction Directions Extra: Nuts and Bolts
Little Engines of Proof An SMT Solver is a collection of Little Engines of Proof
Little Engines of Proof An SMT Solver is a collection of Little Engines of Proof Examples: SAT Solver Equality solver Arithmetic solver
SMT : Basic Architecture • Equality + UF • Arithmetic • Bit-vectors • Data-types • … Case Analysis 15KLOC + 215KLOC = Z3
Theories • Uninterpretedfunctions • Arithmetic (linear) • Bit-vectors • Algebraic data-types • Arrays • User-defined
Theories • Uninterpreted functions • Arithmetic (linear) • Bit-vectors • Algebraic data-types • Arrays • User-defined
Theories • Uninterpreted functions • Arithmetic (linear) • Bit-vectors • Algebraic data-types • Arrays • User-defined
Theories • Uninterpreted functions • Arithmetic (linear) • Bit-vectors • Algebraic data-types • Arrays • User-defined