Lecture 8/9 : Separation Logic Overview Assertion Logic - - PowerPoint PPT Presentation

lecture 8 9 separation logic
SMART_READER_LITE
LIVE PREVIEW

Lecture 8/9 : Separation Logic Overview Assertion Logic - - PowerPoint PPT Presentation

CS6202: Advanced Topics in Programming Languages and Systems Lecture 8/9 : Separation Logic Overview Assertion Logic Semantic Model Hoare-style Inference Rules Specification and Annotations Linked List and Segments


slide-1
SLIDE 1

CS6202 Separation Logic 1

CS6202: Advanced Topics in Programming Languages and Systems Lecture 8/9 : Separation Logic

  • Overview
  • Assertion Logic
  • Semantic Model
  • Hoare-style Inference Rules
  • Specification and Annotations
  • Linked List and Segments
  • Trees and Instuitionistic Logic
  • (above from John Reynold’s mini-course)
  • Automated Verification
slide-2
SLIDE 2

CS6202 Separation Logic 2

Motivation Motivation

Program reasoning is important for: correctness of software safety (fewer or no bugs) performance guarantee

  • ptimization
slide-3
SLIDE 3

CS6202 Separation Logic 3

Hoare Logic Hoare Logic

Can handle reasoning of imperative programs well. Notation : {P} code {Q} {P} precondition before executing code {Q} postcondition after executing code

Some examples : {x=1} x:=x+1 {x=2}

{x=x0} x:=x+1 {x=x0+1} {Q[x+1/x]} x:=x+1 {Q} {P} x:=x+1 { x1. P[x1/x] x=x1+1}

slide-4
SLIDE 4

CS6202 Separation Logic 4

Problem Problem

Hoare logic can handle program variables but not heap

  • bjects well due to aliasing problems.

Consider an in-place list reversal algorithm [i] denotes a heap location at address i

slide-5
SLIDE 5

CS6202 Separation Logic 5

Loop Invariant Loop Invariant

Loop invariant is a statement that holds at the beginning of each iteration of the loop.

heap predicate relates a list

  • f elements and a pointer
slide-6
SLIDE 6

CS6202 Separation Logic 6

Loop Invariant Loop Invariant

in separation logic :

slide-7
SLIDE 7

CS6202 Separation Logic 7

Basics of Separation Logic Basics of Separation Logic

slide-8
SLIDE 8

CS6202 Separation Logic 8

Simple Language with Heap Store Simple Language with Heap Store

slide-9
SLIDE 9

CS6202 Separation Logic 9

Memory Faults Memory Faults

Can be caused by out of range look up of memory.

slide-10
SLIDE 10

CS6202 Separation Logic 10

Assertion Language Assertion Language

slide-11
SLIDE 11

CS6202 Separation Logic 11

Semantic Model Semantic Model

slide-12
SLIDE 12

CS6202 Separation Logic 12

Semantic Model Semantic Model

slide-13
SLIDE 13

CS6202 Separation Logic 13

Separation Conjunction Separation Conjunction -

  • Examples

Examples

slide-14
SLIDE 14

CS6202 Separation Logic 14

Conjunction Conjunction -

  • Examples

Examples

Conjunction describes the same heap space.

slide-15
SLIDE 15

CS6202 Separation Logic 15

Separation Implication Separation Implication -

  • Examples

Examples

slide-16
SLIDE 16

CS6202 Separation Logic 16

Inference Rules Inference Rules

Reasoning with normalization, weakening and strengthening.

slide-17
SLIDE 17

CS6202 Separation Logic 17

Pure Assertion Pure Assertion

Axiom schematic guided by pure formulae

slide-18
SLIDE 18

CS6202 Separation Logic 18

Two Unsound Axiom Schemata Two Unsound Axiom Schemata

Structural logic without contraction and weakening.

slide-19
SLIDE 19

CS6202 Separation Logic 19

Partial Correctness Specification Partial Correctness Specification

slide-20
SLIDE 20

CS6202 Separation Logic 20

Total Correctness Specification Total Correctness Specification

slide-21
SLIDE 21

CS6202 Separation Logic 21

Examples of Valid Specifications Examples of Valid Specifications

slide-22
SLIDE 22

CS6202 Separation Logic 22

Hoare Inference Rules Hoare Inference Rules

slide-23
SLIDE 23

CS6202 Separation Logic 23

Hoare Inference Rules Hoare Inference Rules

Structural rules are applicable to any commands.

slide-24
SLIDE 24

CS6202 Separation Logic 24

Partial Correctness of While Loop Partial Correctness of While Loop

slide-25
SLIDE 25

CS6202 Separation Logic 25

Total Correctness of While Loop Total Correctness of While Loop

slide-26
SLIDE 26

CS6202 Separation Logic 26

Hoare Inference Rules Hoare Inference Rules

slide-27
SLIDE 27

CS6202 Separation Logic 27

Hoare Inference Rules Hoare Inference Rules

slide-28
SLIDE 28

CS6202 Separation Logic 28

Annotated Specifications Annotated Specifications

In annotated specifications, additional assertions called annotations are placed in command in such a way that it assist proof construction process. Examples :

slide-29
SLIDE 29

CS6202 Separation Logic 29

Minimal Annotated Specifications Minimal Annotated Specifications

Should attempt to minimise annotations where possible. Restrict to pre/post of methods and invariant of loops. Further advances : (i) intraprocedural inference (ii) interprocedural inference.

slide-30
SLIDE 30

CS6202 Separation Logic 30

Structural Inference Rules Structural Inference Rules

slide-31
SLIDE 31

CS6202 Separation Logic 31

Structural Inference Rules Structural Inference Rules

slide-32
SLIDE 32

CS6202 Separation Logic 32

Structural Inference Rules Structural Inference Rules

slide-33
SLIDE 33

CS6202 Separation Logic 33

Rule of Constancy from Hoare Logic Rule of Constancy from Hoare Logic

slide-34
SLIDE 34

CS6202 Separation Logic 34

Frame Rule of Separation Logic Frame Rule of Separation Logic

This facilitates local reasoning and specification

slide-35
SLIDE 35

CS6202 Separation Logic 35

Local Specifications Local Specifications

slide-36
SLIDE 36

CS6202 Separation Logic 36

Inference Rules for Mutation Inference Rules for Mutation

slide-37
SLIDE 37

CS6202 Separation Logic 37

Inference Rules for Inference Rules for Deallocation Deallocation

slide-38
SLIDE 38

CS6202 Separation Logic 38

Inference Rules for Inference Rules for Noninterfering Noninterfering Allocation Allocation

slide-39
SLIDE 39

CS6202 Separation Logic 39

Inference Rules for Lookup Inference Rules for Lookup

slide-40
SLIDE 40

CS6202 Separation Logic 40

Notation for Sequences Notation for Sequences

slide-41
SLIDE 41

CS6202 Separation Logic 41

Singly Linked List Singly Linked List

What is the default property (invariant) of this predicate?

slide-42
SLIDE 42

CS6202 Separation Logic 42

Singly Linked List Segment Singly Linked List Segment

slide-43
SLIDE 43

CS6202 Separation Logic 43

Singly Linked List Segment Singly Linked List Segment

Properties

slide-44
SLIDE 44

CS6202 Separation Logic 44

Non Non-

  • Touching Linked List Segment

Touching Linked List Segment

Easier test for emptiness

slide-45
SLIDE 45

CS6202 Separation Logic 45

Braced List Segment Braced List Segment

slide-46
SLIDE 46

CS6202 Separation Logic 46

Bornat Bornat List List

slide-47
SLIDE 47

CS6202 Separation Logic 47

Doubly Linked List Doubly Linked List

slide-48
SLIDE 48

CS6202 Separation Logic 48

XOR XOR-

  • Linked List Segment

Linked List Segment

slide-49
SLIDE 49

CS6202 Separation Logic 49

Array Allocation Array Allocation

Inference rule :

slide-50
SLIDE 50

CS6202 Separation Logic 50

Trees Trees

slide-51
SLIDE 51

CS6202 Separation Logic 51

DAGs DAGs

slide-52
SLIDE 52

CS6202 Separation Logic 52

Intuitionistic Intuitionistic Separation Logic Separation Logic

Supports justification rather than truth. Things that no longer hold include: law of excluded middle (P P) double negation ( P = P) Pierce’s law (((P Q) P) P) Formulae valid in intuitionistic separation logic but not the classical one. x 1,y emp x 1,y * y ,nil x 1,_

slide-53
SLIDE 53

CS6202 Separation Logic 53

Intuitionistic Intuitionistic Assertion Assertion

slide-54
SLIDE 54

CS6202 Separation Logic 54

Inference for Procedures Inference for Procedures

slide-55
SLIDE 55

CS6202 Separation Logic 55

Copying Tree Copying Tree

slide-56
SLIDE 56

CS6202 Separation Logic 56

Copying Tree (Proof) Copying Tree (Proof)

slide-57
SLIDE 57

CS6202 Separation Logic 57

Copying Tree (Proof) Copying Tree (Proof)

slide-58
SLIDE 58

CS6202 Separation Logic 58

Automated Verification Automated Verification

Modular Verification (i) Given pre/post conditions for each method and loop (ii) Determine each postcondition is sound for method body. (iii) Each precondition is satisfied for each call site. Why Verification? (i) can handle more complex examples (ii) can be used to check inference algorithm (iii) grand challenge of verifiable software

slide-59
SLIDE 59

CS6202 Separation Logic 59

Core Imperative Language Core Imperative Language

slide-60
SLIDE 60

CS6202 Separation Logic 60

Data Nodes and Notation Data Nodes and Notation

slide-61
SLIDE 61

CS6202 Separation Logic 61

Shape Predicates Shape Predicates

Linked-list with size Double linked-list (right traversal) with size Sorted linked-list with size, min, max

slide-62
SLIDE 62

CS6202 Separation Logic 62

Insertion Sort Algorithm Insertion Sort Algorithm

slide-63
SLIDE 63

CS6202 Separation Logic 63

Prime Notation Prime Notation

Prime notation is used to capture the latest values

  • f each program variable. This allows a state

transition to be expressed since the unprimed form denotes original values.

slide-64
SLIDE 64

CS6202 Separation Logic 64

Prime Notation Prime Notation

Example : {x’=x y’=y} x:=x+1 {x’=x+1 y’=y} x:=x+y {x’=x+1+y y’=y} y:=2 {x’=x+1+y y’=2}

slide-65
SLIDE 65

CS6202 Separation Logic 65

Forward Verification Forward Verification

Given 1, infer 2 : {1} e {2}

slide-66
SLIDE 66

CS6202 Separation Logic 66

Forward Verification Forward Verification

slide-67
SLIDE 67

CS6202 Separation Logic 67

Separation Constraint Normalization Rules Separation Constraint Normalization Rules

Target :

slide-68
SLIDE 68

CS6202 Separation Logic 68

Separation Constraint Approximation Separation Constraint Approximation

XPuren() returns a sound approximation of the form :

non-null symbolic addresses

Normalization :

slide-69
SLIDE 69

CS6202 Separation Logic 69

Translating to Pure Form Translating to Pure Form

slide-70
SLIDE 70

CS6202 Separation Logic 70

Deriving Shape Invariant Deriving Shape Invariant

From each pure invariant, such as (n 0) for ll<n> We use Inv1(..) to obtain a more precise invariant :

slide-71
SLIDE 71

CS6202 Separation Logic 71

Separation Constraint Entailment Separation Constraint Entailment

denotes

slide-72
SLIDE 72

CS6202 Separation Logic 72

Separation Constraint Entailment Separation Constraint Entailment

slide-73
SLIDE 73

CS6202 Separation Logic 73

Unfolding Predicate in Antecedent Unfolding Predicate in Antecedent

slide-74
SLIDE 74

CS6202 Separation Logic 74

Folding a Predicate in Consequent Folding a Predicate in Consequent

Folding is recursively applied until x::ll<n> matches with the two data nodes in the antecedent, resulting in : Effect of folding is not the same as unfolding a predicate In consequent as values of derived variable may be lost!

slide-75
SLIDE 75

CS6202 Separation Logic 75

Folding a Predicate in Consequent Folding a Predicate in Consequent

slide-76
SLIDE 76

CS6202 Separation Logic 76

Soundness of Entailment Soundness of Entailment