Model-Driven Verifying Compilation of Synchronous Distributed Applications Sagar Chaki, James Edmondson October 1, 2014 MODELS’14, Valencia, Spain © 2014 Carnegie Mellon University Copyright 2014 Carnegie Mellon University This material is based upon work funded and supported by the Department of Defense under Contract No. FA8721-05-C-0003 with Carnegie Mellon University for the operation of the Software Engineering Institute, a federally funded research and development center. Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the United States Department of Defense. NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN “AS-IS” BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. This material has been approved for public release and unlimited distribution except as restricted below. This material may be reproduced in its entirety, without modification, and freely distributed in written or electronic form without requesting formal permission. Permission is required for any other use. Requests for permission should be directed to the Software Engineering Institute at permission@sei.cmu.edu. DM-0001691 Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 2 Outline • Motivation • Approach • Sequentialization : SEQSEM & SEQDBL • Examples • Experimental Results • Synchronizer Protocol : 2BSYNC • Tool Overview & Demo • Future Work Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 3 Motivation Distributed algorithms have always been important • File Systems, Resource Allocation, Internet, … Increasingly becoming safety-critical • Robotic, transportation, energy, medical Prove correctness of distributed algorithm implementations • • Pseudo-code is verified manually (semantic gap) Implementations are heavily tested (low coverage) Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 4 Approach : Verification + Code Generation Program in Domain Specific Language Distributed Application Debug Application, Refine Specification Safety Specification Verification Failure Success The Verifying Compiler: A Grand Challenge for computing research Code Generation Tony Hoare Binary Run on Physical Device Run within simulator Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 5 Verification Model Checking Program in Domain Specific Language Distributed Application Safety Specification Automatic verification technique for finite state concurrent systems. • Sequentialization • Assume Synchronous Model of Computation Single-Threaded C Program Specifications are written in propositional temporal logic. (Pnueli 77) • Software Model Checking (CBMC, BLAST etc.) Failure Developed independently by Clarke and Emerson and by Queille and Sifakis in early 1980’s. ACM Turing Award 2007 Success Computation Tree Logic (CTL), Linear Temporal Logic (LTL), … Verification procedure is an intelligent exhaustive search of the state space of the design Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 6 Code Generation MADARA Middleware Program in Domain Specific Language Distributed Application Safety Specification A database of facts: ๐ท๐ต = ๐๐๐ โฆ ๐๐๐๐ข๐ Node ๐ has a local copy: ๐ท๐ต๐ • update ๐ท๐ต๐ arbitrarily • publish new variable mappings Add synchronizer protocol Guarantee Synchronous Model of Computation • Immediate or delayed • Multiple variable mappings transmitted atomically Implicit “receive” thread on each node C++/MADARA Program Compile (g++,clang,MSVC, etc.) Binary • Receives and processes variable updates from other nodes • Updates ordered via Lamport clocks Portable to different OSes (Windows, Linux, Android etc.) and networking technology (TCP/IP, UDP, DDS etc.) Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 7 Synchronous Distributed Application (SDA) Node ๐ = ๐๐ () Shared Variables:๐ฎ๐ฝ = ๐ฎ๐ฝ ๐ , ๐ฎ๐ฝ[๐] Node ๐ = ๐๐ () ๐ฎ๐ฝ๐ ๐น๐๐๐๐ ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐ [๐] = ๐๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐น๐๐๐๐ ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐ [๐] = ๐๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐−๐ ๐น๐๐๐๐ ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐−๐ ) ๐ฎ๐ฝ๐ [๐] = ๐๐ ๐ฎ๐ฝ๐−๐ ๐ฎ๐ฝ๐ Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 8 SDA Verification Program with ๐ nodes : ๐(๐) • • • Each node has a distinct ๐๐ ∈ 1, ๐ Array ๐บ๐ has ๐ elements, ๐บ๐[๐] writable only by node with id ๐ Each element of ๐บ๐ is drawn from a finite domain In each round, node with id ๐๐ executes function ๐ whose body is a statement ๐ ๐ก๐๐ก โ ๐ ๐๐๐ | ๐๐ฃ๐๐ = ๐๐ฅ๐ (๐๐ ๐ ๐๐๐๐๐๐๐ก) | ๐ผ๐๐ธ ๐๐ฅ๐, ๐ ๐ก๐๐ก, ๐ ๐ก๐๐ก (๐๐, ๐กโ๐๐, ๐๐๐ ๐) | ๐ด๐ฟ๐ฟ ๐ผ๐, ๐ ๐ก๐๐ก (๐๐ก๐๐๐๐ก๐ ๐๐ฃ๐๐ ๐๐๐๐๐ โถ ๐ข๐ ๐ ๐ก๐ ๐โ๐๐๐ ๐๐ฅ๐๐ ๐ก๐๐๐๐) | ๐ ๐ก๐๐ก + (๐๐ก๐๐๐๐ก๐๐๐ ๐๐ ๐ ๐ก๐๐ก๐๐๐๐๐ก๐ ) ๐๐ฃ๐๐ โ ๐บ๐ ๐๐ ๐ค (๐๐ฃ๐๐๐ข๐๐ ) ๐๐ฅ๐ โ โค ⊥ ๐๐ฃ๐๐ ๐บ๐ ๐๐ฃ ๐ค ๐๐ ๐ผ๐ โ (๐๐ฅ๐+ ) (๐๐ฅ๐๐๐๐ ๐ ๐๐๐๐ ) Initial states and “ERROR” states of the program are define • State ≡ value assigned to all variables Verification ≡ decide if there is an execution of the program that starts in an initial state and ends in an ERROR state Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 9 Semantic Sequentialization: SEQSEM Node ๐ = ๐๐ () Shared Variables:๐ฎ๐ฝ = ๐ฎ๐ฝ ๐ , ๐ฎ๐ฝ[๐] ๐จ๐๐๐๐๐ ๐ ๐๐๐ ๐๐ ๐ผ๐๐ ๐ ๐๐๐๐๐๐ ๐๐ ๐ฎ๐ฝ ๐ถ ๐๐ ๐๐๐๐๐๐๐๐๐ ⇒ ๐บ๐๐๐๐ ๐ฌ๐๐๐๐๐๐๐๐ ๐น๐๐๐๐ ๐ Node ๐ = ๐๐ () ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐−๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐−๐ ๐ − ๐ = ๐๐−๐ (๐ฎ๐ฝ๐−๐ ) ๐ฎ๐ฝ๐ ๐ = ๐ฎ๐ฝ๐ ๐ , ๐≠๐ ๐ฎ๐ฝ๐ ๐ = ๐ฎ๐ฝ๐ ๐ , ๐≠๐ ๐ฎ๐ฝ๐−๐ ๐ = ๐ฎ๐ฝ๐ ๐ , ๐≠๐−๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐−๐ ๐ถ๐๐๐๐๐๐๐๐๐ ๐๐๐๐ ๐๐๐ ๐๐๐๐๐ ๐๐๐๐ ⇒ ๐๐๐๐๐ ๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐๐๐. Sagar Chaki, October 1, 2014 ๐น๐๐๐๐ ๐ ๐๐๐ ๐๐๐๐๐๐๐๐ ๐๐ ๐ ๐๐๐๐. Model-Driven Verifying Compilation © 2014 Carnegie Mellon University 10 Double Buffering Sequentialization: SEQDBL Node ๐ = ๐๐ () Shared Variables:๐ฎ๐ฝ = ๐ฎ๐ฝ ๐ , ๐ฎ๐ฝ[๐] ๐ผ๐๐ ๐ ๐๐๐๐๐๐ ๐๐ ๐ฎ๐ฝ ๐ผ๐๐ ๐๐๐๐ ๐๐๐๐ ๐๐ ๐๐๐๐๐ ๐๐ ๐๐๐๐๐๐๐๐๐ ๐๐๐๐๐ ๐ ๐น๐๐๐๐ ๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ ๐ฎ๐ฝ๐ ๐ถ ๐ ๐๐๐๐๐๐๐๐๐ ๐น๐๐๐๐ ๐ Node ๐ = ๐๐ () ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐ ๐ − ๐ = ๐๐−๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐ ๐ − ๐ = ๐๐−๐ (๐ฎ๐ฝ๐ ) ๐ฎ๐ฝ๐ Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 11 Example: 2D Synchronous Collision Avoidance (3,3) Y (0,3) Reserve Reserve (0,0) Reserve (3,0) X Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 12 Example: 2D Synchronous Collision Avoidance (3,3) Y (0,3) Reserve Reserve Reserve (0,0) (3,0) X Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 13 Example: 2D Synchronous Collision Avoidance (0,3) (3,3) Y Reservation Contention Resolved based on Node ID. No collision possible if no over-booking. Potential Collision (0,0) (3,0) X Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 14 2D Collision Avoidance Protocol If time to move to next coordinate REQUEST NEXT If no other node is locking the next coordinate WAITING Reached the next coordinate MOVE Moving to the next coordinate If no other node “with higher id” is trying to lock the next coordinate ๐ถ๐๐๐๐ ๐ฌ๐๐๐๐๐๐๐ 3D Collision Avoidance Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 Mutual Exclusion © 2014 Carnegie Mellon University 15 Results: 3D Collision Avoidance SEQDBL is better ๐ป๐บ , ๐ป๐ซ = ๐๐๐ ๐๐ ๐๐๐๐๐๐๐๐ ๐๐๐๐ ๐๐๐๐ ๐บ๐ฌ๐ธ๐บ๐ฌ๐ด, ๐บ๐ฌ๐ธ๐ซ๐ฉ๐ณ ๐ป๐บ ๐, ๐ = ๐จ๐๐, ๐บ๐๐ซ๐๐ ๐๐ ๐ป๐ซ Model-Driven Verifying Compilation Sagar Chaki,๐๐๐๐ October 1, 2014 ๐ = #๐๐ ๐๐๐ ๐๐ ๐น = #๐๐ ๐๐๐๐๐ ๐ ๐ฎ×๐ฎ = ๐๐๐๐ © 2014 Carnegie Mellon University 16 Results: 2D Collision Avoidance Depends on the example ๐ป๐บ , ๐ป๐ซ = ๐๐๐ ๐๐ ๐๐๐๐๐๐๐๐ ๐๐๐๐ ๐๐๐๐ ๐บ๐ฌ๐ธ๐บ๐ฌ๐ด, ๐บ๐ฌ๐ธ๐ซ๐ฉ๐ณ ๐ป๐บ ๐, ๐ = ๐จ๐๐, ๐บ๐๐ซ๐๐ ๐๐ ๐ป๐ซ Model-Driven Verifying Compilation Sagar Chaki,๐๐๐๐ October 1, 2014 ๐ = #๐๐ ๐๐๐ ๐๐ ๐น = #๐๐ ๐๐๐๐๐ ๐ ๐ฎ×๐ฎ = ๐๐๐๐ © 2014 Carnegie Mellon University 17 Results: Mutual Exclusion SEQSEM and SEQDBL similar ๐ป๐บ , ๐ป๐ซ = ๐๐๐ ๐๐ ๐๐๐๐๐๐๐๐ ๐๐๐๐ ๐๐๐๐ ๐บ๐ฌ๐ธ๐บ๐ฌ๐ด, ๐บ๐ฌ๐ธ๐ซ๐ฉ๐ณ ๐ป๐บ ๐, ๐ = ๐จ๐๐, ๐บ๐๐ซ๐๐ ๐๐ ๐ป๐ซ Model-Driven Verifying Compilation Sagar Chaki,๐๐๐๐ October 1, 2014 ๐ = #๐๐ ๐๐๐ ๐๐ ๐น = #๐๐ ๐๐๐๐๐ ๐ ๐ฎ×๐ฎ = ๐๐๐๐ © 2014 Carnegie Mellon University 18 Synchronizer Protocol: 2BSYNC Node ๐ = ๐๐ () Shared Variables:๐ฎ๐ฝ = ๐ฎ๐ฝ ๐ , ๐ฎ๐ฝ[๐] ๐ผ๐๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐: ๐๐ , ๐๐ ๐ฐ๐๐๐๐๐๐๐๐๐๐ ๐๐ ๐ Atomic Send. Either both ๐ฎ๐ฝ๐ [๐] and ๐๐ are received, or none is received. Can be implemented on existing network stack, e.g., TPC/IP Node ๐ = ๐๐ () ๐ฎ๐ฝ๐ , ๐๐ ๐ฎ๐ฝ๐ , ๐๐ ๐๐ โ ๐๐ + ๐ ๐๐ ! ๐ฉ๐๐๐๐ ๐๐ โ ๐๐ + ๐ ๐๐ ! ๐ฉ๐๐๐๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ ๐ฎ๐ฝ๐ ๐ฎ๐ฝ๐ ๐ = ๐๐ (๐ฎ๐ฝ๐ ) ๐๐ โ ๐๐ + ๐ ๐ฎ๐ฝ๐ ๐ , ๐๐ ! ๐ฉ๐๐๐๐ ๐ฉ๐๐๐๐ ≡ ๐๐๐๐๐ ๐๐ < ๐๐ ๐๐๐๐; Implicit thread receiving messages and updating variables ๐๐ โ ๐๐ + ๐ ๐ฎ๐ฝ๐ ๐ , ๐๐ ! ๐ฉ๐๐๐๐ ๐ท๐๐๐๐ ๐๐ ๐๐๐๐๐๐๐๐๐๐๐ 19 ๐๐ ๐๐๐๐๐ Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University Tool Overview Project webpage (http://mcda.googlecode.com) • Tutorial (https://code.google.com/p/mcda/wiki/Tutorial) Verification • • daslc --nodes 3 --seq --rounds 3 --seq-dbl --out tutorial-02.c tutorial02.dasl cbmc tutorial-02.c (takes about 10s to verify) Code generation & simulation • • • daslc --nodes 3 --madara --vrep --out tutorial-02.cpp tutorial-02.dasl g++ … mcda-vrep.sh 3 outdir ./tutorial-02 … DEMO Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 20 Future Work Improving scalability and verifying with unbounded number of rounds Verifying for unbounded number of nodes (parameterized verification) • Paper at SPIN’2014 Symposium Asynchronous and partially synchronous network semantics Scalable model checking • Abstraction, compositionality, symmetry reduction, partial order reduction Fault-tolerance, uncertainty, … • Combine V&V of safety-critical and mission-critical properties Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 21 QUESTIONS? © 2014 Carnegie Mellon University Contact Information Slide Format Sagar Chaki Principal Researcher SSD/CSC Telephone: +1 412-268-1436 Email: chaki@sei.cmu.edu U.S. Mail Software Engineering Institute Customer Relations 4500 Fifth Avenue Pittsburgh, PA 15213-2612 USA Web www.sei.cmu.edu www.sei.cmu.edu/contact.cfm Customer Relations Email: info@sei.cmu.edu Telephone: +1 412-268-5800 SEI Phone: +1 412-268-5800 SEI Fax: +1 412-268-6257 Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 23 Synchronous Collision Avoidance Code MOC_SYNC; NODE uav (id) CONST X = 4; CONST Y = 4; { CONST NEXT = 0; GLOBAL bool lock [X][Y][#N]; CONST REQUEST = 1; LOCAL int state,x,y,xp,yp,xf,yf; CONST WAITING = 2; void NEXT_XY () { … } CONST MOVE = 3; void ROUND () { INIT { FORALL_NODE(id) state.id = NEXT; //assign x.id and y.id non-deterministically //assume they are within the correct range //assign lock[x.id][y.id][id] appropriately if(state == NEXT) { … EXTERN int state = REQUEST; MOVE_TO (unsigned char x, unsigned char y); state = MOVE; } else if(state == MOVE) { … void INIT () { … } FORALL_DISTINCT_NODE_PAIR (id1,id2) state = WAITING; } else if(state == WAITING) { … NODE uav (id) { … } //nodes don’t collide initially } else if(state == REQUEST) { … state = NEXT; ASSUME(x.id1 != x.id2 || y.id1 != y.id2); } SAFETY { FORALL_DISTINCT_NODE_PAIR (id1,id2) }}} void SAFETY { … } ASSERT(x.id1 != x.id2 || y.id1 != y.id2); } Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 24 Synchronous Collision Avoidance Code if(state == NEXT) { //compute next point on route else if(state == MOVE) { if(x == xf && y == yf) return; //now we have the lock on (xp,yp) NEXT_XY(); if(MOVE_TO()) return; state = REQUEST; lock[x ][y][id] = 0; } else if(state == REQUEST) { x = xp; y = yp; //request the lock but only if it is free if(EXISTS_OTHER(idp,lock[xp][yp][idp] != 0)) return; state = NEXT; } lock[xp][yp][id] = 1; state = WAITING; } else if(state == WAITING) { //grab the lock if we are the highest //id node to request or hold the lock if(EXISTS_HIGHER(idp, lock[xp][yp][idp] != 0)) return; state = MOVE; } Model-Driven Verifying Compilation Sagar Chaki, October 1, 2014 © 2014 Carnegie Mellon University 25