Learning Loop Invariants for Program Verification Xujie Si*, Hanjun - - PowerPoint PPT Presentation

learning loop invariants for program verification
SMART_READER_LITE
LIVE PREVIEW

Learning Loop Invariants for Program Verification Xujie Si*, Hanjun - - PowerPoint PPT Presentation

Learning Loop Invariants for Program Verification Xujie Si*, Hanjun Dai*, Mukund Raghothaman, Mayur Naik, Le Song University of Pennsylvania Georgia Institute of Technology NeurIPS 2018 Code: https://github.com/PL-ML/code2inv * equal


slide-1
SLIDE 1

Learning Loop Invariants for Program Verification

Xujie Si*, Hanjun Dai*, Mukund Raghothaman, Mayur Naik, Le Song University of Pennsylvania Georgia Institute of Technology NeurIPS 2018 Code: https://github.com/PL-ML/code2inv

* equal contribution

slide-2
SLIDE 2

Program verification

  • Prove whether your code is bug-free
slide-3
SLIDE 3

Program verification

  • Prove whether your code is bug-free
  • - Some of rules can be automated:

sequence rule, conditional rule, ......

slide-4
SLIDE 4

Program verification

  • Prove whether your code is bug-free

Loop Invariant <> Halting Problem

  • - Some of rules can be automated:
  • - Except ‘while rule’

sequence rule, conditional rule, ......

slide-5
SLIDE 5

What is loop invariant?

slide-6
SLIDE 6

What is loop invariant?

Program

slide-7
SLIDE 7

What is loop invariant?

Program Loop Invariant

slide-8
SLIDE 8

What is loop invariant?

Program Loop Invariant Requirement:

slide-9
SLIDE 9

Loop Invariant Checker

slide-10
SLIDE 10

Loop Invariant Checker

slide-11
SLIDE 11

Loop Invariant Checker

slide-12
SLIDE 12

Difficulties of learning loop Invariant

  • 1. Highly sparse and non-smooth reward

code

slide-13
SLIDE 13

Difficulties of learning loop Invariant

  • 1. Highly sparse and non-smooth reward

Agent

code

slide-14
SLIDE 14

Difficulties of learning loop Invariant

  • 1. Highly sparse and non-smooth reward

Agent

code

slide-15
SLIDE 15

Difficulties of learning loop Invariant

  • 1. Highly sparse and non-smooth reward

Agent 0 / 1 (Correct or not)

code

slide-16
SLIDE 16

Difficulties of learning loop invariant

  • 2. Generalization ability

Agent 0 / 1 (Correct or not) code1

......

Agent 0 / 1 (Correct or not) codeN

! ≥ 1 ⋁ % = 0

Agent 0 / 1 (Correct or not) code2

() ≤ 2 ⋀ (- > 0

slide-17
SLIDE 17

Difficulties of learning loop invariant

  • 2. Generalization ability

Agent 0 / 1 (Correct or not) code1

......

Agent 0 / 1 (Correct or not) codeN

! ≥ 1 ⋁ % = 0

Agent 0 / 1 (Correct or not) code2

() ≤ 2 ⋀ (- > 0

Agent New code =>

slide-18
SLIDE 18

Solution to sparsity and non-smoothness

Agent 0 (not correct)

code

slide-19
SLIDE 19

Solution to sparsity and non-smoothness

Agent 0 (not correct)

code

Counter-example: why am I wrong?

! = 1, % = −10

slide-20
SLIDE 20

Solution to sparsity and non-smoothness

Agent 0 (not correct)

code

Counter-example: why am I wrong?

! = 1, % = −10

Collection of counter-examples:

slide-21
SLIDE 21

Solution to sparsity and non-smoothness

Agent 0 (not correct)

code

Counter-example: why am I wrong?

! = 1, % = −10

! = 1, % = −1 ! = 0, % = −1 ! = 0, % = −2 ! = 2, % = −1 ! = 2, % = −1 ! = 2, % = −2 ! = 3, % = −1 ! = 3, % = −1 ! = 3, % = −2 ! = 0, % = −3 ! = 0, % = −4

Pre Inv Post Collection of counter-examples:

slide-22
SLIDE 22

Solution to sparsity and non-smoothness

Agent 0 (not correct)

code

Counter-example: why am I wrong?

! = 1, % = −10

! = 1, % = −1 ! = 0, % = −1 ! = 0, % = −2 ! = 2, % = −1 ! = 2, % = −1 ! = 2, % = −2 ! = 3, % = −1 ! = 3, % = −1 ! = 3, % = −2 ! = 0, % = −3 ! = 0, % = −4

Pre Inv Post Collection of counter-examples:

  • Smoothed reward
slide-23
SLIDE 23

Solution to sparsity and non-smoothness

Agent 0 (not correct)

code

Counter-example: why am I wrong?

! = 1, % = −10

! = 1, % = −1 ! = 0, % = −1 ! = 0, % = −2 ! = 2, % = −1 ! = 2, % = −1 ! = 2, % = −2 ! = 3, % = −1 ! = 3, % = −1 ! = 3, % = −2 ! = 0, % = −3 ! = 0, % = −4

Pre Inv Post Collection of counter-examples:

  • Smoothed reward
  • Reduced Z3 calls
slide-24
SLIDE 24

Solution to generalization

  • Transferable graph representation of source code

=> =>

SSA Transformation

slide-25
SLIDE 25

Code2Inv: End-to-end learning framework

......

! ≥ 0 && ! < 4 ' ≥ 100

slide-26
SLIDE 26

Experimental evaluation of Code2Inv

  • We collect 133 benchmark programs

OOPSLA 2013, Dillig et al POPL 2016, Garag et al

slide-27
SLIDE 27

Experimental evaluation of Code2Inv

  • We collect 133 benchmark programs

OOPSLA 2013, Dillig et al POPL 2016, Garag et al

slide-28
SLIDE 28

Code2Inv as an

  • ut-of-the-box

solver

Solved more instances with same # Z3 calls

Ours

slide-29
SLIDE 29

Generalize to new programs

void main (int n) { int x = 0 int m = 0 while (x < n) { if (unknown()) { m = x } x = x + 1 } if (n > 0) { assert (m < n) } }

slide-30
SLIDE 30

Generalize to new programs

void main (int n) { int x = 0 int m = 0 while (x < n) { if (unknown()) { m = x } x = x + 1 } if (n > 0) { assert (m < n) } } int w = 0 int z = 0

slide-31
SLIDE 31

Generalize to new programs

void main (int n) { int x = 0 int m = 0 while (x < n) { if (unknown()) { m = x } x = x + 1 } if (n > 0) { assert (m < n) } } int w = 0 int z = 0 z = z + 1 w = m + x z = m + 1

slide-32
SLIDE 32

Generalize to new programs

void main (int n) { int x = 0 int m = 0 while (x < n) { if (unknown()) { m = x } x = x + 1 } if (n > 0) { assert (m < n) } } void main (int n) { int x = 0 int w = 0 int m = 0 int z = 0 while (x < n) { z = z + 1 if (unknown()) { m = x z = m + 1 } x = x + 1 w = m + x } if (n > 0) { assert (m < n) } } int w = 0 int z = 0 z = z + 1 w = m + x z = m + 1

slide-33
SLIDE 33

Generalization ability of Code2Inv

1 confounding variable 3 confounding variables 5 confounding variables

slide-34
SLIDE 34

Poster session: Room 210 & 230 AB #23 05:00 -- 07:00 PM