Wishnu Prasetya Model Checking with SPIN A Bit More about SPIN.

Slides:



Advertisements
Similar presentations
1 Reasoning with Promela Safety properties bad things do not happen can check by inspecting finite behaviours Liveness properties good things do eventually.
Advertisements

The SPIN System. What is SPIN? Model-checker. Based on automata theory. Allows LTL or automata specification Efficient (on-the-fly model checking, partial.
1 Data Link Protocols By Erik Reeber. 2 Goals Use SPIN to model-check successively more complex protocols Using the protocols in Tannenbaums 3 rd Edition.
Automatic Verification Book: Chapter 6. How can we check the model? The model is a graph. The specification should refer the the graph representation.
The SPIN System. What is SPIN? Model-checker. Based on automata theory. Allows LTL or automata specification Efficient (on-the-fly model checking, partial.
Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
MATH 224 – Discrete Mathematics
1 Model checking. 2 And now... the system How do we model a reactive system with an automaton ? It is convenient to model systems with Transition systems.
CS 290C: Formal Models for Web Software Lecture 3: Verification of Navigation Models with the Spin Model Checker Instructor: Tevfik Bultan.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
Reduction, abstraction, and atomicity: How much can we prove about concurrent programs using them? Serdar Tasiran Koç University Istanbul, Turkey Tayfun.
PROTOCOL VERIFICATION & PROTOCOL VALIDATION. Protocol Verification Communication Protocols should be checked for correctness, robustness and performance,
Formal verification in SPIN Karthikeyan Bhargavan, Davor Obradovic CIS573, Fall 1999.
/ PSWLAB P ROMELA Semantics from “THE SPIN MODEL CHECKER” by G. J. Holzmann Presented by Hong,Shin 5 th Oct :021PROMELA Semantics.
An Overview of PROMELA. A protocol Validation Language –A notation for the specification and verification of procedure rules. –A partial description of.
תרגול 9 META LABELS. Basic types of claims State properties.
Frederico Araujo CS6362 – Fall 2010 The SPIN Model Checker.
Wishnu Prasetya Model Checking with SPIN Modeling and Verification with SPIN.
CS 267: Automated Verification Lecture 10: Nested Depth First Search, Counter- Example Generation Revisited, Bit-State Hashing, On-The-Fly Model Checking.
PSWLAB S PIN Search Algorithm from “THE SPIN MODEL CHECKER” by G Holzmann Presented by Hong,Shin 9 th Nov SPIN Search Algorithm.
1 Temporal Claims A temporal claim is defined in Promela by the syntax: never { … body … } never is a keyword, like proctype. The body is the same as for.
The Spin Model Checker Promela Introduction Nguyen Tuan Duc Shogo Sawai.
1 Spin Model Checker Samaneh Navabpour Electrical and Computer Engineering Department University of Waterloo SE-464 Summer 2011.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Spin Tutorial (some verification options). Assertion is always executable and has no other effect on the state of the system than to change the local.
Introduction to Computability Theory
© 2011 Carnegie Mellon University SPIN: Part Bug Catching: Automated Program Verification and Testing Sagar Chaki November 2, 2011.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture # 11.
Temporal Logic Model- checking with SPIN COMP6004 Stéphane Lo Presti Part 4: Specifications.
UnInformed Search What to do when you don’t know anything.
1 Carnegie Mellon UniversitySPINFlavio Lerda SPIN An explicit state model checker.
Specification Formalisms Book: Chapter 5. Properties of formalisms Formal. Unique interpretation. Intuitive. Simple to understand (visual). Succinct.
CS 290C: Formal Models for Web Software Lecture 4: Model Checking Navigation Models with Spin Instructor: Tevfik Bultan.
The Parallel PV Model-checker Robert Palmer and Ganesh Gopalakrishnan School of Computing University of Utah.
Flavio Lerda 1 LTL Model Checking Flavio Lerda. 2 LTL Model Checking LTL –Subset of CTL* of the form: A f where f is a path formula LTL model checking.
1 Carnegie Mellon UniversitySPINFlavio Lerda Bug Catching SPIN An explicit state model checker.
Maria-Cristina Marinescu Martin Rinard Laboratory for Computer Science Massachusetts Institute of Technology A Synthesis Algorithm for Modular Design of.
Wishnu Prasetya LTL Model Checking.
Correctness requirements. Basic Types of Claims Basic assertions End-state labels Progress-state labels Accept-state labels Never claims Trace assertions.
Korea Advanced Institute of Science and Technology The Spin Model Checker - Advanced Features Moonzoo Kim CS Dept. KAIST.
CIS 842: Specification and Verification of Reactive Systems Lecture Specifications: LTL Model Checking Copyright , Matt Dwyer, John Hatcliff,
Concurrency. A process is a program executing on a virtual computer Processor speed and multiplexing of shared resources are ignored Order of thread execution.
MODEL CHECKING WITH SPIN MODELING AND VERIFICATION WITH SPIN ANDREA ORLANDINI – ISTC (CNR) TexPoint fonts used in EMF. Read the TexPoint manual before.
Inferring Synchronization under Limited Observability Martin Vechev, Eran Yahav, Greta Yorsh IBM T.J. Watson Research Center (work in progress)
The Complexity of Distributed Algorithms. Common measures Space complexity How much space is needed per process to run an algorithm? (measured in terms.
1 CSEP590 – Model Checking and Automated Verification Lecture outline for August 6, 2003.
Temporal Logic Model-checking with SPIN
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
May University of Glasgow Generalising Feature Interactions in Muffy Calder, Alice Miller Dept. of Computing Science University of Glasgow.
The Spin Model Checker : Part I Moonzoo Kim KAIST.
Hwajung Lee. Why do we need these? Don’t we already know a lot about programming? Well, you need to capture the notions of atomicity, non-determinism,
/ PSWLAB S PIN Search Optimization from “THE SPIN MODEL CHECKER” by G. Holzmann Presented by Hong,Shin 23 th Nov SPIN Search.
Lecture 4 Introduction to Promela. Promela and Spin Promela - process meta language G. Holzmann, Bell Labs (Lucent) C-like language + concurrency dyamic.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
Today’s Agenda  Quiz 5 (end of the class)  Quick Review  Finish Search Algorithms Formal Methods in Software Engineering1.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
Wishnu Prasetya Model Checking with SPIN Modeling and Verification with Promela.
Lecture 5 Page 1 CS 111 Summer 2013 Bounded Buffers A higher level abstraction than shared domains or simple messages But not quite as high level as RPC.
CSE 555 Protocol Engineering Dr. Mohammed H. Sqalli Computer Engineering Department King Fahd University of Petroleum & Minerals Credits: Dr. Abdul Waheed.
Formal methods: Lecture
Formal verification in SPIN
Automatic Verification
6.001 SICP Stacks and recursion
Over-Approximating Boolean Programs with Unbounded Thread Creation
The Spin Model Checker - Advanced Features
An explicit state model checker
The Spin Model Checker - Advanced Features
Presentation transcript:

Wishnu Prasetya Model Checking with SPIN A Bit More about SPIN

Content SPIN internal data structures SPIN result report Writing LTL formulas Containing state explosion Example 2 Acknowledgement: some slides are taken and adapted from Theo Ruys’s SPIN Tutorials.

Data structures involved in SPIN DFS Representation of a state. Stack for the DFS To remember where to backtrack in DFS It corresponds to the current “execution prefix” that is being inspected  used for reporting. Something to hold the set of visited states = “state space”. 3

State Each (global) state of a system is a “product” of the states of its processes. E.g. Suppose we have: One global var byte x Process P with byte y Process Q with byte z Each system state should describe: all these variables Program counter of each process Other SPIN predefined vars Represent each global state as a tuple … this tuple can be quite big. 4

The stack, optimization To save space SPIN does not literally keep a stack of states (large)  most of the time, states can be replaced by the ID of the actions that produce them (smaller) But, when you backtrack you need to know the state! SPIN calculated the reverse/undo of every action. So, knowing the current state is sufficient. 5

State-space is stored with a hash table The list of “visited states” is maintained by a Hash-table. So matching if a state occurring in the table is fast! Optimization: bit state hashing 6

Verifier’s output assertion violated !((crit[0]&&crit[1])) (at depth 5) // computation depth... Warning: Search not completed Full statespace search for:... never-claim - (not selected) assertion violations + invalid endstates + State-vector 20 byte, depth reached 7, errors: 1 // max. stack depth 24 states, stored // states stored in hash table 17 states, matched // states found re-revisited 41 transitions (= stored+matched) hash conflicts: 0 (resolved) (max size 2^19 states) memory usage (Mbyte) 7

Watch out for state explosion! Size of each state: > 12 bytes Number of possible states  (2 32 ) 3 = 2 96 Using byte (instead of int) brings this down to 50 MB Focus on the critical aspect of your model; abstract from data when possible. int x,y,z ; P { do :: x++ od } Q { do :: y++ od } R { do :: x/=y  z++ od } int x,y,z ; P { do :: x++ od } Q { do :: y++ od } R { do :: x/=y  z++ od } 8

Another source of explosion : concurrency imposing a coarser grain atomicity more abstract, less error prone, but less parallelism executable if the guard statement is executable none of stmt-i should be blocking; or rather : if any of then blocks, atomicity is lost atomic { guard  stmt_1;... ; stmt_n } active proctype P { x++ ; (s>0) ; y-- ; x=y } 9 put in atomic ?

d_step sequences like an atomic, but must be deterministic and may not block anywhere atomic and d_step sequences are often used as a model reduction method, to lower complexity of large models (improving tractability) No jump into the middle of a d_step d_step { guard  stmt_1;... ; stmt_n } d_step { /* reset array elements to 0 */ i = 0; do :: i x[i] = 0; i++ :: else -> break od; i = 0 } 10

execution without atomics or d_steps 11

execution with one atomic sequence 12

execution with a d_step sequence 13

atomic vs d_step d_step: executed as one block deterministic blocking or non-termination would hang you the verifier does not peek into intermediate states atomic: translated to a series of actions executed step-by-step, but without interleaving it can make non-deterministic choices verifies sees intermediate states 14

Partial Order Reduction The validity of a property ϕ is often insensitive to the order in which ‘independent’ actions are interleaved. e.g. stutter invariant  (does not contain X) that only refers to global variables, is insensitive to the relative order of actions that only access local variables. Idea: if in some global state, a process P can execute only actions updating local variables, always do these actions first (so they will not be interleaved!) We can also do the same with actions that : receive from a queue, from which no other process receives send to a queue, to which no other process sends 15

Reduction Algorithms Partial Order Reduction 16

Results on Partial Order Reduction This result is from Holzmann & Peled in 1994, on a Sparc-10 workstation with 128Mbyte of RAM. (about 40 mhz; so 1 mips??) 17

Specifying LTL properties (Check out the Manual) SPIN then generates the Buchi automaton for this LTL formula; called “Never Claim” in SPIN. #define PinCritical crit[1] #define QinCritical crit[2] []!(PinCritical && QinCritical) #define PinCritical crit[1] #define QinCritical crit[2] []!(PinCritical && QinCritical) 18

Example of a Never Claim To verify: <>[] p SPIN generates this never-claim / Buchi of []<>  p never { init: if ::  p  goto accept :: else  goto init fi; accept: skip; goto init ; } never { init: if ::  p  goto accept :: else  goto init fi; accept: skip; goto init ; } 19

Neverclaim From SPIN perspective, a neverclaim is just another process, but it is executed in “lock-step” : innitially, it is executed first, before the system does it first step then, after each step of the system, we execute a step from the neverclaim. You can use it to “match” an execution To match an infinite execution, as in Buchi automaton NC reaches its final state (its final “}”)  match!  used to match against finite executions. We use to to find a counter example. 20

You can also manually write your custom NC … never { accept : do :: (x==0) ; (x==1) od } never { accept : do :: (x==0) ; (x==1) od } 21 never { do :: (b) ; (!b) ; break :: skip od } never { do :: (b) ; (!b) ; break :: skip od } Will match with an execution where at some point b holds, then at the next step it does not hold. Match with an execution where (x==0)(x==1) holds alternatingly,

Example: distributed sorting Idea: Spec: [0] 193 [1] 31 [2] 333 [3] 31 Network Let P(i) swap values with P(i+1), if they are in the wrong order. Eventually the values will be sorted. 22

SPIN model #define N 5 byte a[N] ; proctype P(byte i) { byte tmp = 0 ; do :: d_step{ a[i]>a[i+1] -> tmp=a[i] ; a[i]=a[i+1] ; a[i+1]=tmp ; tmp=0 } od ; } Swap values, set tmp back to 0 to save state. init { byte i ; do :: i if :: a[i]=0 :: a[i]=1... fi ; i++ :: else -> break ; od ; i=0 ; do :: i run P(i) ; i++ :: else -> run detect() ; break od } 23 (let’s just assume locking a[i] and a[i+1] atomically is reasonable.)

Expressing the spec Eventually the values will be sorted. But SPIN does not support quantification in its Expr! You can still manually write a neverclaim, where you implement the quantification (note that the quantification is meant to be evaluated atomically). <>[] (  i : 0  i < N-1 : a[i]  a[i +1]) With LTL: 24

Detecting “termination” New spec: we want the processes themselves to know, or to be informed, that the goal (to sort values) has been acomplished. proctype detect() { byte i ; timeout -> do :: i assert (a[i]<=a[i+1]) :: else -> break od } done = true Extend P(i), such that when it sees “done” is true, it will terminate. Unfortunately, not good enough. The above solution uses “timeout” which in SPIN is actually implemented as a mechanism to detect non-progress; in the actual system we now assume not to have this mechanism in the first place, and hence have to implement it ourselves. 25 (Central server solution; not a distributed solution)

Detecting “termination” proctype detect() { byte i ; i=0 ; do :: i if :: a[i]>a[i+1] -> i=0 :: else -> i++ fi :: else -> done=true ; break od } proctype detect() { byte i ; i=0 ; do :: i if :: a[i]>a[i+1] -> i=0 :: else -> i++ fi :: else -> done=true ; break od } Unfortunately, this doesn’t work perfectly. Consider this sequence of steps: [ 4, 5, 1 ] detect 0,1  ok swap 1,2 [ 4, 1, 5 ] detect 1,2  ok now “detect” concludes termination! Can you find a solution for this?? Idea: let “detect” keep scanning the array to check if it is sorted. 26 (Central server solution; not a distributed solution)