decidable logics combining heap structures and data

31
Decidable Logics Combining Heap Structures and Data Gennaro Parlato (LIAFA, Paris, France) Joint work with P. Madhusudan Xiaokang Qie University of Illinois at Urbana-Champaign

Upload: lilika

Post on 24-Feb-2016

54 views

Category:

Documents


0 download

DESCRIPTION

Gennaro Parlato (LIAFA, Paris , France) Joint work with P. Madhusudan Xiaokang Qie University of Illinois at Urbana-Champaign. Decidable Logics Combining Heap Structures and Data. What is this talk about …. A new logic to reason with programs that manipulate heap + data using - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Decidable Logics Combining Heap Structures  and Data

Decidable Logics Combining Heap Structures and Data

Gennaro Parlato (LIAFA, Paris, France)

Joint work with• P. Madhusudan• Xiaokang Qie University of Illinois at Urbana-Champaign

Page 2: Decidable Logics Combining Heap Structures  and Data

What is this talk about …

A new logic to reason with programs that manipulate heap + data using deductive verification SMT solvers

157 75

514

151000

1 90

23

7

Program…new(x); …x->next=y->next->next;…y=nil;…x->data = y->data +1;…free(x); …

Page 3: Decidable Logics Combining Heap Structures  and Data

It’s a difficult problem!

Analysis of programs that Dynamically allocated memory Mantain data-structure invariants (ex. Binary Search

Tree) requires to reason with unbounded heaps with

unbounded data

This roles out classical combination of theories▪ like Nelson-Oppen scheme

Page 4: Decidable Logics Combining Heap Structures  and Data

What would be desirable ?

A logic that is: Decidable Expressive enough to state useful properties Efficient in practice on real-world programs

We try to give a solution that has a good balance overall the goals!

Page 5: Decidable Logics Combining Heap Structures  and Data

Releted works

HAVOC (Lahiri, Qadeer: POPL’08) Decidable: YES Expressive: NO (doubly-linked lists cannot be expressed) Efficient: YES on simple programs

CSL (Bouajjani, Dragoi, Enea, Sighireanu: CONCUR’09) Decidable: YES Expressive: NO

▪ extends HAVAC to handle constraints on sizes of structures ▪ still weak (properties of binary trees of unbounded depth cannot be expressed)

Efficient: ? (no implementation is provided)

The technique to decide the logics is encoded in the syntax Hard to extend or generalize

Page 6: Decidable Logics Combining Heap Structures  and Data

STRAND Logic

Page 7: Decidable Logics Combining Heap Structures  and Data

Recursive data structuresDefines a set of graphs that which are interpreted over regular trees

R = ( ψTr, validnode, {nodea}a Lv ∈ , {edgeb}b Le ∈ )

MSO formulaon k-ary Σ-lab trees

Unary predicate

• Family of unary predicates.• Lv is a finite set of node labels

• Family of binary predicates• Le is a finite set of edge labels

R defines a class of graphsFor every tree T=(V,->) accepted by ψTr,

graph(T) = ( N, E, labnodea, labedgeb )

{ v ∈ V | validnode(v) }{(u,v) | b∈Le & edgeb(u,v) }

labnodea(v) =true <=>

v∈ N ∧ nodea(v)=true

labedgeb(u,v) =true

<=> u,v∈ N

∧ edgeb(u,v)=true

Page 8: Decidable Logics Combining Heap Structures  and Data

Examples of data stuctures

En (s,t)= leaf(s) ∧ leaf(t) ∧∃ z1, z2, z3. ( El(z3,z1) ∧ RightMostPath( z1, s) ∧ Er(z3,z2) ∧ LeftMostPath( z2, t) )

s

t

z3

z1 z2

Some data structures that can be expressed:• Nested lists• Cyclic and doubly-linked lists• Threaded trees

Page 9: Decidable Logics Combining Heap Structures  and Data

STRAND logic (STRucture ANd Data)

∃xn. ∀ym. φ(xn,ym)φ is an Monadic Second Order (MSO) formula that combines heap structures and data, where the data-constraints are only allowed to refer to xn and ym

Syntax of STRAND

DATAExpression e::= data(x) | data(y) | c | g(e1,...,en) φFormula φ::= γ(e1,...,en) | α(v1,...,vn) | ¬φ | φ1 φ∧ 2 | φ1 φ∨ 2 | z ∈ S | z. φ | z. φ | S. φ | S. φ∃ ∀ ∃ ∀ ∀Formula ω::= φ | y.ω∀ STRAND ψ::= ω| x.ψ∃

MSO

Page 10: Decidable Logics Combining Heap Structures  and Data

Expressing Binary Search Tree (BST)

leftbranch(y1, y2) ≡ ∃z. (left(y1, z) ∧ z →∗ y2) rightbranch(y1, y2) ≡ ∃z. (right(y1, z) ∧ z →∗ y2) ψbst ≡ ∀y1∀y2. ( leftbranch(y1,y2) ⇒ data(y2) < data(y1) ) ∧ ( rightbranch(y1,y2) ⇒ data(y1) ≤ data(y2) )

left

left

left left leftleft

right

right right

rightrightrightright

Page 11: Decidable Logics Combining Heap Structures  and Data

Verification Conditions in STRAND(bst-search procedure)

bstSearch

PRE: ψbst x.( key(root)=k )∧ ∃Node curr = root; LOOP-INV: ψbst x.(reach(curr,x) key(curr)=k)∧ ∃ ∧ while ( curr.key != k && curr != null ){ if (curr.key > k) curr = curr.left; else curr = curr.right;}

POST: ψbst key(curr)=k∧

Page 12: Decidable Logics Combining Heap Structures  and Data

Deciding STRAND fragments

Page 13: Decidable Logics Combining Heap Structures  and Data

Overview

Given a linear block of statements s a STRAND pre-condition P and a post-condition Q expressed as a Boolean combination of STRAND formulas of the form▪ ∃xn. φ(xn), ∀ym. φ( ym)

checking the validity of the Hoare triple {P} s {Q} reduces to the satisfiability of STRAND

Satisfiability of STRAND is undecidable

We identify a decidable fragment of STRAND semantically defined by using the notion of satisfiability-preseving embeddings

Page 14: Decidable Logics Combining Heap Structures  and Data

Romoving existential quantifications

Let ψ=∃xn. ∀ym. φ(xn, ym) be a STRAND formula over a recursively data-structure R

define a new rec. data-structure R’ that encoperates the existentally quantified variables of xn as pointers in R’ (unary predicate Vali for the var xi )

define ψ’= ∀xn∀ym. ((∧i=1,…,n Vali(xi)) => φ(xn, ym))

Claim: ψ’ is satisfiable on R’ iff ψ is satisfiable on R

Page 15: Decidable Logics Combining Heap Structures  and Data

Decidability: finite model property We define a partial order over heaps that captures the following intuition

S < T (S satisfiability-preservingly embeds into T)

if

- S is smaller than T (fewer nodes)- Each node of S is matched with a distinct node of T- no mutter how data are associated to the nodes of T

if T satisfies ψthen also S satisfies ψby inhering the data-values

TS

Page 16: Decidable Logics Combining Heap Structures  and Data

STRANDdec

• Checking the satisfiability• we ignore T and • check only S

• Satisfiability is done only on the minimal models

• STRANDdec is the class of the formulas that has a finite set of minimal models

• Satisfiability reduces to the satisfiability of the quantifier-free theory of the data-logic

Page 17: Decidable Logics Combining Heap Structures  and Data

Defining satisfiability-preservingly embeddings: sub-models

Let T be a tree defining a graph of the given Rec. Data-structure

A subset S of nodes of T is valid :

Not-empty & least-ancestor closed

The subtree defined by S also defines a data-structure

Submodels can be defined in MSO

Page 18: Decidable Logics Combining Heap Structures  and Data

Defining satisfiability-preservingly embeddings: abstracting dataLet ψ=∀yn. φ(yn) be a STRAND formula, and γ1, …,γr be the atomic relational formulas of the data-

logic. Example:

ψsorted : y∀ 1,y2. ( (y1->*y2 ) => (data(y1) ≤ data(y2)) )

Define the pure MSO formula ψ’=∀yn. b∃ 1, …, br. φ’ (yn, b1, …, br)

where φ’ is obtained from φ by replacing γi with the predicate bi

Example: ψsorted : y∀ 1,y2. ( (y1->*y2 ) => data(y1) ≤ data(y2) )

ψ’sorted : y∀ 1,y2. b. ∃ ( (y1->*y2 ) => b )

Claim: if ψ is satisfiable on a recursive data-structure R then ψ’ is also satisfiable on R.

The other direction does not hold OVER-APPROXIMATION

Page 19: Decidable Logics Combining Heap Structures  and Data

MinModels &Satisfiability-Preserving Embeddings

TS

ψ=∀yn. φ(yn)ψ’=∀yn. ∃b1, …, br. φ’ (yn, b1, …, br)

MinModelψ = \* pure MSO formula *\

ψTr // the tree defines a valide heap T∧ interpret(ψ’) // ψ’ holds true on T∧ // NO satisfiability-preserving embeddings in T

¬ S. ( NonEmpty(S) ValidSubModel(S)∃ ∧ ∧ (∀ym. b∀ 1, …, br. (∧i [m] ∈ (yi S) interpret(∈ ∧ φ’ (yn, b1, …, br)) => interpret( S, φ’ (yn, b1, …, br) ) ) )

Page 20: Decidable Logics Combining Heap Structures  and Data

Decision procedure

Transform MinModels to tree-automaton TA MinModels -> TA

Check finiteness for TA

Extract all trees accepted by TA: TA -> T1, …, Tt

For each Ti build the finite graph Gi Ti -> Gi

Create a quantifier-free formula λi for Gi Gi -> λi a data-variable for each node ’∀ s are “expanded” in conjunctions ’∃ s are “expanded” in disjunctions data-constraints in STRAND are directly written in the data-logic

The quantifier-free formula ∨i=1,…,t λi is a pure data-logic formula that is satisfiable iff the original formula ψ is satisfiable on R

Page 21: Decidable Logics Combining Heap Structures  and Data

Program Verification with STRAND

Page 22: Decidable Logics Combining Heap Structures  and Data

ideaHoare-triples: ( (R, Pre), P, Post )

R Pre ∈ STRAND∃,∀ P:

Node t = newhead; newhead = head; head = head.next; newhead.next = t;

Post ∈ STRAND∃,∀

Idea: capture the entire computation of P starting from a particular recursive data-structure R using a single data-structure RP

⇒ Is ψ ∈ Strand Satisfiable over RP ?

Page 23: Decidable Logics Combining Heap Structures  and Data

The reduction to the satisfiability

Error = ∨i [m]∈ (PreRp ∧ ∧j [i −1]∈ πj ∧ errori )

ViolatePost = PreRp ∧∧j [m]∈ πj ∧¬PostRp

TheoremThe Hoare-triple (R, Pre, P, Post) does not hold

iff the STRAND formula Error ∨ ViolatePost is satisfiable on the trail RP

Page 24: Decidable Logics Combining Heap Structures  and Data

Evaluation

Page 25: Decidable Logics Combining Heap Structures  and Data

ExperimentsPrograms

VerificationCondition

Structural Solving (MONA) Data Constraint Solving (Z3)

In STRANDdec

?

#state

s

FinalBDDsize

Time(sec)

GraphmodelExists

?

Bound#nodes

Formula

size(kB)

Satisfiable?

Time(sec)

sorted-list-search

before-loopin-loop

after-loop

YesYesYes

67131

67

264585264

0.340.590.18

NoNoNo

---

---

---

---

sorted-List-insert

before-headbefore-loop

in-loopafter-loop

YesYesYesYes

73259

1027146

298129

0615

6680

1.660.384.46

13.93

YesNoNoYes

5--7

6.2--

14.5

No--

No

0.02--

0.02

sorted-list-insert -err

before-loop Yes 298 1519

0.34 Yes 7 9.5 Yes 0.02

sorted-list-reverse

before-loopin-loop

after-loop

YesYesYes

35513129

119281

6576

0.242.790.35

NoNoNo

---

---

---

---

Bst-search

before-loopin-loop

after-loop

YesYesYes

52160

52

276113

2276

5.0332.80

3.27

NoYesNo

-9-

-7.7

-

-N0-

-0.02

-

Bst-insert

before-loopin-loop

after-loop

YesYesYes

366820

196452

84

1.349.841.76

NoNoNo

---

---

---

---

Page 26: Decidable Logics Combining Heap Structures  and Data

bst-search procedure

bstSearch(pre: ψbst x.(key(root) = k))∧ ∃Node curr = root; (loop-inv: ψbst x.(reach(curr,x) key(curr)=k)) ∧∃ ∧while ( curr.key != k && curr != null ){ if (curr.key > k) curr = curr.left; else curr = curr.right;}

(post: ψbst key(curr) = k)∧

Page 27: Decidable Logics Combining Heap Structures  and Data

MONA formula for bst-search

Page 28: Decidable Logics Combining Heap Structures  and Data

Webpage of STRAND

http://cs.uiuc.edu/~qiu2/strand/

Code Experiments Table of the experiments

Page 29: Decidable Logics Combining Heap Structures  and Data

Conclusions & Future Work

Page 30: Decidable Logics Combining Heap Structures  and Data

Conclusions

We have presented STRAND a logic for reasoning about structures and data which has good balance among Decidability

Expressiveness

Efficiency

We believe this work breaks new ground in combining structures and data may pave the way for defining decidable fragments of other

logics

Page 31: Decidable Logics Combining Heap Structures  and Data

Future Work

Alternative to MONA?

Syntactic decidable fragments

Back-and-forth connection between the structural part and the data part