Docsity

Program Verification Assignment for CMSC 838Z, Spring 2004 - Prof. Michael W. Hicks, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
Project 4
CMSC 838Z, Spring 2004
Due Wednesday, March 31 (e-mail to me)
This assignment considers program verification, which is the process of prov-
ing properties about the executions of programs. We will do some written
exercises using Hoare Logic, a logic about program executions, and also make
use of the Simplify automatic theorem prover.
For this assignment, you will get experience using the (aka rccjava), a
typechecker that checks for race conditions in Java programs.
Written Exercises
Please do the following exercises from your handout material:
•Exercises 4.3, number 2 (page 242).
•Exercises 4.5, number 2b (page 245). Show your program and the proof
that it satisfies the given post condition using a proof tableaux, as shown
in the examples prior to this exercise.
•Exercises 4.6, number 1 (page 250).
For a primer, try the practice exercises at http://www.cis.ksu.edu/~huth/
lics/tutor/chap4/questions.html.
Proving Properties about Programs
Now for the fun part. We will write our own little program verifier. Given a
program Π, you will prove that executing a program in a state that satisfies
precondition Πpre will result in a state that satsifies postcondition Πpost. This
will occur in two steps:
•Starting from the postcondition Πpost, perform verification condition gen-
eration on Π, resulting in a verification condition V C(Π). You will write
your own verification condition generator following the algorithm we went
over in class, and which is described in Necula’s notes (see http://www.
cs.berkeley.edu/~necula/autded/lecture03.pdf).
pf3

Partial preview of the text

Download Program Verification Assignment for CMSC 838Z, Spring 2004 - Prof. Michael W. Hicks and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

Project 4

CMSC 838Z, Spring 2004

Due Wednesday, March 31 (e-mail to me)

This assignment considers program verification, which is the process of prov- ing properties about the executions of programs. We will do some written exercises using Hoare Logic, a logic about program executions, and also make use of the Simplify automatic theorem prover. For this assignment, you will get experience using the (aka rccjava), a typechecker that checks for race conditions in Java programs.

Written Exercises

Please do the following exercises from your handout material:

  • Exercises 4.3, number 2 (page 242).
  • Exercises 4.5, number 2b (page 245). Show your program and the proof that it satisfies the given post condition using a proof tableaux, as shown in the examples prior to this exercise.
  • Exercises 4.6, number 1 (page 250).

For a primer, try the practice exercises at http://www.cis.ksu.edu/~huth/ lics/tutor/chap4/questions.html.

Proving Properties about Programs

Now for the fun part. We will write our own little program verifier. Given a program Π, you will prove that executing a program in a state that satisfies precondition Πpre will result in a state that satsifies postcondition Πpost. This will occur in two steps:

  • Starting from the postcondition Πpost , perform verification condition gen- eration on Π, resulting in a verification condition V C(Π). You will write your own verification condition generator following the algorithm we went over in class, and which is described in Necula’s notes (see http://www. cs.berkeley.edu/~necula/autded/lecture03.pdf).
  • Prove that Πpre implies V C(Π). To do this, we will simply invoke the Simplify theorem prover.

We will define programs as having the following grammar:

E ::= n | x | (+ E E) | (− E E) | (∗ E E) B ::= TRUE | FALSE | (NOT B) | (AND B B) | (OR B B) | (EQ E E) | (< E E) C ::= (SET! x E) | (SEQ C C) | (IF B C C) | (WHILE P B C)

All program forms are s-expressions, as in Lisp or Scheme. This will simplify the process of feeding assertions to Simplify for proof, which expects s-expressions in the form above, and will also simplify the process of writing a parser for your language. All WHILE expressions are annotated with an assertion P , which serves as the loop invariant. Our assertion language P essentially extends boolean expressions with implication and universal quantification:

P ::= (FORALL (V ) P ) | (IMPLIES P P ) | TRUE | FALSE | (NOT P ) | (AND P P ) | (OR P P ) | (EQ E E) | (< E E) V ::= x | V x

Your prover will read in programs which start with a precondition, then have a command, and conclude with a postcondition. As an example, the factorial program on page 249 of the handout would be written as follows:

(TRUE) ; precondition (SEQ (SET! y 1) (SEQ (SET! z 0) (SEQ (WHILE (EQ Y (FACT Z)) ; loop invariant (NOT (EQ Z X)) ; loop guard (SEQ (SET! Z (+ Z 1)) ; loop body (SET! Y (* Y Z))))))) (EQ Y (FACT X)) ; postcondition

The text following ; are comments. Note that the loop invariant and postcondi- tion here is not actually expressible in our assertion language P , since we don’t have a predicate FACT. We’ll have to relegate ourselves to simpler assertions. Your program will read in a program Π like the above, generate a verification condition V C(Π) for it, and then feed the compound assertion to simplify that suggests the precondition implies the verification condition. Simplify should return either valid, or invalid. You can ignore the error context. Your program should print out the assertion you gave to simplify, and whether Simplify thought it was valid or not. To test your solution, try out your answers to the exercises above, and see what verifications get generated and whether Simplify can prove them correct. Submit for me your working prover, and its output for these exercises.