Avoiding Exponential Explosion: Generating Compact Verification Conditions Cormac Flanagan and James B. Saxe Compaq Systems Research Center With help from.

Slides:



Advertisements
Similar presentations
A SAT characterization of boolean-program correctness K. Rustan M. Leino Microsoft Research, Redmond, WA 14 Nov 2002 IFIP WG 2.4 meeting, Schloβ Dagstuhl,
Advertisements

Advanced programming tools at Microsoft
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
Extended Static Checking for Java Cormac Flanagan K. Rustan M. Leino Mark Lillibridge Greg Nelson James B. Saxe Raymie Stata Compaq SRC 18 June 2002 PLDI02,
Demand-driven inference of loop invariants in a theorem prover
1 Towards a Verifying Compiler: The Spec# Approach Wolfram Schulte Microsoft Research Formal Methods 2006 Joint work with Rustan Leino, Mike Barnett, Manuel.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 Summer school on Formal Models.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 0 Summer school on Formal Models.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Abstraction of Source Code (from Bandera lectures and talks)
A Program Transformation For Faster Goal-Directed Search Akash Lal, Shaz Qadeer Microsoft Research.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
Symmetry-Aware Predicate Abstraction for Shared-Variable Concurrent Programs Alastair Donaldson, Alexander Kaiser, Daniel Kroening, and Thomas Wahl Computer.
CS 355 – Programming Languages
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Extended Static Checking for Java Cormac Flanagan Slides courtesy of Rustan Leino.
1 Automatic Software Model Checking via Constraint Logic Programming Cormac Flanagan Systems Research Center HP Labs.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Hoare-style program verification K. Rustan M. Leino Guest lecturer Rob DeLine’s CSE 503, Software Engineering University of Washington 26 Apr 2004.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 Summer School on Logic and Theorem-Proving in Programming.
Modular Verification of Multithreaded Software Shaz Qadeer Compaq Systems Research Center Shaz Qadeer Compaq Systems Research Center Joint work with Cormac.
Building a program verifier K. Rustan M. Leino Microsoft Research, Redmond, WA 10 May 2006 Guest lecture, Shaz Qadeer’s cse599f, Formal Verification of.
Houdini: An Annotation Assistant for ESC/Java Cormac Flanagan and K. Rustan M. Leino Compaq Systems Research Center.
Predicate Abstraction for Software Verification Shaz Qadeer Compaq Systems Research Center (joint work with Cormac Flanagan)
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Review: forward E { P } { P && E } TF { P && ! E } { P 1 } { P 2 } { P 1 || P 2 } x = E { P } { \exists … }
Predicate Abstraction for Software Verification Cormac Flanagan Shaz Qadeer Compaq Systems Research Center.
Thread-Modular Verification Shaz Qadeer Joint work with Cormac Flanagan Stephen Freund Shaz Qadeer Joint work with Cormac Flanagan Stephen Freund.
Review: forward E { P } { P && E } TF { P && ! E } { P 1 } { P 2 } { P 1 || P 2 } x = E { P } { \exists … }
Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Describing Syntax and Semantics
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Proving Program Correctness The Axiomatic Approach.
Proving Program Correctness The Axiomatic Approach.
Jonathan Kuhn Robin Mange EPFL-SSC Compaq Systems Research Center Flanagan, Leino, Lillibridge, Nelson, Saxe and Stata.
Extended Static Checking for Java or Light-weight formal methods: from objects to components Joint work with Cormac Flanagan, Mark Lillibridge, Greg Nelson,
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Extended Static Checking for Java  ESC/Java finds common errors in Java programs: null dereferences, array index bounds errors, type cast errors, race.
Program Correctness. 2 Program Verification An object is a finite state machine: –Its attribute values are its state. –Its methods optionally: Transition.
Houdini, an annotation assistant for ESC/Java K. Rustan M. Leino Compaq SRC Joint work with Cormac Flanagan K. Rustan M. Leino Compaq SRC Joint work with.
Synthesis, Analysis, and Verification Lecture 05a Lectures: Viktor Kuncak Programs with Data Structures: Assertions for Accesses. Dynamic Allocation.
Applications of extended static checking K. Rustan M. Leino Compaq SRC K. Rustan M. Leino Compaq SRC Systems Research Center Invited talk, SAS’01, Paris,
Reasoning about programs March CSE 403, Winter 2011, Brun.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata.
Specifying and verifying programs in Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Invited talk, PSI 2006 Novosibirsk, Russia 27 June 2006.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Institute for Applied Information Processing and Communications (IAIK) – Secure & Correct Systems 1 Static Checking  note for.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
ESCJ 14: ESC/Java Project Review Slides March 6th, 1997.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
Extended Static Checking for Java
Weakest Precondition of Unstructured Programs
Further with Hoare Logic Sections 6.12, 6.10, 6.13
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Hoare-style program verification
Over-Approximating Boolean Programs with Unbounded Thread Creation
Hoare-style program verification
The Zoo of Software Security Techniques
COP4020 Programming Languages
Presentation transcript:

Avoiding Exponential Explosion: Generating Compact Verification Conditions Cormac Flanagan and James B. Saxe Compaq Systems Research Center With help from our ESC colleagues: Rustan Leino, Mark Lillibridge, Greg Nelson, Shaz Qadeer, Raymie Stata

Software QA via Testing u Useful (the dominant methodology), but.. u Costly l half of development cost is testing l finds errors late in development cycle u Incomplete l often fails to ensure needed reliability l hard to test all configurations

Software QA via Static Checking u Statically verify many correctness properties u Type systems catch many errors l e.g. “Cannot multiply a number and a string” u Would like to catch additional errors l e.g. “Array index out of bounds at line 10” u And verify other correctness properties l assertions l object invariants l lightweight method specifications

Extended Static Checker Architecture Java method + annotations Counterexamples  x.  y.(x > y ==> … ) Verification Condition VC Generator Decision Procedure Index out of bounds on line 218 Method does not preserve object invariant on line 223

Extended Static Checker Architecture Java method + annotations Guarded Command Counterexamples Front End Verification Condition VC Generator Decision Procedure Index out of bounds on line 218 Method does not preserve object invariant on line 223 Intermediate representation assume preconditions assume preconditions assume object invariants assume object invariants... translated body translated body... assert postconditions assert postconditions assert object invariants assert object invariants

private int scanPunctuation(int nextchr) { try { boolean possibleFloatingPointNumber = (nextchr == '.'); text[0] = (char)nextchr; textlen = 1; m_in.mark(); // All paths out of the try must unmark the stream!! PunctuationPrefixTree prefix = punctuationTable; PunctuationPrefixTree lastPunctuation = prefix; int lastPunctuationLength = 0; int index = nextchr - '!'; if (index < 0 || PunctuationPrefixTree.CHILDLEN <= index) prefix = null; else prefix = prefix.children[nextchr - '!']; nextchr = m_in.read(); if (possibleFloatingPointNumber && Character.isDigit((char)nextchr)) { m_in.clearMark(); return finishFloatingPointLiteral(nextchr); } this.append(nextchr); if (prefix != null && prefix.code != TagConstants.NULL) { lastPunctuation = prefix; lastPunctuationLength = textlen - 1; m_in.mark(); } while(prefix != null) { index = nextchr - '!'; if (index < 0 || PunctuationPrefixTree.CHILDLEN <= index) prefix = null; else prefix = prefix.children[nextchr - '!']; nextchr = m_in.read(); this.append(nextchr); if (prefix != null && prefix.code != TagConstants.NULL) { lastPunctuation = prefix; lastPunctuationLength = textlen - 1; m_in.mark(); } m_in.reset(); textlen = lastPunctuationLength; endingLoc = m_in.getLocation(); ttype = lastPunctuation.code; if (ttype != TagConstants.C_COMMENT&& ttype != TagConstants.EOL_COMMENT) nextchr = m_in.read(); return ttype; } catch (IOException e) { m_in.clearMark(); ErrorSet.fatal(m_in.getLocation(), e.toString()); return TagConstants.NULL; // Dummy }

Extended Static Checker Architecture Java method + annotations Guarded Command Counterexamples Exponential in size of GC Front End Verification Condition VC Generator Decision Procedure Index out of bounds on line 218 Method does not preserve object invariant on line 223 Weakest preconditions Strongest postconditions Symbolic forward execution

Statement S x := e A ; B assert e assume e A B while {I} e do S end {exceptions} Guarded Command Language Variables have arbitrary values in program’s initial state if e then A else B end  (assume e ; A) (assume  e ; B)

Weakest Precondition Semantics wp.S.Q Q(x  e) wp.A.(wp.B.Q) e  Q e  Q wp.A.Q  wp.B.Q Statement S x := e A ; B assert e assume e A B

Blow-up from assignment rule wp.(x := e).Q = Q(x  e)  Q(x  e) may contain many copies of e u Sequential composition of assignment statements may yield exponentially large VC, e.g. wp.( b=a+a ; c=b+b ;... ; z=y+y).(z>0)

Blow-up from Choice Statements wp.(A B).Q = wp.A.Q  wp.B.Q  The postcondition Q of a choice statement occurs twice in weakest precondition  Copies of Q modified due to assignment statements in A and B u Sequential composition of choice statements may yield exponentially large VC

Key Insight u Assignment statements are the culprit! l They cause problems both by themselves l And through their interaction with choice statements u Let’s get rid of them!

VC Generator for Passive Form Two-Stage VC Generation Alg. Passive Form Compact Verification Condition Guarded Command Passify Translation Remove Assignments

Basic Passify Translation u To passify an assignment statement x := e  Introduce a fresh variable, say x’ u Replace assignment statement by assume x’ = e  Subsequently use x’ instead of x

Passify for Choice Statements u To passify a choice statement A B  Let A’ and B’ be passive forms of A and B  Suppose x resides in xa after A’ and x resides in xb after B’  Introduce a fresh variable, say x’ u Replace the choice statement by ( A’; assume x’=xa) (B’; assume x’=xb)  Subsequently use x’ instead of x  Introduce a fresh variable, say x’ u Replace assignment statement by assume x’ = e  Subsequently use x’ instead of x

VC Generator for Passive Form Two-Stage VC Gen. Results (I) Passive Form Compact Verification Condition Guarded Command Passify Translation Remove Assignments At most quadratic in size of GC

Generating VCs for Passive Form u Execution of a passive statement l Cannot affect the program state (!) l Can only choose among the two possible outcomes Normal termination Going wrong u Semantics of a passive statement S can be completely captured by two outcome predicates N.S - initial states from which S may terminate normally W.S - initial states from which S may go wrong

Outcome Predicates Semantics N.S e N.A  N.B N.A  N.B Statement S assume e assert e A B A ; B W.S false  e W.A  W.B W.A  (N.A  W.B) Normal outcome Wrong outcome

Size of Outcome Predicates  The size of N.S is linear in the size of S  The size of W.S is quadratic in the size of S W.(A;B;C) = W.A  (N.A  W.B)  (N.A  N.B  W.C) = let t = N.A in W.A  (t  W.B)  (t  N.B  W.C)

VC Generator for Passive Form Two-Stage VC Gen. Results (II) Passive Form Compact Verification Condition  (W.P) Guarded Command Passify Translation Remove Assignments At most quadratic in size of GC At most n^4 (without lets) n^4 (without lets) quadratic (with lets) quadratic (with lets) in size of GC

Results in Practice u Benchmark: ESC/Java front-end, 20 KLOC u Passify increases code size by ~30% on average u For “simple” methods l VC size 60% - 70% of original l proof time roughly the same u For “complex” methods l VC size 0.1% - 10% of original l proof time 2% - 50% of original u Can now verify all methods in benchmark

private int scanPunctuation(int nextchr) { try { boolean possibleFloatingPointNumber = (nextchr == '.'); text[0] = (char)nextchr; textlen = 1; m_in.mark(); // All paths out of the try must unmark the stream!! PunctuationPrefixTree prefix = punctuationTable; PunctuationPrefixTree lastPunctuation = prefix; int lastPunctuationLength = 0; int index = nextchr - '!'; if (index < 0 || PunctuationPrefixTree.CHILDLEN <= index) prefix = null; else prefix = prefix.children[nextchr - '!']; nextchr = m_in.read(); if (possibleFloatingPointNumber && Character.isDigit((char)nextchr)) { m_in.clearMark(); return finishFloatingPointLiteral(nextchr); } this.append(nextchr); if (prefix != null && prefix.code != TagConstants.NULL) { lastPunctuation = prefix; lastPunctuationLength = textlen - 1; m_in.mark(); } while(prefix != null) { index = nextchr - '!'; if (index < 0 || PunctuationPrefixTree.CHILDLEN <= index) prefix = null; else prefix = prefix.children[nextchr - '!']; nextchr = m_in.read(); this.append(nextchr); if (prefix != null && prefix.code != TagConstants.NULL) { lastPunctuation = prefix; lastPunctuationLength = textlen - 1; m_in.mark(); } m_in.reset(); textlen = lastPunctuationLength; endingLoc = m_in.getLocation(); ttype = lastPunctuation.code; if (ttype != TagConstants.C_COMMENT&& ttype != TagConstants.EOL_COMMENT) nextchr = m_in.read(); return ttype; } catch (IOException e) { m_in.clearMark(); ErrorSet.fatal(m_in.getLocation(), e.toString()); return TagConstants.NULL; // Dummy }

Current Status of ESC u Scales well to complex methods u Ready for educational/research use? Yes! l u Ready for commercial use? Not really. l annotation overhead significant l annotations increase program size by 10% l requires 1 programmer-hour to annotate 300 lines of code

Future Directions u Annotation Inference l Houdini annotation inference system Infer annotations via whole-program analysis (up to 40 KLOC) “Generate and test” strategy leverages ESC l Loop invariant inference via predicate abstraction Infers universally-quantified loop invariants, e.g. (\forall int j; spot == MAXDIRENTRY && 0 <= j && j < i ==> bdisk[addr].dirEntries[j].inum != UNUSED ) u Full verification of systems software l Frangipani distributed file system