Axiomatic Methods for Software Verification Hongseok Yang.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 12.
Semantics Static semantics Dynamic semantics attribute grammars
Copyright , Doron Peled and Cesare Tinelli. These notes are based on a set of lecture notes originally developed by Doron Peled at the University.
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.
Reasoning About Code; Hoare Logic, continued
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
Partial correctness © Marcelo d’Amorim 2010.
Axiomatic Semantics The meaning of a program is defined by a formal system that allows one to deduce true properties of that program. No specific meaning.
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.
Dynamic semantics Precisely specify the meanings of programs. Why? –programmers need to understand the meanings of programs they read –programmers need.
Simple Example {i = 0} j := i * i {j < 100} Can we ‘verify’ this triple? Only if we know the semantics of assignment.
Copyright © 2006 Addison-Wesley. All rights reserved. 3.5 Dynamic Semantics Meanings of expressions, statements, and program units Static semantics – type.
Predicate Transformers
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
Announcements We are done with homeworks Second coding exam this week, in recitation –Times will be posted later today –If in doubt, show up for your regular.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
Axiomatic Semantics Dr. M Al-Mulhem ICS
Computing Fundamentals 1 Lecture 1 Lecturer: Patrick Browne Room K308 Based on Chapter 1. A Logical approach to Discrete.
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
Local Reasoning Peter O’Hearn John Reynolds Hongseok Yang.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
ESC Java. Static Analysis Spectrum Power Cost Type checking Data-flow analysis Model checking Program verification AutomatedManual ESC.
Dr. Muhammed Al-Mulhem 1ICS ICS 535 Design and Implementation of Programming Languages Part 1 Fundamentals (Chapter 4) Axiomatic Semantics ICS 535.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Describing Syntax and Semantics
Verifying a Wait Free Register Algorithm Using Assertional Reasoning Xu Qiwen Faculty of Science and Technology University of Macau.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
1 Formal Semantics of Programming Languages “Program testing can be used to show the presence of bugs, but never to show their absence!” --Dijkstra.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
© Andrew IrelandDependable Systems Group Cooperative Reasoning for Automatic Software Verification Andrew Ireland School of Mathematical & Computer Sciences.
Recursion. What is recursion? Rules of recursion Mathematical induction The Fibonacci sequence Summary Outline.
A Certifying Compiler and Pointer Logic Zhaopeng Li Software Security Lab. Department of Computer Science and Technology, University of Science and Technology.
1 cs205: engineering software university of virginia fall 2006 Avoiding Software Disasters.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Chapter 3 Part II Describing Syntax and Semantics.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Separation and Information Hiding Peter W. O’Hearn (Queen Mary, University of London) John C. Reynolds (Carnegie Mellon University) Hongseok Yang (Seoul.
From Hoare Logic to Matching Logic Reachability Grigore Rosu and Andrei Stefanescu University of Illinois, USA.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Software Verification 1 Deductive Verification Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt Universität und Fraunhofer Institut.
Program Analysis and Verification
Boolean Programs: A Model and Process For Software Analysis By Thomas Ball and Sriram K. Rajamani Microsoft technical paper MSR-TR Presented by.
11/22/2016IT 3271 A formal system:Axioms and Rules, for inferring valid specification x := m; y := n; while ¬(x=y) do if x>y then x := x-y else y := y-x.
Further with Hoare Logic Sections 6.12, 6.10, 6.13
Spring 2017 Program Analysis and Verification
Matching Logic An Alternative to Hoare/Floyd Logic
Proving Loops Testing debugging and verification
Formal Methods in Software Engineering 1
Hoare Logic LN chapter 5, 6 but without 6. 8, 6. 12, 6
Mathematical Structures for Computer Science Chapter 1
Lecture 5 Floyd-Hoare Style Verification
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Predicate Transformers
Formal Methods in software development
Predicate Transforms II
Program correctness Axiomatic semantics
Programming Languages and Compilers (CS 421)
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Axiomatic Methods for Software Verification Hongseok Yang

Things like even software verification, this has been the Holy Grail of computer science for many decades but now in some very key areas, for example, driver verification we ’ re building tools that can do actual proof about the software and how it works in order to guarantee the reliability." Bill Gates, April 18, Keynote address at WinHec 2002Keynote address WinHec 2002

Verification Tools Tools for software verification: –Compaq: ESC/Java –Microsoft: SLAM –KSU, NASA: Bandera Axiomatic methods play a crucial role in those tools.

Axiomatic Methods Hoare triple {P}C{Q} –P, Q: assertions such as (x==3)&&(y==z) –C: imperative programs –e.g. {x==4}y=x;{y%2==0} Weakest precondition WP(C,Q) –WP(C,Q): the weakest P s.t. {P}C{Q} –WP(y=x;, y%2==0) = (x%2==0)

History Naur66, Floyd67: –used assertions to specify/verify flowchart programs Hoare69: –developed the proof system for Hoare triples Reynolds00, Ishtiaq&O ’ Hearn01 –extended Hoare ’ s proof system using separating connectives to handle pointers

Fibonacci Numbers n ’ th Fibonacci number fib(n): –fib(0) = 0, fib(1) = 1 –fib(n+2) = fib(n+1) + fib(n)

Implementation in C if (n==0) { a=0; } else { i=1; p=0; a=1; while (i != n) { t=p; p=a; a=p+t; i=i+1; } Does this program calculate “ fib(n) ” and store the result in “ a ” ?

Specification Spec: {true}FIB{a==fib(n)}

Specification Spec: {true}FIB{a==fib(n)} FIB does not satisfy the spec: when n<0, fib(n) is not even defined!!

Specification Spec: {true}FIB{a==fib(n)} FIB does not satisfy the spec: when n<0, fib(n) is not even defined!! New spec: {n>=0}FIB{a==fib(n)} But, how can we be sure that the new spec holds?

Hoare Logic Hoare logic consists of inference rules for proving valid Hoare triples. So, we can use these rules to show that {n>=0}FIB{a==fib(n)} holds.

Rule for Conditional So, {n>=0}FIB{a==fib(n)} holds if FIB satisfies: if (n==0) { {n>=0&&n==0}C 1 {a==fib(n)} } else { {n>=0&&!(n==0)}C 2 {a==fib(n)}}

Rule for Assignment So, {n==0}a=0;{a==fib(n)} because n==0 implies 0==fib(n). It suffices to show the correctness of C 2 : if (n==0) { {n>=0&&n==0}a=0;{a==fib(n)} } else { {n>=0&&!(n==0)}C 2 {a==fib(n)} }

Rule for Sequencing So, it suffices to show: if (n==0) { {n>=0&&n==0}a=0;{a==fib(n)} } else { {n>=0&&!(n==0)} i=1;p=0;a=1; {a==fib(i)&&p==fib(i-1)&&i<=n} while (I!=n) { t=p;p=a; a=p+t;i=i+1; } {a==fib(n)} } We focus on this step

Rule for Loop So, we have: {a==fib(i)&&p==fib(i-1)&&i<=n} while(i!=n) { {a==fib(i)&&p==fib(i-1)&&i<=n&&i!=n} t=p; p=a; a=p+t; i=i+1; {a==fib(i)&&p==fib(i-1)&&i<=n} } {a==fib(i)&&p==fib(i-1)&&i<=n&&!(i!=n)} We prove this in the next slide

Preservation of the Loop Invariant {a==fib(i)&&p==fib(i-1)&&i<=n&&i!=n} {(a+p)==fib(i+1)&&a==fib(i+1-1)&&(i+1)<=n} t=p; {(a+t)==fib(i+1)&&a==fib(i+1-1)&&(i+1)<=n} p=a; {(p+t)==fib(i+1)&&p==fib(i+1-1)&&(i+1)<=n} a=p+t; {a==fib(i+1)&&p==fib(i+1-1)&&(i+1)<=n} i=i+1; {a==fib(i)&&p==fib(i-1)&&i<=n}

Consequence Since a==fib(i)&&!(i!=n) implies a==fib(n), we have: {a==fib(i)&&p==fib(i-1)&&i<=n} while(i!=n) { t=p; p=a; a=p+t; i=i+1; } {a==fib(i)&&p==fib(i-1)&&i<=n&&!(i!=n)} {a==fib(n)}

Simple Twist void PFIB(int *n, int *a) {int t,i,p; if (*n==0) { *a=0; } else { i=1; p=0; *a=1; while (i != *n) { t=p; p=*a; *a=p+t; i=i+1; } } Does the same reasoning prove {*n>=0}PFIB(n,a){*a==fib(*n)}?

Pointers cause a problem! Not quite!! What if a=n? The problem is that the following rule is not sound. Two Solutions: –Morris ’ s solution: modify subsitution using dynamic aliasing checks in the above rule –Reynolds ’ s solution: use separating conjunction “ ** ’’ in assertions.

Semantics of Assertions Semantic Domains –s 2 Stacks = Vars ! fin Ints –h 2 Heaps = Nats ! fin Ints –(s,h) 2 States = Stacks x Heaps “ (s,h)²P ” : P holds for the state (s,h). –(s,h)²P&&Q iff (s,h)²P and (s,h)²Q –(s,h)²(x  E) iff dom(h)={s(x)} and h(s(x))=«E¬

Separating Conjunction #,* for heaps: –h 1 #h 2 iff dom(h 1 )\dom(h 2 ) = ; –When h 1 #h 2, h 1 *h 2 =h 1 [h 2 (s,h)²P**Q iff there exist h 1,h 2 such that –h 1 *h 2 =h; and –(s,h 1 ) ² P and (s,h 2 ) ² Q. e.g. (n  n 0 )**true, (n  n 0 )**(a  fib(n 0 ))

Rule for Pointer Swing By this rule we can prove: {(n  n 0 )**(a  fib(i))**(t==fib(i-1)&&p==fib(i)&&i+1<=n 0 )} *a=p+t; {(n  n 0 )**(a  p+t)**(t==fib(i-1)&&p==fib(i)&&i+1<=n 0 )}

Correctness of PFIB(n,a) Spec: {(n  n 0 )**(a  -)**(n 0 >=0)} PFIB(n,a) {(n  n 0 )**(a  fib(n 0 ))**true} Loop Invariant: (n  n 0 )**(a  fib(i))**(p==fib(i-1)&& i<=n 0 )

Preservation of Loop Invariant {(n  n 0 )**(a  fib(i))**(p==fib(i-1)&& i<=n 0 &&i!=n 0 )} {(n  n 0 )**(a  fib(i))**(p==fib(i-1)&& i+1<=n 0 )} t=p; {(n  n 0 )**(a  fib(i))**(t==fib(i-1)&& i+1<=n 0 )} p=*a; {(n  n 0 )**(a  fib(i))**(t==fib(i-1)&&p==fib(i)&& i+1<=n 0 )} *a=p+t; {(n  n 0 )**(a  p+t)**(t==fib(i-1)&&p==fib(i)&&i+1<=n 0 )} {(n  n 0 )**(a  fib(i+1))**(p==fib(i)&&i+1<=n 0 )} i=i+1; {(n  n 0 )**(a  fib(i))**(p==fib(i-1)&&i<=n 0 )}

Concluding Remarks Why don ’ t you verify your C program using Hoare logic? Well, even if you are lazy, you still might want to play with verification tools. Look at: