ecbs 2013 smt bounded model checking of c programs
play

ECBS 2013 SMT-Bounded Model Checking of C++ Programs Mikhail - PowerPoint PPT Presentation

ECBS 2013 SMT-Bounded Model Checking of C++ Programs Mikhail Ramalho, Mauro Freitas , Felipe Sousa, Hendrio Marques, Lucas Cordeiro, Bernd Fischer Bounded Model Checking (BMC) Idea: check negation of given property up to given depth property


  1. ECBS 2013 SMT-Bounded Model Checking of C++ Programs Mikhail Ramalho, Mauro Freitas , Felipe Sousa, Hendrio Marques, Lucas Cordeiro, Bernd Fischer

  2. Bounded Model Checking (BMC) Idea: check negation of given property up to given depth property ¬ ϕ 0 ¬ ϕ 1 ¬ ϕ 2 ¬ ϕ k -1 ¬ ϕ k ∨ ∨ ∨ ∨ . . . transition M 0 M 1 M 2 M k -1 M k system bound counterexample trace counterexample trace • transition system M unrolled k times – for programs: unroll loops, unfold arrays, … • translated into verification condition ψ such that ψ satisfiable iff ϕ ϕ has counterexample of max. depth k ψ ψ ψ ϕ ϕ • has been applied successfully to verify (sequential) software

  3. BMC of C++ Programs • there have been attempts to apply BMC to the verification of C++ programs but with limited success – handle large programs and support complex features • problem: BMC of C++ programs presents greater challenges than that of C programs – more complex features such as templates , containers , – more complex features such as templates , containers , and exception handling (contains and handles error situations in embedded systems) • main insights: – optimized implementation of the standard C++ library complicates the VCs unnecessarily – abstract representation of the standard C++ libraries to conservatively approximate their semantics

  4. Objetive of this work Extend BMC to support complex features of C++ • exploit background theories of Satisfability Modulo Theories (SMT) solvers • provide suitable encodings for – template – template – exception handling – exception handling – containers – arithmetic over- and underflow • build and evaluate an SMT-based BMC tool (ESBMC++) – build on top of CBMC front-end – use different SMT encodings as back-ends

  5. ESBMC Architecture (1) Goto C Goto C C Programs Solver Source Symex Parser Typecheck Converter C++ C++ C++ Source Parser Typecheck • originally only ANSI-C language was supported • extend to support the verification of C++ programs with: – template (creation and instantiation) – exception handling (converted to goto functions) – standart template library (operational model)

  6. ESBMC Architecture (2) Goto C C Goto C Programs Solver Parser Source Symex Typecheck Converter C++ C++ C++ Parser Source Typecheck • lexer/parser based on the flex/bison • most of the intermediate representation of the program (IRep) is created – this IRep is the base for the remaining phases of the verification

  7. ESBMC Architecture (3) Goto C C Goto C Programs Solver Typecheck Source Symex Parser Converter C++ C++ C++ Typecheck Source Parser • some checks are made in this step: – assignment check – typecast check – pointer initialization check – function call check – template instantiation

  8. ESBMC Architecture (4) Goto C Goto C C Programs Solver Source Symex Parser Typecheck Converter C++ C++ C++ Source Parser Typecheck • conversion from IRep to goto programs : int main () main() (c::main): { int x; int x=5; x = 5; if (x==5) IF !(x == 5) THEN GOTO 1 return 0; return 0; 1: return -1; return -1; } END_FUNCTION

  9. ESBMC Architecture (5) Goto Goto C C C Programs Solver Symex Source Parser Typecheck Converter C++ C++ C++ Source Parser Typecheck • creation of SSA expressions x = 5; from goto programs: x = 6; y = x; – assertions are inserted to check 0 0 for pointer safety, memory-leak, 0 division by zero, etc x 1 = 5; – jump instructions are inserted for x 2 = 6; exception handling y 1 = x 2 ;

  10. ESBMC Architecture (6) Goto C Goto C C Solver Programs Source Symex Parser Typecheck Converter C++ C++ C++ Source Parser Typecheck • encoding to bit-vector or integer/real arithmetic • verification results can depend on encodings: – majority of VCs solved faster if numeric types are modelled by abstract domains but possible loss of precision

  11. SMT-Based BMC of C++ Programs • there have been attempts to apply BMC to the verification of C++ programs but with limited success – handle large programs and support complex features • standard C++ libraries contain complex (and low-level) data structures (complicates the VCs unnecessarily) – provide a C++ operational model (COM) which is an – provide a C++ operational model (COM) which is an abstract representation of the standard C++ libraries that conservatively approximates their semantics executable g++ compiler file Standard Libraries of C++ C++ Programs verification ESBMC++ result COM

  12. Container Model (1) • the container model uses three variables: – P that points to the first element of the array – size that stores the quantity of elements in the container – capacity that stores the total capacity of a container • iterators are modelled using two variables ( source and pos ) container container e0 e1 e2 e3 ... eN-1 pos contains the index size = N value pointed by the iterator capacity < 2*size iterator in the container source pos P source points to the underlying container

  13. Container Model (2) • the core container model only supports the insert , erase , and search methods – push_back, pop_back, front, back, push_front ,and pop_front are variation of these basic methods decrement the size = = C c i c erase i (( ' , ' ) . ( )) : of the container of the container ∧ ∧ = = − − c c size size c c size size '. '. . . 1 1 ∧ = c array store store c array the exclusion is made '. (...( ( . , by a given position, + i pos select c array i pos . , ( . , . 1 )), regardless the value ..., − − c size select c array c size . 2 , ( . , . 1 )) ∧ = i source c '. ' points to the position next ∧ = i pos i pos '. . to the previously erased part of the container

  14. Inheritance and Polymorphism • polymorphism allows the creation of reusable code by changing only specific methods from the base class – in constrast to Java, C++ allows multiple inheritance which increase the complexity of the static analysis • in ESBMC++, each new class instantiation • in ESBMC++, each new class instantiation replicate all the methods and attributes from the base classes – this feature allows base classes pointers to keep reference to derived classes – during verification time decides which method is being called from such pointer

  15. Running Example (1) triple <C, ≺ s , ≺ r > where C is the set of classes • shared inheritance ≺ s ⊆ C x C – replicated inheritance ≺ r ⊆ C x C ≺ ⊆ – square class relation: <C, ∅ , {(Square, Rectangle, • Shape), (Square, Rectangle, Display)}> Shape), (Square, Rectangle, Display)}> – direct access to the attributes and methods of the derived class – replicate information to any new class

  16. Running Example (2) Square ( int w) : Rectangle (w,w) Square { width = w; } Shape *sqre = new Square(10); constructor and assert (sqre->area() == 100); area method int area( void ) { return width*width; } = = , ,   j j store store j j vtable vtable   ( ( , , Rectanle Rectanle ) ) 1 1 0 0   ∧ = j store j width ( , , 10 )   2 1   ∧ = j store j height ( , , 10 )  3 2  = ∧ = C j store j vtable :  ( , , Square)  4 3   ∧ = j store j width ( , , 10 )   5 4 ∧ = return value   _ 1   × select j width select j width   ( ( , ) ( , ) 5 5 = = P return value : [ _ 100 ] 1

  17. Running Example (2) Square ( int w) : Rectangle (w,w) Instantiation of { width = w; } Shape *sqre = new Square(10); square and area assert (sqre->area() == 100); call int area( void ) { return width*width; } = = , ,   j j store store j j vtable vtable   ( ( , , Rectanle Rectanle ) ) 1 1 0 0   ∧ = j store j width ( , , 10 )   2 1   ∧ = j store j height ( , , 10 )  3 2  = ∧ = C j store j vtable :  ( , , Square)  4 3   ∧ = j store j width ( , , 10 )   5 4 ∧ = return value   _ 1   × select j width select j width   ( ( , ) ( , ) 5 5 = = P return value : [ _ 100 ] 1

  18. Running Example (2) Square ( int w) : Rectangle (w,w) { width = w; } Shape *sqre = new Square(10); assert (sqre->area() == 100); Internal SMT int area( void ) { return width*width; } representation = = , ,   j j store store j j vtable vtable   ( ( , , Rectanle Rectanle ) ) 1 1 0 0   ∧ = j store j width ( , , 10 )   2 1   ∧ = j store j height ( , , 10 )  3 2  = ∧ = C j store j vtable :  ( , , Square)  4 3   ∧ = j store j width ( , , 10 )   5 4 ∧ = return value   _ 1   × select j width select j width   ( ( , ) ( , ) 5 5 = = P return value : [ _ 100 ] 1

Recommend


More recommend