Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,

Slides:



Advertisements
Similar presentations
1 Lecture 5 Towards a Verifying Compiler: Multithreading Wolfram Schulte Microsoft Research Formal Methods 2006 Race Conditions, Locks, Deadlocks, Invariants,
Advertisements

Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte Formal techniques.
Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
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,
Bor-Yuh Evan Chang Daan Leijen Peter Müller David A. Naumann The Spec# programming system Mike Barnett Rob DeLine Manuel Fähndrich Bart Jacobs K. Rustan.
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 3 Summer school on Formal Models.
Technologies for finding errors in object-oriented software K. Rustan M. Leino Microsoft Research, Redmond, WA Lecture 1 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?
Lecture 4 Towards a Verifying Compiler: Data Abstraction Wolfram Schulte Microsoft Research Formal Methods 2006 Purity, Model fields, Inconsistency _____________.
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.
Automated Software Verification with a Permission-Based Logic 20 th June 2014, Zürich Malte Schwerhoff, ETH Zürich.
Verification of Multithreaded Object- Oriented Programs with Invariants Bart Jacobs, K. Rustan M. Leino, Wolfram Schulte.
A simple sequential reasoning approach for sound modular verification of mainstream multithreaded programs Wolfram Schulte & Bart Jacobs Microsoft Research.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland.
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.
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
ECI 2007: Specification and Verification of Object-Oriented Programs Lecture 2 Courtesy: K. Rustan M. Leino and Wolfram Schulte.
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.
ECI 2007: Specification and Verification of Object-Oriented Programs Lecture 3 Courtesy: K. Rustan M. Leino and Wolfram Schulte.
Building a program verifier K. Rustan M. Leino Microsoft Research, Redmond, WA 10 May 2006 Guest lecture, Shaz Qadeer’s cse599f, Formal Verification of.
K. Rustan M. Leino Microsoft Research, Redmond NUI Maynooth Maynooth, Ireland 8 June 2007.
K. Rustan M. Leino Microsoft Research, Redmond Invited talk, TACAS 2007 ETAPS, Braga, Portugal 28 March 2007.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Toward enforceable contracts.
Well-cooked Spaghetti: Weakest-Precondition of Unstructured Programs Mike Barnett and Rustan Leino Microsoft Research Redmond, WA, USA.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 5 LASER.
Describing Syntax and Semantics
K. Rustan M. Leino Microsoft Research, Redmond, WA 10 Oct 2007 IFIP WG 2.3 meeting Santa Fe, NM.
Spec# K. Rustan M. Leino Senior Researcher Programming Languages and Methods Microsoft Corporation Joint work with: Mike Barnett, Robert DeLine, Manuel.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 1 Summer School on Logic and Theorem-Proving in Programming.
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
K. Rustan M. Leino RiSE, Joint work with: Peter Müller (ETH Zurich) Jan Smans (KU Leuven) Special thanks to Mike Barnett VMCAI, Madrid, Spain, 18 January.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
1 Abstraction  Identify important aspects and ignore the details  Permeates software development programming languages are abstractions built on hardware.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 19 July 2007 Invited talk, CADE-21 Bremen, Germany.
Using and Building an Automatic Program Verifier K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond Lecture 3 Marktoberdorf.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
Rustan Leino RiSE, Microsoft Research, Redmond MIT 5 June 2009 Joint work with: Peter Müller, ETH Zurich Jan Smans, KU Leuven.
Verification of Programs with Inspector Methods Bart Jacobs and Frank Piessens Dept. CS, K.U.Leuven, Belgium.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Spec# Writing and checking.
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
Spec# Andreas Vida. Motivation Correct and maintainable software Correct and maintainable software Cost effective software production Cost effective software.
K. Rustan M. Leino Principal Researcher Microsoft Research, Redmond, WA, USA 14 Nov 2007 Øredev Malmö, Sweden.
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 RiSE, Microsoft Research, Redmond joint work with Peter Müller and Jan Smans Lecture 1 2 September 2009 FOSAD 2009, Bertinoro, Italy.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 15 Nov 2007 Chalmers Göteborg, Sweden.
Spec# John Lefor Program Manager Developer Division, Microsoft.
1 Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte ECOOP 2003.
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 8 Nov 2007 Invited talk, ASE 2007 Atlanta, GA.
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,
Specification techniques for verifying object-oriented software
Class-local object invariants
Spec# Writing and checking contracts in a .NET language
Hoare-style program verification
Semantics In Text: Chapter 3.
CIS 199 Final Review.
Presentation transcript:

Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps, Subtyping and dynamic binding, Pre- and postconditions, method framing _______________ Joint work with Rustan Leino, Mike Barnett, Manuel Fähndrich, Herman Venter, Rob DeLine, Wolfram Schulte (all MSR), and Peter Müller (ETH), Bart Jacobs (KU Leuven) and Bor-Yuh Evan Chung (Berkley)

2 Review: Boogie PL Source language (eg. Spec#) BoogiePL Formulas Translate source language features using particular programming methodology Translate Boogie PL code using particular VC generation Intermediate language for verification

3 Review Boogie PL What components does Boogie PL have, and what does it not have? What is the purpose of assert, assume and havoc? What’s the meaning of a procedure and its modifies clause? What do we need to translate an OO language into Boogie PL?

4 Mapping Spec# to BoogiePL Axiomatizing Spec#’s class and field declarations The storage model Translating methods and code Method framing (simplified) Loop framing

5 Axiomatizing the Spec# Type System On notation: We use the following C# class class C : object { object f = null; C(){} } to describe the result of the axiomatization. We use the function Tr (anslate) to translate Spec# statements into BoogiePL

6 Axiomatizing the Spec# Type System Introduce a typename for each Spec# type type C : name; Assert subtyping relationship for program types axiom C <: System.Object; by using a predefined partial order operation <:

7 Axiomatizing C#’ Type Declarations Introduce field names as constants const C.f : name; Assert field properties (kind, type etc). axiom IsRefField(C.f, System.Object); by using the appropriate functions function IsRefField(field:name, type:name) returns bool

8 Storage Model Use Boogie’s type ref to denote runtime object references A Heap maps object references and field names to values var Heap: [ref, name] any; // Heap : ref  name  any Allocatedness is represented as another field of the heap const allocated: name; Access to an instance field f declared in C is translated as Tr[[ x = o.f; ]] = Tr[[ o.f = x; ]] = assert o ≠ null ; x := Heap[ o, C.f ] assert o ≠ null ; Heap[ o, C.f ] := x

9 Allocation Tr[[x = new T()]] = {var o: ref; assume o != null ∧ typeof(o) == T; assume Heap[o, allocated] == false; Heap[o, allocated] := true; call T..ctor(o); }

10 Methods Recall: Boogie PL has only procedures, no instance methods → Add this as first parameter to generated proc is weakly typed (just int, bool, ref) → Spec# types must be preserved via contracts has no idea of heap properties → Allocatedness must be preserved via contracts has no inheritance → Strengthening of postconditions must be implemented via multiple procedures

11 Constructors and Non-Virtual Methods Tr [[C() {}]] = proc C..ctor(this: ref); requires this != null ∧ typeof(this) <: C; modifies Heap; impl C..ctor(this: ref) { assume Heap[this, allocated] == true; //for constructors only assume Heap[this, C.f] == null; call System.Object..ctor(this); … } Preserve type information Preserve initialization semantics

12 Virtual Methods: Example class Cell{ public int x; protected virtual void Set(int x) modifies this.*; ensures this.x == x; { this.x = x; } public void Inc(int x) modifies this.*; ensures this.x==old(this.x)+x; { this.Set(Get()+x); } } class BackupCell: Cell{ int b; protected override void Set(int x) ensures this.b == old(this.x); { this.b = this.x; base.Set(x); }

13 Behavioral Subtyping Behavioral Subtyping should guarantee substitutability Wherever an object of type T is expected an object of type S, where S<:T, should do without changing the program’s behavior expressed in wp Sufficient conditions: Let M1 be a virtual method and M2 be its overridden method, then M2 can weaken M1’s precondition M2 can strengthen M1’s postcondition

14 Virtual Methods Translate each method m declared in C into a proc m.C (this, …) requires this != null ∧ typeof(this) <: C; … The precondition of the overriding method is inherited from the overridden method; additional postconditions are conjoined Translate calls of the form o.m() to the method on o’s most specific static type

15 Method Framing For sound verification we assume that every method modifies the heap Modifies clauses in Spec# express which locations (evaluated in the method’s prestate) a method is allowed to modify Modifies clauses for an object o or array a have the form: –o.f allows modification of o’s f field –o.* allows modification of all of o’s fields –a[k] allows modification of a’s array location k –a[*] allows modification of all of a’s array locations

16 Method Framing Let W denote all locations a method is allowed to modify The Boogie PL post condition for a Spec# modifies clause Tr [[W]] = (∀o: ref, f: name :: old(Heap[o,allocated])  (o,f)  old(W)  old(Heap[o,f]) = Heap[o,f])

17 Virtual Methods: Example Translation Spec# protected virtual void Set(int x) modifies this.*; Boogie proc Cell.Set(this : Cell, x : int) requires this != null ∧ typeof(this) <: Cell; modifies Heap; ensures (∀o:ref, f: name :: old(Heap[o,allocated])  o = this  old(Heap[o,f]) = Heap[o,f]);

18 Loop Framing Loops might change the heap. Let W denote the set of locations potentially changed by the loop For sound verification we havoc the heap. We add as loop invariant the assertion that fields not written to don’t change Tr [[W]] = (∀o : ref, f: name :: Heap entry [o,allocated]  f  W  Heap entry [o,f] = Heap current [o,f]) where Heap entry/current denote the entry/current incarnations of the Heap variable in the loop

19 Summary Verifying object-oriented programs requires to axiomatize the declaration environment –to keep enough information around for verification decide on a storage model –to model updates and framing translate the method bodies, paying particular attention to –partiality of operations –virtual dispatch –method and loop frames