Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA.

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

Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
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,
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Lunch seminar, Praxis Bath, UK 6 Dec 2005 joint work with Mike Barnett,
Demand-driven inference of loop invariants in a theorem prover
Object Invariants in Specification and Verification K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel.
Writing specifications for object-oriented programs K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 21 Jan 2005 Invited talk, AIOOL 2005 Paris,
1 Towards a Verifying Compiler: The Spec# Approach Wolfram Schulte Microsoft Research Formal Methods 2006 Joint work with Rustan Leino, Mike Barnett, Manuel.
Program Verification Using the Spec# Programming System ETAPS Tutorial K. Rustan M. Leino, Microsoft Research, Redmond Rosemary Monahan, NUIM Maynooth.
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.
Spec# K. Rustan M. Leino Senior Researcher Programming Languages and Methods Microsoft Research, Redmond, WA, USA Microsoft Research faculty summit, Redmond,
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.
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Distinguished Lecture Series Max Planck Institute for Software Systems.
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Automated Software Verification with a Permission-Based Logic 20 th June 2014, Zürich Malte Schwerhoff, ETH Zürich.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland.
Partial correctness © Marcelo d’Amorim 2010.
ISBN Chapter 3 Describing Syntax and Semantics.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
CS 355 – Programming Languages
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 International Summer School Marktoberdorf Marktoberdorf,
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 1 LASER.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 0 Summer School on Logic and Theorem-Proving in Programming.
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
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)
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Toward enforceable contracts.
Chair of Software Engineering Automatic Verification of Computer Programs.
Describing Syntax and Semantics
K. Rustan M. Leino Microsoft Research, Redmond, WA 10 Oct 2007 IFIP WG 2.3 meeting Santa Fe, NM.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Caltech Pasadena, CA 12 November 2009.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 1 Summer School on Logic and Theorem-Proving in Programming.
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.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 3 Marktoberdorf.
CS 363 Comparative Programming Languages Semantics.
Reasoning about object structures with Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel Fähndrich,
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Spec# Writing and checking.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 0 Marktoberdorf.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
Specifying and verifying programs in Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Invited talk, PSI 2006 Novosibirsk, Russia 27 June 2006.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 2 International Summer School Marktoberdorf Marktoberdorf,
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 15 Nov 2007 Chalmers Göteborg, Sweden.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Reasoning about object structures with Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA Joint work with: Mike Barnett, Ádám Darvas, Manuel Fähndrich,
Hoare Logic LN chapter 5, 6 but without 6.8, 6.12, 6.13 (to be discussed later) Hoare Logic is used to reason about the correctness of programs. In the.
Dafny An automatic program verifier for functional correctness
Specification techniques for verifying object-oriented software
Weakest Precondition of Unstructured Programs
Program Verification via an Intermediate Verification Language
Hoare Logic LN chapter 5, 6 but without 6. 8, 6. 12, 6
Spec# Writing and checking contracts in a .NET language
Syntax Questions 6. Define a left recursive grammar rule.
Hoare-style program verification
Semantics In Text: Chapter 3.
Dafny An automatic program verifier for functional correctness
Assertions References: internet notes; Bertrand Meyer, Object-Oriented Software Construction; 4/25/2019.
Presentation transcript:

Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA

2 Spec# Programming System V.C. generator automatic theorem prover verification condition Spec# “correct” or list of errors Spec# compiler MSIL (“bytecode”) translator Boogie PL inference engine Spec# program verifier runtime monitoring

3 Spec# demo

4 Spec# Demo: What It Showed Non-null type system Pre- and postconditions Object invariants Dynamic monitoring Static verification

5 Verification Condition First-order logical formula Valid if and only if program meets its specification This leaves a lot of room for engineering…

6 General Problem Duplication of postconditions for if- statements wp( if (b) {x++;} else {x--;}, p ≠ null ) = (b ⇒ wp( x++, p ≠ null )) ∧ (¬b ⇒wp( x--, p ≠ null ))

7 Definition of Language Program::=Block + Block::=BlockId : Stmt; goto BlockId * Stmt::=VarId := Expr | havoc VarId |assert Expr | assume Expr |Stmt ; Stmt | skip

8 Example y := … x … z := x x := … z 1 := x 0 x 1 := …x 2 := … x 1 := … x 3 := x 1 x 2 := … x 3 := x 2 y 1 := … x 3 … goto S,T; assume E; S; assume ¬E; T; … if (E){ S; }else{ T; }

9 The recipe 0. Cut Loops Consider arbitrary loop iteration 1. Passify the program Combine control flow and data flow 2. Construct weakest precondition formula Connect the program to its semantics

10 Cutting Loops: the general idea x := … Without a loop invariant, this loses all information about x. havoc x;

11 Cut Loops: Sub-steps 0.0. assert P assert P; assume P 0.1. Push asserts up-stream Delete back edges after “havoc”-ing loop targets.

12 Cutting the loops… Putting the steps together assert J; x := … assert J; assume J; assume J; x := … assert J; assert J; Note how this corresponds to the classical notion of a loop invariant: checking it in two places allows you to assume it at the top of the loop. havoc x; assume J;

13 Passification y := … x … z := x x := … z 1 := x 0 x 1 := …x 2 := … x 1 := … x 3 := x 1 x 2 := … x 3 := x 2 y 1 := … x 3 … assume z 1 = x 0 assume x 1 = … assume x 3 = x 1 assume x 2 = … assume x 3 = x 2 assume y 1 = … x 3 …

14 Weakest Precondition For each block A, A ok holds when all executions starting at A are okay. Block Equation for each block A (BE A ): VC (semantics of entire program): VC is obviously linear (in size of the passive program) A ok ≡ wp(S, (∧ B ∈ Succ(A) : B ok )) (∧ A : BE A ) ⇒ Start ok

15 Example int M(int x) requires 100 <= x; ensures result == 0; { while (0 < x) invariant 0 <= x; { x = x – 1; } return x; }

16 CFG assert 0 ≤ x; assume 100 ≤ x; assume 0 < x; x := x – 1; assume ¬(0 < x); r := x; assert r = 0; postcondition precondition loop invariant loop guard negation of guard Body Start LoopHead After

17 Loop-Free CFG havoc x; assume 0 ≤ x; assume 100 ≤ x; assert 0 ≤ x; assume 0 < x; x := x – 1; assert 0 ≤ x; assume ¬(0 < x); r := x; assert r = 0; Body Start LoopHead After

18 Passive Program skip; assume 0 ≤ x 1 ; assume 100 ≤ x 0 ; assert 0 ≤ x 0 ; assume 0 < x 1 ; assume x 2 = x 1 – 1; assert 0 ≤ x 2 ; assume ¬(0 < x 1 ); assume r 1 = x 1 ; assert r 1 = 0; Body Start LoopHead After

19 Block Equations LoopHead ok ≡ 0 ≤ x 1 ⇒ Body ok ∧ After ok Start ok ≡ 100 ≤ x 0 ⇒ 0 ≤ x 0 ∧ LoopHead ok Body ok ≡ 0 < x 1 ⇒ x 2 = x 1 – 1 ⇒ 0 ≤ x 2 ∧ true After ok ≡ ¬(0 < x 1 ) ⇒ r 1 = x 1 ⇒r 1 = 0 ∧ true

20 Verification Condition LoopHead ok ≡ 0 ≤ x 1 ⇒ Body ok ∧ After ok ∧ Body ok ≡ 0 < x 1 ⇒ x 2 = x 1 – 1 ⇒ 0 ≤ x 2 ∧ true After ok ≡ ¬(0 < x 1 ) ⇒ r 1 = x 1 ⇒r 1 = 0 ∧ true Start ok ∧ ∧ ⇒ Start ok ≡ 100 ≤ x 0 ⇒ 0 ≤ x 0 ∧ LoopHead ok

21 Related Work Distribution via wlp: We could have done this too (it is ESC/Java’s technique), but converting to a structured program leads to a blow up (and requires heuristics). Possibly could have used a target language with “S!T” (and “raise”) for exceptional composition.

22 Conclusion Room for more improvement –Recent experiments on directing theorem prover along certain paths. Useful even for systems that use structured programs.