36
Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Embed Size (px)

Citation preview

Page 1: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Verifying the Composite Pattern using Separation Logic

Bart JacobsJan SmansFrank PiessensKatholieke Universiteit Leuven, Belgium

Page 2: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Overview

General Idea Example: Binary Tree

Interface Client Specification Client Proof Implementation and Implementation Proof Non-contiguous Focus Changes

Demonstration Conclusion

Page 3: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

General Idea

Module Client

Invariant

Page 4: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeInterface

Page 5: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeClient

Page 6: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpecification

Page 7: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpecification: Datatype tree

n0

n1

n2 n3

tree(n0, tree(n1, tree(n2, nil, nil), tree(n3, nil, nil)), nil)

Page 8: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Pure function count

count(tree(n0, tree(n1, tree(n2, nil, nil), tree(n3, nil, nil)), nil)) = 4

n0

n1

n2 n3

Page 9: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Datatype context

root

n0

left_context(root, n0, nil)

n0

n1

n2

right_context(left_context(root, n0, nil), n1, tree(n2, nil, nil))

Page 10: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Predicate tree

n0

n1

n2 n3

memory region

tree(n0, root, tree(n0, tree(n1, tree(n2, nil, nil), tree(n3, nil, nil)), nil))

focus node

Page 11: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Predicate tree

n0

n1

n2 n3

memory region

tree(n1, left_context(root, n0, nil), tree(n1, tree(n2, nil, nil), tree(n3, nil, nil)))

focus node

Page 12: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Predicate tree

n0

n1

n2 n3

memory region

tree(n3, right_context( left_context(root, n0, nil), n1, tree(n2, nil, nil)), tree(n3, nil, nil))

focus node

Page 13: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Function create_tree

result

focus node

Page 14: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

c

Example: Binary TreeSpec’n: Function tree_add_left

node

r focus node

cnode

r

result

focus node

Page 15: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

c

Example: Binary TreeSpec’n: Function tree_get_count

node

t

focus node

cnode

t

focus node

Page 16: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Function tree_get_parent

node

tfocus node

pns

r

pnode

t

pns

r

p

focus node(case left_context)

Page 17: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeSpec’n: Function tree_dispose

node

focus node

Page 18: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeClient Proof

Page 19: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImplementation: struct node

Page 20: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImplementation: predicate tree

cnode

subtree

focus node cnode

node

subtree

context(node, parent, count(subtree), c)

subtree(node, parent, subtree)

Page 21: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImplementation: predicate subtree

left

left-Nodes

right-Nodes

node

right

node->left |-> left

node->right |-> right

node->parent |-> parent

node->count |-> count(t)

malloc_block_node(node)

left

left-Nodes

right

right-Nodes

Page 22: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImplementation: predicate context

n

pns

r

pright

p->left |-> n

p->right |-> right

p->parent |-> gp

p->count |-> pcount

malloc_block_node(p)

right

r

pnsp

Page 23: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImplementation: function create_tree

Page 24: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImpl’n: function subtree_get_count

Page 25: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImpl’n: function fixup_ancestors

Page 26: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImpl’n: function tree_add_left

Page 27: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImpl’n: function tree_get_count

Page 28: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Example: Binary TreeImpl’n: function tree_get_parent

Page 29: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Overview

General Idea Example: Binary Tree

Interface Client Specification Client Proof Implementation and Implementation Proof Non-contiguous Focus Changes

Demonstration Conclusion

Page 30: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Non-contiguous Focus ChangesExample Client Program

Page 31: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Non-contiguous Focus ChangesAdditional Specification Elements

Page 32: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Non-contiguous Focus ChangesProof of Example Client Program

Page 33: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Non-contiguous Focus ChangesProof of lemma change_focus

Page 34: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Overview

General Idea Example: Binary Tree

Interface Client Specification Client Proof Implementation and Implementation Proof Non-contiguous Focus Changes

Demonstration Conclusion

Page 35: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Overview

General Idea Example: Binary Tree

Interface Client Specification Client Proof Implementation and Implementation Proof Non-contiguous Focus Changes

Demonstration Conclusion

Page 36: Verifying the Composite Pattern using Separation Logic Bart Jacobs Jan Smans Frank Piessens Katholieke Universiteit Leuven, Belgium

Bart Jacobs, Jan Smans, Frank Piessens - Verifying the Composite Pattern using Separation Logic

Conclusion

Approach: Structure = 1 seplogic predicate In proof: Separate out focus node In client: Change focus node using

lemma VeriFast:

www.cs.kuleuven.be/~bartj/verifast