Top Banner
DAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and Shaz Qadeer Microsoft Research In: Programming Language Design and Implementation (PLDI) 2015
39

DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Feb 07, 2018

Download

Documents

buitram
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

DAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in

Hierarchical Programs

Akash Lal and Shaz Qadeer

Microsoft Research

In: Programming Language Design and Implementation (PLDI) 2015

Page 2: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Bug Finding via Bounded Verification

• Several success stories of automated verification • Static Driver Verifier, F-Soft, Facebook Infer, …

• In finding bugs!

• Design for finding bugs quickly • Instead of discovering them as a by-product of proof failure

• Bounded verification: analyze a (useful) subset of program behaviors really fast

Page 3: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Bounded Verification

• Build efficient decision procedures for Bounded Verification • Inspired by the success in Hardware verification

SV-COMP 2015

Static Driver Verifier uses Corral [FSE’14]

Page 4: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Bounded Verification done previously

• Standard approach: Inline all procedures, generate a SAT/SMT constraint, invoke solver

• Procedure Inlining causes exponential blowup

Program + Bound

Single Proc. Program

Inline VC-Gen SMT Formula

Page 5: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Our Work: DAG Inlining

P0

P1

P2

Program Call Graph

Exponentially Blowup in Program Size

Potentially Exponential Savings!

Standard Procedure Inlining

P0

P1

P2

2i copies of Pi

P1

P2 P2 P2

DAG Inlining

P0

P1

P2

DAG structure program dependent

P1

P2

Page 6: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Micro Benchmark

0.1

1

10

100

1000

4 6 8 10 12 14 16

Tim

e (

seco

nd

s)

N

CBMC Corral DI

var g: int; procedure main() { g := 0; if(*) { call P0(); } else { call P0(); } } procedure Pi() { g := g + 1; if(*) { call Pi+1(); } else { call Pi+1(); } } procedure PN() { assert g == N; }

Page 7: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Talk Outline

• Problem definition

• VC Generation Algorithms [Background] • Single-procedure programs

• Multi-procedure programs

• DAG Inlining Algorithm

• Evaluation

Page 8: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Definitions

• Hierarchical Programs: Sequential programs without loops and recursion

• Reachability Modulo Theories (RMT): Find a terminating execution of a program whose operational semantics can be encoded in decidable logic.

Page 9: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Programming Language // variables var x: T // functions func f: T T // commands x := expr assume expr call foo(x);

SMT

// procedures procedure foo(args) { LocalDecls; Body; } // control if(expr) { cmds; } else { cmds; } while(*) { cmds; } Example:

Linear arithmetic via the theory of linear arithmetic (LIA) Non-linear arithmetic via uninterpreted functions (EUF) Memory lookup using theory of arrays Floating-point as uninterpreted

Page 10: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Reachability Modulo Theories

• Finding assertion failures is equivalent to finding terminating executions

assert e; err := e; if(!err) return;

call foo();

main() { … return; }

call foo(); if(!err) return;

main() { err := true; … assume !err; return; }

Page 11: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Reachability Modulo Theories

• RMT in hierarchical programs is decidable (NEXPTIME hard) [RP’13] • Can’t hide all sorts of complexity behind undecidability

• Direct application to bounded verification • E.g., “Bounded Model Checking”

• Relevant to unbounded verification • Checking inductive proofs (loop invariants) without pre-post conditions

Page 12: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Talk Outline

• Problem definition

• VC Generation Algorithms Solving RMT in Hierarchical programs • Single-procedure programs

• Multi-procedure programs

• DAG Inlining Algorithm

• Evaluation

Page 13: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation: Single Procedure

VC-Gen: f f(w, x, y)

Theorem: f(w, x, y, z) holds iff f(w) can return (x,y)

procedure f(w: int) returns (x: int, y: int) { start: x := *; y := x + w; goto l1, l2; l1: x := x + 1; goto l3; l2: x := x + 2; goto l3; l3: assume !(x > y); return; }

Corollary: f is SAT iff f has a terminating execution

Page 14: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation procedure f(w: int) returns (x: int, y: int) { start: x := *; y := x + w; goto l1, l2; l1: x := x + 1; goto l3; l2: x := x + 2; goto l3; l3: assume !(x > y); return; }

procedure f(w: int) returns (x: int, y: int) { start: x1 := *; y1 := x1 + w; goto l1, l2; l1: x2 := x1 + 1; goto l3; l2: x3 := x1 + 2; goto l3; l3: x4 := 𝜙(x2, x3); assume !(x4 > y1); x := x4; y := y1; return; }

SSA

Page 15: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation procedure f(w: int) returns (x: int, y: int) { start: x := *; y := x + w; goto l1, l2; l1: x := x + 1; goto l3; l2: x := x + 2; goto l3; l3: assume !(x > y); return; }

procedure f(w: int) returns (x: int, y: int) { start: x1 := *; y1 := x1 + w; goto l1, l2; l1: x2 := x1 + 1; x4 := x2; goto l3; l2: x3 := x1 + 2; x4 := x3; goto l3; l3: x4 := φ(x2, x3); assume !(x4 > y1); x := x4; y := y1; return; }

SSA

Page 16: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation procedure f(w: int) returns (x: int, y: int) { start: x := *; y := x + w; goto l1, l2; l1: x := x + 1; goto l3; l2: x := x + 2; goto l3; l3: assume !(x > y); return; }

procedure f(w: int) returns (x: int, y: int) { start: assume y1 == x1 + w; goto l1, l2; l1: assume x2 == x1 + 1; assume x4 == x2; goto l3; l2: assume x3 == x1 + 2; assume x4 == x3; goto l3; l3: assume !(x4 > y1); assume x == x4; assume y == y1; return; }

SSA+Passify

Page 17: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation procedure f(w: int) returns (x: int, y: int) { start: assume y1 == x1 + w; goto l1, l2; l1: assume x2 == x1 + 1; assume x4 == x2; goto l3; l2: assume x3 == x1 + 2; assume x4 == x3; goto l3; l3: assume !(x4 > y1); assume x == x4; assume y == y1; return; }

Cstart: 𝑦1 == 𝑥1 + 𝑤 Cl1: 𝑥2 == 𝑥1 + 1 ∧ 𝑥4 == 𝑥2 Cl2: 𝑥3 == 𝑥1 + 2 ∧ 𝑥4 == 𝑥3 Cl3: ¬ 𝑥4 > 𝑦1 ∧ 𝑥 == 𝑥4 ∧ 𝑦 == 𝑦1

Block constraints

Page 18: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation procedure f(w: int) returns (x: int, y: int) { start: assume y1 == x1 + w; goto l1, l2; l1: assume x2 == x1 + 1; assume x4 == x2; goto l3; l2: assume x3 == x1 + 2; assume x4 == x3; goto l3; l3: assume !(x4 > y1); assume x == x4; assume y == y1; return; }

1. Introduce Boolean constant bL for each block L 2. EL is 𝑏𝐿 == 𝐶𝐿 if L ends in return 𝑏𝐿 == 𝐶𝐿 ∧ ∨𝑚∈𝑆𝑢𝑐𝑐 𝐿 𝑏𝑚

3. VC(f) is 𝑏𝑠𝑡𝑎𝑟𝑡 ∧ ( ∧𝐿∈𝐵𝑙𝑜𝑐𝑘𝑠 𝑓 𝐸𝐿 )

Algorithm

Block constraints

Estart: bstart == 𝑦1 == 𝑥1 + 𝑤 ∧ (𝑏𝑙1 ∨ 𝑏𝑙2) El1: bl1 == 𝑥2 == 𝑥1 + 1 ∧ 𝑥4 == 𝑥2 ∧ 𝑏𝑙3 El2: bl2 == 𝑥3 == 𝑥1 + 2 ∧ 𝑥4 == 𝑥3 ∧ 𝑏𝑙3 El3: bl3 == ¬ 𝑥4 > 𝑦1 ∧ 𝑥 == 𝑥4 ∧ 𝑦 == 𝑦1

Page 19: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation: Multiple Procedures procedure f(v1: int, v2: int) returns (r: int) { var c: bool; goto l1, l2; l1: assume c; call r := g(v1); goto l3; l2: assume !c; call r := g(v2); goto l3; l3: return; }

procedure g(a: int) returns (b: int) { b := a + 1; }

Page 20: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation: Multiple Procedures procedure f(v1: int, v2: int) returns (r: int) { var c: bool; goto l1, l2; l1: assume c; call r := g(v1); assume M0; goto l3; l2: assume !c; call r := g(v2); assume M1; goto l3; l3: return; }

procedure g(a: int) returns (b: int) { b := a + 1; }

1. Introduce Boolean constant 𝑀𝑖 for each call

Algorithm

VC(f): 𝑐 ∧ 𝑀0 ∨ ¬𝑐 ∧ 𝑀1 VC(g): 𝑏 == 𝑎 + 1

Page 21: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation: Multiple Procedures procedure f(v1: int, v2: int) returns (r: int) { var c: bool; goto l1, l2; l1: assume c; call r := g(v1); assume M0; goto l3; l2: assume !c; call r := g(v2); assume M1; goto l3; l3: return; }

procedure g(a: int) returns (b: int) { b := a + 1; }

1. Introduce Boolean constant 𝑀𝑖 for each call 2. Introduce Boolean constant 𝑁𝑖 for each procedure

instance 3. Connect

Algorithm

𝑁0 Execution starts in f ∧ 𝑁0 ⇒ 𝑐 ∧ 𝑀0 ∨ ¬𝑐 ∧ 𝑀1 VC of f ∧ 𝑀0 ⇒ 𝑁1 ∧ 𝑣1 == 𝑎1 ∧ 𝑟 == 𝑏1 formals equals actuals ∧ 𝑀1 ⇒ 𝑁2 ∧ 𝑣2 == 𝑎2 ∧ 𝑟 == 𝑏2 formals equals actuals ∧ 𝑁1 ⇒ 𝑏1 == 𝑎1 + 1 VC of g ∧ 𝑁2 ⇒ (𝑏2 == 𝑎2 + 1) VC of g

Page 22: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

VC Generation: Multiple Procedures procedure f(v1: int, v2: int) returns (r: int) { var c: bool; goto l1, l2; l1: assume c; call r := g(v1); assume M0; goto l3; l2: assume !c; call r := g(v2); assume M1; goto l3; l3: return; }

procedure g(a: int) returns (b: int) { b := a + 1; }

1. Introduce Boolean constant 𝑀𝑖 for each call 2. Introduce Boolean constant 𝑁𝑖 for each procedure

instance 3. Connect

Algorithm

f

g g

Page 23: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

DAG Inlining: Algorithm

• Dynamic Procedure Instances: A procedure qualified by its call stack

procedure main() { if(…) { A: bar(); } else { B: baz(); } }

procedure baz() { C: foo(); }

procedure bar() { D: foo(); }

[A; C; foo] [B; D; foo]

• Disjoint instances: Two procedure instances that cannot be taken on the same execution

Page 24: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

DAG Inlining: Algorithm • Theorem: Any two disjoint instances of the same procedure can be

merged together when inlining.

Page 25: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

DAG Inlining: Algorithm procedure f(v1: int, v2: int) returns (r: int) { var c: bool; goto l1, l2; l1: assume c; call r := g(v1); goto l3; l2: assume !c; call r := g(v2); goto l3; l3: return; }

Standard (Tree) Inlining

DAG Inlining

f

g g

f

g

Page 26: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

DAG Inlining: Algorithm procedure f(v1: int, v2: int) returns (r: int) { var c: bool; goto l1, l2; l1: assume c; call r := g(v1); goto l3; l2: assume !c; call r := g(v2); goto l3; l3: return; }

𝑁0 Execution starts in f ∧ 𝑁0 ⇒ 𝑐 ∧ 𝑀0 ∨ ¬𝑐 ∧ 𝑀1 VC of f ∧ 𝑀0 ⇒ 𝑁1 ∧ 𝑣1 == 𝑎1 ∧ 𝑟 == 𝑏1 formals equals actuals ∧ 𝑀1 ⇒ 𝑁2 ∧ 𝑣2 == 𝑎2 ∧ 𝑟 == 𝑏2 formals equals actuals ∧ 𝑁1 ⇒ 𝑏1 == 𝑎1 + 1 VC of g ∧ 𝑁2 ⇒ (𝑏2 == 𝑎2 + 1) VC of g

𝑁0 Execution starts in f ∧ 𝑁0 ⇒ 𝑐 ∧ 𝑀0 ∨ ¬𝑐 ∧ 𝑀1 VC of f ∧ 𝑀0 ⇒ 𝑁1 ∧ 𝑣1 == 𝑎1 ∧ 𝑟 == 𝑏1 formals equals actuals ∧ 𝑀1 ⇒ 𝑁1 ∧ 𝑣2 == 𝑎1 ∧ 𝑟 == 𝑏1 formals equals actuals ∧ 𝑁1 ⇒ 𝑏1 == 𝑎1 + 1 VC of g

Standard (Tree) Inlining

DAG Inlining

𝑐 ⇒ 𝑟 == 𝑣1 + 1 ∧ ¬𝑐 ⇒ (𝑟 == 𝑣2 + 1 )

Page 27: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

bar baz

foo foo

DAG Inlining: Algorithm

main

bar baz

foo foo

Disjoint([main; bar; foo], [main, baz, foo])

Disjoint(…) Disjoint(…)

DAG Consistency: For each node n, all configurations represented by n should be mutually disjoint

Algorithm: While inlining, keep merging with existing instances as long as the DAG is consistent

Page 28: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Optimal merging reduces to Graph Coloring

Entry

A: foo(); B: foo();

C: foo(); D: foo();

Exit

C A

B D

A

BC

D

AB CD

Control-Flow Graph

Conflict Graph: Edge not disjoint

Optimal merging requires computation of maximal independent sets, which is equivalent to graph

coloring

main

foo foo foo foo

A B C D

main

foo foo foo

A D B C

main

foo foo

A B

D C

C A

B D

Page 29: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Implementing the Algorithm • We can decide disjointness in linear time based on control flow

[A1; A2; A3; A4; foo]

[A1; A2; B1; B2; B3; B4; foo]

longest common prefix

These calls should not appear on the same path in the CFG of Proc(A2)

• Disjointness of procedure instances can be resolved by disjointness in a single CFG.

Page 30: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Implementing the Algorithm [See Paper]

• Disjointness of two configurations in linear time

• Deciding DAG consistency in quadratic time

• Greedy graph coloring (8% off the optimal)

• Overall: Less than 0.4% time spent in DAG operations

Page 31: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Experiments: Static Driver Verifier

• Commercial tool, ships with Windows • Used internally and by third-party driver developers • Part of Windows Driver Certification program

• Uses Corral, an RMT solver • Based on Tree Inlining, but: • Includes several optimizations over tree inlining

• Total LOC: 800K

• Total verification time: well over a month

Page 32: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Compression in Practice

• Tree/DAG Sizes

10

100

1,000

10,000

100,000

1,000,000

10,000,000

0 50 100 150 200 250

Nu

mb

er

of

pro

ed

ure

s in

line

d

Benchmarks

Tree DAG

Page 33: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Compression strategy • We use a greedy merging strategy: turns out to be around 8% off the

optimal in practice

Page 34: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Results: Summary

• Find more bugs in less time

• Almost twice as fast as the production system

Production Quality

Tree-2

DAG-2

Tree-1

DAG-1

Page 35: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Results - 1

0

200

400

600

800

1000

1200

1400

1600

1800

2000

0 500 1000 1500 2000

DI-

Inv

(se

con

ds)

SI-Inv (seconds)

• Number of instances: 619

• Reduction in Timeouts: 64

• 5X speedup: 35

• 5X slowdown: 2

Page 36: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Results - 2

0

200

400

600

800

1000

1200

1400

1600

1800

2000

0 200 400 600 800 1000 1200 1400 1600 1800 2000

DI+

Inv

(se

c)

SI+Inv (sec)

• Number of instances: 619

• Reduction in Timeouts: 78

• 5X speedup: 45

• 5X slowdown: 1

Page 37: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Before the last slide …

Page 38: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Microsoft Research India We are hiring!

Researchers, post-docs & engineers

Systems, ML, Crypto, Theory, PL, HCI, ICT4D,…

Page 39: DAG Inlining: A Decision Procedure for Reachability-Modulo ... · PDF fileDAG Inlining: A Decision Procedure for Reachability-Modulo-Theories in Hierarchical Programs Akash Lal and

Summary

• Reachability in Hierarchical Programs is fundamental

• Standard (Tree) inlining causes exponential blowup • Limits many BMC tools to small programs

• DAG inlining refines the age-old idea of procedure inlining • Demonstrated significant speedups of a production system