Effectively-Propositional Reasoning about Reachability in Linked Data Structures Shachar Itzhaky Anindya Banerjee Neil Immerman Aleks Nanevski Mooly Sagiv.

Slides:



Advertisements
Similar presentations
Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Quantified Invariant Generation using an Interpolating Saturation Prover Ken McMillan Cadence Research Labs TexPoint fonts used in EMF: A A A A A.
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Semantics Static semantics Dynamic semantics attribute grammars
Predicate Abstraction and Canonical Abstraction for Singly - linked Lists Roman Manevich Mooly Sagiv Tel Aviv University Eran Yahav G. Ramalingam IBM T.J.
Gennaro Parlato (LIAFA, Paris, France) Joint work with P. Madhusudan Xiaokang Qie University of Illinois at Urbana-Champaign.
Shape Analysis by Graph Decomposition R. Manevich M. Sagiv Tel Aviv University G. Ramalingam MSR India J. Berdine B. Cook MSR Cambridge.
3-Valued Logic Analyzer (TVP) Tal Lev-Ami and Mooly Sagiv.
Hybrid Systems Presented by: Arnab De Anand S. An Intuitive Introduction to Hybrid Systems Discrete program with an analog environment. What does it mean?
1 A Logic of Reachable Patterns in Linked Data-Structures Greta Yorsh joint work with Alexander Rabinovich, Mooly Sagiv Tel Aviv University Antoine Meyer,
David Evans CS655: Programming Languages University of Virginia Computer Science Lecture 19: Minding Ps & Qs: Axiomatic.
ISBN Chapter 3 Describing Syntax and Semantics.
Predicate Transformers
Program Proving Notes Ellen L. Walker.
CSE 331 Software Design & Implementation Dan Grossman Winter 2014 Lecture 2 – Reasoning About Code With Logic 1CSE 331 Winter 2014.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Program analysis Mooly Sagiv html://
Program analysis Mooly Sagiv html://
ECI 2007: Specification and Verification of Object- Oriented Programs Lecture 1.
Separation Logic A Logic of Shared Mutable Data Structures John Reynolds CMU Extended subset Mooly Sagiv.
Overview of program analysis Mooly Sagiv html://
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Program Verification using Templates over Predicate Abstraction Saurabh Srivastava University of Maryland, College Park Sumit Gulwani Microsoft Research,
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Describing Syntax and Semantics
Floyd Hoare Logic. Semantics A programming language specification consists of a syntactic description and a semantic description. Syntactic description:symbols.
Dagstuhl Seminar "Applied Deductive Verification" November Symbolically Computing Most-Precise Abstract Operations for Shape.
1 Employing decision procedures for automatic analysis and verification of heap-manipulating programs Greta Yorsh under the supervision of Mooly Sagiv.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
1 Formal Semantics of Programming Languages “Program testing can be used to show the presence of bugs, but never to show their absence!” --Dijkstra.
Verifying Properties of Well-Founded Linked Lists Verifying Properties of Well-Founded Linked Lists Shuvendu K. Lahiri Shaz Qadeer Software Reliability.
Symbolically Computing Most-Precise Abstract Operations for Shape Analysis Greta Yorsh Thomas Reps Mooly Sagiv Tel Aviv University University of Wisconsin.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
Adaptive Shape Analysis Thomas Wies joint work with Josh Berdine Cristiano Calcagno TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Quantified Data Automata on Skinny Trees: an Abstract Domain for Lists Pranav Garg 1, P. Madhusudan 1 and Gennaro Parlato 2 1 University of Illinois at.
Property-Guided Shape Analysis S.Itzhaky, T.Reps, M.Sagiv, A.Thakur and T.Weiss Slides by Tomer Weiss Submitted to TACAS 2014.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
Roman Manevich Ben-Gurion University Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 16: Shape Analysis.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Program Analysis and Verification
Operational Semantics Mooly Sagiv Tel Aviv University Sunday Scrieber 8 Monday Schrieber.
1 Simulating Reachability using First-Order Logic with Applications to Verification of Linked Data Structures Tal Lev-Ami 1, Neil Immerman 2, Tom Reps.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Finding bugs with a constraint solver daniel jackson. mandana vaziri mit laboratory for computer science issta 2000.
Putting Static Analysis to Work for Verification A Case Study Tal Lev-Ami Thomas Reps Mooly Sagiv Reinhard Wilhelm.
Operational Semantics Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Spring 2017 Program Analysis and Verification
Spring 2017 Program Analysis and Verification
Spring 2016 Program Analysis and Verification
Matching Logic An Alternative to Hoare/Floyd Logic
Reasoning About Code.
Reasoning about code CSE 331 University of Washington.
Lecture 5 Floyd-Hoare Style Verification
Lecture 2: Axiomatic semantics
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Predicate Transformers
Linked lists Prof. Noah Snavely CS1114
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
COP4020 Programming Languages
Presentation transcript:

Effectively-Propositional Reasoning about Reachability in Linked Data Structures Shachar Itzhaky Anindya Banerjee Neil Immerman Aleks Nanevski Mooly Sagiv TAU IMDEA UMASS IMDEA TAU

Motivation Proving presence (absence) of pointer paths between memory allocated objects in a given program –Partial program correctness Memory safety Absence of memory leaks Data structure invariants –Acylicity, Sortedness –Total program correctness –Program equivalence

Program Termination traverse(Node x, Node y) { for (t =x; t != y ; t = t.n) { … } {x y} null nnnn x y

Disjoint Parallelism for (x =h; x != null; x = x.n) { … }  for (y=k; y != null; y = y.n) { … } {  :   null   (h   k  )} null nnnn h nnn k x y

Challenges Complexity of reasoning about reachability assertions –Undecidability of reachability [Inferring reachability properties from the code] " there is a mismatch between the simple intuitions about the way pointer operations work and the complexity of their axiomatic treatments " O'Hearn, Reynolds, Yang [CSL 2001]

Link list manipulations are simple Simple to reason about correctness –Small counterexamples “Simple” invariants –Alternation Free + Reachability “  ”  *  *

EA(  *  * ) formulas Bernays-Schönfinkel-Ramsey t ::= var | constant (Terms) ap ::= t 1 = t 2 | r(t 1,t 2, …, t n ) qf ::= ap | qf 1  qf 2 | qf 1  qf 2 |  qf ea ::=  1,  2,  n :   1,  2,  m : qf Effectively Propositional –Skolimization yields finite models –EQ-satisfiable to a propositional formula –Support from Z3

EA(  ) formulas Bernays-Schönfinkel-Ramsey  1,  2, :   1 : r(  1,  1 )  r(  1,  2 ) = sat  1 : r(c 1,  1 )  r(  1, c 2 ) = sat (r(c 1, c 1 )  r(c 1, c 2 ))  (r(c 1, c 2 )  r(c 2, c 2 )) = sat (P 11  P 12 )  (P 12  P 22 )

Alternation Free Reachability (AF R ) “Extended subset” of EA –Closed under negation t ::= var | constant (Terms) ap ::= t 1 = t 2 | r(t 1,t 2, …, t n ) | t 1 t 2 (Reachability via sequences of f’s) ( exists k: f k (t 1 )=t 2 ) qf ::= qf | qf 1  qf 2 | qf 1  qf 2 |  qf e ::=  1,  2,…,  n : qf a: ::=  1,  2,…,  m : qf af R ::= e | a | af R 1  af R 2 | af R 1  af R 2

AF R Program Properties Acylicity – ,  :      – ,  :       =  Acyclic list with a head h – ,  : h   h          =  Sorted segment – ,  :      data    n*n* n*n*   n*n* n*n* h u   n*n* v u  v

AF R Program Properties Doubly linked lists – ,  :      Disjoint lists with heads h and k –  :   null   (h   k  )   f * b*b* 11 n*n* h k 22

List Reversal (isolatd) h d   n*n* n*n* n*n* n*n* n*n* n*n* n n      null Node reverse(Node h) { Node c = h; Node d = null; while (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d } {ac [h]  : h  }

Invariant List Reversal (isolatd) Node reverse(Node h) { Node c = h; Node d = null; while (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d } {ac [h]  : h  } h d   n*n* n*n* n*n* n*n* n*n* n*n* n n null n c d       c   (      )  d  I= ,  :

List Reversal (isolated) Node reverse(Node h) { Node c = h; Node d = null; while {I} (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d } {ac [h]  : h  } {ac[d]  ,  :      } d       c   (      )  d  I= ,  :

List Reversal (isolated) Node reverse(Node h) { Node c = h; Node d = null; while {I} (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d } {ac [h]  : h  } {ac[d]  ,  :        : d  } d       c   (      )  d  I= ,  :

List Reversal (ownership) { ,  : h    h  } Node reverse(Node h) { Node c = h; Node d = null; while {I} (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d }

List Reversal (ownership) h d   n*n* n*n* n*n* n*n* n*n* n*n* n n h   h       null Case 1:

List Reversal (ownership) h<n*>  h<n*>h<n*>  h<n*> h d   n*n* n *, n * n*n*      n null n Case 2:

List Reversal (ownership)   h d n*n* n*n* n*n* n*n* h<n*>  h<n*>h<n*>  h<n*>    false n null n Case 3:

List Reversal (ownership)  d h=h= n*n* n*n* n *, n *  h   h      h=  n null n Case 4:

List Reversal (ownership) Node reverse(Node h) { Node c = h; Node d = null; while (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d; } {ac [h] ,  : h    h  } h   h  <n*><n*> <n*><n*> h<n*>  h<n*>h<n*>  h<n*> ,  :    h<n*>  h<n*>h<n*>  h<n*> false  h=   h   h 

Why AF R ? Represents the invariants of simple linked list manipulations Closed under , , ,  Finite model property Decidable for satisfiability/validity AF R  AF Can be reduced to a propositional formula –SAT solver is complete for verification/falsification

AF R  AF Introduce an auxiliary relation n* t[   ] =n * ( ,  ) Completely axiomatize n* by an AF formula  linOrd = ,  : n * ( ,  )  n * ( ,  )   =  , ,  : n * ( ,  )  n * ( ,  )  n * ( ,  )  , ,  : n * ( ,  )  n * ( ,  )  (n * ( ,  )  n * ( ,  ))  is satisfiable  (  linOrd  t[  ]) is satisfiable –AF formulas have finite model

Inverting n*  n Every finite model in which n* satisfies the order requirements:  linOrd = ,  : n * ( ,  )  n * ( ,  )   =  , ,  : n * ( ,  )  n * ( ,  )  n * ( ,  )  , ,  : n * ( ,  )  n * ( ,  )  (n * ( ,  )  n * ( ,  )) n * uniquely determines n

Inverting n*  n u v w x y    n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n* n*n*

Inverting n*  n u v w x y n(  ) =     :    n+n+ n+n+ n+n+ n+n+ n+n+ n+n+ n+n+ n+n+ n n+n+ n n n+n+ n

Simple SAT Application Determine if two clients are identical –Produce isomorphic reachable stores reverse(reverse(h)) = h ,  :      ,  :      ,  :      

Verification Process Program P Assertions  VC gen Verification Condition  P  “  ”  SAT Solver Counterexample Proof

wp Weakest Precondition wp: Stm  (Ass  Ass) wp  S  (Q) – the weakest condition such that every terminating computation of S results in a state satisfying Q   wp  S  (Q)   ’:   S   ’   ’  Q Can be used to compute verification conditions Q

Hoare Assignment Rule wp  x := e  (Q) =Q[e / x] wp  x := 5  (x=5) = 5=5  true wp  x := 5  (x=6) = 6=5  false wp[x := x +1](x=7) = x+1 = 7  x = 6 d     c       d  wc  c := d  ,  : = d     d       d  ,  :

WP Compound statements wp  skip  (Q) = Q wp  x := e  (Q) = Q[e / x] wp  S 1 ; S 2  (Q) = wp  S 1  (wp  S 2  (Q)) wp  if B then S 1 else S 2  = (  B   wp  S 1  (Q))  (   B   wp  S 2  (Q)) wp  while B do {I} S  = I

VC rules VC gen ({P} S {Q}) = P  wp  S  (Q)   VC aux (S, Q) VC aux (S, Q) = {} (for any atomic statement) VC aux (S 1 ; S 2, Q) = VC aux (S 1, wp(S 2, Q))  VC aux (S 2, Q) VC aux (if C then S 1 else S 2, Q) = VC aux (S 1, Q)  VC aux (S 2, Q) VC aux (while B do S, Q) = VC aux (S, I)  {I   B   wp  S  (I)}  {I   B   Q}

But how about heap mutations? McCarthy assignment rule does not work wp  c.n := null  (Q) = Q[n[c  null] / n] –Refers to n –Does not explicitly update reachability –Outside AF R Employ incremental updates n n’ x.n := null QF n’* n* FO TC

Dong & Su [SIGMOD’00] DAG   c d   :     c  n(  )=       c

Deterministic Graphs (function)   c d   c d  c d    c d

Mutating Single Linked Lists wp  c.n := null  (Q) = Q[(   (  c  c)) /   ] Can also enforce absence of null dereferences c  null

Circular Linked Lists Slightly more complex but Quantifier-Free [Hesse’03,Reps, Lahiri&Quadeer POPL’08] wp remains in QF

Single Mutation c.n := y (assuming c.n =null) Simple for general graphs AF R for arbitrary data structures wp  c.n := y  (Q) = Q[(   (  c  y  ))/   ] Can also enforce acyclicity  y c  ,  :       (  x  y  )

But what about pointer traversals? x := x.n Hoare assignment rule goes outside AF R wp  x := y.n  (Q) = Q[n(y) / x] –Outside AF R Reason about list segments Coincides with complications in pointer and shape analysis

WP Compound statements wp  skip  (Q) = Q wp  x := e  (Q) = Q[e / x] wp  S 1 ; S 2  (Q) = wp  S 1  (wp  S 2  (Q)) wp  if B then S 1 else S 2  = (  B   wp  S 1  (Q))  (   B   wp  S 2  (Q)) wp  while B do {I} S  = I

VC rules VC gen ({P} S {Q}) = P  wp  S  (Q)   VC aux (S, Q) VC aux (S, Q) = {} (for any atomic statement) VC aux (S 1 ; S 2, Q) = VC aux (S 1, wp(S 2, Q))  VC aux (S 2, Q) VC aux (if C then S 1 else S 2, Q) = VC aux (S 1, Q)  VC aux (S 2, Q) VC aux (while B do S, Q) = VC aux (S, I)  {I   B   wp  S  (I)}  {I   B   Q}

Pointer Traversals Observe that wp is only used positively in VCs (unlike invariants and preconditions) Allows EA formulas with reachability (AE R ) wp  x := y.n  (Q) =  : ‘n(y)=  ’  Q[  /x] –Replace n with n * using reachability inversions Universal quantifications are also used for allocation x := new()

Backward Reasoning with WP {a  n *  e  c  n *  b  disjoint(a,c)} d := e.n ; d.n := null ; d.n := c ; {a  n *  b} {a  n *  b  (a  n *  d  c  n *  b)} ( a  n *  b  (  a  n *  d  b  n *  d ) )  ( a  n *  d  (  a  n *  d  d  n *  d )  c  n *  b  (  c  n *  d  b  n *  d ) ) {}  true

Backward Reasoning with WP {a  n *  e  c  n *  b  disjoint(a,c)} d := e.n ; d.n := null ; d.n := c ; {a  n *  b} {a  n *  b  (a  n *  d  c  n *  b)} ( a  n *  b  (  a  n *  d  b  n *  d ) )  ( a  n *  d  c  n *  b  (  c  n *  d  b  n *  d ) ) {}  : “n(e) =  ”  ( a  n *  b  (  a  n *   b  n *  ) )  ( a  n *   c  n *  b  (  c  n *   b  n *  ) ) {}

Closure Properties QF AE EA ,,,,,,,, wp  x:=y , wp  x.n:=y     AF ,, , , , wp  x:=y.n  wp  x:=new( )  ,,,,

Benchmark Formula Size Solving time P,QIVC #  #  #  (Z3) SLL: reverse ms SLL: filter ms SLL: create ms SLL: delete ms SLL: deleteAll ms SLL: insert ms SLL: find ms SLL: last ms SLL: merge ms SLL: rotate ms SLL: swap ms DLL: fix ms DLL: splice ms

Disproving with SAT BenchmarkNature of defect Formula Size Solving time C.e. Size P,QIVC #  #  #  (Z3) (vertices) SLL: find null pointer dereference ms 2 SLL: deleteAll Loop invariant in annotation is too weak to prove the desired property ms 5 SLL: rotate Transient cycle introduced during execution ms 3 SLL: insert Unhandled corner case when an element with the same value already exists in the list --- ordering violated ms 4

Example Bug Node insert(Node h, Node e) { Node i = h, j = null; while {I} (i != null && e.val >= i.val) { j = i; i = i.n; } if (j != null) { j.n = e; e.n = i; } else { e.n = h; h = e; } return h; } I =  : h  i   e < val  null vnn h vn i e i’

Data Structures outside AF R Lists with the same lengths DAGs Grids …

List Reversal (general) Node reverse(Node h) { Node c = h; Node d = null; while {I} (c != null) { Node t = c.next; c.next = d; d = c; c = t; } return d } {ac [h] ,  : h    h  } h<n*> h<n*>h<n*> h<n*><n*><n*> <n*><n*> h    h  h    h  false  :     h    n(  )  h   h  null h    ,  :   

Related Work Axiomatizing Rechability –[Nelson POPL’83] Useful axioms –[Lev-Ami’09] Useful axioms + completeness study Descriptive Complexity [Hesse’03, Reps’03, Lahiri&Qadeer POPL’08] Decidable Logics [Mona, STRAND, LRP]

Summary Reduction to SAT Works for many programs Principles –Restricted invariants –Inversion n* –Incremental updates –Two logics