Formal Verification of LabVIEW Diagrams Mark Reitblatt Dept. of - - PowerPoint PPT Presentation

formal verification of labview diagrams
SMART_READER_LITE
LIVE PREVIEW

Formal Verification of LabVIEW Diagrams Mark Reitblatt Dept. of - - PowerPoint PPT Presentation

Formal Verification of LabVIEW Diagrams Mark Reitblatt Dept. of Computer Sciences, University of Texas National Instruments, Inc. Monday, April 27, 2009 1 Outline LabVIEW Overview ACL2 Overview Overview of approach Walk


slide-1
SLIDE 1

Mark Reitblatt

  • Dept. of Computer Sciences, University of Texas

National Instruments, Inc.

Formal Verification of LabVIEW Diagrams

1 Monday, April 27, 2009

slide-2
SLIDE 2

Outline

  • LabVIEW Overview
  • ACL2 Overview
  • Overview of approach
  • Walk through example verification
  • Conclusion

2 Monday, April 27, 2009

slide-3
SLIDE 3

Project History

  • Jeff Kodosky started playing around in 2004 with the idea of verifying

a LabVIEW program

  • Warren Hunt and J Moore met on occasion with Jeff and Jacob

Kornerup over a couple of years, culminating with NI engaging Grant as an intern in 2005

  • Summer 2007: Alternate approach developed with Matt Kaufmann

models LabVIEW programs, including loop structures, directly as ACL2 functions. At the end of the summer Grant Passmore left for Edinburgh and transferred his work to the author

  • Current: Matt continued contracting, approach has been fully

automated, expanded and used to verify a dozen examples

3 Monday, April 27, 2009

slide-4
SLIDE 4

Credit

  • To reiterate

4 Monday, April 27, 2009

slide-5
SLIDE 5

Credit

  • To reiterate
  • Joint work with Matt Kaufmann

4 Monday, April 27, 2009

slide-6
SLIDE 6

Credit

  • To reiterate
  • Joint work with Matt Kaufmann
  • Building off work with Matt and Grant

4 Monday, April 27, 2009

slide-7
SLIDE 7

Credit

  • To reiterate
  • Joint work with Matt Kaufmann
  • Building off work with Matt and Grant
  • Project fully funded by National

Instruments, Inc.

4 Monday, April 27, 2009

slide-8
SLIDE 8

LabVIEW (in brief)

  • Graphical dataflow language (G) with control structures
  • Shift register memory elements
  • Separate Front (user interface) and Back (implementation) panels

5 Monday, April 27, 2009

slide-9
SLIDE 9

LabVIEW For-Loops

6 Monday, April 27, 2009

slide-10
SLIDE 10

LabVIEW For-Loops

loop bound

6 Monday, April 27, 2009

slide-11
SLIDE 11

LabVIEW For-Loops

loop bound

6 Monday, April 27, 2009

slide-12
SLIDE 12

LabVIEW For-Loops

constant loop bound

6 Monday, April 27, 2009

slide-13
SLIDE 13

LabVIEW For-Loops

constant loop bound

6 Monday, April 27, 2009

slide-14
SLIDE 14

LabVIEW For-Loops

constant loop bound shift registers

6 Monday, April 27, 2009

slide-15
SLIDE 15

LabVIEW For-Loops

constant loop bound shift registers

6 Monday, April 27, 2009

slide-16
SLIDE 16

LabVIEW For-Loops

constant loop bound shift registers

6 Monday, April 27, 2009

slide-17
SLIDE 17

LabVIEW For-Loops

constant loop bound shift registers loop counter

6 Monday, April 27, 2009

slide-18
SLIDE 18

LabVIEW For-Loops

constant loop bound shift registers loop counter

6 Monday, April 27, 2009

slide-19
SLIDE 19

ACL2

  • Programming Language
  • Formal Logic
  • Automated Theorem Prover

7 Monday, April 27, 2009

slide-20
SLIDE 20

ACL2 The Language

  • Subset of Lisp
  • S-Expressions
  • Untyped
  • First Order
  • Applicative
  • Purely functional
  • Total
  • All functions

defined on all inputs

  • I.E. everything

terminates

8 Monday, April 27, 2009

slide-21
SLIDE 21

ACL2 Syntax

  • S-Expressions
  • Primary syntax is ()
  • Prefix notation
  • (f x) instead of f(x)
  • Predicates end in a -p by convention
  • Use defun to define a function

9 Monday, April 27, 2009

slide-22
SLIDE 22

ACL2 (cont.)

(defun fib (i) (if (or (zp i) (= i 1)) 1 (+ (fib (- i 1)) (fib (- i 2)))))

  • (zp x) returns false if x is a natural number

and x > 0

  • Note that zp recognizes all non-integers

10 Monday, April 27, 2009

slide-23
SLIDE 23

ACL2 The Logic

  • Definitional Principle

11 Monday, April 27, 2009

slide-24
SLIDE 24

ACL2 The Logic

  • Definitional Principle
  • Use defthm to name, define and prove a

new theorem

11 Monday, April 27, 2009

slide-25
SLIDE 25

ACL2 The Logic

  • Definitional Principle
  • Use defthm to name, define and prove a

new theorem

  • Theorems are stored as rules (usually

rewrite)

11 Monday, April 27, 2009

slide-26
SLIDE 26

ACL2 The Logic (cont.)

(defthm fib-is-bigger-than-n (implies (integerp n) (>= (fib n) n)))

  • integerp recognizes integers
  • fib is defined on every ACL2 object
  • But fib(n) >= n is not true for all objs.

12 Monday, April 27, 2009

slide-27
SLIDE 27

ACL2 The Theorem Prover

  • ACL2 proves theorems with existing

theorems and function definitions

  • User guides the process with hints and

theory control

  • A theory is a list of enabled rules and

definitions

13 Monday, April 27, 2009

slide-28
SLIDE 28

ACL2 The Thm. Prover

ACL2 !>(defthm fib-is-bigger-than-n (implies (integerp n) (>= (fib n) n))) ([ A key checkpoint: Goal' (IMPLIES (INTEGERP N) (<= N (FIB N))) *1 (Goal') is pushed for proof by induction. ]) Perhaps we can prove *1 by induction. One induction scheme is suggested by this conjecture. We will induct according to a scheme suggested by (FIB N). This suggestion was produced using the :induction rule FIB. If we let (:P N) denote *1 above then the induction scheme we'll use is (AND (IMPLIES (AND (NOT (OR (ZP N) (= N 1))) (:P (+ -1 N)) (:P (+ -2 N))) (:P N)) (IMPLIES (OR (ZP N) (= N 1)) (:P N))). This induction is justified by the same argument used to admit FIB. When applied to the goal at hand the above induction scheme produces five nontautological subgoals. *1 is COMPLETED! Thus key checkpoint Goal' is COMPLETED! Q.E.D. Summary Form: ( DEFTHM FIB-IS-BIGGER-THAN-N ...) Rules: ((:COMPOUND-RECOGNIZER ZP-COMPOUND-RECOGNIZER) (:DEFINITION =) (:DEFINITION FIB) (:DEFINITION NOT) (:EXECUTABLE-COUNTERPART <) (:EXECUTABLE-COUNTERPART FIB) (:EXECUTABLE-COUNTERPART INTEGERP) (:EXECUTABLE-COUNTERPART NOT) (:FAKE-RUNE-FOR-LINEAR NIL) (:FAKE-RUNE-FOR-TYPE-SET NIL) (:INDUCTION FIB) (:TYPE-PRESCRIPTION FIB)) Warnings: None Time: 0.01 seconds (prove: 0.00, print: 0.00, other: 0.00) FIB-IS-BIGGER-THAN-N 14 Monday, April 27, 2009

slide-29
SLIDE 29

Formal Verification

  • Application of formal methods for

correctness proofs of SW/HW

  • Uses formal specifications of behavior
  • Utilizes theorem provers and decision

procedures to complete proofs

15 Monday, April 27, 2009

slide-30
SLIDE 30

Problem at Hand

  • We desire to verify LabVIEW/G diagrams
  • LabVIEW/G lacks an assertion primitive
  • LabVIEW/G lacks a formal semantics

16 Monday, April 27, 2009

slide-31
SLIDE 31

Solution

  • Add assertion block to LabVIEW/G

17 Monday, April 27, 2009

slide-32
SLIDE 32

Solution

  • Add assertion block to LabVIEW/G
  • Construct semantics for LabVIEW/G in

ACL2

17 Monday, April 27, 2009

slide-33
SLIDE 33

Solution

  • Add assertion block to LabVIEW/G
  • Construct semantics for LabVIEW/G in

ACL2

  • Convert assertions into ACL2 proof
  • bligations

17 Monday, April 27, 2009

slide-34
SLIDE 34

Solution

  • Add assertion block to LabVIEW/G
  • Construct semantics for LabVIEW/G in

ACL2

  • Convert assertions into ACL2 proof
  • bligations
  • Use LabVIEW semantics for semantics of

assertions

17 Monday, April 27, 2009

slide-35
SLIDE 35

Our Approach

  • “assertion” blocks are written in

LabVIEW/G

  • This allows simulation, validation

18 Monday, April 27, 2009

slide-36
SLIDE 36

Translation

GCompiler Translator ACL2 Diagram

Written in LabVIEW/G Written in ACL2

19 Monday, April 27, 2009

slide-37
SLIDE 37

Our Approach (cont.)

20 Monday, April 27, 2009

slide-38
SLIDE 38

Our Approach (cont.)

  • Translate LabVIEW/G diagrams into ACL2

functions (shallow embedding)

20 Monday, April 27, 2009

slide-39
SLIDE 39

Our Approach (cont.)

  • Translate LabVIEW/G diagrams into ACL2

functions (shallow embedding)

  • 1-1 correspondence between function

nodes,wires and ACL2 functions

20 Monday, April 27, 2009

slide-40
SLIDE 40

Naming

21 Monday, April 27, 2009

slide-41
SLIDE 41

Naming

  • LabVIEW/G doesn’t allow naming of (most)

nodes

21 Monday, April 27, 2009

slide-42
SLIDE 42

Naming

  • LabVIEW/G doesn’t allow naming of (most)

nodes

  • Human readability is essential to

understanding proofs

21 Monday, April 27, 2009

slide-43
SLIDE 43

Naming

  • LabVIEW/G doesn’t allow naming of (most)

nodes

  • Human readability is essential to

understanding proofs

  • Auto-naming of nodes based on type

21 Monday, April 27, 2009

slide-44
SLIDE 44

Naming (cont.)

  • Fn nodes are named as fntype-number

22 Monday, April 27, 2009

slide-45
SLIDE 45

Naming (cont.)

  • Fn nodes are named as fntype-number
  • ADD-1

22 Monday, April 27, 2009

slide-46
SLIDE 46

Naming (cont.)

  • Fn nodes are named as fntype-number
  • ADD-1
  • Constant nodes are named by value

22 Monday, April 27, 2009

slide-47
SLIDE 47

Naming (cont.)

  • Fn nodes are named as fntype-number
  • ADD-1
  • Constant nodes are named by value
  • CONSTANT[0]-2

22 Monday, April 27, 2009

slide-48
SLIDE 48

Naming (cont.)

  • Fn nodes are named as fntype-number
  • ADD-1
  • Constant nodes are named by value
  • CONSTANT[0]-2
  • Third instance of the constant ‘0’

22 Monday, April 27, 2009

slide-49
SLIDE 49

Naming (cont.)

  • Wires are named a little differently
  • Because it’s dataflow, each wire retrieves
  • ne terminal from one node
  • Wire named after its source

CONSTANT[0]-2<_T_0>

23 Monday, April 27, 2009

slide-50
SLIDE 50

Naming (cont.)

  • Diagram inputs are named by label
  • Diagram structures are also named by label
  • Function terminals are named by LabVIEW

term-name field

  • Output terminal of assertion diagrams is

named :ASN

24 Monday, April 27, 2009

slide-51
SLIDE 51

ACL2 Model

  • Nodes have input and output terminals

(wire ports)

  • Each node takes a record (IN) as input
  • Returns output record
  • Wires extract values from records

25 Monday, April 27, 2009

slide-52
SLIDE 52

Translation

(DEFUN-N CONSTANT[0]-0 (IN) (S* :|_T_0| 0)) (DEFUN-W CONSTANT[0]-0<_T_0> (IN) (G :|_T_0| (CONSTANT[0]-0 IN))) (DEFUN-N INCREMENT-0 (IN) (S* :X+1 (1+ (CONSTANT[0]-0<_T_0> IN))))

26 Monday, April 27, 2009

slide-53
SLIDE 53

Translation

(DEFUN-N CONSTANT[0]-0 (IN) (S* :|_T_0| 0)) (DEFUN-W CONSTANT[0]-0<_T_0> (IN) (G :|_T_0| (CONSTANT[0]-0 IN))) (DEFUN-N INCREMENT-0 (IN) (S* :X+1 (1+ (CONSTANT[0]-0<_T_0> IN))))

  • (S* :key1 val1 :key2 val2 ...) creates new

record binding :keyi to vali (“set”)

26 Monday, April 27, 2009

slide-54
SLIDE 54

Translation

(DEFUN-N CONSTANT[0]-0 (IN) (S* :|_T_0| 0)) (DEFUN-W CONSTANT[0]-0<_T_0> (IN) (G :|_T_0| (CONSTANT[0]-0 IN))) (DEFUN-N INCREMENT-0 (IN) (S* :X+1 (1+ (CONSTANT[0]-0<_T_0> IN))))

  • (S* :key1 val1 :key2 val2 ...) creates new

record binding :keyi to vali (“set”)

  • (G :key rec) returns the value associated

with :key in rec (“get”)

26 Monday, April 27, 2009

slide-55
SLIDE 55

Our Approach (cont.)

  • Translate assertions into proof obligations

(DEFTHM ASSERTION-BLOCK-HOLDS (IMPLIES (AND (NATP (G :NUMBER IN))) (G :ASN (ASSERTION-BLOCK IN))))

27 Monday, April 27, 2009

slide-56
SLIDE 56

Caveats

  • We use unbounded arithmetic, so this is a

theorem for us, but not for LabVIEW/G

  • We view this as verifying a slightly

“idealized” form of LabVIEW/G

28 Monday, April 27, 2009

slide-57
SLIDE 57

LabVIEW Loops

  • We separate for-loop structures into 4

ACL2 functions

  • $step function
  • Executes loop body and binds outputs to

next iteration inputs

(DEFUN FOR-LOOP$STEP (IN) (S :|_T_4| (G :|_T_1| (|_N_5| IN)) IN))

29 Monday, April 27, 2009

slide-58
SLIDE 58

LabVIEW Loops (cont.)

  • $loop function
  • Compares loop counter to loop bound
  • Updates loop counter and calls $step fn

(DEFUN FOR-LOOP$LOOP (N IN) (DECLARE (XARGS :MEASURE (NFIX (- N (G :LC IN))))) (COND ((OR (>= (G :LC IN) N) (NOT (NATP N)) (NOT (NATP (G :LC IN)))) IN) (T (FOR-LOOP$LOOP N (S :LC (1+ (G :LC IN)) (FOR-LOOP$STEP IN))))))

30 Monday, April 27, 2009

slide-59
SLIDE 59

LabVIEW Loops (cont.)

  • $init function
  • Binds loop variables to initial values

(DEFUN FOR-LOOP$LOOP$INIT (IN) (S* :LC 0 :|_T_2| (CONSTANT[10]-1<_T_0> IN) :|_T_4| (CONSTANT[0]-0<_T_0> IN)))

31 Monday, April 27, 2009

slide-60
SLIDE 60

LabVIEW Loops (cont.)

  • Top function
  • Binds loop bound and calls $loop fn with

results of $init fn

(DEFUN-N FOR-LOOP (IN) (FOR-LOOP-SRN$LOOP (CONSTANT[10]-1<_T_0> IN) (FOR-LOOP-SRN$LOOP$INIT IN)))

32 Monday, April 27, 2009

slide-61
SLIDE 61

LabVIEW Structures

  • LabVIEW loops are split into inner and
  • uter structures
  • Inner structures are called “Self-reference

Nodes” (SRN)

  • SRN nodes contain the body of the loop
  • Outer nodes map external values to

internal names

33 Monday, April 27, 2009

slide-62
SLIDE 62

Top Loop Assertions

  • Assertions about loops (in general) require

inductive proofs

  • We split loop assertions into “top”

assertions and loop invariants

34 Monday, April 27, 2009

slide-63
SLIDE 63

Loop Assertions (cont.)

35 Monday, April 27, 2009

slide-64
SLIDE 64

Loop Invariant

36 Monday, April 27, 2009

slide-65
SLIDE 65

Top Loop Assertion

37 Monday, April 27, 2009

slide-66
SLIDE 66

Proving Loop Assertions

  • Hold the user’s hand to prove invariants
  • Autogenerate highly structured proof

scaffolding

  • Strictly guide proof process by way of

theory control

38 Monday, April 27, 2009

slide-67
SLIDE 67

Proof Scaffolding

  • Generate 13 lemmas, 6 predicates
  • 4 lemmas potentially require user

assistance

  • All other lemmas (should) be automatic
  • Generated file has ~50 lines of comments
  • User assisted lemmas are marked

39 Monday, April 27, 2009

slide-68
SLIDE 68

Generic Theory

  • We use a generic theory to avoid induction

in the invariant proof

  • Use encapsulate to define a generic

$step, $loop

  • Prove that if $prop holds on entry to

$loop and is preserved by $step then it holds when $loop is run

40 Monday, April 27, 2009

slide-69
SLIDE 69

Example Diagram

41 Monday, April 27, 2009

slide-70
SLIDE 70

Example Diagram

42 Monday, April 27, 2009

slide-71
SLIDE 71

Our Goal

(DEFTHM ACL2-TOP-ASN$INV (IMPLIES (GAUSS$INPUT-HYPS IN) (G :ASN (ACL2-TOP-ASN IN))))

43 Monday, April 27, 2009

slide-72
SLIDE 72

Our Goal

  • But we can’t prove this immediately

(DEFTHM ACL2-TOP-ASN$INV (IMPLIES (GAUSS$INPUT-HYPS IN) (G :ASN (ACL2-TOP-ASN IN))))

43 Monday, April 27, 2009

slide-73
SLIDE 73

Extend Loop Invariant

(DEFUN LOOP-INV-SRN$PROP (N IN) (DECLARE (IGNORABLE N)) (AND (LOOP-INV-SRN$HYPS IN) (EQUAL N (G :|_T_2| IN)) (G :ASN (ACL2-LOOP-INV IN))))

  • LOOP-INV-SRN$HYPS is a type predicate that recognizes the

types on the inputs to LOOP-INV-SRN

  • ACL2-LOOP-INV is the name of the loop invariant

44 Monday, April 27, 2009

slide-74
SLIDE 74

Loop Inv. is Preserved

(DEFTHMDL LOOP-INV-SRN$PROP{FOR-LOOP-SRN$STEP} (IMPLIES (AND (NATP (G :LC IN)) (< (G :LC IN) N) (LOOP-INV-SRN$PROP N IN)) (LOOP-INV-SRN$PROP N (S :LC (1+ (G :LC IN)) (FOR-LOOP-SRN$STEP IN)))))

  • Defthmdl is a macro for (local (defthmd foo ...))

45 Monday, April 27, 2009

slide-75
SLIDE 75

Use Generic Theory

(DEFTHML LOOP-INV-SRN$PROP{FOR-LOOP-SRN} (IMPLIES (AND (NATP N) (NATP (G :LC IN)) (LOOP-INV-SRN$PROP N IN)) (LOOP-INV-SRN$PROP N (FOR-LOOP-SRN$LOOP N IN))) :HINTS (("Goal" :BY (:FUNCTIONAL-INSTANCE LOOP-GENERIC-THM (STEP-GENERIC FOR-LOOP-SRN$STEP) (PROP-GENERIC LOOP-INV-SRN$PROP) (LOOP-GENERIC FOR-LOOP-SRN$LOOP)) :IN-THEORY (UNION-THEORIES '(LOOP-INV-SRN$PROP{FOR-LOOP-SRN$STEP}) (THEORY 'MINIMAL-THEORY)) :EXPAND ((|FOR-LOOP-SRN$LOOP| N IN)))) :RULE-CLASSES NIL)

46 Monday, April 27, 2009

slide-76
SLIDE 76

Inv Holds on Input, with type hyps

(DEFTHML ACL2-LOOP-INV$INV{INIT} (IMPLIES (ACL2-LOOP-INV$INV{PRE} IN) (LOOP-INV-SRN$PROP (ARRAY-SIZE-0<SIZE(S)> IN) (LOOP-INV-SRN$PROP$INIT IN))) :RULE-CLASSES NIL)

47 Monday, April 27, 2009

slide-77
SLIDE 77

Loop Inv. Holds w/o type hyps

(DEFTHML ACL2-LOOP-INV$INV (IMPLIES (ZERO-ARRAY$INPUT-HYPS IN) (ACL2-LOOP-INV$INV+ IN)) :HINTS (("Goal" :IN-THEORY (UNION-THEORIES '(ACL2-LOOP-INV$INV{PRE}) (THEORY 'MINIMAL-THEORY)) :USE (ACL2-LOOP-INV$INV$CONDITIONAL ACL2-LOOP-INV$INV{PRE}{HOLDS}))) :RULE-CLASSES NIL)

48 Monday, April 27, 2009

slide-78
SLIDE 78

Loop counter = Loop bound

(DEFTHML LC$FOR-LOOP-SRN (IMPLIES (AND (NATP N) (NATP (G :LC IN)) (<= (G :LC IN) N)) (EQUAL (G :LC (FOR-LOOP-SRN$LOOP N IN)) N)) :HINTS (("Goal" :BY (:FUNCTIONAL-INSTANCE LOOP-GENERIC-LC (STEP-GENERIC FOR-LOOP-SRN$STEP) (PROP-GENERIC LOOP-INV-SRN$PROP) (LOOP-GENERIC FOR-LOOP-SRN$LOOP)) :IN-THEORY (THEORY 'MINIMAL-THEORY) :EXPAND ((FOR-LOOP-SRN$LOOP N IN)))))

49 Monday, April 27, 2009

slide-79
SLIDE 79

Top Inv. Holds

  • Uses several small lemmas not shown here

(DEFTHM ACL2-TOP-ASN$INV (IMPLIES (GAUSS$INPUT-HYPS IN) (G :ASN (ACL2-TOP-ASN IN))) :HINTS (("Goal" :IN-THEORY (DISABLE |FOR-LOOP-SRN$LOOP|) :USE (ACL2-LOOP-INV$INV LEMMA-2-ACL2-LOOP))))

50 Monday, April 27, 2009

slide-80
SLIDE 80

Lemma Library

  • Lemmas about LabVIEW primitives

essential to automatic proofs

  • Primitive definitions are disabled by default

to (weakly) remove dependence upon defintions

  • Currently ~80 theorems

51 Monday, April 27, 2009

slide-81
SLIDE 81

Not Shown Here

  • LabVIEW/G diagrams can use ACL2

functions for specifications

  • Existential ghost variables for specifications
  • Pick-a-point strategies
  • By-hand approach to compositionality

52 Monday, April 27, 2009

slide-82
SLIDE 82

Future Work

  • Compositional Verification
  • Initial Approach done by hand
  • Use encapsulate to export diagram

properties

  • Use bounded arithmetic
  • Use encapsulate for primitive definitions
  • Diagrams containing state

53 Monday, April 27, 2009

slide-83
SLIDE 83

Conclusion

  • Prototype system for verifying LabVIEW

diagrams

  • About a dozen (fully automatic) examples

completed

  • Feasibility of approach has been proven (for

state-free diagrams)

54 Monday, April 27, 2009

slide-84
SLIDE 84

Thanks

  • J, for advising me these past 2 years
  • Matt, for teaching me all about ACL2
  • Jacob, JeffK and NI, for making this project possible
  • My committee, the ACL2 seminar and Jessica, for

helpful comments on the presentation and thesis

  • My roommates, Yonatan and David Reaves, for all

the support over the past couple of years

55 Monday, April 27, 2009