How banks can maintain stability Carlo A. Furia Chalmers - - PowerPoint PPT Presentation

how banks can
SMART_READER_LITE
LIVE PREVIEW

How banks can maintain stability Carlo A. Furia Chalmers - - PowerPoint PPT Presentation

How banks can maintain stability Carlo A. Furia Chalmers University of Technology bugcounting.net Class-invariant based reasoning with semantic collaboration Reasoning about OO Ill present a framework for reasoning about the functional


slide-1
SLIDE 1

How banks can maintain stability

Carlo A. Furia Chalmers University of Technology bugcounting.net

slide-2
SLIDE 2

Class-invariant based reasoning with semantic collaboration

slide-3
SLIDE 3

Reasoning about OO

I’ll present a framework for reasoning about the functional correctness

  • f object-oriented programs

based on class (object) invariants.

slide-4
SLIDE 4

Reasoning about OO

Methodology: semantic collaboration

– includes an ownership scheme

Implementation: AutoProof verifier

– for simplicity, I will also use “AutoProof” to refer to the methodology

Reference language: Eiffel

– but practically everything applicable to Java/JML and similar OO languages

slide-5
SLIDE 5

Main features of the framework

  • Targets idiomatic OO structures (OO patterns)
  • Flexible (semantic)
  • Reasonably concise (defaults)
  • Applicable to realistic implementations

(data structure library)

  • Sequential programs only
slide-6
SLIDE 6

AutoProof in a nutshell

AutoProof is an auto-active verifier for Eiffel

  • Prover for functional properties
  • All-out support of object-oriented idiomatic

structures (e.g. patterns)

– Based on class invariants

6

Julian Tschannen Nadia Polikarpova Bertrand Meyer

slide-7
SLIDE 7

Auto-active user/tool interaction

  • 1. Code + Annotations
  • 2. Push button
  • 3. Verification outcome
  • 4. Correct/Revise

7

slide-8
SLIDE 8

Sound program verifiers compared

8

more complex properties more automation

static analysis interactive (KIV) ESC/Java2 OpenJML Spec# VCC Chalice Dafny KeY VeriFast

slide-9
SLIDE 9

How AutoProof works

Program + specification + annotations Boogie program Verification conditions Proof AutoProof

pre-/postconditions loop invariants intermediate assertions class invariants frame specification

  • bject dependencies

Failed proof

  • bligation

SMT Boogie

procedures axioms specification functions memory model background theory triggers

slide-10
SLIDE 10

Reasoning with class invariants

Class invariants are a natural way to reason about object-oriented programs: invariant = consistency of objects

10

ACCOUNT

invariant balance >= 0

slide-11
SLIDE 11

Demo: AutoProof warmup

AutoProof verifies a basic version of the bank ACCOUNT class

deposit (amount: INTEGER) withdraw (amount: INTEGER)

11

Follow this demo at: http://comcom.csail.mit.edu/e4pubs/#demo-key (Tab account_warmup.e)

slide-12
SLIDE 12

Stability of invariant reasoning

Invariant-based reasoning should ensure stability: stability = an operation can affect an object’s invariant only if it modifies the object explicitly With stability, no one can invalidate an object behind its back!

12

internal representation OK

slide-13
SLIDE 13

Stability and encapsulation

Invariant-based reasoning with stability:

  • enforces encapsulation/information hiding
  • simplifies client reasoning
  • retains flexibility

13

internal representation OK make effects explicit

slide-14
SLIDE 14

LIST ACCOUNT

Multi-object structures

Object-oriented programs involve multiple

  • bjects (duh!), whose consistency is often

mutually dependent

14

invariant balance >= 0 balance = sum (transactions)

transactions

slide-15
SLIDE 15

AUDITOR LIST ACCOUNT

Consistency of multi-object structures

Mutually dependent object structures require extra care to enforce, and reason about, consistency (cmp. encapsulation)

15

invariant balance >= 0 balance = sum (transactions)

transactions

slide-16
SLIDE 16

AUDITOR LIST ACCOUNT

Consistency of multi-object structures

Mutually dependent object structures require extra care to enforce, and reason about, consistency (cmp. encapsulation)

16

invariant balance >= 0 balance = sum (transactions)

transactions

slide-17
SLIDE 17

Open and closed objects

When (at which program points) must class invariants hold? To provide flexibility, objects in AutoProof can be open or closed

17

CLOSED OPEN Object: consistent inconsistent State: stable transient Invariant: holds may not hold

slide-18
SLIDE 18

LIST ACCOUNT

Ownership

For hierarchical object structures, AutoProof

  • ffers an ownership protocol

18

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

transactions AUDITOR

  • wns
slide-19
SLIDE 19

add_node LIST ACCOUNT

Ownership

For hierarchical object structures, AutoProof

  • ffers an ownership protocol

19

transactions AUDITOR

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-20
SLIDE 20

add_node LIST ACCOUNT

Ownership

For hierarchical object structures, AutoProof

  • ffers an ownership protocol

20

transactions AUDITOR

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-21
SLIDE 21

add_node LIST ACCOUNT

Ownership

For hierarchical object structures, AutoProof

  • ffers an ownership protocol

21

transactions AUDITOR

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-22
SLIDE 22

add_node LIST ACCOUNT

Ownership

For hierarchical object structures, AutoProof

  • ffers an ownership protocol

22

transactions AUDITOR

  • wns

update_balance

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-23
SLIDE 23

LIST ACCOUNT

Ownership

For hierarchical object structures, AutoProof

  • ffers an ownership protocol

23

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

transactions AUDITOR

  • wns
slide-24
SLIDE 24

Demo: ownership in AutoProof

AutoProof verifies deposit and withdraw in ACCOUNT with an owned list of transactions

transactions: SIMPLE_LIST [INTEGER]

  • - History of transactions:
  • positive integer = deposited amount
  • negative integer = withdrawn amount
  • latest transactions in back of list

24

Follow this demo at: http://comcom.csail.mit.edu/e4pubs/#demo-key (Tab account_ownership.e)

slide-25
SLIDE 25

Wrapping and unwrapping

25

WRAPPED UNWRAPPED Invariant: holds may not hold Clients: any object within owner Modifications: modify after unwrapping wrap after modifying

Combination on ownership and invariants: Wrapped object = closed and not owned Unwrapped object = open (or owned)

slide-26
SLIDE 26

add_node LIST ACCOUNT

Wrapping and unwrapping

Typical modification pattern: unwrap, modify, wrap (check consistency)

26

transactions

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-27
SLIDE 27

add_node: unwrap LIST ACCOUNT

Wrapping and unwrapping

Typical modification pattern: unwrap, modify, wrap (check consistency)

27

transactions

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-28
SLIDE 28

add_node: unwrap; modify LIST ACCOUNT

Wrapping and unwrapping

Typical modification pattern: unwrap, modify, wrap (check consistency)

28

transactions

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-29
SLIDE 29

add_node: unwrap; modify; wrap (check) LIST ACCOUNT

Wrapping and unwrapping

Typical modification pattern: unwrap, modify, wrap (check consistency)

29

transactions

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-30
SLIDE 30

add_node: unwrap; modify; wrap (check) LIST ACCOUNT

Wrapping and unwrapping

Typical modification pattern: unwrap, modify, wrap (check consistency)

30

transactions

  • wns

invariant balance >= 0

  • wns = [ transactions ]

balance = sum (transactions)

slide-31
SLIDE 31

Demo: ownership preserves stability

Ownership achieves stability when leaking references to the internal transactions list in ACCOUNT

leak_transactions: SIMPLE_LIST [INTEGER] leak_transactions_unsafe: SIMPLE_LIST [INTEGER]

31

Follow this demo at: http://comcom.csail.mit.edu/e4pubs/#demo-key (Tabs account_ownership.e and auditor.e)

slide-32
SLIDE 32

ACCOUNT

Semantic collaboration

For collaborative object structures, AutoProof

  • ffers a novel protocol: semantic collaboration

32

invariant interest_rate = bank.rate

BANK bank

slide-33
SLIDE 33

bank bank ACCOUNT

Semantic collaboration

For collaborative object structures, AutoProof

  • ffers a novel protocol: semantic collaboration

33

invariant interest_rate = bank.rate

BANK bank

slide-34
SLIDE 34

subjects

  • bservers

Semantic collaboration

  • Subjects = objects my consistency depends on
  • Observers = objects whose consistency depends
  • n me

34

invariant subjects = [ bank ] Current in bank.observers

  • - Implicit in AutoProof

interest_rate = bank.rate

bank bank ACCOUNT BANK bank

slide-35
SLIDE 35

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

35

bank bank ACCOUNT BANK bank

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

update

slide-36
SLIDE 36

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

36

bank bank ACCOUNT BANK bank

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

update: open bank, observers

slide-37
SLIDE 37

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

37

bank bank ACCOUNT BANK bank

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

update: set rate

slide-38
SLIDE 38

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

38

bank bank ACCOUNT BANK bank

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

update: set rate, notify all accounts update

slide-39
SLIDE 39

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

39

bank bank ACCOUNT BANK bank

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

update: set rate, notify all accounts update

slide-40
SLIDE 40

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

40

bank bank ACCOUNT BANK bank

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

update: set rate, notify all accounts update update update

slide-41
SLIDE 41

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

41

bank bank ACCOUNT BANK bank update: wrap bank, all observers (check)

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

slide-42
SLIDE 42

subjects

  • bservers

Semantic collaboration

The bank changes the rate (and notifies accounts)

42

bank bank ACCOUNT BANK bank update: open, modify, wrap (check)

invariant subjects = [ bank ] Current in bank.observers interest_rate = bank.rate

slide-43
SLIDE 43

Demo: collaboration in AutoProof

AutoProof verifies update_rate in ACCOUNT and change_master_rate in BANK based on semantic collaboration features

subjects_definition: subjects = [ bank ] consistent_rate: interest_rate = bank.master_rate

43

Follow this demo at: http://comcom.csail.mit.edu/e4pubs/#demo-key (Tabs account_collaboration.e and bank.e)

slide-44
SLIDE 44

Wrapping and unwrapping

44

In hierarchical structures there is one typical modification pattern: unwrap, modify, wrap (check consistency) In collaborative structures, there is more flexibility:

  • unwrap, modify, wrap
  • unwrap, modify, leave open (invalidate)
  • share responsibility for restoring consistency

between subjects and observers

slide-45
SLIDE 45

Data structures

The features of semantic collaboration work well to reason about data structure implementations.

45

slide-46
SLIDE 46

Data structures: doubly-linked list

As an example, let’s outline node insertion in a doubly-linked list:

  • A singly linked list is hierarchical: the head

controls access to the whole list.

  • A (circular) doubly-linked list is collaborative:

every node depends on its neighbors, and they depend on it

46

slide-47
SLIDE 47

var r := right wrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] unwrap Current, r, n

Insert node n to right of Current

47

right left n Current

slide-48
SLIDE 48

Insert node n to right of Current

48

right left n Current var r := right wrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] unwrap Current, r, n r

slide-49
SLIDE 49

var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n

Insert node n to right of Current

49

right left n Current r

slide-50
SLIDE 50

Insert node n to right of Current

50

right left n Current r var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n right

slide-51
SLIDE 51

Insert node n to right of Current

51

right left n Current r right var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n left

slide-52
SLIDE 52

Insert node n to right of Current

52

right left n Current r right left var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n

slide-53
SLIDE 53

Insert node n to right of Current

53

right left n Current r right left var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n

slide-54
SLIDE 54

Insert node n to right of Current

54

right left n Current r right left var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n

slide-55
SLIDE 55

Insert node n to right of Current

55

var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n right left n Current r right left

slide-56
SLIDE 56

Insert node n to right of Current

56

var r := right unwrap Current, r, n n.right := r n.left := Current r.left := n right := n n.subjects, n.observers := [r, Current] subjects, observers := [left, n] r.subjects, r.observers := [n, r.right] wrap Current, r, n right left Current r n

slide-57
SLIDE 57

Attribute update guards

Who’s responsible for checking that an update to an attribute satisfies the invariant?

  • every observer o of Current that satisfies the

guard g is responsible for checking that updating Current’s attribute a to the value a’ does not violate the invariant of o

57

a: A guard: g(a’, o)

slide-58
SLIDE 58

Update guards in doubly-linked list

When changing the value of attribute right:

  • the left node checks that its invariant is not violated

by changing right in the current node

– the left node’s invariant does not depend on Current.right (it remains wrapped)

  • the current node checks that right’s invariant is not

violated by changing Current.right

– the right node is open when changing Current.right (invariant vacuously holds) – actual check performed when wrapping right

58

right: NODE guard: o /= right

slide-59
SLIDE 59

Demo: doubly-linked list

AutoProof verifies class NODE, representing the generic node of a doubly-linked list

insert_right (n: NODE)

  • - Insert n to the right of Current.

59

Follow this demo at: http://comcom.csail.mit.edu/e4pubs/#demo-key (Tab node.e)

slide-60
SLIDE 60

Proving realistic implementations

Semantic collaboration is part of a verification framework with features suitable to reason about realistic implementations:

  • model-based specifications

– completeness

  • extensible specification types and MML library
  • (abstract) framing with inheritance
  • modular verification with inheritance

– nonvariant, covariant methods

  • finely-tuned encoding in AutoProof

60

slide-61
SLIDE 61

AutoProof on realistic software

Verification benchmarks: EiffelBase2 – a realistic container library:

# programs LOC SPEC/CODE Verification time

25 4400 Lines: 1.0 Tokens: 1.9 Total: 3.4 min Longest method: 12 sec Average method: < 1 sec

# classes LOC SPEC/CODE Verification time

46 8400 Lines: 1.4 Tokens: 2.7 Total: 7.2 min Longest method: 12 sec Average method: < 1 sec

slide-62
SLIDE 62

Class-invariant based reasoning with semantic collaboration

subjects

  • bservers
  • wns

[VSTTE ‘13, FM ‘14, TACAS ‘15, FM ‘15, STTT ‘16]