ECI 2007: Specification and Verification of Object-Oriented Programs Lecture 2 Courtesy: K. Rustan M. Leino and Wolfram Schulte.

Slides:



Advertisements
Similar presentations
Joint work with Mike Barnett, Robert DeLine, Manuel Fahndrich, and Wolfram Schulte Verifying invariants in object-oriented programs K. Rustan M. Leino.
Advertisements

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,
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.
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.
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.
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
Automated Software Verification with a Permission-Based Logic 20 th June 2014, Zürich Malte Schwerhoff, ETH Zürich.
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
Lecture 2 Towards a Verifying Compiler: Logic of Object oriented Programs Wolfram Schulte Microsoft Research Formal Methods 2006 Objects, references, heaps,
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.
Using data groups to specify and check side effects K. Rustan M. Leino Microsoft Research Arnd Poetzsch-Heffter Universität Kaiserslautern Yunhong Zhou.
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.
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 RiSE, Microsoft Research 1 Dec 2008 Invited talk, working group meeting COST Action IC0701, Formal Verification of Object-Oriented Software.
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.
CS 363 Comparative Programming Languages Semantics.
Parameterized Unit Tests By Nikolai Tillmann and Wolfram Schulte Proc. of ESEC/FSE 2005 Presented by Yunho Kim Provable Software Lab, KAIST TexPoint fonts.
Verification of Programs with Inspector Methods Bart Jacobs and Frank Piessens Dept. CS, K.U.Leuven, Belgium.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Chapter 3 Part II Describing Syntax and Semantics.
Semantics In Text: Chapter 3.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Spec# Andreas Vida. Motivation Correct and maintainable software Correct and maintainable software Cost effective software production Cost effective software.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA part 3 International Summer School Marktoberdorf Marktoberdorf,
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.
FEN 2014UCN Teknologi/act2learn1 Object-Oriented Programming “ The Three Pillars of OOP”: Encapsulation Inheritance Polymorphism The Substitution Principle.
Extended Static Checking for Java Cormac Flanagan Joint work with: Rustan Leino, Mark Lillibridge, Greg Nelson, Jim Saxe, and Raymie Stata Compaq Systems.
1 Verification of object-oriented programs with invariants Mike Barnett, Robert DeLine, Manuel Fahndrich, K. Rustan M. Leino, Wolfram Schulte ECOOP 2003.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Prof. Necula CS 164 Lecture 171 Operational Semantics of Cool ICOM 4029 Lecture 10.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 8 Nov 2007 Invited talk, ASE 2007 Atlanta, GA.
Class-local object invariants
Program Verification via an Intermediate Verification Language
Lecture 5 Floyd-Hoare Style Verification
Hoare-style program verification
Semantics In Text: Chapter 3.
CIS 199 Final Review.
Programming Languages and Compilers (CS 421)
Presentation transcript:

ECI 2007: Specification and Verification of Object-Oriented Programs Lecture 2 Courtesy: K. Rustan M. Leino and Wolfram Schulte

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 Mapping Spec# to BoogiePL Axiomatizing Spec#’s class and field declarations The storage model Translating methods and code Method framing Loop framing

4 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

5 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 <:

6 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

7 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

8 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); }

9 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

10 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); }

11 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 Sufficient conditions: Let M1 be a virtual method and M2 be a method that overrides M1, then M2 can weaken M1’s precondition M2 can strengthen M1’s postcondition

12 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 Additional preconditions not allowed on overriding methods. Translate calls of the form o.m() to the method on o’s most specific static type

13 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 pre-state) 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

14 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])

15 Virtual Methods: Example Translation Spec# class Cell { protected virtual void Set(int x) modifies this.*; ensures this.x == x; … } Boogie proc Cell.Set(this : ref, 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]); ensures Heap[this,x] = x;

16 Virtual Methods: Example Translation Spec# class BackupCell { protected override void Set(int x) modifies this.*; ensures this.b == old(this.x); … } Boogie proc BackupCell.Set(this : ref, x : int) requires this != null ∧ typeof(this) <: BackupCell; modifies Heap; ensures (∀o:ref, f: name :: old(Heap[o,allocated])  o == this  old(Heap[o,f]) == Heap[o,f]); ensures Heap[this,x] == x; ensures Heap[this,b] == old(Heap[this,x]);

17 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

18 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