Austin, Texas 2011 Theorem Proving Tools for Program Analysis SMT Solvers: Yices & Z3 Austin, Texas 2011 Nikolaj Bjørner 2, Bruno Dutertre 1, Leonardo.

Slides:



Advertisements
Similar presentations
Logical Abstract Interpretation Sumit Gulwani Microsoft Research, Redmond.
Advertisements

A practical and complete approach to predicate abstraction Ranjit Jhala UCSD Ken McMillan Cadence Berkeley Labs.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Satisfiability Modulo Theories and Network Verification Nikolaj Bjørner Microsoft Research Formal Methods and Networks Summer School Ithaca, June
Using SMT solvers for program analysis Shaz Qadeer Research in Software Engineering Microsoft Research.
Linear real and integer arithmetic. Fixed-size bit-vectors Uninterpreted functions Extensional arrays Quantifiers Model generation Several input formats.
Finding bugs: Analysis Techniques & Tools Symbolic Execution & Constraint Solving CS161 Computer Security Cho, Chia Yuan.
Satisfiability Modulo Theories (An introduction)
SMT Solvers (an extension of SAT) Kenneth Roe. Slide thanks to C. Barrett & S. A. Seshia, ICCAD 2009 Tutorial 2 Boolean Satisfiability (SAT) ⋁ ⋀ ¬ ⋁ ⋀
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Proofs from SAT Solvers Yeting Ge ACSys NYU Nov
Programming with Constraint Solvers CS294: Program Synthesis for Everyone Ras Bodik Emina Torlak Division of Computer Science University of California,
1 Regression-Verification Benny Godlin Ofer Strichman Technion.
Software Engineering & Automated Deduction Willem Visser Stellenbosch University With Nikolaj Bjorner (Microsoft Research, Redmond) Natarajan Shankar (SRI.
1 Translation Validation: From Simulink to C Michael RyabtsevOfer Strichman Technion, Haifa, Israel Acknowledgement: sponsored by a grant from General.
Logic as the lingua franca of software verification Ken McMillan Microsoft Research TexPoint fonts used in EMF: A A A A A Joint work with Andrey Rybalchenko.
Panel on Decision Procedures Panel on Decision Procedures Randal E. Bryant Lintao Zhang Nils Klarlund Harald Ruess Sergey Berezin Rajeev Joshi.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Plan for today Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search.
Nikolaj Bjørner Microsoft Research Lecture 3. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
1 Satisfiability Modulo Theories Sinan Hanay. 2 Boolean Satisfiability (SAT) Is there an assignment to the p 1, p 2, …, p n variables such that  evaluates.
Yeting Ge Leonardo de Moura New York University Microsoft Research.
Counterexample Generation for Separation-Logic-Based Proofs Arlen Cox Samin Ishtiaq Josh Berdine Christoph Wintersteiger.
Program Exploration with Pex Nikolai Tillmann, Peli de Halleux Pex
Nikolaj Bjørner Leonardo de Moura Nikolai Tillmann Microsoft Research August 11’th 2008.
Quantifier Elimination Procedures in Z3 Support for Non-linear arithmetic Fixed-points – features and a preview.
1 A propositional world Ofer Strichman School of Computer Science, Carnegie Mellon University.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Caltech Pasadena, CA 12 November 2009.
MCA –Software Engineering Kantipur City College. Topics include  Formal Methods Concept  Formal Specification Language Test plan creation Test-case.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
Smten: Automatic Translation of High-level Symbolic Computations into SMT Queries Richard Uhler (MIT-CSAIL) and Nirav Dave (SRI International) CAV 2013.
Nikolaj Bjørner and Leonardo de Moura Microsoft Research Microsoft Corporation McMaster University, November 28, 2007.
Leonardo de Moura Microsoft Research. Quantifiers in Satisfiability Modulo Theories Logic is “The Calculus of Computer Science” (Z. Manna). High computational.
Formal Methods: Three suggestions for rapid adoption Wolfram Schulte RiSE, MSR Workshop on Usable Verification 11/15/2010.
Nikolaj Bjørner, Leonardo de Moura Microsoft Research Bruno Dutertre SRI International.
From SAT to SMT A Tutorial Nikolaj Bjørner Microsoft Research Dagstuhl April 23, 2015.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Advances in Automated Theorem Proving Leonardo de Moura, Nikolaj Bjørner Ken McMillan, Margus Veanes presented by Thomas Ball
Leonardo de Moura Microsoft Research. Is formula F satisfiable modulo theory T ? SMT solvers have specialized algorithms for T.
Ethan Jackson, Nikolaj Bjørner and Wolfram Schulte Research in Software Engineering (RiSE), Microsoft Research 1. A FORMULA for Abstractions and Automated.
1 MVD 2010 University of Iowa New York University Comparing Proof Systems for Linear Real Arithmetic Using LFSC Andrew Reynolds September 17, 2010.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
CJAdviser: SMT-based Debugging Support for ContextJ* Shizuka Uchio(Kyushu University, Japan) Naoyasu Ubayashi(Kyushu University, Japan) Yasutaka Kamei(Kyushu.
Ruzica Piskac Max Planck Institute for Software Systems, Germany.
Integrating high-level constructs into programming languages Language extensions to make programming more productive Underspecified programs –give assertions,
Leonardo de Moura Microsoft Research. Quantifiers in Satisfiability Modulo Theories Logic is “The Calculus of Computer Science” (Z. Manna). High computational.
Leonardo de Moura Microsoft Research. Verification/Analysis tools need some form of Symbolic Reasoning.
Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Automated tactics for separation logic VeriML Reconstruct Z3 Proof Safe incremental type checker Certifying code transformation Proof carrying hardware.
Symbolic and Concolic Execution of Programs Information Security, CS 526 Omar Chowdhury 10/7/2015Information Security, CS 5261.
Welcome to CS 477 Formal Methods in Software Development Spring 2011 Madhusudan Parthasarathy ( Madhu )
Leonardo de Moura Microsoft Research. Applications and Challenges in Satisfiability Modulo Theories Verification/Analysis tools need some form of Symbolic.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
Logic Engines as a Service Leonardo de Moura and Nikolaj Bjørner Microsoft Research.
Finding Conflicting Instances of Quantified Formulas in SMT Andrew Reynolds Cesare Tinelli Leonardo De Moura July 18, 2014.
Selected Decision Procedures and Techniques for SMT More on combination – theories sharing sets – convex theory Un-interpreted function symbols (quantifier-free.
Nikolaj Bjørner Microsoft Research DTU Winter course January 4 th 2012 Organized by Hanne Riis Nielson, Flemming Nielson.
Formal Verification – Robust and Efficient Code Lecture 1
Satisfiability Modulo Theories and DPLL(T) Andrew Reynolds March 18, 2015.
Mostly-Automated Verification of Low-Level Programs in Computational Separation Logic Adam Chlipala Harvard University PLDI 2011.
Dafny An automatic program verifier for functional correctness
Satisfiability Modulo Theories
Lazy Proofs for DPLL(T)-Based SMT Solvers
Solving Linear Arithmetic with SAT-based MC
Satisfiability Modulo Theories
Dafny An automatic program verifier for functional correctness
The SMT-LIB Initiative
Presentation transcript:

Austin, Texas 2011 Theorem Proving Tools for Program Analysis SMT Solvers: Yices & Z3 Austin, Texas 2011 Nikolaj Bjørner 2, Bruno Dutertre 1, Leonardo de Moura 2 SRI International 1, Microsoft Research 2

Yices is SRI’s SMT Solver Freely available for non-commercial use Multiple platforms are supported (Windows, Mac OS X, Linux) Backend of other SRI tools (PVS, SAL model checkers) Two versions exist Yices 1 is the official system (first release, August 2006) Yices 2 is an improved version under development (prerelease prototypes are available) Interface: Text: both SMT LIB Yices’s own input language Library API (C/C++)

Z3 is a new solver developed at Microsoft Research. Development/Research driven by internal customers. Free for academic research. Interfaces: Z3 SMT-LIB Simplify Native C/C++.NETOCaml

1. The Logic of SMT solvers 2. Decidability and Decision Procedures 3. User Interaction and Guidance 4. Main Applications

1. The Logic of SMT solvers Many-sorted first-order logic + background theories. 2. Decidability and Decision Procedures Ground decision procedures: SAT, Uninterpreted Functions, Linear Arithmetic, Bit-vectors, Algebraic data-types, Arrays – emphasis on scale. First-order quantifiers: decidable fragments, quantifier-elimination, generally undecidable and incomplete – no induction or planning. 3. User Interaction and Guidance Back-ends inside analysis tools – not end-to-end. 4. Main Applications Program verification, Symbolic execution, Modeling

The Logic of SMT Solvers

SMT: Satisfiability Modulo Theories Input: a first-order formula  over background theory Output: is  satisfiable? does  have a model? Is there a refutation of  = proof of  ? For most SMT solvers:  is a ground formula Background theories: Arithmetic, Arrays, Bit-vectors, Algebraic Datatypes Most SMT solvers support simple first-order sorts

b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)

ArithmeticArithmetic

ArithmeticArithmetic Array Theory b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)

ArithmeticArithmetic Array Theory Uninterpreted Functions b + 2 = c and f(read(write(a,b,3), c-2)) ≠ f(c-b+1)

Substituting c by b+2

b + 2 = c and f(read(write(a,b,3), b+2-2)) ≠ f(b+2-b+1) Simplifying

b + 2 = c and f(read(write(a,b,3), b)) ≠ f(3)

Applying array theory axiom forall a,i,v: read(write(a,i,v), i) = v

b + 2 = c and f(3) ≠ f(3) Inconsistent/Unsatisfiable

Simple sorts: Bool - Booleans Int, Real - Integers and Reals BitVec[32], BitVec[n] - Bit-vectors (Array Int Int) - Arrays Sorted Terms: (+ (xCoord q) (yCoord q)) Formulas = Terms of Boolean Sort Quantified formulas: (forall ((x Int)) (=> (> x 0) (p x)))

Machines Jobs P = NP?Laundry Tasks

Constraints: Precedence: between two tasks of the same job Resource : Machines execute at most one job at a time

Not convex

(set-logic QF_IDL) (declare-fun t11 () Int) (declare-fun t12 () Int) (declare-fun t21 () Int) (declare-fun t22 () Int) (declare-fun t31 () Int) (declare-fun t32 () Int) Optionally specify the logic. The benchmark is going to use Integer Difference Logic and use the a solver for difference logic Declare constants that are going to be used in the problem. Constants are functions that don’t take any arguments. Z3.exe /smt2 /is /m Start Z3 using smt-lib mode in interactive (/si) enable models (/m).

(assert (and (>= t11 0) (>= t12 (+ t11 2)) (<= (+ t12 1) 8))) (assert (and (>= t21 0) (>= t22 (+ t21 3)) (<= (+ t22 1) 8))) (assert (and (>= t31 0) (>= t32 (+ t31 2)) (<= (+ t32 3) 8))) Add the precedence constraints

(assert (or (>= t11 (+ t21 3)) (>= t21 (+ t11 2)))) (assert (or (>= t11 (+ t31 2)) (>= t31 (+ t11 2)))) (assert (or (>= t21 (+ t31 2)) (>= t31 (+ t21 3)))) (assert (or (>= t12 (+ t22 1)) (>= t22 (+ t12 1)))) (assert (or (>= t12 (+ t32 3)) (>= t32 (+ t12 1)))) (assert (or (>= t22 (+ t32 3)) (>= t32 (+ t22 1)))) Add the resource constraints

(check-sat) (model) Check satisfiability of the assertions Display the model ("model" "t11 -> 5 t12 -> 7 t21 -> 2 t22 -> 5 t31 -> 0 t32 -> 2")

(declare-fun id (sort*) sort)declare function (define-fun id ((id sort)*) sort term) define an expression shorthand (assert term)assert formula (check-sat) check satisfiability of assertions (push [number])push 1 (or number) scopes (pop [number])pop 1 (or number) scopes (get-info model)model from satisfied assertions

term ::= id | number | (id term+) | (forall (id sort)+ term) sort ::= id | (id sort+) id ::= and | or | => | + | - | * | …| token | …

Heuristic quantifier instantiationCombining SMT with Saturation proversComplete quantifier instantiationDecidable fragmentsModel based quantifier instantiation

(declare-sort Type) (declare-fun subtype (Type Type) Bool) (delcare-fun List (Type) Type) (assert (forall (x Type) (subtype x x))) (assert (forall (x Type) (y Type) (z type) (=> (and (subtype x y) (subtype y z)) (subtype x z)))) (assert (forall (x Type) (y Type) (=> (and (subtype x y) (subtype y x)) (= x y)))) (assert (forall (x Type) (y Type) (z type) (=> (and (subtype x y) (subtype x z)) (or (subtype y z) (subtype z y))))) (assert (forall (x Type) (y Type) (=> (subtype x y) (subtype (List x) (List y))))) Example: Single inheritance subtyping

(assert (forall (x Type) (y Type) (=> (subtype x y) (subtype (List x) (List y))) :pat {(List x) (List y) } ) Example: Single inheritance subtyping Multi-pattern Terminates: depth of new terms is bounded  Expensive: Quadratic Instantiated for every pair of (List a) and (List b) created during search.. But transitive closure is worse – it is cubic.

(assert (forall (x Type) (y Type) (=> (subtype x y) (subtype (List x) (List y))) :pat {(subtype (List x) (List y)) } ) Example: Single inheritance subtyping

(assert (forall (x Type) (y Type) (=> (subtype x y) (subtype (List x) (List y))) :pat {(subtype x y) } ) Example: Single inheritance subtyping (=> (subtype a b) (subtype (List a) (List b))) (=> (subtype (List a) (List b)) (subtype (List (List a)) (List (List b))) ) … matching loop

Decidability and Decision Procedures

Is formula  satisfiable modulo theory T ? SMT solvers have specialized algorithms for T

An SMT Solver is a collection of Little Engines of Proof CS359: Little Engines of Proof Shankar et al

An SMT Solver is a collection of Little Engines of Proof Examples: SAT Solver Equality solver Arithmetic, Array, Bit-vector, data-type solvers Examples: SAT Solver Equality solver Arithmetic, Array, Bit-vector, data-type solvers

Uninterpreted functions Arithmetic (linear) Bit-vectors Algebraic data-types Arrays User-defined

Uninterpreted functions Arithmetic (linear) Bit-vectors Algebraic data-types Arrays User-defined

Uninterpreted functions Arithmetic (linear) Bit-vectors Algebraic data-types Arrays User-defined

Uninterpreted functions Arithmetic (linear) Bit-vectors Algebraic data-types Arrays User-defined

Uninterpreted functions Arithmetic (linear) Bit-vectors Algebraic data-types Arrays User-defined

User-interaction and Guidance

Text: SMT-LIB1.2, SMT-LIB2, Native Yices (high-level), Native Z3 (low-level), Simplify Programmatic APIs: C, Ocaml,.NET, LINQ,

Logical Formula Sat/Model

Logical Formula Unsat/Proof

Simplify Logical Formula

Implied Equalities Implied Equalities -x and y are equal -z + y and x + z are equal Logical Formula

Quantifier Elimination Quantifier Elimination Logical Formula

Unsat. Core

Yices (and Z3, but unweighted) have support for soft constraints (define-type uri) (define relatedProject::(-> uri uri bool)) (define PASO-107::uri) (define PASO-107b::uri)... (assert+ (relatedProject PASO-47 PASO-33) ) (assert+ (relatedProjectIs PASO-76 PASO-21) 32768)... (max-sat) (define-type uri) (define relatedProject::(-> uri uri bool)) (define PASO-107::uri) (define PASO-107b::uri)... (assert+ (relatedProject PASO-47 PASO-33) ) (assert+ (relatedProjectIs PASO-76 PASO-21) 32768)... (max-sat) Search for model of maximal weight Weighted Assertions Sat... (= PASO-47 1) (= PASO-33 2)... (= (relatedProject 7 2) true) Cost: Sat... (= PASO-47 1) (= PASO-33 2)... (= (relatedProject 7 2) true) Cost:

Main applications

Test case generationVerifying CompilersPredicate Abstraction Invariant Generation Type Checking Model Based Testing

Model checking: Back-end solver for SAL model checkers Model Checker Modulo Theories (MCMT, Ghilardi & Ranise) Analysis of Hybrid Systems (Tiwari) Lustre Model Verification (Hagen & Tinelli) Program analysis: Test-case generation (Sireum/Kiasan, CREST) Code synthesis (Gulwani, et al.) Code refactoring Scheduling: Timed-triggered systems (Steiner) Biological system modeling

- SDV: The Static Driver Verifier - PREfix: The Static Analysis Engine for C/C++. - 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 - 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

unsigned GCD(x, y) { requires(y > 0); while (true) { unsigned m = x % y; if (m == 0) return y; x = y; y = m; } We want a trace where the loop is executed twice. (y 0 > 0) and (m 0 = x 0 % y 0 ) and not (m 0 = 0) and (x 1 = y 0 ) and (y 1 = m 0 ) and (m 1 = x 1 % y 1 ) and (m 1 = 0) SolverSolver x 0 = 2 y 0 = 4 m 0 = 2 x 1 = 4 y 1 = 2 m 1 = 0 SSASSA

Rich Combination Linear Arithmetic Bitvector s Arrays Free Functions Models Model used as test inputs  -Quantifier Used to model custom theories (e.g.,.NET type system) API Huge number of small problems. Textual interface is too inefficient.

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

Summary

To discharge basic theorems automatically Larger search problems: Integration with SAT solver cores enable modern, efficient search algorithms. When your problem uses common theories: Arithmetic, Arrays, Data-types, bit-vectors. Mostly ground, but with some support for quantifiers: Quantifier methods by instantiation tuned for program verification problems