Model Checking Formal Methods Workshop August 18, 2017 Amrita

Slides:



Advertisements
Similar presentations
1 Verification by Model Checking. 2 Part 1 : Motivation.
Advertisements

1 Reasoning with Promela Safety properties bad things do not happen can check by inspecting finite behaviours Liveness properties good things do eventually.
Automatic Verification Book: Chapter 6. How can we check the model? The model is a graph. The specification should refer the the graph representation.
CS 267: Automated Verification Lecture 2: Linear vs. Branching time. Temporal Logics: CTL, CTL*. CTL model checking algorithm. Counter-example generation.
M ODEL CHECKING -Vasvi Kakkad University of Sydney.
Algorithmic Software Verification VII. Computation tree logic and bisimulations.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
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.
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
An Introduction to the Model Verifier verds Wenhui Zhang September 15 th, 2010.
ECE Synthesis & Verification - L271 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Model Checking basics.
François Fages MPRI Bio-info 2006 Formal Biology of the Cell Modeling, Computing and Reasoning with Constraints François Fages, Constraints Group, INRIA.
Temporal Logic and the NuSMV Model Checker CS 680 Formal Methods Jeremy Johnson.
Model Checking I What are LTL and CTL?. and or dreq q0 dack q0bar.
CS6133 Software Specification and Verification
UPPAAL Introduction Chien-Liang Chen.
Timed Automata.
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.
Model Checking I What are LTL and CTL?. and or dreq q0 dack q0bar D D.
1 Formal Methods in SE Qaisar Javaid Assistant Professor Lecture # 11.
1 Carnegie Mellon UniversitySPINFlavio Lerda SPIN An explicit state model checker.
Lecture 4&5: Model Checking: A quick introduction Professor Aditya Ghose Director, Decision Systems Lab School of IT and Computer Science University of.
Temporal Logic and Model Checking. Reactive Systems We often classify systems into two types: Transformational: functions from inputs available at the.
Witness and Counterexample Li Tan Oct. 15, 2002.
Review of the automata-theoretic approach to model-checking.
Embedded Systems Laboratory Department of Computer and Information Science Linköping University Sweden Formal Verification and Model Checking Traian Pop.
ESE601: Hybrid Systems Introduction to verification Spring 2006.
Witness and Counterexample Li Tan Oct. 15, 2002.
1 Formal Engineering of Reliable Software LASER 2004 school Tutorial, Lecture1 Natasha Sharygina Carnegie Mellon University.
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.
Verification technique on SA applications using Incremental Model Checking 컴퓨터학과 신영주.
Cheng/Dillon-Software Engineering: Formal Methods Model Checking.
1 Introduction to SMV and Model Checking Mostly by: Ken McMillan Cadence Berkeley Labs Small parts by: Brandon Eames ISIS/Vanderbilt.
Copyright 2001, Matt Dwyer, John Hatcliff, and Radu Iosif. The syllabus and all lectures for this course are copyrighted materials and may not be used.
10/19/2015COSC , Lecture 171 Real-Time Systems, COSC , Lecture 17 Stefan Andrei.
Automatic Verification of Finite-State Concurrent Systems Using Temporal Logic Specifications 1.
On Reducing the Global State Graph for Verification of Distributed Computations Vijay K. Garg, Arindam Chakraborty Parallel and Distributed Systems Laboratory.
- 1 -  P. Marwedel, Univ. Dortmund, Informatik 12, 05/06 Universität Dortmund Validation - Formal verification -
Verification & Validation By: Amir Masoud Gharehbaghi
1 CSEP590 – Model Checking and Automated Verification Lecture outline for July 9, 2003.
Software Systems Verification and Validation Laboratory Assignment 4 Model checking Assignment date: Lab 4 Delivery date: Lab 4, 5.
From Natural Language to LTL: Difficulties Capturing Natural Language Specification in Formal Languages for Automatic Analysis Elsa L Gunter NJIT.
Today’s Agenda  Quiz 4  Temporal Logic Formal Methods in Software Engineering1.
6/12/20161 a.a.2015/2016 Prof. Anna Labella Formal Methods in software development.
Model Checking Lecture 2. Model-Checking Problem I |= S System modelSystem property.
CS5270 Lecture 41 Timed Automata I CS 5270 Lecture 4.
Model Checking Lecture 2 Tom Henzinger. Model-Checking Problem I |= S System modelSystem property.
Complexity of Compositional Model Checking of Computation Tree Logic on Simple Structures Krishnendu Chatterjee Pallab Dasgupta P.P. Chakrabarti IWDC 2004,
Basic concepts of Model Checking
Formal methods: Lecture
CTL model checking algorithms
CIS 842: Specification and Verification of Reactive Systems
Automatic Verification
CSCI1600: Embedded and Real Time Software
CSEP590 – Model Checking and Automated Verification
Automatic Verification of Industrial Designs
Formal Methods in software development
CSCI1600: Embedded and Real Time Software
Computer Security: Art and Science, 2nd Edition
CSCI1600: Embedded and Real Time Software
A Refinement Calculus for Promela
Introduction to verification
Formal Methods in software development
Formal Methods in software development
Program correctness Branching-time temporal logics
Model Checking CS 680 Formal Methods Jeremy Johnson.
Program correctness Model-checking CTL
Model Checking Graph Grammars
Presentation transcript:

Model Checking Formal Methods Workshop August 18, 2017 Cybersecurity @ Amrita Jayaraman

The Origins of Model Checking (late 1970’s) Difficulty of carrying out proofs for real programs, with arrays, pointers, classes, threads, … even with the aid of automated proof assistants: - loop invariants, termination proofs, lemmas, etc. For many systems, a finite-state model can be developed. Can replace proof-based approach by algorithmic approach of checking whether the finite-state model (M) satisfies specification (S) written in temporal logic. M ⊨ S Aug 18, 2017 Jayaraman

Finite State Models Initial focus of model checking was on systems amenable to finite-state models: Hardware Systems Controllers in Embedded Systems Programs, conceptually, are not finite state: - an integer variable can take an unbounded number of values - but we can abstract them in many cases, although state space can be very large Aug 18, 2017 Jayaraman

The Need for Models Every model is an abstraction of reality – omit needless details, keep what is of interest to modeler. Example: A resistor in an electrical circuit is made of carbon, ceramic, resin, … Model of Resistor for Electrical Engineer: R – resistance value V – voltage across resistor I – current through resistor V = I * R This abstraction is useful because it helps analyze and predict behavior of complex circuits. Aug 18, 2017 Jayaraman

Model vs Reality Finite State Models useful since they helps analyze global properties without being bogged down in minutiae. - network communication protocols were early examples of success in building finite-state models; - ideally, use model-checking “in the large” and traditional program verification “in the small”. But checking the model ≠ checking the actual system. model may not agree with actual system; methods that help bridge the gap between model and reality also needed. Aug 18, 2017 Jayaraman

Model Checking Model Checking involves two main steps: Build a finite-state model of the program or system of interest. Check whether the model satisfies the specification. Aug 18, 2017 Jayaraman

A Classic Paper Received the ACM Turing Award for their work on Model Checking Aug 18, 2017 Jayaraman

Ex: Two Concurrent Threads import java.util.concurrent.Semaphore; class Main { public static void main(String[] args) { Semaphore lock = new Semaphore(1); MyThread p1 = new MyThread(lock); MyThread p2 = new MyThread(lock); p1.start(); p2.start(); } Two Concurrent Threads Synchronizing with a Semaphore Aug 18, 2017 Jayaraman

class MyThread public class MyThread extends Thread { Semaphore lock; MyThread(Semaphore lock) { this.lock = lock } public void run() { try { while(true) { not_relevant_code; lock.acquire(); critical_section lock.release(); } } catch(Exception e){} N T C Aug 18, 2017 Jayaraman

Concurrent Program Abstraction Thread 1 Thread 2 while (true) { N1; T1; [[ C1; ]] } while (true) { N2; T2; [[ C2; ]] } Critical Region Aug 18, 2017 Jayaraman

Finite State Model N1, N2 T1, N2 N1, T2 C1, N2 T1, T2 N1, C2 C1, T2 Aug 18, 2017 Jayaraman

Kripke Structure (Model) The finite state model is also called a Kripke Structure (in modal logic): <S, R, P>, where S = finite set of states R = transition relation (total) P = labeling function, S  2AP AP = atomic propositions Aug 18, 2017 Jayaraman

Concurrent Program The Transition Relation is total because there is a transition coming out of every state. The set of Atomic Propositions, AP, is: {N1, T1, C1, N2, T2, C2} e.g., C1 means “Thread 1 is in the Critical Region” The Labeling function S  2AP is defined by showing which atomic propositions are true for each state. Aug 18, 2017 Jayaraman

Aside: State Explosion Problem Given n concurrent threads each with m states, the number of possible states is: mn Integer variable with n bits: 2n states Approaches to deal with this problem: Symbolic Model Checking (OBDD, 10120 states) Partial Order Reduction (used by SPIN) Bounded Model Checking (most popular) Abstraction Refinement … Continues to be an active area of research! Aug 18, 2017 Jayaraman

The SPIN Tool Since the number of states can get very large, it is not feasible to list all the states in providing a finite state model of some system. Tools, such as SPIN, adopt a high-level language for defining the model. - This language is called PROMELA, for PROcess MEta LAnguage. - SPIN stands for Simple Promela INterpreter. To be discussed by Mr. Jinesh later today … Aug 18, 2017 Jayaraman

Simple PROMELA Model byte x = 0; proctype A() { atomic { x = x + 1 } proctype B() x = x + 2 init { run A(); run B() P: x = 0 Q: x = 1 R: x = 2 S: x = 3 P Q R S Aug 18, 2017 Jayaraman

Model Checking Model Checking involves two main steps: Build a finite-state model of the program or system of interest. Check whether the model satisfies the specification. Specifications stated in Propositional Temporal Logic. Aug 18, 2017 Jayaraman

Branching vs Linear Time Temporal Logic We can view the state transitions either as a computation tree or as a set of sequences. a b a b {abababababab …, abbabbabababba…, abbbabbbbbabbbab…, … abbbbbbbbbbbbb…. } Aug 18, 2017 Jayaraman

Computation Tree vs Sets of Sequences Programmers and system engineers may be more comfortable thinking in terms of Sets of Sequences: timing diagrams, message sequence charts, etc. Also, popular tool SPIN (to be studied) is founded on this model. But the model-checking with Computation Trees is more efficient than with sets of sequences (to be studied), and this also influenced early adoption of this approach. Aug 18, 2017 Jayaraman

Linear-time Logic (LTL) Propositional Logic over the atomic propositions AP augmented with four temporal operators: X p  “p is true in the next state” F p  “p is true in some future state” G p  “p is true globally in all states” p U q  “p is true until q becomes true” Aug 18, 2017 Jayaraman

Linear-time Logic (LTL) Aug 18, 2017 Jayaraman

Computation Tree Logic (CTL) Here we attach path quantifiers (A, E) to the temporal operators F, G, and X. A stands for “all” and E stands for “exists”. CTL temporal operators: AX, EX, AF, EF, AG, EG Note: there is also the U operator (“until”) Aug 18, 2017 Jayaraman

s |= EX p s p . . . . . . . . . . . . . . . . Aug 18, 2017 Jayaraman

s |= AX p s p p p . . . . . . . . . . . . . . . . Aug 18, 2017 Jayaraman

s |= EF p s p . . . . . . . . . . . . . . . . Aug 18, 2017 Jayaraman

s |= AF p s p p p p p p p . . . . . . . . . . . . . . . . Aug 18, 2017 Jayaraman

s |= EG p s p p p p p . . . . . . . . . . . . . . . . p Aug 18, 2017 Jayaraman

s |= AG p . . . . . . . . . . . . . . . . s p p p p p p p p p p p p p . . . . . . . . . . . . . . . . Aug 18, 2017 Jayaraman

CTL Semantics Aug 18, 2017 Jayaraman

CTL Semantics (cont’d) Aug 18, 2017 Jayaraman

Relating A and E Formulae AF p = ¬ EG ¬p AG p = ¬ EF ¬p These equivalences can be easily understood in terms of the computation tree. During model-checking, we will see that AF and AG formulae will be implemented in term of EG and EF (respectively), thanks to the equivalences. Aug 18, 2017 Jayaraman

Checking EF and EG Formulae For s |= EF p, perform a depth-first search from the state s until you find a state where property p is true. For s |= EG p, find a path from s leading to a state s’ that is part of a cycle and p is true globally on this path including the cycle. Break complex formula into parts. More later on a systematic approach … Aug 18, 2017 Jayaraman

s |= AF C1 ? False N1, N2 s T1, N2 N1, T2 C1, N2 T1, T2 N1, C2 C1, T2 Aug 18, 2017 Jayaraman

s |= AG [T1  AF C1]? False N1, N2 s T1, N2 N1, T2 C1, N2 T1, T2 N1, C2 C1, T2 T1, C2 Aug 18, 2017 Jayaraman

A More Refined Model N1, N2 s T1, N2 N1, T2 T1, T2 T1, T2 C1, N2 N1, C2 C1, T2 T1, C2 Aug 18, 2017 Jayaraman

Which model should we use? The model with one state for T1,T2 does not give any consideration to which request came first. Thus, even if process P1 tried for the resource before process P2, P2 could continually overtake T1 and hence AG[T1AF C1] is false in this model. On the other hand, the model with two states for T1,T2 distinguishes whether the request for T1 came before T2 or not. Hence, here AG[T1AF C1] is true in this model. Aug 18, 2017 Jayaraman

s |= AG[T1  AF C1] N1, N2 s T1, N2 N1, T2 T1, T2 T1, T2 C1, N2 N1, C2 C1, T2 T1, C2 Aug 18, 2017 Jayaraman

s |= AG ~(C1 /\ C2) N1, N2 s T1, N2 N1, T2 T1, T2 T1, T2 C1, N2 N1, C2 C1, T2 T1, C2 Aug 18, 2017 Jayaraman

JIVE Model Checking JIVE supports Kripke structures given as a Papyrus UML state diagrams. Simple CTL formulae are supported where one of the temporal operators (EX, EF, EG, AX, AF, AG) appears at the outermost level. JIVE also extracts a run-time state diagram from a Java program execution trace and checks consistency of design-time and run-time diagrams (to be discussed later). Aug 18, 2017 Jayaraman

JIVE: EF [C1 /\ T2] Aug 18, 2017 Jayaraman

JIVE: EG [N1] Aug 18, 2017 Jayaraman

JIVE: AG [~(C1 /\ C2)] Aug 18, 2017 Jayaraman

JIVE Property Violation: AG [~(T1 /\ T2)] Aug 18, 2017 Jayaraman

Another Example of Model Checking: States of a Microwave Oven Aug 18, 2017 Jayaraman

States of a Microwave Oven s |= EG [¬Error /\ Heat] ? AG [Start  AF Heat] ? AG [Start /\ ¬Error  AF Heat] ? Aug 18, 2017 Jayaraman

Model Checking of CTL AF f = ¬ EG ¬f AG f = ¬ EF ¬f 1. Check propositional formulae without any temporal operators: EX, EF, EG, AX, AF, AG 2. Replace A formulae by E formulae, and develop technique for EF and EG formulae: AF f = ¬ EG ¬f AG f = ¬ EF ¬f 3. Divide and conquer: - compute sets for subformulae - combine sets together Aug 18, 2017 Jayaraman

Checking Propositional Formulae a. To check whether s |= a, where a ∈ AP, the set of atomic propositions: - just check that a ∈ P(s), where P is the labeling function. b. To check whether s |= f, where formula f is made up of only atomic propositions and /\, \/, ¬, : - just evaluate f using the truth values of the atomic propositions at state s. Aug 18, 2017 Jayaraman

s |= Close /\ (¬Start \/ Heat) Aug 18, 2017 Jayaraman

Checking EF f … EF f = Sn S1 = {s | s |= f}. 2. S2 = {t | s ∈ S1 /\ R(t, s)} U S1, where R is the transition relation. 3. S3 = {t | s ∈ S2 /\ R(t, s)} U S2 … n. Sn = Sn-1 EF f = Sn Aug 18, 2017 Jayaraman

… Explanation of EF f Sn-1 Sn-2 S3 S2 S1 Edge in Transition Graph State in Transition Graph S3 S2 S1 f f f f f f Aug 18, 2017 Jayaraman

Checking EG f SCC = { s | s |= f /\ s is in some strongly connected component in the transition graph} S1 = { t | R(t, s) /\ t |= f /\ s ∈ SCC /\ t ∈ SCC } U SCC 2. S2 = { t | R(t, s) /\ t |= f /\ s ∈ S1} U S1 … n. Sn = Sn-1 EG f = Sn Aug 18, 2017 Jayaraman

… Explanation of EG f Sn-1 Sn-2 S1 SCC f f f f f f f State in Transition Graph Edge in Transition Graph S1 f f f f f f f f f SCC f f f f f f f Aug 18, 2017 Jayaraman

Check: AG[Error  EG[Close]] Convert AG to EF: ¬ EF ¬[Error  EG[Close]] ≡ ¬ EF ¬[¬Error \/ EG[Close]] ≡ ¬ EF [Error /\ ¬ EG[Close]] 2. Compute ¬ EG[Close] … Aug 18, 2017 Jayaraman

Check: ¬ EF [Error /\ ¬ EG[Close]] a. EG [Close] = {5, 3, 6, 7, 4} b. ¬ EG [Close] = {1, 2} Aug 18, 2017 Jayaraman

Check: ¬ EF [Error /\ ¬ EG[Close]] = {1, 2} 3. Error = {2, 5} 4. Error /\ ¬ EG[Close] = {2, 5} ∩ {1,2} = {2} Aug 18, 2017 Jayaraman

Check: ¬ EF [Error /\ ¬ EG[Close]] = {2} 5. EF {2} = {1,2,3,4,5,6,7} 6. ¬ EF {2} = {} AG[Error  EG[Close]] ≡ False Aug 18, 2017 Jayaraman

Complexity of CTL Model Checking Theorem (Clarke, Emerson, Sistla 1986): Given a Kripke Structure M = <S, R, P>, a state s ∈ S, and a CTL formula f, M, s |= f can be checked in time O(|f| x (|S| + |R|)). Note: SCC can be constructed in time O(|S| + |R|), using Tarjan’s algorithm. Aug 18, 2017 Jayaraman

Linear-time Logic (LTL) Propositional Logic over the atomic propositions AP augmented with four temporal operators: X p  “p is true in the next state” F p  “p is true in some future state” G p  “p is true globally in all states” p U q  “p is true until q becomes true” Aug 18, 2017 Jayaraman

Linear-time Logic (LTL) An LTL formula is true for a state transition graph only if it is true for every execution trace of the state transition graph. Aug 18, 2017 Jayaraman

Meaning of LTL Formula suffix Aug 18, 2017 Jayaraman

p,… |= G [T1  F C1] N1, N2 p T1, N2 N1, T2 T1, T2 T1, T2 C1, N2 N1, C2 C1, T2 T1, C2 Aug 18, 2017 Jayaraman

Comparison of LTL and CTL For many practical problems, LTL and CTL are both suitable for expressing the desired properties. In CTL, a formula f is true or false at some state, i.e., s |= f In LTL, a formula f is true or false for some path, i.e., p |= f But are these two approaches equivalent? Aug 18, 2017 Jayaraman

LTL: ‘Sometime’ is ‘Not Never’ In LTL, ‘sometime p’ can be defined as F p. - this means that, for every infinite path, p is true somewhere along the path. In LTL, F p ≡ ¬G¬p therefore, ‘sometime’ is equivalent to ‘not never’ Aug 18, 2017 Jayaraman

CTL: ‘Sometime’ is not ‘Not Never’ In CTL, ‘not never p’ is defined as ¬AG ¬p. Note: ¬EG ¬p would not be correct for ‘not never’. But, ¬AG ¬p ≡ EF p p is true somewhere along some path But LTL ‘sometime’ requires p to be true somewhere along every path, i.e., AF p Hence CTL ‘sometime’ is not equivalent to ‘not never’. Aug 18, 2017 Jayaraman

Comparing LTL and CTL LTL formulae must be true for all paths. Hence the CTL operators EX, EF, and EG cannot always be translated into LTL. - there are exceptions when negation is used; - for example, ¬EF ¬p ≡ AG p, and we can express AG p in LTL as G p. Aug 18, 2017 Jayaraman

Comparing LTL and CTL s0 s1 s2 p FG p is true in state s0 but AFAG p is not true: Every infinite sequence will end with an infinite sequence of p’s, hence FG p is true (LTL) But the computation tree will include s1 and p is false at s1 (CTL) – see next slide. Aug 18, 2017 Jayaraman

s |= AFAG p s p p p p p p p p p p . . . . . . . . . . . . . . . . Aug 18, 2017 Jayaraman

Explanation for s |= AFAG p Recall that s0 |= AF f if for every infinite path s0, s1, s2, …, there is some k ≥ 0 such sk |= f. In the present example, the formula f = AG p. The figure on the previous slide shows one path starting from s, namely, the leftmost spine, along which there is no state sk such that sk |= AG p. Hence, s |= AFAG p. Aug 18, 2017 Jayaraman

Final Remarks Model Checking is a mature technology with proven success in a number of domains. Still, many research problems remain, both in terms theory, applications, implementation. Variations: Probabilistic Model Checking (as in PRISM) Real-time Model Checking (as in UPPAAL) Run-time Model Checking (as in JIVE) Aug 18, 2017 Jayaraman