Program Analysis and Verification

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 12.
In this episode of The Verification Corner, Rustan Leino talks about Loop Invariants. He gives a brief summary of the theoretical foundations and shows.
Program Analysis and Verification
Models of Concurrency Manna, Pnueli.
50.530: Software Engineering Sun Jun SUTD. Week 13: Rely-Guarantee Reasoning.
A Rely-Guarantee-Based Simulation for Verifying Concurrent Program Transformations Hongjin Liang, Xinyu Feng & Ming Fu Univ. of Science and Technology.
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
Formal Semantics of Programming Languages 虞慧群 Topic 5: Axiomatic Semantics.
This Week Finish relational semantics Hoare logic Interlude on one-point rule Building formulas from programs.
Program Analysis and Verification
Axiomatic Verification I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 17.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Predicate Transformers
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Programming Language Semantics Rely/Guarantee Reasoning Parallel Programs Tal Lev-Ami Viktor Vafeiadis Mooly Sagiv.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
1 Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
Operational Semantics Semantics with Applications Chapter 2 H. Nielson and F. Nielson
Programming Language Semantics Axiomatic Semantics of Parallel Programs.
Describing Syntax and Semantics
CSE 755, part3 Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP: ::=skip | | | | ; | | Only integer vars; no procedures/fns; vars declared.
Proofs of Correctness: An Introduction to Axiomatic Verification Prepared by Stephen M. Thebaut, Ph.D. University of Florida CEN 5035 Software Engineering.
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.
Concurrency Verification. Why concurrency verification Concurrent programs show in many systems –Multi-task support in OS kernels –Handling interrupts.
Program Correctness. 2 Program Verification An object is a finite state machine: –Its attribute values are its state. –Its methods optionally: Transition.
Eran Yahav 1. Previously…  An algorithmic view  Abstract data types (ADT)  Correctness Conditions  Sequential consistency  Linearizability  Treiber’s.
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.
Program Logic for Concurrency Refinement Verification Xinyu Feng University of Science and Technology of China Joint work with Hongjin Liang (USTC) and.
Program Analysis and Verification Spring 2015 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Compositionality Entails Sequentializability Pranav Garg, P. Madhusudan University of Illinois at Urbana-Champaign.
Operational Semantics Mooly Sagiv Tel Aviv University Textbook: Semantics with Applications Chapter.
Cs7100(Prasad)L18-9WP1 Axiomatic Semantics Predicate Transformers.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
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.
Program Analysis and Verification Noam Rinetzky Lecture 2: Operational Semantics 1 Slides credit: Tom Ball, Dawson Engler, Roman Manevich, Erik.
Spring 2017 Program Analysis and Verification
Formal methods: Lecture
Spring 2017 Program Analysis and Verification
Verification of Concurrent Programs
Concurrency Verification
Program Analysis and Verification
Hongjin Liang, Xinyu Feng & Ming Fu
Concurrent Separation Logic
Lecture 5 Floyd-Hoare Style Verification
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages and Compilers (CS 421)
Axiomatic Verification I
Formal Methods in software development
Predicate Transformers
Concurrent Separation Logic
Formal Methods in software development
Axiomatic Semantics Will consider axiomatic semantics (A.S.) of IMP:
Proofs of Correctness: An Introduction to Axiomatic Verification
Axiomatic Verification I
Program correctness Axiomatic semantics
CIS 720 Lecture 3.
Programming Languages and Compilers (CS 421)
CIS 720 Lecture 3.
COP4020 Programming Languages
Presentation transcript:

Program Analysis and Verification 0368-4479 Noam Rinetzky Lecture 5: Rely/Guarantee Reasoning Slides credit: Roman Manevich, Mooly Sagiv, Eran Yahav

While + Concurrency Abstract syntax: a ::= n | x | a1 + a2 | a1  a2 | a1 – a2 b ::= true | false | a1 = a2 | a1  a2 | b | b1  b2 S ::= x := a | skip | S1; S2 | if b then S1 else S2 | while b do S | S1‖ …‖Sn

While + concurrency: structural semantics ⟨Si, s⟩ → ⟨Si’, s’ ⟩  ⟨S1… Sn, s⟩ → ⟨ S1… S’i…Sn, s’⟩  i=1..n ⟨Si, s⟩ → s’   ⟨S1… Sn, s⟩ → ⟨ S1… done…Sn, s’⟩ i=1..n

Challenge: Interference Proofs … … { P1 } S1 { Q2 } { P2 } S2 { Q2 } … {P1 Λ P2 } S1 ‖ S2 { Q1 Λ Q2 } Challenge: Interference

Axiomatic Semantics (Hoare Logic) Disjoint parallelism Global invariant Owicky – Gries [PhD. ‘76] Rely/Guarantee [Jones. ] … … { P } S1 ‖ S2 { Q }

Rely / Guarantee Aka assume Guarantee Cliff Jones Main idea: Modular capture of interference Compositional proofs

Commands as relations It is convenient to view the meaning of commands as relations between pre-states and post-states In {P} C {Q} P is a one state predicate Q is a two-state predicate Recall auxiliary variables Example {true} x := x + 1 {x= x + 1}

Intuition: Rely Guarantee Thread-view ⟨c0⟩ ⟨c1⟩ ⟨ck⟩ ⟨ck+1⟩ ⟨ck+2⟩ ⟨ck+3⟩ ⟨ck+3⟩ ⟨cn⟩ ⟨S0, s0⟩⇒ s1 ⇒ … ⇒ sk+1 ⇒ sk+2 ⇒ sk+3 ⇒ sk+3 ⇒ sk+4… ⇒ sn+1 … … ⇒ ⇒ ⇒ ⇒ ⇒

Intuition: Rely Guarantee Thread-view ⟨c0⟩ ⟨c1⟩ ⟨ck⟩ ⟨ck+1⟩ ⟨ck+2⟩ ⟨ck+3⟩ ⟨ck+3⟩ ⟨cn⟩ ⟨S0, s0⟩⇒ s1 ⇒ … ⇒ sk+1 ⇒ sk+2 ⇒ sk+3 ⇒ sk+3 ⇒ sk+4… ⇒ sn+1 G R* G G R* G R* … … ⇒ ⇒ ⇒ ⇒ ⇒

Intuition: Rely Guarantee Thread-view ⟨c0⟩ ⟨c1⟩ ⟨ck⟩ ⟨ck+1⟩ ⟨ck+2⟩ ⟨ck+3⟩ ⟨ck+3⟩ ⟨cn⟩ ⟨S0, s0⟩⇒ s1 ⇒ … ⇒ sk+1 ⇒ sk+2 ⇒ sk+3 ⇒ sk+3 ⇒ sk+4… ⇒ sn+1 G G G G RRRR R RRRR … … ⇒ ⇒ ⇒ ⇒ ⇒

Intuition (again) C C Hoare: { P } S { Q } ~ {P} ⇒⇒⇒⇒{Q} R/G: R,G⊢{ P } S { Q } ~ {P} ⇒⇒⇒⇒⇒⇒⇒{Q} R G R R G G G

Relational Post-Conditions meaning of commands a relations between pre-states and post-states {P} C {Q} P is a one state predicate Q is a two-state predicate Example {true} x := x + 1 {x= x + 1}

Goal: Parallel Composition R  G2, G1⊢{ P } S1 { Q } R  G1, G2⊢{ P } S2 { Q } R, G1G2⊢{ P } S1‖S2 { Q } (PAR)

Relational Post-Conditions meaning of commands a relations between pre-states and post-states Option I: {P} C {Q} P is a one state predicate Q is a two-state predicate Example {true} x := x + 1 {x= x + 1}

From one- to two-state relations p(, ) =p() A single state predicate p is preserved by a two-state relation R if p R p , : p() R(, ) p()

Operations on Relations (P;Q)(, )=:P(, ) Q(, ) ID(, )= (=) R*=IDR (R;R) (R;R;R) … 

Formulas ID(x) = (x = x) ID(p) =(p p) Preserve (p)= p p

Informal Semantics c  (p, R, G, Q) For every state  such that  p: Every execution of c on state  with (potential) interventions which satisfy R results in a state  such that (, )  Q The execution of every atomic sub-command of c on any possible intermediate state satisfies G

Informal Semantics c  (p, R, G, Q) c  [p, R, G, Q] For every state  such that  p: Every execution of c on state  with (potential) interventions which satisfy R results in a state  such that (, )  Q The execution of every atomic sub-command of c on any possible intermediate state satisfies G c  [p, R, G, Q] Every execution of c on state  with (potential) interventions which satisfy R must terminate in a state  such that (, )  Q

A Formal Semantics Let CR denotes the set of quadruples <1, 2, 3, 4 > s.t. that when c executes on 1 with potential interferences by R it yields an intermediate state 2 followed by an intermediate state 3 and a final state 4 as usual 4= when c does not terminate CR = {<1, 2, 3, 4> :  : <1, >  R  ( <C, > * 2  2 = 3= 4   ’, C’: <C, >* <C’, ’ >  ( (2= 1  2 = )  (3 =   3=’)  4= )  <’, 2, 3, 4 >  C’R ) c  (p, R, G, Q) For every <1, 2, 3 , 4 >  CR such that 1 p < 2, 3>  G If 4 : <1, 4 >  Q

Simple Examples X := X + 1  (true, X=X, X =X+1X=X, X =X+1) X := X + 1  (X 0, X X, X>0 X=X, X>0) X := X + 1 ; Y := Y + 1  (X 0Y 0, X X  Y Y, G, X>0 Y>0)

Inference Rules Define c  (p, R, G, Q) by structural induction on c Soundness If c  (p, R, G, Q) then c  (p, R, G, Q)

atomic {c}  (p, preserve(p), QID, Q) Atomic Command {p} c {Q} atomic {c}  (p, preserve(p), QID, Q) (Atomic)

Conditional Critical Section {pb} c {Q} await b then c  (p, preserve(p), QID, Q) (Critical)

Sequential Composition c1 (p1, R, G, Q1) c2 (p2, R, G, Q2) Q1  p2 c1 ; c2  (p1, R, G, (Q1; R*; Q2)) (SEQ)

if atomic {b} then c1 else c2  (p, R, G, Q) Conditionals c1 (p b1, R, G, Q) p  b  R* b1 c2 (p  b2, R, G, Q) p  b  R* b2 if atomic {b} then c1 else c2  (p, R, G, Q) (IF)

while atomic {b} do c  (j, R, G, b j) Loops c (j b1, R, G, j) j  b  R* b1 R  Preserve(j) while atomic {b} do c  (j, R, G, b j) (WHILE)

Refinement c (p, R, G, Q) p’  p Q Q’ R’  R G  G’ (REFINE)

Parallel Composition c1 (p1, R1, G1, Q1) c2 (p2, R2, G2, Q2) G1  R2 c1 || c2  (p1 p1, (R1 R2), (G1 G2), Q) where Q= (Q1 ; (R1R2)*; Q2)  (Q2 ; (R1R2)*; Q1) (PAR)

Issues in R/G Total correctness is trickier Restrict the structure of the proofs Sometimes global proofs are preferable Many design choices Transitivity and Reflexivity of Rely/Guarantee No standard set of rules Suitable for designs