Specification techniques for verifying object-oriented software

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,
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,
Spec# K. Rustan M. Leino Senior Researcher Programming Languages and Methods Microsoft Research, Redmond, WA, USA Microsoft Research faculty summit, Redmond,
Challenges in increasing tool support for programming K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 23 Sep 2004 ICTAC Guiyang, Guizhou, PRC joint.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 15 January 2009 Séminaire Digiteo Orsay, France.
The Spec# programming system K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Distinguished Lecture Series Max Planck Institute for Software Systems.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA Invited talk Informatics Education in Europe (IEE III’08)
K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland.
MIX 09 4/15/ :14 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
K. Rustan M. Leino RiSE, Microsoft Research Typing, Analysis and Verification of Heap-Manipulating Programs Dagstuhl, Germany 20 July 2009.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Windows 7 Training Microsoft Confidential. Windows ® 7 Compatibility Version Checking.
Multitenant Model Request/Response General Model.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Announcing Demo Announcing.
Feature: Web Client Keyboard Shortcuts © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
Session 1.
Built by Developers for Developers…. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
WinHEC /22/2017 © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or.
Feature: Customer Combiner and Modifier © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
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,
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.
demo Instance AInstance B Read “7” Write “8”

customer.
demo © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names.
Specifying and verifying programs in Spec# K. Rustan M. Leino Microsoft Research, Redmond, WA, USA Invited talk, PSI 2006 Novosibirsk, Russia 27 June 2006.
demo Demo.
Feature: Void Historical/Open Transaction Updates © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
demo QueryForeign KeyInstance /sm:body()/x:Order/x:Delivery/y:TrackingId1Z
projekt202 © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are.
The CLR CoreCLRCoreCLR © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product.
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks.
K. Rustan M. Leino Microsoft Research, Redmond, WA, USA 15 Nov 2007 Chalmers Göteborg, Sweden.
© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or.

IoCompleteRequest (Irp);... p = NULL; …f(p);
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,
demo User Signs Up Temporary Account is Created with Verification Link Sent User Clicks Link Account is Activated Login.Register(userName,
Dafny An automatic program verifier for functional correctness
Class-local object invariants
Возможности Excel 2010, о которых следует знать
Verification of concurrent object-oriented programs
Title of Presentation 11/22/2018 3:34 PM
Title of Presentation 12/2/2018 3:48 PM
Hoare-style program verification
1/3/2019 1:21 PM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Dafny An automatic program verifier for functional correctness
8/04/2019 9:13 PM © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
4/27/17, Bell #8 What amount of net pay has been earned this period?
Виктор Хаджийски Катедра “Металургия на желязото и металолеене”
PENSACOLA ENERGY WORK PLAN OCTOBER 10, 2016
Title of Presentation 5/12/ :53 PM
Шитманов Дархан Қаражанұлы Тарих пәнінің
Title of Presentation 5/24/2019 1:26 PM
5/24/2019 6:44 PM 1/8/18 Bell #10 In a world governed by the gods, is there any room for human will? Do human choices make a difference? EXPLAIN © 2007.
Title of Presentation 7/24/2019 8:53 PM
Presentation transcript:

Specification techniques for verifying object-oriented software 5/9/2018 3:23 PM Specification techniques for verifying object-oriented software K. Rustan M. Leino Research in Software Engineering (RiSE) Microsoft Research, Redmond, WA, USA 3 December 2008 U. Lugano Lugano, Switzerland © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Collaborators most relevant to this talk Mike Barnett Manuel Fähndrich Bart Jacobs Peter Müller Wolfram Schulte Jan Smans Herman Venter Angela Wallenburg

Software engineering problem Building and maintaining programs that are correct Approach Specifications record design decisions bridge intent and code Tools amplify human effort manage details find inconsistencies ensure quality

Verified Software Initiative 5/9/2018 3:23 PM Verified Software Initiative Hoare, Joshi, Leavens, Misra, Naumann, Shankar, Woodcock, et al. “We envision a world in which computer programs are always the most reliable component of any system or device that contains them” [Hoare & Misra] © 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Spec# programming system Spec# language Object-oriented .NET language Superset of C# 2.0, adding: more types (e.g., non-null types) specifications (e.g., pre- and postconditions) Usage rules (methodology) Checking: Static type checking Run-time checking Static verification (optional)

Spec# demo

Spec# verifier architecture Spec# compiler MSIL (“bytecode”) Translator Boogie Inference engine V.C. generator verification condition SMT solver “correct” or list of errors

Boogie – a verification tool bus Spec# C with HAVOC specifications C with vcc specifications Dafny Chalice Your language here Boogie-to-Boogie transformations: Inference engines Program transformations Logic optimizers Boogie Your prover here Simplify Z3 SMT Lib

Comparison of some specification techniques Boogie methodology Dafny dynamic frames Chalice implicit dynamic frames (permission model)

Example: Composite object :RockBand songs invariant: r.songs = r.gt.solos gt :Guitar solos

Problem: Invariants don't always hold :RockBand r.gt.solos := r.gt.solos + 1; r.songs := r.songs + 1; songs invariant: r.songs = r.gt.solos gt :Guitar solos

Problem: Overlapping representations :RockBand :RockBand 5 songs 5 6 songs gt gt :Guitar solos 6 5

Boogie methodology To control overlapping representations: invariant declarations To address that invariants don’t always hold: ghost field inv methodology guarantees that (o  o.inv  Inv(o)) always holds inv is changed by: expose (o) { … } To control overlapping representations: ghost field owner methodology guarantees that (o  o.owner.inv  o.inv) always holds rep modifiers indicate ownership intentions

RockBand in Boogie methodology class RockBand { int songs; rep Guitar gt; invariant songs == gt.solos; public void Play() requires inv ¬owner.inv; modifies this.*; { expose (this) { gt.Strum(); songs++; } } …

Spec# demo: RockBand public class RockBand { int songs; [Rep] Guitar gt; invariant songs == gt.solos; public void Play() { expose (this) { gt.Strum(); songs++; } … using Microsoft.Contracts; public class RockBand { int songs; [Rep] Guitar gt; invariant songs == gt.solos; public void Play() { expose (this) { gt.Strum(); songs++; } public RockBand() { songs = 0; gt = new Guitar(); public class Client { public void Main() { RockBand b = new RockBand(); b.Play(); public class Guitar { public int solos; public Guitar() ensures solos == 0; { public void Strum() modifies solos; ensures solos == old(solos) + 1; solos++;

Dynamic frames [Kassios 2006] A dynamic frame is a set of memory locations Functions, which used to decribed invariants, are defined over dynamic frames Methods operate over dynamic frames In Dafny: dynamic frames are usually specified using a programmer-defined ghost field footprint

Dafny demo: RockBand class RockBand { var footprint: set<object>; var songs: int; var gt: Guitar; function Valid(): bool reads {this}, footprint; { this in footprint && gt != null && gt in footprint && gt.footprint <= footprint && !(this in gt.footprint) && gt.Valid() && songs == gt.solos } method Play() requires Valid(); modifies footprint; ensures Valid() && fresh(footprint - old(footprint)); call gt.Strum(); songs := songs + 1; footprint := footprint + gt.footprint; … class RockBand { var footprint: set<object>; var songs: int; var gt: Guitar; function Valid(): bool { reads {this}, footprint; this in footprint && gt.footprint <= footprint && !(this in gt.footprint) && gt != null && gt in footprint && gt.Valid() && songs == gt.solos } requires Valid(); method Play() modifies footprint; ensures Valid() && fresh(footprint - old(footprint)); call gt.Strum(); songs := songs + 1; footprint := footprint + gt.footprint; modifies {this}; method Init() ensures Valid() && fresh(footprint - {this}); songs := 0; var g := new Guitar; call g.Init(); footprint := {this}; gt := g; footprint := footprint + {gt} + gt.footprint; class Client { method Main() { call b.Init(); var b := new RockBand; call b.Play(); class Guitar { var solos: int; { this in footprint && !(null in footprint) } ensures solos == 0; solos := 0; method Strum() ensures solos == old(solos) + 1; solos := solos + 1;

Implicit dynamic frames [Smans et al. 2008] Like in separation logic, define dynamic frames as part of specification predicates acc(o.f) specifies the ability to read/write o.f modifies specifications implicitly follow from accessibility predicates in preconditions

Chalice demo: RockBand class RockBand { var songs: int var gt: Guitar predicate Valid { acc(songs) && acc(gt) && gt != null && gt.Valid && acc(gt.solos) && songs == gt.solos } method Play() requires Valid ensures Valid { call gt.Strum() songs := songs + 1 … class RockBand { var songs: int var gt: Guitar predicate Valid { acc(songs) && acc(gt) && gt != null && gt.Valid && acc(gt.solos) && songs == gt.solos } method Play() requires Valid ensures Valid { call gt.Strum() songs := songs + 1 method Init() requires acc(this.*) songs := 0 gt := new Guitar call gt.Init() class Client { method Main() { var b := new RockBand call b.Init() call b.Play() class Guitar { var solos: int predicate Valid { true } ensures Valid && acc(solos) && solos == 0 solos := 0 method Strum() requires Valid && acc(solos) ensures Valid && acc(solos) && solos == old(solos) + 1 solos := solos + 1

Chalice with -autoMagic class RockBand { var songs: int var gt: Guitar predicate Valid { gt.Valid && songs == gt.solos } method Play() requires Valid ensures Valid { call gt.Strum() songs := songs + 1 … class RockBand { var songs: int var gt: Guitar predicate Valid { gt.Valid && songs == gt.solos } method Play() requires Valid ensures Valid { call gt.Strum() songs := songs + 1 method Init() requires acc(this.*) songs := 0 gt := new Guitar call gt.Init() class Client { method Main() { var b := new RockBand call b.Init() call b.Play() class Guitar { var solos: int predicate Valid { true } ensures Valid && acc(solos) && solos == 0 solos := 0 method Strum() requires Valid && acc(solos) ensures Valid && acc(solos) && solos == old(solos) + 1 solos := solos + 1

Comparison: Spec# Spec# (Boogie methodology) specifications are simple, many defaults invariant declarations admissibility restrictions control overlapping representations restrictive

Comparison: Dafny Dafny (dynamic frames) flexible overlapping representations allowed errors reported when they would cause problems simple language design verbose specifications manual updates of footprints

Comparison: Chalice Chalice (permission accounting) flexible overlapping representations allowed these must be specified with partial permissions verbose specifications, but -autoMagic helps thinking through partial permissions is complicated

Conclusions Difficult: designing a programming methodology that fits common programming idioms is easy to use and teach can be handled well by automatic provers invariant declarations come at a price Wanted: better presentation of errors http://research.microsoft.com/specsharp http://research.microsoft.com/rise