1 / 25

Axiomatic Methods for Software Verification

Axiomatic Methods for Software Verification. Hongseok Yang.

saxon
Download Presentation

Axiomatic Methods for Software Verification

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Axiomatic Methods for Software Verification Hongseok Yang

  2. 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, 2002. Keynote address at WinHec 2002

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

  4. 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)

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

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

  7. 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”?

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

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

  10. 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?

  11. 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.

  12. Rule for Conditional • So, {n>=0}FIB{a==fib(n)} holds if FIB satisfies: if (n==0) { {n>=0&&n==0}C1{a==fib(n)} } else { {n>=0&&!(n==0)}C2{a==fib(n)}}

  13. 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 C2: if (n==0) { {n>=0&&n==0}a=0;{a==fib(n)} } else { {n>=0&&!(n==0)}C2{a==fib(n)} }

  14. 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

  15. 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

  16. 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}

  17. 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)}

  18. 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)}?

  19. 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.

  20. 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)²(xaE) iff dom(h)={s(x)} and h(s(x))=«E¬

  21. Separating Conjunction • #,* for heaps: • h1#h2 iff dom(h1)\dom(h2) = ; • When h1#h2, h1*h2=h1[h2 • (s,h)²P**Q iff there exist h1,h2 such that • h1*h2=h; and • (s,h1)²P and (s,h2)²Q. • e.g. (nan0)**true, (nan0)**(aafib(n0))

  22. Rule for Pointer Swing • By this rule we can prove: {(nan0)**(aafib(i))**(t==fib(i-1)&&p==fib(i)&&i+1<=n0)} *a=p+t; {(nan0)**(aap+t)**(t==fib(i-1)&&p==fib(i)&&i+1<=n0)}

  23. Correctness of PFIB(n,a) • Spec: {(nan0)**(aa-)**(n0>=0)} PFIB(n,a) {(n a n0)**(a a fib(n0))**true} • Loop Invariant: (n a n0)**(a a fib(i))**(p==fib(i-1)&& i<=n0)

  24. Preservation of Loop Invariant {(n a n0)**(aafib(i))**(p==fib(i-1)&& i<=n0&&i!=n0)} {(n a n0)**(aafib(i))**(p==fib(i-1)&& i+1<=n0)} t=p; {(n a n0)**(aafib(i))**(t==fib(i-1)&& i+1<=n0)} p=*a; {(n a n0)**(aafib(i))**(t==fib(i-1)&&p==fib(i)&& i+1<=n0)} *a=p+t; {(n a n0)**(aap+t)**(t==fib(i-1)&&p==fib(i)&&i+1<=n0)} {(n a n0)**(aafib(i+1))**(p==fib(i)&&i+1<=n0)} i=i+1; {(n a n0)**(a a fib(i))**(p==fib(i-1)&&i<=n0)}

  25. 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: http://research.microsoft.com/SLAM

More Related