predicate abstraction for software and hardware verification

43
Predicate Abstraction for Software and Predicate Abstraction for Software and Hardware Verification Hardware Verification Himanshu Jain Himanshu Jain Model checking seminar Model checking seminar April 22, 2005 April 22, 2005

Upload: flo

Post on 17-Jan-2016

50 views

Category:

Documents


0 download

DESCRIPTION

Predicate Abstraction for Software and Hardware Verification. Himanshu Jain Model checking seminar April 22, 2005. Introduction. Scalable software verification Properties Array bounds check, division by zero Pointer safety Assertion checking Lock and unlocking - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Predicate Abstraction for Software and Hardware Verification

Predicate Abstraction for Software and Hardware VerificationPredicate Abstraction for Software and Hardware Verification

Himanshu JainHimanshu Jain

Model checking seminarModel checking seminarApril 22, 2005April 22, 2005

Page 2: Predicate Abstraction for Software and Hardware Verification

Introduction

Scalable software verification

Properties Array bounds check, division by zero Pointer safety Assertion checking Lock and unlocking

Focus on partial specifications

Page 3: Predicate Abstraction for Software and Hardware Verification

Predicate Abstraction

Extract a finite state model from an infinite state system

Used to prove assertions or safety properties

Successfully applied for verification of C programs SLAM (used in windows device driver verification) MAGIC, BLAST, F-Soft

Page 4: Predicate Abstraction for Software and Hardware Verification

Example for Predicate Abstraction

int main() { int i;

i=0;

while(even(i)) i++;}

int main() { int i;

i=0;

while(even(i)) i++;}

+ p1 i=0p2 even(i)

p1 i=0p2 even(i) =

void main() { bool p1, p2;

p1=TRUE; p2=TRUE;

while(p2) { p1=p1?FALSE:nondet(); p2=!p2; }}

void main() { bool p1, p2;

p1=TRUE; p2=TRUE;

while(p2) { p1=p1?FALSE:nondet(); p2=!p2; }}

PredicatesC program Boolean program

[Ball, Rajamani ’01]

[Graf, Saidi ’97]

Page 5: Predicate Abstraction for Software and Hardware Verification

Computing Predicate Abstraction

How to get predicates for checking a given property?

How do we compute the abstraction?

Predicate Abstraction is an over-approximation

How to refine coarse abstractions

Page 6: Predicate Abstraction for Software and Hardware Verification

Counterexample Guided Abstraction Refinement loop

CProgram

CProgram

Abstract model

Abstract model

ModelChecker

Abstraction refinement

VerificationInitial

AbstractionNo error

or bug found

Simulator

Propertyholds

Simulationsucessful

Bug found

Refinement

Spurious counterexample

Page 7: Predicate Abstraction for Software and Hardware Verification

Abstraction

1: x = ctr;

2: y = ctr + 1;

3: if (x = i-1){

4: if (y != i){

ERROR: }

}

1: skip;

2: skip;

3: if (*){

4: if (*){

ERROR: }

}

Abstract

C program No predicates available currently

Page 8: Predicate Abstraction for Software and Hardware Verification

Checking the abstract model

1: skip;

2: skip;

3: if (*){

4: if (*){

ERROR: }

}

Abstract model has a path leading to error state

Is ERROR reachable?

yes

Page 9: Predicate Abstraction for Software and Hardware Verification

Simulation

1: x = ctr;

2: y = ctr + 1;

3: assume(x == i-1)

4: assume (y != i)

1: skip;

2: skip;

3: if (*){

4: if (*){

ERROR: }

}

Does this correspond to a

real bug?

Not possible

Concrete traceCheck using a SAT solver

Page 10: Predicate Abstraction for Software and Hardware Verification

Refinement

1: x = ctr;

2: y = ctr + 1;

3: assume(x == i-1)

4: assume (y != i)

1: skip;

2: skip;

3: if (*){

4: if (*){

ERROR: }

}

Spurious Counterexample Initial abstraction

Page 11: Predicate Abstraction for Software and Hardware Verification

Refinement

1: x = ctr;

2: y = ctr + 1;

3: assume(x == i-1)

4: assume (y != i)

1: skip;

2: skip;

3: if (*){

4: if (b0){

ERROR: }

}

boolean b0 : y != i

Page 12: Predicate Abstraction for Software and Hardware Verification

Refinement

1: x = ctr;

2: y = ctr + 1;

3: assume(x == i-1)

4: assume (y != i)

1: skip;

2: skip;

3: if (b1){

4: if (b0){

ERROR: }

}

boolean b0 : y != i

boolean b1 : x== i-1

Page 13: Predicate Abstraction for Software and Hardware Verification

Refinement

1: x = ctr;

2: y = ctr + 1;

3: assume(x == i-1)

4: assume (y != i)

1: skip;

2: b0 = b2;

3: if (b1){

4: if (b0){

ERROR: }

}

boolean b0 : y != i

boolean b1 : x== i-1

boolean b2 : ctr + 1 ! = iWeakest precondition of y != i

Page 14: Predicate Abstraction for Software and Hardware Verification

Refinement

1: x = ctr;

2: y = ctr + 1;

3: assume(x == i-1)

4: assume (y != i)

1: b1 = b3;

2: b0 = b2;

3: if (b1){

4: if (b0){

ERROR: }

}

boolean b0 : y != i

boolean b1 : x== i-1

boolean b2 : ctr + 1 ! = i

boolean b3: ctr == i -1

Page 15: Predicate Abstraction for Software and Hardware Verification

Refinement

1: b1 = b3;

2: b0 = b2;

3: if (b1){

4: if (b0){

ERROR: }

}

boolean b0 : y != i

boolean b1 : x== i-1

boolean b2 : ctr + 1 ! = i

boolean b3: ctr == i -1

b2 and b3 are mutually

exclusive.

b2 =1, b3 = 0

b2 =0 , b3 = 1

What about initial values of b2 and b3?

So system is safe!

Page 16: Predicate Abstraction for Software and Hardware Verification

Tools for Predicate Abstraction of C

SLAM at Microsoft Used for verifying correct sequencing of function calls in windows

device drivers

MAGIC at CMU Allows verification of concurrent C programs Found bugs in MicroC OS

BLAST at Berkeley Lazy abstraction, interpolation

SATABS at CMU Computes predicate abstraction using SAT Can handle pointer arithmetic, bit-vectors

F-Soft at NEC Labs Localization, register sharing

Page 17: Predicate Abstraction for Software and Hardware Verification

Applications of Predicate Abstraction inHardware Verification

Page 18: Predicate Abstraction for Software and Hardware Verification

System on chip design

Increase in complexity

Gate level (netlists)

Structural

Behavioral/RTL

…………

Level Number of components

10E7

10E5

10E3

10E0

Ab

stra

ctio

n

System Level

Page 19: Predicate Abstraction for Software and Hardware Verification

Introduction

Emergence of system design languages

HardwareC, SpecC, Handel-C, and SystemC

Based on C / C++

Allows joint modeling of both hardware and software components of a system

Support for bit vectors, concurrency, synchronization, exception handling, timing

Page 20: Predicate Abstraction for Software and Hardware Verification

Verification support

Most model-checkers used in hardware industry work at netlist level

Higher abstraction levels offered by languages like SpecC or RTL Verilog are not yet supported

Languages like SpecC are more closer to concurrent software

Verification tools must reason about: Programming languages constructs Concurrency Pointers, Objects Bit vector operations like concatenation, extraction

Page 21: Predicate Abstraction for Software and Hardware Verification

Why predicate abstraction

Many properties depend on relationship between registers, and not the values stored in them

Predicate Abstraction Keeps tracks of certain predicates on data Successfully used in software verification

Can handle larger designs

Page 22: Predicate Abstraction for Software and Hardware Verification

Abstraction-Refinement loopAbstraction-Refinement loop

VerilogProgramVerilog

ProgramAbstract model

Abstract model

ModelChecker

Abstraction refinement

VerificationInitial

AbstractionNo error

or bug found

Simulator

Propertyholds

Simulationsucessful

Bug found

Refinement

Spurious counterexample

Page 23: Predicate Abstraction for Software and Hardware Verification

An exampleAn example

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Property:

AG (x = 100 or x = 200)

Verilog program

Page 24: Predicate Abstraction for Software and Hardware Verification

Abstraction-Refinement loopAbstraction-Refinement loop

VerilogProgramVerilog

ProgramAbstract model

Abstract model

ModelChecker

Abstraction refinement

VerificationInitial

AbstractionNo error

or bug found

Simulator

Propertyholds

Simulationsucessful

Bug found

Refinement

Spurious counterexample

Page 25: Predicate Abstraction for Software and Hardware Verification

Predicate AbstractionPredicate Abstraction

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Property:

AG (x = 100 or x = 200)

Initial set of predicates:

{x = 100, x = 200}

Verilog program Word level predicates

Page 26: Predicate Abstraction for Software and Hardware Verification

Computing Most Precise AbstractionComputing Most Precise Abstraction

<x = 100, x = 200> + x’ = yy’ = x

+ <x’ = 100, x’ = 200>

Current state Next state

Equation passed to the SAT solver

Transition Relation

Computing abstract transitions

Page 27: Predicate Abstraction for Software and Hardware Verification

Obtain transitionsObtain transitions

Computing abstract transitions

10 00

01 11 … … and so on …and so on …

Page 28: Predicate Abstraction for Software and Hardware Verification

Abstract ModelAbstract Model

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Property: AG (x = 100 or x = 200)

Initial set of predicates:{x = 100, x = 200}

Verilog program

Initial state

Failure state10 00

01 11

Page 29: Predicate Abstraction for Software and Hardware Verification

Abstraction-Refinement loopAbstraction-Refinement loop

VerilogProgramVerilog

ProgramAbstract model

Abstract model

ModelChecker

Abstraction refinement

VerificationInitial

AbstractionNo error

or bug found

Simulator

Propertyholds

Simulationsucessful

Bug found

Refinement

Spurious counterexample

Page 30: Predicate Abstraction for Software and Hardware Verification

Model checking Model checking

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Verilog program

Failure state

10 00

01 11

Initial state

Abstract Model

Page 31: Predicate Abstraction for Software and Hardware Verification

Model checking Model checking

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Verilog program

Failure state

10 00

01 11

Initial state

Abstract Model

Counterexample

Page 32: Predicate Abstraction for Software and Hardware Verification

Abstraction-Refinement loopAbstraction-Refinement loop

VerilogProgramVerilog

ProgramAbstract model

Abstract model

ModelChecker

Abstraction refinement

VerificationInitial

AbstractionNo error

or bug found

Simulator

Propertyholds

Simulationsucessful

Bug found

Refinement

Spurious counterexample

Page 33: Predicate Abstraction for Software and Hardware Verification

Counterexample in the abstract model Counterexample in the abstract model <1 , 0> <1 , 0> <0 , 0> (length = 1)<0 , 0> (length = 1)

Each state is a valuation of Each state is a valuation of hh x = 100, x=200 x = 100, x=200 ii

Simulation equation

Simulation of the counterexampleSimulation of the counterexample

Initial values of the registerspredicate values

in the first state of the counterexample

Transition relation

predicate valuesin the second state of the counterexample

equation is unsatisfiable So counterexample is spurious

Page 34: Predicate Abstraction for Software and Hardware Verification

Abstraction-Refinement loopAbstraction-Refinement loop

VerilogProgramVerilog

ProgramAbstract model

Abstract model

ModelChecker

Abstraction refinement

VerificationInitial

AbstractionNo error

or bug found

Simulator

Propertyholds

Simulationsucessful

Bug found

Refinement

Spurious counterexample

Page 35: Predicate Abstraction for Software and Hardware Verification

RefinementRefinement

Let length of spurious counterexample be Let length of spurious counterexample be kk

Take Take weakest pre-condition of propertyweakest pre-condition of property for k steps with respect for k steps with respect

to transition functionsto transition functions

Pick atomic predicates from weakest preconditionPick atomic predicates from weakest precondition

Page 36: Predicate Abstraction for Software and Hardware Verification

RefinementRefinement

(x’ = 100 Ç x’ = 200)Holds after one step

x’ = yy’ = x

(y = 100 Ç y = 200)weakest precondition

x’ = yy’ = x

AG (x = 100 Ç x = 200)+

Transition functions

Property

length =1+

spurious counterexampleNew predicates

y = 100, y = 200

Page 37: Predicate Abstraction for Software and Hardware Verification

Abstract againAbstract again

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Property: AG (x = 100 or x = 200)

Updated set of predicates:{x = 100, x = 200, y=100, y=200}

Verilog program

1001 0110Initialstate

Model check

New abstraction

Page 38: Predicate Abstraction for Software and Hardware Verification

Model checkingModel checking

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Property: AG (x = 100 or x = 200)

Updated set of predicates:{x = 100, x = 200, y=100, y=200}

Verilog program

1001 0110Initialstate

Property holds!

New abstraction

Page 39: Predicate Abstraction for Software and Hardware Verification

Result Result

module main (clk)input clk;reg [10:0] x, y;

initial x= 100, y= 200;

always @ (posedge clk)begin x <= y; y <= x;endendmodule

Property: AG (x = 100 or x = 200)

Verilog program

Property holds!

Page 40: Predicate Abstraction for Software and Hardware Verification

Experimental results (VIS benchmarks)Experimental results (VIS benchmarks)

BenchmarkBenchmark Lines of Lines of

codecode

#Latches#Latches #Variables#Variables Veracity Veracity

Time Time

#Predicates#Predicates #Iteration#Iteration

cachecache

coherencecoherence

549549 4343 170170 49s49s 2525 99

mpegmpeg

decoder 1decoder 1

12151215 567567 800800 29s29s 99 33

mpegmpeg

decoder 2decoder 2

12151215 567567 800800 47s47s 99 44

SDLXSDLX 898898 4141 8181 139s139s 4343 3030

MiimMiim 841841 8383 237237 0.57s0.57s** 44 22

PI-BusPI-Bus 10201020 312312 863863 2.42s2.42s** 1010 11

* Using lazy abstraction All use predicate partitioning

Page 41: Predicate Abstraction for Software and Hardware Verification

Bigger benchmarksBigger benchmarks

BenchmarkBenchmark #Latches#Latches Veracity timeVeracity time Cadence SMV timeCadence SMV time

ICUICU 2828 1.3s1.3s 0.1s0.1s

ICRAM2KBICRAM2KB 1642716427 450.7s450.7s 25s25s

ICRAM4KBICRAM4KB 3279632796 843.3s843.3s terminatesterminates

ARITH100ARITH100 202202 3.5s3.5s 182.4s182.4s

ARITH200ARITH200 402402 9.6s9.6s 2147s2147s

ARITH500ARITH500 10021002 32.2s32.2s timeouttimeout

ARITH1000ARITH1000 20022002 122.6s122.6s timeouttimeout

Page 42: Predicate Abstraction for Software and Hardware Verification

ToolsTools

VCEGARVCEGAR (Verilog Counterexample Guided Abstraction (Verilog Counterexample Guided Abstraction

Refinement) at CMURefinement) at CMUwww.cs.cmu.edu/~modelcheck/vcegarwww.cs.cmu.edu/~modelcheck/vcegar

Page 43: Predicate Abstraction for Software and Hardware Verification

QuestionsQuestions