A Deep Embedding of a Decidable Fragment of Separation Logic in HOL - - PowerPoint PPT Presentation

a deep embedding of a decidable fragment of separation
SMART_READER_LITE
LIVE PREVIEW

A Deep Embedding of a Decidable Fragment of Separation Logic in HOL - - PowerPoint PPT Presentation

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work A Deep Embedding of a Decidable Fragment of Separation Logic in HOL Thomas Tuerk Mike Gordon ARG Lunch, 26th June 2006 Motivation Basic


slide-1
SLIDE 1

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

A Deep Embedding of a Decidable Fragment of Separation Logic in HOL

Thomas Tuerk Mike Gordon ARG Lunch, 26th June 2006

slide-2
SLIDE 2

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Overview

Motivation Basic Definitions A Decision Procedure for Entailments HOL embedding Example Conclusions and Future Work

slide-3
SLIDE 3

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Smallfoot

  • ”Smallfoot is an automatic verification tool which checks

separation logic specifications of concurrent programs which manipulate dynamically-allocated recursive data structures.” (Smallfoot documentation)

  • developed by
  • Cristiano Calcagno
  • Josh Berdine
  • Peter O’Hearn
slide-4
SLIDE 4

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Smallfoot II

Example from list.sf

list_copy(p) [list(p)] { local t; t = p; q = NULL; while(t != NULL) [list(q) * lseg(p,t) * list(t)] { sq = q; q = new(); q->tl = sq; t = t->tl; } } [list(p) * list(q)]

slide-5
SLIDE 5

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Motivation

  • we deeply embedded the fragment of separation logic used by

Smallfoot in HOL

  • a decision procedure for entailments has been implemented in

HOL

  • this formalisation may increase the trust in Smallfoot
  • it may be used as a basis for non decidable fragments of

separation logic and an interactive proof environment

  • it may be extended to a HOL implementation of Smallfoot
slide-6
SLIDE 6

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Pure Formulae

  • an expression is either a constant or a variable
  • nil is a special constant
  • a stack is a variable assignment
  • pure formulae are inductively defined by
  • true
  • e1 .

= e2, e1 . = e2

  • pf1 ∧ pf2
  • the semantics of pure formulae with respect to a stack are

defined in the natural way

slide-7
SLIDE 7

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae

  • a heap is finite map h : (Values \ {nil}) fin

− → Fields

fin

− → Values

  • spatial formulae are inductively defined by
  • emp
  • e ֒

→ [t1 : e1, . . . , tn : en]

  • sf1 ∗ sf2
  • tree((t1, . . . , tn), es, e)
  • list segments and binary trees are defined as syntactic sugar
  • bin-tree(l, r, e) := tree((l, r), nil, e)
  • ls(tl, e1, e2) := tree(tl, e2, e1)
slide-8
SLIDE 8

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] bin-tree(l, r, x1)

slide-9
SLIDE 9

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] tree((l, r), nil, x1)

slide-10
SLIDE 10

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] ∃el, er. x1 ֒ → [l : el, r : er] ∗ tree((l, r), nil, el) ∗ tree((l, r), nil, er)

slide-11
SLIDE 11

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] x1 ֒ → [l : 2, r : nil] ∗ tree((l, r), nil, 2) ∗ tree((l, r), nil, nil)

slide-12
SLIDE 12

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] x1 ֒ → [l : 2, r : nil] ∗ tree((l, r), nil, 2) ∗ tree((l, r), nil, nil)

slide-13
SLIDE 13

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] x1 ֒ → [l : 2, r : nil] ∗ 2 ֒ → [l : nil, r : nil] ∗ tree((l, r), nil, nil) ∗ tree((l, r), nil, nil) ∗ tree((l, r), nil, nil)

slide-14
SLIDE 14

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Spatial Formulae II

l r 2 l r 1 s(xi) := i h := [1 → [l → 2, r → nil], 2 → [l → nil, r → nil]] x1 ֒ → [l : 2, r : nil] ∗ 2 ֒ → [l : nil, r : nil] ∗ tree((l, r), nil, nil) ∗ tree((l, r), nil, nil) ∗ tree((l, r), nil, nil)

slide-15
SLIDE 15

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Entailments

  • entailments are important for Smallfoot
  • example from list.sf

x0 . = nil, x1 . = nil, x2 . = nil, x0 . = x3, x0 . = x2, x4 . = x5, x1 . = x3, x1 . = x2, x3 . = x2, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢ ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil)

  • entailments in this fragment of separation logic are decidable
  • inferences can be easily combined to form a decision procedure
  • inferences and decision procedure are presented in

Josh Berdine, Cristiano Calcagno, and Peter W. O’Hearn. Symbolic Execution with Separation Logic. In K. Yi (Ed.): APLAS 2005, LNCS 3780, pp. 52-68, 2005.

slide-16
SLIDE 16

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

RemoveTrivial

RemoveTrivial-EQ-L Π, Σ ⊢ Π′, Σ′ e . = e, Π, Σ ⊢ Π′, Σ′ RemoveTrivial-EQ-R Π, Σ ⊢ Π′, Σ′ Π, Σ ⊢ e . = e, Π′, Σ′ RemoveTrivial-EmpTree-L Π, Σ ⊢ Π′, Σ′ Π, tree((t1, . . . , tk), e, e), Σ ⊢ Π′, Σ′ RemoveTrivial-EmpTree-R Π, Σ ⊢ Π′, Σ′ Π, Σ ⊢ Π′, tree((t1, . . . , tk), e, e), Σ′

slide-17
SLIDE 17

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Hypothesis

Hypothesis pf, Π, Σ ⊢ Π′, Σ′ pf, Π, Σ ⊢ pf, Π′, Σ′

slide-18
SLIDE 18

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Axiom / Inconsistent

Axiom Π ⊢ Inconsistent-unequal e . = e, Π, Σ ⊢ Π′, Σ′ Inconsistent-pointsto-nil Π, nil ֒ → [. . .], Σ ⊢ Π′, Σ′

slide-19
SLIDE 19

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Frame

Frame-base Π, Σ ⊢ Π′, Σ′ Π, sf, Σ ⊢ Π′, sf, Σ′

  • problem: this is a real implication, information is lost
  • thus, order of inference application matters
  • example: e ֒

→ [f : e1], e ֒ → [g : e2] ⊢ e ֒ → [f : e1]

  • solution: add additional informations to entailments
slide-20
SLIDE 20

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Frame II

Frame-points to e, η, π, Π, Σ ⊢ Π′, Σ′ η, π, Π, e ֒ → [t1 : e1, . . . , tn : en], Σ ⊢ Π′, e ֒ → [t1 : e1, . . . , tm : em], Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =m ≤ n Frame-tree η, (e, es), π, Π, Σ ⊢ Π′, Σ′ η, π, Π, tree((t1, . . . , tk), es, e), Σ ⊢ Π′, tree((t1, . . . , tk), es, e), Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

  • all used inferences are equivalences
  • order of application does not matter
  • continued applications of inferences will terminate
slide-21
SLIDE 21

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Substitution

Substitution η[e/x], π[e/x], Π[e/x], Σ[e/x] ⊢ Π′[e/x], Σ′[e/x] η, x . = e, π, Π, Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

slide-22
SLIDE 22

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

NIL-NOT-LVAL

NIL-NOT-LVAL-pointsto η, π, e . = nil, Π, e ֒ → [. . .], Σ ⊢ Π′, Σ′ η, π, Π, e ֒ → [. . .], Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = NIL-NOT-LVAL-tree η, π, e . = nil, e . = es, Π, tree (. . . , es, e) , Σ ⊢ Π′, Σ′ η, π, e . = es, Π, tree (. . . , es, e) , Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

side condition

In order to prevent looping only new facts are added.

slide-23
SLIDE 23

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Partial

Partial-pointsto-pointsto η, π, e1 . = e2, Π, e1 ֒ → [. . .], e2 ֒ → [. . .], Σ ⊢ Π′, Σ′ η, π, Π, e1 ֒ → [. . .], e2 ֒ → [. . .], Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Partial-pointsto-tree η, π, e1 . = e2, e2 . = e3, Π, e1 ֒ → [. . .], tree(. . . , e3, e2), Σ ⊢ Π′, Σ′ η, π, e2 . = e3, Π, e1 ֒ → [. . .], tree(. . . , e3, e2), Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = . . .

side condition

In order to prevent looping only new facts are added.

slide-24
SLIDE 24

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Simple Unroll

Unroll-right-list e1, η, π, e1 . = e3, Π, Σ ⊢ Π′, ls(tl, e2, e3), Σ′ η, π, e1 . = e3, Π, e1 ֒ → [tl : e2, . . .], Σ ⊢ Π′, ls(tl, e1, e3), Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Unroll-right-bintree e, η, π, Π, Σ ⊢ Π′, bin-tree(l, r, el), bin-tree(l, r, er), Σ′ η, π, Π, e ֒ → [l : el, r : er, . . .], Σ ⊢ Π′, bin-tree(l, r, e), Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Unroll-NilList η, π, e . = nil, Π, Σ ⊢ Π′, Σ′ η, π, Π, ls(tl, nil, e), Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Unroll-precond-list e1, η, π, e1 . = e2, Π, Σ ⊢ Π′, Σ′ e1, η, π, Π, ls(tl, e1, e2), Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

slide-25
SLIDE 25

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Unroll

Unroll-list η, π, e1 . = e2, Π, Σ ⊢ Π′, Σ′ ∀x. η, π, e1 . = e2, e2 . = x, Π, e1 ֒ → [fl : x], x ֒ → [fl : e2], Σ ⊢ Π′, Σ′ η, π, Π, ls(tl, e1, e2), Σ ⊢ Π′, Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

  • logic can not consider the content of a list
  • therefore, two cases are sufficient
  • no induction needed!
  • similar inference exists for arbitrary trees
  • however, in general useful for decision procedure
slide-26
SLIDE 26

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Append-list

Append-list η, (e1, e2), π, e1 . = e3, Π, Σ ⊢ Π′, ls(tl, e2, e3), Σ′ η, π, e1 . = e3, Π, ls(tl, e1, e2), Σ ⊢ Π′, ls(tl, e1, e3), Σ′ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

  • this inference holds under some complicated side condition
  • it is preferable to unrolling lists
  • its correctness proof uses unrolling of lists and simple unrolls

and the frame inference

slide-27
SLIDE 27

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Decision Procedure

  • these inferences can be easily combined to form a decision

procedure for entailments

  • apply inferences in arbitrary order as long as possible
  • be careful with NIL-NOT-LVAL, Partial, Hypothesis to avoid

looping

  • iff the entailment could not be reduced to true, it is false
  • remaining entailments are as simple, that a concrete

counterexample can be easily constructed

slide-28
SLIDE 28

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

HOL embedding

  • deep embedding in HOL is straight forward except for trees
  • trees are introduced considering their maximal depth
  • equivalence with other recursive definition is formally proofed
  • inferences are implemented as conversions
  • the decision procedure is implemented as a conversion
slide-29
SLIDE 29

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

HOL embedding II

LOC deep embedding and inferences

  • approx. 10 000

special versions of inferences for conversions

  • approx. 2 500

conversions and decision procedure

  • approx. 2 000
slide-30
SLIDE 30

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example from list.sf

x0 . = nil, x1 . = nil, x2 . = nil, x0 . = x3, x0 . = x2, x4 . = x5, x1 . = x3, x1 . = x2, x3 . = x2, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢ ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil)

slide-31
SLIDE 31

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example from list.sf

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢ ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil)

slide-32
SLIDE 32

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example inference application

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢ ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil)

slide-33
SLIDE 33

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example inference application

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Frame

ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil) ⇐ ⇒ x2, (x3, nil), Π, ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢ ls(tl, x1, x2)

slide-34
SLIDE 34

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example inference application

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Frame

ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil) ⇐ ⇒ x2, (x3, nil), Π, ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Append-List

ls(tl, x1, x2) ⇐ ⇒ x2, (x3, nil), (x1, x0), Π, x0 ֒ → [tl, x2] ⊢ ls(tl, x0, x2)

slide-35
SLIDE 35

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example inference application

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Frame

ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil) ⇐ ⇒ x2, (x3, nil), Π, ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Append-List

ls(tl, x1, x2) ⇐ ⇒ x2, (x3, nil), (x1, x0), Π, x0 ֒ → [tl, x2] ⊢

Simple-Unroll

ls(tl, x0, x2) ⇐ ⇒ x2, x0, (x3, nil), (x1, x0), Π ⊢ ls(tl, x2, x2)

slide-36
SLIDE 36

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example inference application

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Frame

ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil) ⇐ ⇒ x2, (x3, nil), Π, ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Append-List

ls(tl, x1, x2) ⇐ ⇒ x2, (x3, nil), (x1, x0), Π, x0 ֒ → [tl, x2] ⊢

Simple-Unroll

ls(tl, x0, x2) ⇐ ⇒ x2, x0, (x3, nil), (x1, x0), Π ⊢

Remove-Trivial

ls(tl, x2, x2) ⇐ ⇒ x2, x0, (x3, nil), (x1, x0), Π ⊢

slide-37
SLIDE 37

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example inference application

Π, x2 ֒ → [hd : x5, tl : x3], ls(tl, x3, nil), ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Frame

ls(tl, x1, x2), x2 ֒ → [tl : x3], ls(tl, x3, nil) ⇐ ⇒ x2, (x3, nil), Π, ls(tl, x1, x0), x0 ֒ → [tl, x2] ⊢

Append-List

ls(tl, x1, x2) ⇐ ⇒ x2, (x3, nil), (x1, x0), Π, x0 ֒ → [tl, x2] ⊢

Simple-Unroll

ls(tl, x0, x2) ⇐ ⇒ x2, x0, (x3, nil), (x1, x0), Π ⊢

Remove-Trivial

ls(tl, x2, x2) ⇐ ⇒ x2, x0, (x3, nil), (x1, x0), Π ⊢

Axiom

⇐ ⇒ ⊤

slide-38
SLIDE 38

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example HOL

val t = ‘‘LIST_DS_ENTAILS ([],[]) ([pf_unequal (dse_var 0) dse_nil; pf_unequal (dse_var 1) dse_nil; pf_unequal (dse_var 2) dse_nil; pf_unequal (dse_var 0) (dse_var 3); pf_unequal (dse_var 0) (dse_var 2); pf_unequal (dse_var 4) (dse_var 5); pf_unequal (dse_var 1) (dse_var 3); pf_unequal (dse_var 1) (dse_var 2); pf_unequal (dse_var 3) (dse_var 2)], [sf_points_to (dse_var 2) [("hd",dse_var 5); ("tl", dse_var 3)]; sf_ls "tl" (dse_var 3) dse_nil; sf_ls "tl" (dse_var 1) (dse_var 0); sf_points_to (dse_var 0) [("tl", (dse_var 2))]]) ([], [sf_ls "tl" (dse_var 1) (dse_var 2); sf_points_to (dse_var 2) [("tl", dse_var 3)]; sf_ls "tl" (dse_var 3) dse_nil])‘‘;

slide-39
SLIDE 39

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

example HOL II

val thm1 = (ds_inference_FRAME___CONV THENC ds_inference_APPEND_LIST___CONV THENC ds_inference_SIMPLE_UNROLL___CONV THENC ds_inference_REMOVE_TRIVIAL___CONV THENC ds_inference_AXIOM___CONV) t; val thm2 = ds_DECIDE_CONV t;

slide-40
SLIDE 40

Motivation Basic Definitions Entailments HOL embedding Example Conclusions and Future Work

Conclusions

  • there is a deep embedding of the decidable fragment of

separation logic used by Smallfoot

  • all inferences used by Smallfoot have been verified using HOL
  • a decision procedure for entailments has been implemented

Future Work

  • add symbolic execution to build a Smallfoot implementation

in HOL

  • extend the logic
  • try interactive proofs for more complicated fragments of

separation logic