272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software.

Slides:



Advertisements
Similar presentations
The behavior of SAT solvers in model checking applications K. L. McMillan Cadence Berkeley Labs.
Advertisements

Exploiting SAT solvers in unbounded model checking
Bounded Model Checking of Concurrent Data Types on Relaxed Memory Models: A Case Study Sebastian Burckhardt Rajeev Alur Milo M. K. Martin Department of.
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Modeling issues Book: chapters 4.12, 5.4, 8.4, 10.1.
Heuristic Search techniques
Jeremy Morse, Mikhail Ramalho, Lucas Cordeiro, Denis Nicole, Bernd Fischer ESBMC 1.22 (Competition Contribution)
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
Representing Boolean Functions for Symbolic Model Checking Supratik Chakraborty IIT Bombay.
CS 267: Automated Verification Lecture 2: Linear vs. Branching time. Temporal Logics: CTL, CTL*. CTL model checking algorithm. Counter-example generation.
CS 267: Automated Verification Lecture 8: Automata Theoretic Model Checking Instructor: Tevfik Bultan.
Partial Order Reduction: Main Idea
Satisfiability Modulo Theories (An introduction)
Automatic Verification Book: Chapter 6. What is verification? Traditionally, verification means proof of correctness automatic: model checking deductive:
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Abstraction and Modular Reasoning for the Verification of Software Corina Pasareanu NASA Ames Research Center.
ECE Synthesis & Verification - L271 ECE 697B (667) Spring 2006 Synthesis and Verification of Digital Systems Model Checking basics.
1/20 Generalized Symbolic Execution for Model Checking and Testing Charngki PSWLAB Generalized Symbolic Execution for Model Checking and Testing.
SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
CS 290C: Formal Models for Web Software Lecture 4: Implementing and Verifying Statecharts Specifications Using the Spin Model Checker Instructor: Tevfik.
Timed Automata.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 13.
CS 267: Automated Verification Lecture 10: Nested Depth First Search, Counter- Example Generation Revisited, Bit-State Hashing, On-The-Fly Model Checking.
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.
Best-First Search: Agendas
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
SAT and Model Checking. Bounded Model Checking (BMC) A.I. Planning problems: can we reach a desired state in k steps? Verification of safety properties:
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Plan for today Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CPSC 322, Lecture 12Slide 1 CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12 (Textbook Chpt ) January, 29, 2010.
1 Predicate Abstraction of ANSI-C Programs using SAT Edmund Clarke Daniel Kroening Natalia Sharygina Karen Yorav (modified by Zaher Andraus for presentation.
CS 267: Automated Verification Lectures 14: Predicate Abstraction, Counter- Example Guided Abstraction Refinement, Abstract Interpretation Instructor:
Validating High-Level Synthesis Sudipta Kundu, Sorin Lerner, Rajesh Gupta Department of Computer Science and Engineering, University of California, San.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
1 Formal Engineering of Reliable Software LASER 2004 school Tutorial, Lecture1 Natasha Sharygina Carnegie Mellon University.
CS 267: Automated Verification Lecture 13: Bounded Model Checking Instructor: Tevfik Bultan.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Formal Verification of SpecC Programs using Predicate Abstraction Himanshu Jain Daniel Kroening Edmund Clarke Carnegie Mellon University.
Daniel Kroening and Ofer Strichman Decision Procedure
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 17: Code Mining.
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 3: Modular Verification with Magic, Predicate Abstraction.
CS6133 Software Specification and Verification
Predicate Abstraction of ANSI-C Programs Using SAT By Edmund Clarke, Daniel Kroening, Natalia Sharygina, Karen Yorav Presented by Yunho Kim Provable Software.
Lazy Annotation for Program Testing and Verification Speaker: Chen-Hsuan Adonis Lin Advisor: Jie-Hong Roland Jiang November 26,
Reasoning about programs March CSE 403, Winter 2011, Brun.
On the Relation between SAT and BDDs for Equivalence Checking Sherief Reda Rolf Drechsler Alex Orailoglu Computer Science & Engineering Dept. University.
Learning Symbolic Interfaces of Software Components Zvonimir Rakamarić.
Author: Alex Groce, Daniel Kroening, and Flavio Lerda Computer Science Department, Carnegie Mellon University Pittsburgh, PA Source: R. Alur and.
Verification & Validation By: Amir Masoud Gharehbaghi
Intro to Planning Or, how to represent the planning problem in logic.
This Week Lecture on relational semantics Exercises on logic and relations Labs on using Isabelle to do proofs.
© 2006 Carnegie Mellon University Introduction to CBMC: Part 1 Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Arie Gurfinkel,
CS357 Lecture 13: Symbolic model checking without BDDs Alex Aiken David Dill 1.
Bounded Model Checking A. Biere, A. Cimatti, E. Clarke, Y. Zhu, Symbolic Model Checking without BDDs, TACAS’99 Presented by Daniel Choi Provable Software.
Error Explanation with Distance Metrics Authors: Alex Groce, Sagar Chaki, Daniel Kroening, and Ofer Strichman International Journal on Software Tools for.
Presented by: Belgi Amir Seminar in Distributed Algorithms Designing correct concurrent algorithms Spring 2013.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
© 2006 Carnegie Mellon University Introduction to CBMC: Part 1 Software Engineering Institute Carnegie Mellon University Pittsburgh, PA Arie Gurfinkel,
Bernd Fischer RW714: SAT/SMT-Based Bounded Model Checking of Software.
Complexity of Compositional Model Checking of Computation Tree Logic on Simple Structures Krishnendu Chatterjee Pallab Dasgupta P.P. Chakrabarti IWDC 2004,
SAT for Software Model Checking Introduction to SAT-problem for newbie
SS 2017 Software Verification Bounded Model Checking, Outlook
Weakest Precondition of Unstructured Programs
Introduction to Software Verification
Over-Approximating Boolean Programs with Unbounded Thread Creation
CSCI1600: Embedded and Real Time Software
Presentation transcript:

272: Software Engineering Fall 2012 Instructor: Tevfik Bultan Lecture 4: SMT-based Bounded Model Checking of Concurrent Software

Bounded Model Checking Represent the transitions of the system as Boolean logic formulas Instead of exploring all states exhaustively, unroll the transition relation up to a certain fixed bound and search for violations of the property within that bound Transform this search to a Boolean satisfiability problem and solve it using a SAT solver

Bounded Model Checking The basic observation is that we can define a bounded semantics for existential temporal logic properties so that if a path satisfies a property based on the bounded semantics, then it satisfies the property based on the unbounded semantics –Using this observation, we can show that a counter-example found on a bounded path is guaranteed to be a real counter- example –However, not finding a violation using bounded model checking does not guarantee correctness

Bounded Model Checking: Proving Correctness One can also show that given a finite state transition system, if a temporal logic property is violated by that transition system, then it will also be violated for that transition system using bounded semantics for some bound k So if we keep increasing the bound, then we are guaranteed to find all violations eventually –And, if we do not find a violation, then we decide that the the system does not violate the property –Is there a problem here?

Proving Correctness We can modify the bounded model checking algorithm as follows: –Start from an initial bound. –If no counter-examples are found using the current bound, increment the bound and try again. The problem is: We do not know when to stop

Proving Correctness If we can find a way to figure out when we should stop then we would be able to guarantee correctness There is a way to define a diameter of a transition system so that a property holds for the transition system if and only if it is not violated on a path bounded by the diameter. So if we do bounded model checking using the diameter of the system as our bound, then we can guarantee correctness if no counter-example is found. However, there is no efficient algorithm for identifying this diameter in general

Bounded Model Checking A bounded model checker needs an efficient SAT solver –zChaff SAT solver is one of the most commonly used ones Most SAT solvers require their input to be in Conjunctive Normal Form (CNF) –So the final formula has to be converted to CNF

Bounded Model Checking for Software CBMC is a bounded model checker for ANSI-C programs Handles function calls using inlining Unwinds the loops a fixed number of times Allows user input to be modeled using non-determinism –So that a program can be checked for a set of inputs rather than a single input Allows specification of assertions which are checked using the bounded model checking It targets sequential programs

Loops Unwind the loop n times by duplicating the loop body n times –Each copy is guarded using an if statement that checks the loop condition At the end of the n repetitions an unwinding assertion is added which is the negation of the loop condition –Hence if the loop iterates more than n times in some execution, the unwinding assertion will be violated and we know that we need to increase the bound in order to guarantee correctness A similar strategy is used for recursive function calls –The recursion is unwound up to a certain bound and then an assertion is generated stating that the recursion does not go any deeper

A Simple Loop Example x=0; while (x < 2) { y=y+x; x++; } x=0; if (x < 2) { y=y+x; x++; } if (x < 2) { y=y+x; x++; } if (x < 2) { y=y+x; x++; } assert (! (x < 2)) Original codeUnwinding the loop 3 times Unwinding assertion:

From Code to SAT After eliminating loops and recursion, CBMC converts the input program to the static single assignment (SSA) form –In SSA each variable appears at the left hand side of an assignment only once –This is a standard program transformation that is performed by creating new variables In the resulting program each variable is assigned a value only once and all the branches are forward branches (there is no backward edge in the control flow graph) CBMC generates a Boolean logic formula from the program using bit vectors to represent variables

Another Simple Example x=x+y; if (x!=1) x=2; else x++; assert(x<=3); x 1 =x 0 +y 0 ; if (x 1 !=1) x 2 =2; else x 3 =x 1 +1; x 4 =(x 1 !=1)?x 2 :x 3 ; assert(x 4 <=3); C  x 1 =x 0 +y 0  x 2 =2  x 3 =x 1 +1  (x 1 !=1  x 4 =x 2  x 1 =1  x 4 =x 3 ) P  x 4 <= 3 Check if C   P is satisfiable, if it is then the assertion is violated C   P is converted to boolean logic using a bit vector representation for the integer variables y 0,x 0,x 1,x 2,x 3,x 4 Original codeConvert to static single assignment Generate constraints

Bounded model checking with SMT-Solvers Bounded model checking has been originally proposed based on SAT solvers More recently, there has been work on doing bounded model checking with SMT-solvers SMT: Satisfiability Modula Theories –SMT-solvers are a type of theorem provers –They combine decision procedures for multiple theories such as Theory of integers with addition Theory of uninterpreted functions with equality Theory of reals Theory of arrays

SMT-solvers vs. SAT-solvers Since SMT-solvers can express and reason about high level constraints such as x=y+z in some cases they can be more efficient than SAT solvers –To handle a constraint like x=y+z using a SAT solver, we need convert the constraint to a Boolean logic formula using a bit-vector representation SMT-solvers can also be used for bounded model checking like SAT solvers –Instead of generating a SAT formula, we generate a formula using the theories that are supported by the SMT-solver There are several public domain SMT-solvers

ESBMC ESBMC is a SMT-based bounded model checking tool for concurrent C programs Concurrent C programs consist of a set of threads In order to verify behavior of a concurrent program all possible thread interleavings must be checked The number of thread interleavings can be exponential in the number of threads –This is one of the causes of state space explosion problem

Context-bounded verification A recent approach to verification of concurrent programs is to bound the number of context-switches –This means bounding the number of thread interleavings that are being explored The motivation is that, if there is a concurrency error in the program, it can typically be caught using a bounded number of context switches So the idea, in context-bounded verification is to bound the number of context-switches, but then explore all thread interleavings within that bound

Context-bounded verification with ESBMC ESBMC is a SMT-based context-bounded model checker for concurrent C programs ESBMC bounds the number of context-switches and explores all possible interleavings within that bound It uses three different heuristics in exploring different thread interleavings 1.Lazy approach 2.Schedule recording approach 3.Under-approximation and widening approach

Goto programs ESBMC converts C programs to a simplified language (has gotos, but no loops) –C programs are converted to this basic language automatically by a front end Goto programs support “assume” and “assert” statements These statements are used to specify properties to be verified (assertions) and the assumptions under which we want to verify them (assumes) –What ESBMC tries to determine is the following: Assuming that the constraints specified in assume statements hold, is it guaranteed that all the assertions hold?

Formal model for a concurrent program A concurrent program is a tuple M = (S, S 0, T, V) where –S is a finite set of states –T = t 0, t 1, …, t n is the set of threads –V = V global  V j where V j is the set of local variables for t j Each state s  S consists of values of all global and local variables and values of program counters for all threads Each thread j is a tuple t j = (R j, l j ) where –R j  S  S is the transition relation of thread j, and –l j = is the sequence of thread locations

Reachability Tree They model the execution of the concurrent program as a reachability tree (RT), where execution of instructions create new children and thread interleavings cause the branches in the tree Each node in the RT is a tuple v = (A i, C i, s i, j=1 n ) i –A i represents the currently active thread –C i represents the context switch number – s i represents the current state –l j i represents the current location of thread j –G j i represents the control flow guards accumulated in thread j along the path from l 0 j to l i j They discuss how the reachability tree can be expanded for each type of statement

Exploring the Reachability Tree Lazy approach: It is a type of depth first search. They create a single formula from a single interleaving and then send it to the SMT-solver. If they do not find an error in that interleaving, they continue with the next interleaving. Schedule Recording approach: They create a single formula that encodes all the interleavings (part of the formula encodes the different scheduling choices). Then they send the formula to the SMT-solver at the end. Under-approximation and widening approach: They start with a single interleaving and send it to the SMT-solver and then add more interleavings iteratively. While choosing the new interleavings to add they use the results from the previous call to the SMT-solver.

Lazy Approach Given a particular thread interleaving schedule I, they generate a formula ψ I k such that the property (an assertion) is violated at step k with the interleaving I, if and only if the formula is satisfiable ψ I k = I(s 0 )  R(s 0,s 1 )  R(s 1,s 2 )  …  R(s k-1,s k )   p k The formula corresponds to unrolling of the transition relation R k times If the generated formula is satisfiable, then the satisfying assignment to the formula demonstrates a counter-example behavior showing thevassertion violation and we are done If the generated formula is unsatisfiable, then a new formula is generated for another thread interleaving, and the process continues

Schedule Recording Approach In this approach, the interleaving schedule is encoded as part of the generated formula by using schedule guards –Schedule guards record in which order the scheduler has executed the program Using this approach all interleavings are encoded as part of a single formula ψ k = I(s 0 )  R(s 0,s 1 )  R(s 1,s 2 )  …  R(s k-1,s k )   p k  SCH(s 0 )  SCH(s 1 )  …  SCH(s k ) SCH(s i ) represents the schedule guard on state s i If there are no additional constraints then  i=0 k SCH(s 0 ) = true which means that all possible interleavings are considered However, it is possible to remove interleavings by restricting the schedule constraints

Under-approximation and widening approach They first generate a formula that characterizes all interleavings: ψ Then, they restrict is to a single interleaving using schedule guards: ψ’ = ψ  SCH(s 0 )  SCH(s 1 )  …  SCH(s k ) Note that ψ’ is an under-approximation of ψ and if we find a counter-example using ψ’ then that means that there is a real error and we are done. However, if we cannot find a counter-example using ψ’ that does not mean there is no error. So they incrementally relax the schedule constraints to add more interleavings. While modifying the schedule constraints, they use the information obtained from the SMT-solver about the unsatisfiability of the ψ’, so that they modify the schedule constraints to make it more likely that the modified formula will be satisfiable

Implementation and Experiments They model the synchronization operations in Pthread library using their approach They make some atomicity assumptions which may cause them miss some errors (false negatives), but they say that they did not observe this in their experiments They compare their approach with an explicit state context-bounded model checker (CHESS). Their approach performs better and the Lazy heuristic performs the best. They compare their approach with a SAT based model checker that uses the CEGAR technique (SATABS). Their approach performs better.