Automating Induction for Solving Horn Clauses

Slides:



Advertisements
Similar presentations
Functional Decompositions for Hardware Verification With a few speculations on formal methods for embedded systems Ken McMillan.
Advertisements

Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
Type-based termination analysis with disjunctive invariants Dimitrios Vytiniotis, MSR Cambridge with Byron Cook (MSR Cambridge) and Ranjit Jhala (UCSD)
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
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.
1 Regression-Verification Benny Godlin Ofer Strichman Technion.
1 1 Regression Verification for Multi-Threaded Programs Sagar Chaki, SEI-Pittsburgh Arie Gurfinkel, SEI-Pittsburgh Ofer Strichman, Technion-Haifa Originally.
Software Engineering & Automated Deduction Willem Visser Stellenbosch University With Nikolaj Bjorner (Microsoft Research, Redmond) Natarajan Shankar (SRI.
1 Dependent Types for Termination Verification Hongwei Xi University of Cincinnati.
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
© Anvesh Komuravelli Spacer Automatic Abstraction in SMT-Based Unbounded Software Model Checking Anvesh Komuravelli Carnegie Mellon University Joint work.
Automating Relatively Complete Verification of Higher-Order Functional Programs Hiroshi Unno (University of Tsukuba) Tachio Terauchi (Nagoya University)
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.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
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:
An Integration of Program Analysis and Automated Theorem Proving Bill J. Ellis & Andrew Ireland School of Mathematical & Computer Sciences Heriot-Watt.
Nikolaj Bjørner Microsoft Research Lecture 3. DayTopicsLab 1Overview of SMT and applications. SAT solving, Z3 Encoding combinatorial problems with Z3.
Interpolants [Craig 1957] G(y,z) F(x,y)
1 Predicate Abstraction of ANSI-C Programs using SAT Edmund Clarke Daniel Kroening Natalia Sharygina Karen Yorav (modified by Zaher Andraus for presentation.
Formal Verification of SpecC Programs using Predicate Abstraction Himanshu Jain Daniel Kroening Edmund Clarke Carnegie Mellon University.
An Investigation of the Multimorphisms of Tractable and Intractable Classes of Valued Constraints Mathematics of Constraint Satisfaction: Algebra, Logic.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.
© Andrew IrelandDependable Systems Group Proof Automation for the SPARK Approach to High Integrity Ada Andrew Ireland Computing & Electrical Engineering.
SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.
Refinement Type Inference via Horn Constraint Optimization Kodai Hashimoto and Hiroshi Unno (University of Tsukuba, Japan)
Type Systems CS Definitions Program analysis Discovering facts about programs. Dynamic analysis Program analysis by using program executions.
© Gudmund Grov & Andrew Ireland Dependable Systems Group Planning for System Development Gudmund Grov & Andrew Ireland Dependable Systems Group School.
Analyzing relational logic Daniel Jackson, MIT WG 2.3 · Newcastle April 2000.
Chapter 3 Part II Describing Syntax and Semantics.
© Andrew IrelandDependable Systems Group Proof Automation for the SPARK Approach to High Integrity Ada Andrew Ireland Computing & Electrical Engineering.
Random Interpretation Sumit Gulwani UC-Berkeley. 1 Program Analysis Applications in all aspects of software development, e.g. Program correctness Compiler.
Formal Specification: a Roadmap Axel van Lamsweerde published on ICSE (International Conference on Software Engineering) Jing Ai 10/28/2003.
This Week Lecture on relational semantics Exercises on logic and relations Labs on using Isabelle to do proofs.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
1 Interactive Computer Theorem Proving CS294-9 October 19, 2006 Adam Chlipala UC Berkeley Lecture 9: Beyond Primitive Recursion.
Proof And Strategies Chapter 2. Lecturer: Amani Mahajoub Omer Department of Computer Science and Software Engineering Discrete Structures Definition Discrete.
Chapter 12. Chapter Summary Boolean Functions Representing Boolean Functions Logic Gates Minimization of Circuits (not currently included in overheads)
Sub-fields of computer science. Sub-fields of computer science.
Spring 2017 Program Analysis and Verification
Integer Programming An integer linear program (ILP) is defined exactly as a linear program except that values of variables in a feasible solution have.
SS 2017 Software Verification Bounded Model Checking, Outlook
Further with Hoare Logic Sections 6.12, 6.10, 6.13
Computability and Complexity
Chapter 3 The Real Numbers.
SMT-Based Verification of Parameterized Systems
Solving Linear Arithmetic with SAT-based MC
Parametric Symbolic Reachability
MoCHi: Software Model Checker for a Higher-Order Functional Language
Propositional Calculus: Boolean Algebra and Simplification
Relatively Complete Refinement Type System for Verification of Higher-Order Non-deterministic Programs Hiroshi Unno (University of Tsukuba) Yuki Satake.
Inferring Simple Solutions to Recursion-free Horn Clauses via Sampling
Complexity 6-1 The Class P Complexity Andrei Bulatov.
Lecture 5 Floyd-Hoare Style Verification
IS 2935: Developing Secure Systems
Programming Languages 2nd edition Tucker and Noonan
Over-Approximating Boolean Programs with Unbounded Thread Creation
Copyright © Cengage Learning. All rights reserved.
Computer Security: Art and Science, 2nd Edition
The Zoo of Software Security Techniques
Some Programming Paradigms
Programming Languages and Compilers (CS 421)
Agenda Proofs (Konsep Pembuktian) Direct Proofs & Counterexamples
Programming Languages 2nd edition Tucker and Noonan
Rich Model Toolkit – An Infrastructure for Reliable Computer Systems
Presentation transcript:

Automating Induction for Solving Horn Clauses Hiroshi Unno, Sho Torii, and Hiroki Sakamoto University of Tsukuba, Japan 2017/7/28 Computer Aided Verification 2017

Program Verification via Horn Constraint Solving Verification Problems of Programs in Various Paradigms (e.g., functional [U.+ ’08, ’09, Rondon+ ’08, …], procedural [Grebenshchikov+ ’12, Gurfinkel+ ’15], object-oriented [Kahsai+ ’16], multi-threaded [Gupta+ ’11], constraint logic) with Advanced Language Features (e.g., algebraic data structures, linked data structures, exceptions, higher-order functions) with Side-Effects (e.g., non-termination, non-determinism, concurrency, assertions, destructive updates) Reduce Horn Constraint Solving Problems 2017/7/28 Computer Aided Verification 2017

Overall Flow of Horn Constraint based Program Verification Program & Specification (* OCaml *) let rec mult x y = if y = 0 then 0 else x + mult x (y - 1) /* C */ int mult(int x, int y) { int s = 0; while(y != 0){ s += x; y--; } return s; {- Haskell -} mult :: Int -> Int -> Int mult x 0 = 0 mult x y = x + mult x (y - 1) Constraint Generation Horn Constraint Set 𝑃 𝑥,𝑦,𝑟 ≡𝑟=𝑥×𝑦 Constraint Solving Solution or Counterexample 2017/7/28 Computer Aided Verification 2017

This Work Horn Constratint Solving Horn Constraint Set Reduce Inductive Theorem Proving Constraint Solving Solvable or Not SMT Solving Enable verification of relational specifications across programs in various paradigms Support constraints over any background theories (if the backend SMT solver does) 2017/7/28 Computer Aided Verification 2017

Relational Specifications Specifications that involve multiple function calls Equivalence Invertibility Non-interference Associativity Commutativity Distributivity Monotonicity Idempotency … 2017/7/28 Computer Aided Verification 2017

Overall Flow of Horn Constraint based Program Verification (Functional) Program & Relational Specification Constraint Generation Horn Constraint Set Constraint Solving Solvable or Not 2017/7/28 Computer Aided Verification 2017

Example: (Functional) Program and Relational Specification (* recursive function to compute “x × y” *) let rec mult x y = if y = 0 then 0 else x + mult x (y - 1) (* tail recursive function to compute “x × y + a” *) let rec mult_acc x y a = if y = 0 then a else mult_acc x (y - 1) (a + x) (* functional equivalence of mult and mult_acc *) let main x y a = assert (mult x y + a = mult_acc x y a) 2017/7/28 Computer Aided Verification 2017

Overall Flow of Horn Constraint based Program Verification (Functional) Program & Relational Specification Constraint Generation Horn Constraint Set Constraint Solving Solvable or Not 2017/7/28 Computer Aided Verification 2017

Horn Constraint Generation [U.+ ’09] let rec mult x y = if y = 0 then 0 else x + mult x (y - 1) let rec mult_acc x y a = if y = 0 then a else mult_acc x (y - 1) (a + x) let main x y a = assert (mult x y + a = mult_acc x y a) 2017/7/28 Computer Aided Verification 2017

Overall Flow of Horn Constraint based Program Verification (Functional) Program & Relational Specification Constraint Generation Horn Constraint Set Constraint Solving Solvable or Not 2017/7/28 Computer Aided Verification 2017

Horn Constraint Solving Check the existence of a solution for predicate variables satisfying all the Horn constraints If a solution exists, the original program is guaranteed to satisfy the specification Example (Non-relational) specification: let main x y = if x >= 0 && y >= 0 then assert (mult x y >= 0) Solution 1: 𝑃 𝑥,𝑦,𝑟 ≡𝑥≥0∧𝑦≥0⇒𝑟≥0 QF-LIA Solution 2: 𝑃 𝑥,𝑦,𝑟 ≡𝑟=𝑥×𝑦 QF-NIA Nonlinear 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Previous Methods for Solving Horn Clause Constraints [U.+ ’08,’09, Rondon+ ’08, Gupta+ ’11, Hoder+ ’11,’12, McMillan+ ’13, Rümmer+ ’13, …] Find a solution expressible in QF-LIA (or QF-LRA) Solution 1: 𝑃 𝑥,𝑦,𝑟 ≡𝑥≥0∧𝑦≥0⇒𝑟≥0 QF-LIA Solution 2: 𝑃 𝑥,𝑦,𝑟 ≡𝑟=𝑥×𝑦 QF-NIA 2017/7/28 Computer Aided Verification 2017

Example Constraints that Can Not be Solved by Previous Methods Constraint Solving Fails! Analyzed separately from 𝑄 Analyzed separately from 𝑃 QF-NIA 𝑃 𝑥,𝑦, 𝑠 1 ≡ 𝑠 1 =𝑥×𝑦 𝑄 𝑥,𝑦,𝑎, 𝑠 2 ≡ 𝑠 2 =𝑥×𝑦+𝑎 2017/7/28 Computer Aided Verification 2017

Our Constraint Solving Method Horn Constraint Set Reduce Inductive Theorem Proving Constraint Solving Simultaneously analyze multiple predicates by expressing and exploiting mutual invariants Solvable or Not 2017/7/28 Computer Aided Verification 2017

Reduction from Constraint Solving to Inductive Theorem Proving 𝑃 𝑥,0,0 𝑃 𝑥,𝑦,𝑥+𝑟 ⇐𝑃 𝑥,𝑦−1,𝑟 ∧𝑦≠0 𝑄 𝑥,0,𝑎,𝑎 𝑄 𝑥,𝑦,𝑎,𝑟 ⇐𝑄 𝑥,𝑦−1,𝑎+𝑥,𝑟 ∧𝑦≠0 𝑠 1 +𝑎= 𝑠 2 ⇐𝑃 𝑥,𝑦, 𝑠 1 ∧𝑄 𝑥,𝑦,𝑎, 𝑠 2 Prove this by induction on derivation of 𝑃 𝑥,𝑦, 𝑠 1 , Q x,y, s 2 ∀𝑥,𝑦, 𝑠 1 ,𝑎, 𝑠 2 .𝑃 𝑥,𝑦, 𝑠 1 ∧𝑄 𝑥,𝑦,𝑎, 𝑠 2 ⇒ 𝑠 1 +𝑎= 𝑠 2 2017/7/28 Computer Aided Verification 2017

Principle of Induction on Derivation ∀𝐷. 𝜓 𝐷 if and only if ∀𝐷. ∀ 𝐷 ′ . 𝐷 ′ ≺𝐷⇒𝜓 𝐷′ ⇒𝜓 𝐷 where 𝐷′≺𝐷 represents that 𝐷′ is a strict sub-derivation of 𝐷 𝐷= 𝐷 1 𝐽 3 𝐷 2 𝐽 2 𝐷 3 𝐷 4 𝐽 4 𝐽 1 Assume 𝜓 𝐷 1 ,𝜓 𝐷 2 , 𝜓 𝐷 3 , 𝜓 𝐷 4 and prove 𝜓 𝐷 2017/7/28 Computer Aided Verification 2017

Horn Constraint Solving: Induction hypotheses and lemmas Judgment Inductive Theorem Proving: ∅;𝑃 𝑥,𝑦, 𝑠 1 ,𝑄 𝑥,𝑦,𝑎, 𝑠 2 ⊢ 𝑠 1 +𝑎= 𝑠 2 Premises 2017/7/28 Computer Aided Verification 2017

Guard to avoid unsound application Add an induction hypothesis: 𝛾= ∀ 𝑥 ′ , 𝑦 ′ , 𝑠 1 ′ , 𝑎 ′ , 𝑠 2 ′ .𝐷 𝑃 𝑥 ′ , 𝑦 ′ , 𝑠 1 ′ ≺𝐷 𝑃 𝑥,𝑦, 𝑠 1 ∧ 𝑃 𝑥′,𝑦′, 𝑠 1 ′ ∧𝑄 𝑥 ′ , 𝑦 ′ , 𝑎 ′ , 𝑠 2 ′ ⇒ 𝑠 1 ′+𝑎′= 𝑠 2 ′ Induct Unfold Case analysis on the last rule used 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 2017/7/28 Computer Aided Verification 2017

Case analysis on the last rule used Unfold 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Validity checking Valid 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Valid 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 2017/7/28 Computer Aided Verification 2017

Case analysis on the last rule used Unfold Case analysis on the last rule used 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Valid 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 2017/7/28 Computer Aided Verification 2017

Apply induction hypothesis 𝜎 𝛾 = 𝐷 𝑃 𝑥,𝑦−1, 𝑠 1 −𝑥 ≺𝐷 𝑃 𝑥,𝑦, 𝑠 1 ∧𝑃 𝑥,𝑦−1, 𝑠 1 −𝑥 ∧ 𝑄 𝑥,𝑦−1,𝑎+𝑥, 𝑠 2 ⇒ 𝑠 1 −𝑥 +(𝑎+𝑥)= 𝑠 2 𝛾= ∀ 𝑥 ′ , 𝑦 ′ , 𝑠 1 ′ , 𝑎 ′ , 𝑠 2 ′ .𝐷 𝑃 𝑥 ′ , 𝑦 ′ , 𝑠 1 ′ ≺𝐷 𝑃 𝑥,𝑦, 𝑠 1 ∧ 𝑃 𝑥′,𝑦′, 𝑠 1 ′ ∧𝑄 𝑥 ′ , 𝑦 ′ , 𝑎 ′ , 𝑠 2 ′ ⇒ 𝑠 1 ′+𝑎′= 𝑠 2 ′ IndHyp Apply induction hypothesis 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Valid QED 2017/7/28 Computer Aided Verification 2017

Properties of Inductive Proof System for Horn Constraint Solving Soundness: If the goal is proved, the original Horn constraints have a solution (which may not be expressible in the underlying logic) Relative Completeness: If the original constraints have a solution expressible in the underlying logic, the goal is provable 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Automating Induction Use the following rule application strategy: Repeatedly apply INDHYP until no new premises are added Apply VALID whenever a new premise is added Select some 𝑃 𝑡 and apply INDUCT and UNFOLD Close a proof branch by using: SMT solvers: provide efficient and powerful reasoning about data structures (e.g., integers, reals, algebraic data structures) but predicates are abstracted as uninterpreted functions Horn constraint solvers: provide bit costly but powerful reasoning about inductive predicates 2017/7/28 Computer Aided Verification 2017

Prototype Constraint Solver Use Z3 and 𝝁Z PDR engine respectively as the backend SMT and Horn constraint solvers Integrated with a refinement type based verification tool RCaml for the OCaml functional language Can exploit lemmas which are: User-supplied, Heuristically obtained from the given constraints, or Automatically generated by an abstract interpreter Can generate a counterexample (if any) 2017/7/28 Computer Aided Verification 2017

Experiments on IsaPlanner Benchmark Set 85 (mostly) relational verification problems of total functions on inductively defined data structures Inductive Theorem Prover #Successfully Proved RCaml 68 Zeno 82 [Sonnex+ ’12] HipSpec 80 [Claessen+ ’13] CVC4 80 [Reynolds+ ’15] ACL2s 74 (according to [Sonnex+ ’12]) IsaPlanner 47 (according to [Sonnex+ ’12]) Dafny 45 (according to [Sonnex+ ’12]) Support automatic lemma discovery & goal generalization 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Experiments on Benchmark Programs with Advanced Language Features & Side-Effects 30 (mostly) relational verification problems for: Complex integer functions: Ackermann, McCarthy91 Nonlinear real functions: dyn_sys Higher-order functions: fold_left, fold_right, repeat, find, ... Exceptions: find Non-terminating functions: mult, sum, … Non-deterministic functions: randpos Imperative procedures: mult_Ccode 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 28 (2 required lemmas) successfully proved by RCaml 3 proved by Horn constraint solver 𝝁Z PDR 2 proved by inductive theorem prover CVC4 (if inductive predicates are encoded using uninterpreted functions) 2017/7/28 Computer Aided Verification 2017

Computer Aided Verification 2017 Conclusion Proposed an automated verification method combining Horn constraint solving and inductive theorem proving Enable relational verification across programs in various paradigms with advanced language features and side-effects Support constraints over any background theories (if the backend SMT solver does) Future and ongoing work: Automatic lemma discovery and goal generalization Relational program synthesis Coinduction 2017/7/28 Computer Aided Verification 2017