Generating Verifiable Java Code from Verified PVS Specifications - - PowerPoint PPT Presentation

generating verifiable java code from verified pvs
SMART_READER_LITE
LIVE PREVIEW

Generating Verifiable Java Code from Verified PVS Specifications - - PowerPoint PPT Presentation

Leonard Lensink, Sjaak Smetsers and Marko van Eekelen Generating Verifiable Java Code from Verified PVS Specifications NFM2012 Generating Verifiable Java Code from Verified PVS Specifications Overview Motivation Code generation


slide-1
SLIDE 1

Generating Verifiable Java Code from Verified PVS Specifications

Leonard Lensink, Sjaak Smetsers and Marko van Eekelen

slide-2
SLIDE 2

a

Overview

  • Motivation
  • Code generation
  • Feasibility study on distributed communication protocol
  • Future work

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

slide-3
SLIDE 3

a

Motivation

  • The problem:

– How do we create reliable software?

  • The solution:

– Create a proven model – Take the model and run!

  • The catch:

– Efficiency – Model not always executable

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

slide-4
SLIDE 4

a

Motivation

  • New problem:

– Code corresponds with Model?

  • The solution:

– Prove generated code to be correct

  • The catch:

– Proof of translator? – Proof of translation?

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

slide-5
SLIDE 5

a

From verified specifications to verifiable code

  • Generate code for Specification
  • Generate annotations from verified Specification
  • Use Verification Condition Generator/Theorem prover

– Input: Annotated code – Output: Proof obligations

  • Early vs Late use of FM in Software engineering
  • All around:

– Early: Take formal model and generate code – Late: Generate precise and relevant assertions

  • Proven reference implementation

– Integrate – modify

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

slide-6
SLIDE 6

a

Focus

  • Integration

– Abstract functions – Source to source translation – Multiple target languages using IL

  • Verifiable

– Generate code with annotations – Use Verification Condition Generator/Theorem prover

  • Efficiency

– Destructive updates when possible – Optimizations in intermediate language – Translate functions on finite domains into arrays

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-7
SLIDE 7

a

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-8
SLIDE 8

a

Translation

  • Implemented as a part of PVS in common Lisp
  • Extended Why:

– Modules – Records – Abstract datatypes

  • Subset of PVS specification language
  • Translation of arrays only on finite (primitive) domains

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-9
SLIDE 9

Mappings

  • PVS

–Abstract datatypes –Higher order functions –Records –Tuples

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

  • PVS

–Type parameters –Theories –Quantifiers (finite) –Expressions –(Dependent) subtypes –Lemmas

  • Java

–(inline) Classes –Generic abstract Lambda class –(inline) Classes –(inline) Classes –Generic type classes –Classes –H.O. Predicate loops –Expressions –Annotations –Annotations

slide-10
SLIDE 10

a

Abstract Datatypes - PVS

LinkFrame : DATATYPE BEGIN GDP(gdp:GDPFrame,cs:CheckSum) : GDPFrame? WDP(wdp:WDPFrame,cs:CheckSum) : WDPFrame? END LinkFrame …

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-11
SLIDE 11

a

Abstract Datatypes – Java

public abstract class LinkFrame { public boolean isGDPFrame() { return false; } public boolean isWDPFrame() { return false; } } public class WDP extends LinkFrame { public WDPFrame wdp; public int cs; public WDP (WDPFrame wdp, int cs) { this.wdp = wdp; this.cs = cs; } @override public boolean isWDPFrame() { return true; } .. }

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-12
SLIDE 12

a

Functions – Higher order PVS

add (elem:E,b:[E -> nat]) : [E -> nat] LAMBDA (t:E): IF elem = t THEN b(t) + 1 ELSE b(t) ENDIF) Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-13
SLIDE 13

a

Functions – Higher order Java

  • Lambda

public abstract class Lambda<T1,T2> { abstract public T2 apply(T1 obj); }

  • Higher order function

Public class Bag<E> { public static <E> Lambda<E,Integer> add ( final E elem, final Lambda<E,Integer> bag) { return new Lambda<E,Integer> () { public integer apply(final E arg) { if (arg.equals(elem)) { return bag.apply(arg) + 1; } else { return bag.apply(arg); }}};} Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-14
SLIDE 14

a

Annotation generation

  • Subtype predicates become pre/postconditions
  • Executable functions are generated pure
  • Non executable functions become abstract functions with

a contract

  • Lemma’s used in proofs become axioms and/or pre/post

conditions, if they are properly formed

  • Measure becomes variant
  • Quantifiers on subtype predicated variables are rewritten

to use the supertype.

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-15
SLIDE 15

a

Annotations

  • PVS

idx : TYPE = below(N) init(idx i) : [idx -> nat]

  • Java

boolean /*@pure*/ nat(int s) { return 0 <= s; } boolean /*@pure*/ below(int x, int y) = { return nat(x) && x < y; } boolean /*@pure*/ idx(int x) = { return below(x,N); } boolean /*@pure*/ array(int[] x, int l) = x.length - 1 == l && nat(l); /*@ requires idx(i); @ ensures array(\result,N-1) && (\forall integer i; idx(i) ==> nat(\result[i])); @*/ public abstract int[] init(int i); Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-16
SLIDE 16

a

Feasibility study model

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-17
SLIDE 17

a

Extracting pre/postconditions

  • Most models do not fully utilize type predicates
  • We need to generate pre/postconditions for

Key/Krakatoa

  • There is information in theorems

– square(x:nat) : nat = x * x – Lemma: ∀ (x:int) : x > 0 → square(x) > 0

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-18
SLIDE 18

a

Extracting pre/postconditions

  • PVS

square(x:nat) : nat = x*x square_lemma : LEMMA FORALL (x:int) : X > 0 IMPLIES square(x) > 0

  • Extract pre/post information:

– ∀ (x:T) : Pre(x) → Post (F(x))

  • Java

/*@requires x > 0 @ensures \result > 0 */ int square(int x) { return x*x; } Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-19
SLIDE 19

a

Extracting for state transition models

  • Pinit : [S → Bool ]
  • R : [[S, S] → Bool ]
  • Pinv : [ S → Bool ]
  • Pinit(S) → Pinv (S)
  • R(S1,S2) ∧ Pinv (S1) → Pinv (S2)
  • Pinv postcondition for Pinit
  • Pinv invariant for R

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-20
SLIDE 20

a

More complicated cases

  • r : [nat → S]
  • ∀r,n : Pinv (r(n))
  • ∀r,n : Pinit(r(0)) ∧ R(r(n), r(n+1))
  • Pinv postcondition for Pinit
  • Pinv invariant for R

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-21
SLIDE 21

a

Verified invariant

  • PVS

wdp_soundness : THEOREM invariant(is_subset?) invariant(p) : bool = FORALL (r : (run), n:nat ): p(r(n))

  • Java

/*@ requires no_null_pointers(s) @ && WDPAbstract.wdp_in_app_to_wdp(s) @ && WDPAbstract.is_subset(s); @ ensures \result ==> WDPAbstract.is_subset(n); */ public boolean WDP(final WDPState s, final WDPState n) Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-22
SLIDE 22

a

Evaluation

  • Possible to prove invariants
  • Key proofs structured similarly to PVS
  • Generics support lacking
  • Multiple branching points do not translate well into KeY
  • Null pointer checking ubiquitous
  • Small bugs

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-23
SLIDE 23

a

PVS2Why – Future work

  • Generate proof alongside annotations

– Restricted subset of prover commands

  • Optimizations

– Recursion elimination

– Deletion of unnecessary statements – Optimization correctness conditions

  • Generate threads from relational models
  • Annotations for semantic attachments

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-24
SLIDE 24

a

Summary

  • Translation of PVS specifications to intermediate

language WHY

– Export as XML

  • Translation of Why to Java with annotations
  • Feasibility study on Airstar model

– Generated annotations strong enough for (manual) proof in Key – Proofs structured similarly to PVS in KeY

  • Future work:

– More transformations – More proof information/portable proofs

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-25
SLIDE 25

a

Acknowledgements

  • Alwyn Goodloe
  • César A. Muñoz
  • Yeisson Oviedo
  • Marcelo Cordini

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen

slide-26
SLIDE 26

a

Questions?

Generating Verifiable Java Code from Verified PVS Specifications

NFM2012

Leonard Lensink, Sjaak Smetsers, Marko van Eekelen