• Keine Ergebnisse gefunden

• Verifying heap-manipulating object-oriented programs

N/A
N/A
Protected

Academic year: 2022

Aktie "• Verifying heap-manipulating object-oriented programs"

Copied!
7
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

8. Program Verification 8.6 Verifying procedural, heap-manipulating programs

Verifying Java-KE programs

• Verifying virtual methods / interface properties

• Verifying heap-manipulating object-oriented programs

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 542

8. Program Verification 8.6 Verifying procedural, heap-manipulating programs

Example: Virtual methods

interface MyInf { int m( int par );

}

class Impl1 implements MyInf { int m( int par ) {

if( p < 0 ) res = 0; else res = p;

} }

class Impl2 implements MyInf { int m( int par ) { res = 3; } }

public class VerifVirtualMethods {

int main( MyInf par ) { res = par. m( -9 ); } }

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 543

8. Program Verification 8.6 Verifying procedural, heap-manipulating programs

Example: Virtual methods (2)

Prove:

B { par , null } VerifVirtualMethods@main { res0 }

8. Program Verification 8.6 Verifying procedural, heap-manipulating programs

Example: Heap-manipulating OO programs

class Null {}

class Node { int elem;

Node next ; }

class List { Node elems;

boolean isempty () { res = (elems == null); } void add( int par ) { ... } // next slide

void append ( List par ) { ... } // second next slide

}

(2)

Example: Heap-manipulating OO programs (2)

void add( int par ) { Node newNd;

Node oldNd;

newNd = new Node ();

newNd .elem = par ; oldNd = this. elems;

newNd .next = oldNd;

this. elems = newNd;

}

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 546

Example: Heap-manipulating OO programs (3)

void append ( List par ) { Node appl ;

appl = par . elems;

while( appl != null ) { int el ;

el = appl. elem;

this. add ( el );

appl = appl. next;

} }

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 547

8. Program Verification 8.6 Verifying procedural, heap-manipulating programs

Example: Heap-manipulating OO programs (4)

Develop:

1. abstraction predicates for lists 2. invariant of object store/heap

3. specifications for isempty , add and append

Prove correctness of class List (see lecture and technical report)

8. Program Verification 8.7 Software verification tools

Section 8.7

Software verification tools

(3)

8. Program Verification 8.7 Software verification tools

Overview

Considered techniques and tools:

• Tools for interactive software verification (e.g., KeY, Why)

• Extended static checking (e.g., Spec#, Chalice, VeriFast, BLAST)

• Refinement and compatibility checking (e.g., Event B, KIV, BCVerifier)

• Automated theorem proving, in particular:

I

Superposition provers (e.g., SPASS, E)

I

SMT solvers and model checkers (e.g., Z3, SPIN)

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 550

8. Program Verification 8.7 Software verification tools

Subsection 8.7.1

Tools for interactive software verification

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 551

8. Program Verification 8.7 Software verification tools

General approach

• Programming-language-specific front end/development environment

• Programming-language-specific specification language

• Verification condition generator (VCG)

• Possibly several provers to discharge the VCs (automated and/or interactive)

8. Program Verification 8.7 Software verification tools

Example systems

• KeY: www.key-project.org/

I

programming language: JavaCard; specifications in JML

I

based on an interactive prover for dynamic logic

I

makes extensive use of symbolic evaluation

• Why, Why3: why.lri.fr/

I

programming languages: Java subset, C subset

I

specific specification languages

I

general-purpose verification condition generator

I

uses many interactive and automated provers

(4)

Discussion of refinement-based approach

• Advantages:

I

quite close to programming language and programmer

I

special IDEs for programs, specifications and proofs

I

can smoothly integrate powerful logics and dedicated automated techniques

• Disadvantages:

I

expensive solution

I

not very flexible w.r.t. extensions

I

meta-logical aspects cannot be handled

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 554

Subsection 8.7.2

Extended static checking

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 555

8. Program Verification 8.7 Software verification tools

General approach

• Programming-language-specific front end/development environment

• Programming-language-specific specification language

• Verification condition generator (VCG)

• Automated prover to discharge the VCs

8. Program Verification 8.7 Software verification tools

Example systems

• Spec#: research.microsoft.com/en-us/projects/specsharp/

I

programming and specification language: Spec# (extension of C#)

I

specific focus on modularity of specifications

I

uses first-order ATP

I

also supports dynamic checking

• VeriFast: people.cs.kuleuven.be/~bart.jacobs/verifast/

I

verifier for single-threaded and multi-threaded C and Java programs

I

pre- and postconditions written in separation logic

I

user guides the proofs by so-called “lemma functions”

I

uses the SMT solver Z3

• BLAST: mtc.epfl.ch/software-tools/blast/

I

software model checker for C programs

(5)

8. Program Verification 8.7 Software verification tools

Typical architecture for ESC

B oo g ie

Spec# tool architecture:

Spec# (annotated C#)

BoogiePL Spec# Compiler

Translator

VC Generator

Verification conditions Automated Theorem

Prover

Annotated CIL

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 558

8. Program Verification 8.7 Software verification tools

Discussion of extended static checking

• Advantages:

I

close to programming language and programmer

I

good integration with normal IDEs

I

in principle, no contact with the prover needed

• Disadvantages:

I

specifications less expressive (why?), in particular w.r.t. abstraction

I

error messages can be tricky if checking fails

I

helping the prover can get difficult

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 559

8. Program Verification 8.7 Software verification tools

Subsection 8.7.3

Refinement and compatibility checking

8. Program Verification 8.7 Software verification tools

General approach

• Support the formal development from software models to programs

• Refinement relates software models on different levels of abstraction

• Compatibility checking relates different program versions

• Proofs based on simulation techniques

• Possibly several provers to discharge the VCs (automated and/or

interactive)

(6)

Example systems refinement

• Event B: www.event-b.org/

I

correctness by construction in the tradition of VDM

I

system = software + environment: represented as transition systems

I

B notation following the Z notation

I

specific development and proof platform Rodin

I

programs are generated from most concrete model

• KIV: www.informatik.uni-augsburg.de/lehrstuehle/swt/se/kiv/

I

formal systems development and interactive verification

I

specification support:

I

functional aspects: abstract data types and HOL

I

state-based aspects: programs and abstract state machines

I

supports various kinds of refinements

I

sophisticated IDE for proof engineering

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 562

Example systems compatibility checking

BCVerifier: softech.informatik.uni-kl.de/bcverifier/

• checks two packages written in a Java subset for backward compatibility

• supports a specification language for writing coupling invariants

• uses Boogie as checking platform

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 563

8. Program Verification 8.7 Software verification tools

Discussion

• Software verification goes beyond program verification

• Other interesting aspects:

I

Correctness of software systems

I

Correctness of refactoring methods

I

Correctness of compilers and programming tools

8. Program Verification 8.7 Software verification tools

Subsection 8.7.4

ATP: Automated theorem proving

(7)

8. Program Verification 8.7 Software verification tools

Techniques for automated verification

A rough classification:

The software verification tools use many techniques for automating proofs or proof steps, in particular:

• Superposition provers (e.g., SPASS, E)

• SMT solvers and model checkers (e.g., Z3, SPIN)

• Abstract interpretation and abstraction refinement

©Arnd Poetzsch-Heffter et al. TU Kaiserslautern 566

Referenzen

ÄHNLICHE DOKUMENTE

8.3 Formalization and soundness of the Hoare logic 8.4 Program verification with Isabelle/HOL.. 8.5 Verifying procedural, heap-manipulating programs 8.6 Software

Program Verification 8.6 Verifying procedural, heap-manipulating programs.. Verifying

(s3) Here, we essentially use the property x#(rev yl) = rev (yl@[x]) and the fact that by taking the tail of the list reachable from appl, the corresponding prefix gets longer by

5.2 Case study: Greatest common devisor 5.3 Well-definedness of recursive functions 5.4 Case study: Quicksort.. ©Arnd Poetzsch-Heffter

Inductive Definitions and Fixed Points 6.3 Specifying and verifying transition systems. Modeling approach

In the correct protocol, if A or B receive the expected nonce, then the server has sent message 3 in precisely the right form.. Agents need guarantees (subject to conditions they

Removing intermediate data structures is called deforestation, since data structures are tree-shaped in the general case. In our case, we would like to fuse an unfold followed by

Die Schnittstelle ist durch die abstrakte Klasse Priority- Queue gegeben: offer fügt ein Zeichen ein; poll liefert das größte Zeichen und entfernt es; size liefert die Anzahl