220 likes | 357 Views
Automated Verification with HIP and SLEEK. Asankhaya Sharma. Recall the List length Example. int length( struct node* p) /*@ requires p::list<n,B> ensures p::list<n,B> & res=n; */ { if(p == NULL) return 0; else return 1 + length(p->next); }. Memory Safety. Length of the List.
E N D
Automated Verification withHIP and SLEEK Asankhaya Sharma
Recall the List length Example int length(struct node* p)/*@requires p::list<n,B>ensures p::list<n,B> & res=n;*/{ if(p == NULL) return 0; else return 1 + length(p->next);} Memory Safety Length of the List Bag of Values
With Inference int length(struct node* p)/*@infer [H,G]requires H(p)ensures G(p);*/{ if(p == NULL) return 0; else return 1 + length(p->next);} Second Order Variables for Unknown Predicates Modular Shape Inference
Relational Assumptions // Post (1) H(p) & x = null => G(p) // Bind (2) H(p) & x != null => x::node<_,q> * HP(q) // Pre-Rec (3) HP(q) => H(p) //Post (4) x::node<_,q> * G(q) => G(p)
Predicate Derivation For Pre Condition H(p) == emp & p = null or p::node<_,q> * H(q) For Post Condition G(p) == emp * p = null or p::node<_,q> * G(q) Linked List Predicate Inferred Automatically
Bi-Abduction 1 42 R3 antecedent consequent residue precondition Compositional shape analysis by means of bi-abduction Calcagno C, Distefano D, O'Hearn P W and Yang H POPL 2009 Achievement : Scalable automated shape analysis!
Incremental Specification Formal specs are important for verification and documentation. Tedious for legacy system and maintenance efforts. Users role to guide inference process Our thesis : Specification can be developed incrementally and when needed.
Inference Example infer [x,Q3] requires x::lln1 y::lln2 ensures x::lln3 & Q3(n1,n2,n3) requires x::lln1 y::lln2 & x null ensures x::lln3 & n1+n2=n3
Inference Example infer [R] requires x::lln1 y::lln2 & n null & Term[R(n1, n2)] ensures x::lln3 & n1+n2=n3 requires x::lln1 y::lln2 & n null & Term[n1] ensures x::lln3 & n1+n2=n3
Selective Entailment [v*] 1 4 2 3 d definitions antecedent residue consequent precondition
Key Principles Selective Inference Inferable Heap Locations Never Inferring False Antecedent Contradiction Unknown Relation/Function Derivation
Selective Inference [x] x::lln x::node<_,q> x null q:: lln-1 [n] x::lln x::node<_,q> n > 0 q:: lln-1
Selective Inference [x] x::lln x::node<_,null> FAIL [n] x::lln x::node<_,null> n=1 emp
Inferring Heap Locations Heap state may be inferred x::node<_,null> [x] emp x::node<_,null> emp Allows predicates to be inferred Allows cascaded heaps by adding auxiliary variables
Never Inferring False [x] true x>x FAIL [x] true x::node<_,_> x::node<_,_> FAIL
Antecedent Contradiction What if contradiction detected between 1 and 2 ? [v*] 1 2 Add pre over v* to support contradicted antecedent.
Antecedent Contradiction [b] x=1 & b>0 x=2 b0 false [x] x=null x::node<_,q> x null false
Selective Inference [Q] x::node(_,y) y::lln2 & n1=1 x::lln3 & Q(n1 ,n2, n3) n1=1 & n3= n2+1 Q(n1,n2,n3) [Q] x::node(_,y) y::lln2 & Q(n1-1,n2,n3) x::lln3 & Q(n1 ,n2, n3) n3= n2+1 & n1>0 & Q(n1-1,n2,n3) Q(n1,n2,n3)
FixPoint Calculation n1=1 & n3= n2+1Q(n1,n2,n3) n3= n2+1 & n1>0 & Q(n1-1,n2,n3) Q(n1,n2,n3) n1>0 & n2 0 & n3= n2+ n2 Q(n1,n2,n3)
Inferring Heap Locations Auxiliary variables may be added [x] emp x::node<_,q> q::node<_,null> x::node<_,x1> & x1=q [x,x1] emp x::node<_,q> q::node<_,null> x::node<_,x1> x1::node<_,null> & x1=q [x, x1] emp x::node<_,q> q::node<_,null>
Inferring Unknown Relations Two kinds of relationships inferred Relational Obligation: R(..) c Relational Definition: R(..) & c R(…)
Further Reading • Trinh, Minh-Thai, Quang Loc Le, Cristina David, and Wei-Ngan Chin. "Bi-Abduction with Pure Properties for Specification Inference." In Programming Languages and Systems, pp. 107-123. Springer International Publishing, 2013.