Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task...

58
Path-based Inductive Synthesis for Program Inversion Saurabh Srivastava (a) Sumit Gulwani (b) Swarat Chaudhuri (c) Jeffrey S. Foster (d) (a) University of California, Berkeley (b) Microsoft Research, Redmond (c) Rice University (d) University of Maryland, College Park

Transcript of Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task...

Page 1: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Path-based Inductive Synthesis for Program Inversion

Saurabh Srivastava (a)

Sumit Gulwani (b)

Swarat Chaudhuri (c)

Jeffrey S. Foster (d)

(a) University of California, Berkeley(b) Microsoft Research, Redmond

(c) Rice University(d) University of Maryland, College Park

Page 2: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Program Inversion as Synthesis

• TaskGiven a program P, synthesis P-1 such that P-1(P(x)) = x

• Motivation: Many common program/inverse pairs• Compress/decompress, insert/delete, lossless encode/decode,

encrypt/decrypt, rollback, many more• Only having to write one increases productivity, reduces bugs

• Problem• Existing synthesis techniques not well-suited for inversion• Dedicated inversion techniques limited in scope

Page 3: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

PINS: Path-based Inductive Synthesis

• Specification• Program to be inverted• Template hints: Control flow, and expressions, predicates• Functional requirement: Program + Inverse = Identity

• Engine: SMT solver (Z3)

• Algorithm: Inspired by testing• Explore path through program + template• Ask engine for instantiations on path to match spec• Iterate, refining space

Page 4: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Small path-bound hypothesis

• Same hypothesis underlies program testing

• As in testing, two questions:1) Which paths?

• Especially since the template describes “set of programs”

2) How can we ensure the generated inverse is correct?• We check using: manual inspection, testing, bounded verification

“Program behavior can be summarized by examining a carefully

chosen, small, finite set of paths”

Page 5: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Example of templates

In-place run-length encoding:

A = [1,1,1,0,0,2,2,2,2]

A = [1,0,2]N = [3,2,4]

A’ = [1,1,1,0,0,2,2,2,2]

Page 6: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Example of templates

In-place run-length encoding:

A = [1,1,1,0,0,2,2,2,2]

A = [1,0,2]N = [3,2,4]

A’ = [1,1,1,0,0,2,2,2,2]

assume(n>=0);i, m := 0, 0; // parallel assignmentwhile (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Original encoder

Page 7: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Example of templates

In-place run-length encoding:

A = [1,1,1,0,0,2,2,2,2]

A = [1,0,2]N = [3,2,4]

A’ = [1,1,1,0,0,2,2,2,2]

assume(n>=0);i, m := 0, 0; // parallel assignmentwhile (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Original encoder

iʼ, mʼ := e1, e2; // ei ∈ Ewhile (p1) // pi ∈ P rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

Template decoder

Page 8: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Example of templates

In-place run-length encoding:

A = [1,1,1,0,0,2,2,2,2]

A = [1,0,2]N = [3,2,4]

A’ = [1,1,1,0,0,2,2,2,2]

assume(n>=0);i, m := 0, 0; // parallel assignmentwhile (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Original encoder

iʼ, mʼ := e1, e2; // ei ∈ Ewhile (p1) // pi ∈ P rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

Template decoder

E = {0, 1, mʼ+1, mʼ-1, rʼ+1, rʼ-1,

iʼ+1, iʼ-1, Aʼ[mʼ]:=A[iʼ], Aʼ[iʼ] := A[mʼ], N[mʼ]

}

Page 9: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Example of templates

In-place run-length encoding:

A = [1,1,1,0,0,2,2,2,2]

A = [1,0,2]N = [3,2,4]

A’ = [1,1,1,0,0,2,2,2,2]

assume(n>=0);i, m := 0, 0; // parallel assignmentwhile (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Original encoder

iʼ, mʼ := e1, e2; // ei ∈ Ewhile (p1) // pi ∈ P rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

Template decoder

P = { mʼ<m, rʼ>0, Aʼ[iʼ]=Aʼ[iʼ+1]}

E = {0, 1, mʼ+1, mʼ-1, rʼ+1, rʼ-1,

iʼ+1, iʼ-1, Aʼ[mʼ]:=A[iʼ], Aʼ[iʼ] := A[mʼ], N[mʼ]

}

Page 10: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Example of templates

In-place run-length encoding:

A = [1,1,1,0,0,2,2,2,2]

A = [1,0,2]N = [3,2,4]

A’ = [1,1,1,0,0,2,2,2,2]

assume(n>=0);i, m := 0, 0; // parallel assignmentwhile (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Original encoder

iʼ, mʼ := e1, e2; // ei ∈ Ewhile (p1) // pi ∈ P rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

Template decoder

P = { mʼ<m, rʼ>0, Aʼ[iʼ]=Aʼ[iʼ+1]}

E = {0, 1, mʼ+1, mʼ-1, rʼ+1, rʼ-1,

iʼ+1, iʼ-1, Aʼ[mʼ]:=A[iʼ], Aʼ[iʼ] := A[mʼ], N[mʼ]

}

Template control flow, expressions E, and predicates P, semi-automatically mined from

original

Page 11: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

Page 12: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

Page 13: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

(n>=0)i, m := 0, 0(i < n)

iʼ, mʼ := e1, e2(p1)

¬

¬

Page 14: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 15: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 16: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

(n>=0)i, m := 0, 0(i < n)

iʼ, mʼ := e1, e2(p1)

¬

(p1)¬

rʼ := e3(p2)¬ mʼ := e7

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 17: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 18: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 19: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

(n>=0)i, m := 0, 0(i < n)r := 1(i+1 < n && A[i] = A[i+1])A[m], N[m], m, i := A[i], r, m+1, i+1

iʼ, mʼ := e1, e2

(p1)

(i < n)

¬

¬

¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 20: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

assume(n>=0);i, m := 0, 0;while (i < n) r := 1; while (i+1 < n && A[i] = A[i+1]) r, i := r + 1, i+1; A[m], N[m], m, i := A[i], r, m+1, i+1;

Symbolic execution of program paths

iʼ, mʼ := e1, e2;while (p1) rʼ := e3; while (p2) rʼ, iʼ, Aʼ := e4, e5, e6; mʼ := e7;

(n>=0)i, m := 0, 0(i < n)r := 1(i+1 < n && A[i] = A[i+1])A[m], N[m], m, i := A[i], r, m+1, i+1

iʼ, mʼ := e1, e2

(p1)

(i < n)

¬

¬

¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 21: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Symbolic execution of program paths

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 22: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Solving using SMT and SAT

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

Page 23: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Solving using SMT and SAT

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

ϕ1(e1,e2,p1) ⇒ identity

Page 24: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Solving using SMT and SAT

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

ϕ1(e1,e2,p1) ⇒ identity ϕ2(e1,e2,p1,e3,e7,p2)

⇒ identity

Page 25: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Solving using SMT and SAT

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

ϕ1(e1,e2,p1) ⇒ identity

ϕ2(e1,e2,p1) ⇒ identity

ϕ2(e1,e2,p1,e3,e7,p2) ⇒ identity

Page 26: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Solving using SMT and SAT

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

ϕ1(e1,e2,p1) ⇒ identity

ϕ2(e1,e2,p1) ⇒ identity

ϕ2(e1,e2,p1,e3,e7,p2) ⇒ identity

∃ ei,pj∀program vars

Page 27: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Solving using SMT and SAT

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧r1 = 1 ∧(i1+1 < n0 && A[i1] = A[i1+1])A[m1]=A[i1]∧N[m1]=r1∧m2= m1+1∧i2=i1+1

(p1V)

(i2 < n0)

¬

¬

¬ ⇒ identityiʼ1=e1V ∧ mʼ1=e2V ∧

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1Vʼ) ∧

⇒ identity

rʼ1=e3Vʼ ∧(p2Vʼʼ) ∧mʼ2=e7Vʼʼ ∧(p1Vʼʼʼ)¬

¬

¬

(n0>=0) ∧i1 = 0 ∧ m1 = 0 ∧(i1 < n0) ∧

iʼ1=e1V ∧ mʼ1=e2V ∧(p1V)

⇒ identity

ϕ1(e1,e2,p1) ⇒ identity

ϕ2(e1,e2,p1) ⇒ identity

ϕ2(e1,e2,p1,e3,e7,p2) ⇒ identity

∃ ei,pj∀program vars

• Naive approach:• Enumerate ei,pj and “validate”• Will not scale

• 211 to 237 candidates our experiments

Page 28: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Efficient solving from prior work on verification using SAT/SMT

• Efficient solving strategy:

• Verification solves ∃Invariant∀vars• Reuse SMT-based verifier technology

• Core idea:• Predicates/expressions form a lattice• Efficient encoding using lattice instead

of enumerating entire domain• See prior work in PLDI’09/POPL’10

∃ei,pj∀varsϕk(e1,e2,p1) ⇒ identity∧k

Page 29: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

Page 30: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

C holds the accumulated constraints

Page 31: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

C holds the accumulated constraints

Initialize with termination cnstrSimple linear constraints that ensure that symbolic execution terminates( )

Page 32: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

C holds the accumulated constraints

If no change to candidate set then they are likely not refutable

Initialize with termination cnstrSimple linear constraints that ensure that symbolic execution terminates( )

Page 33: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

C holds the accumulated constraints

If no change to candidate set then they are likely not refutable

Else use one s to parameterize next path exploration

Initialize with termination cnstrSimple linear constraints that ensure that symbolic execution terminates( )

Page 34: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

C holds the accumulated constraints

If no change to candidate set then they are likely not refutable

Else use one s to parameterize next path exploration

Explore another path and add its constraint

Initialize with termination cnstrSimple linear constraints that ensure that symbolic execution terminates( )

Page 35: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

The PINS Algorithm

C = termination (T)while (true) {

solns = solve (C,P,E,Spec)if (empty(solns)) failif (stabilized(solns)) return solnss = pickone (solns)C = C∧ directed-path-explore (T,s)

}

C holds the accumulated constraints

If no change to candidate set then they are likely not refutable

Else use one s to parameterize next path exploration

Explore another path and add its constraint

Initialize with termination cnstrSimple linear constraints that ensure that symbolic execution terminates( )

We do not have a way of certifiably saying which remaining solutions are

correct and which are not.

So how do we find a path that prunes the space further?

Page 36: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

x |E|(# Expr Holes)2|P|(# Pred Holes)

Template program T

Remaining search space

Explored paths

Page 37: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

x |E|(# Expr Holes)2|P|(# Pred Holes)

Template program T

Remaining search space

Explored paths

Page 38: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

x |E|(# Expr Holes)2|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

Page 39: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

⇒ specS✓

S✗

x |E|(# Expr Holes)2|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

Page 40: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

⇒ specS✓

S✗

What if?

x |E|(# Expr Holes)2|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

Page 41: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

⇒ specS✓

S✗

S✓⇒ false

What if?

x |E|(# Expr Holes)2|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

T Instantiated with S✓

Page 42: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

⇒ specS✓

S✗

⇒ specS✓⇒ false

What if?

x |E|(# Expr Holes)2|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

T Instantiated with S✓

Page 43: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

⇒ specS✓

S✗

⇒ specS✓⇒ false

S✗

⇒ false

What if?

x |E|(# Expr Holes)2|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

T Instantiated with S✓

Page 44: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

⇒ specS✓

S✗

⇒ specS✓⇒ false

S✗

⇒ false

What if?

⇒ specx |E|(# Expr Holes)2

|P|(# Pred Holes)

S✓

S✗

Template program T

Remaining search space

Explored paths

T Instantiated with S✓

Page 45: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

S✓

S✗

⇒ spec

S✓ ⇒ spec⇒ false

S✗

⇒ false⇒ spec

Page 46: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

S✓

S✗

⇒ spec

S✓ ⇒ spec⇒ false

S✗

⇒ false

Pick any solution from remaining space; don’t care

about its validity

⇒ spec

Page 47: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Directed path exploration

S✓

S✗

⇒ spec

S✓ ⇒ spec⇒ false

S✗

⇒ false

Pick any solution from remaining space; don’t care

about its validity

Instantiate template with picked solution, and now symbolically

execute to find feasible path

Directed path exploration

⇒ spec

Page 48: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Program inversion benchmarks

• Three domains• Lossless compression• Format conversion• Arithmetic

• Semi-automatic procedure to extract template T• Control-flow derived from original program• Expression/predicates mined

• Ran PINS to invert using template T

Page 49: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Results!"#$%&'()* +"'($%*

,-'$"*("./$01#*

2/&3"(**14**56"('01#,*

78&"* 9'#/':*;%"$)*

91.":*;%"$)"(*

!"#$%&#'()$ **+$,-$.$ /$ *01$ 23$ 45%675(&7$

8#$9%5:&$!;$ *<=$,-$.$ /$ <01$ 23$ 45%675(&7$

;>//$ **+$,-$*$ 0$ .?.=1$ .$2@$*$23$ 45%675(&7$

;>A$ *<.$,-$*$ B$ .+=1$ *$2@$*$23$ (22$:2C9%&D$

E51&$0B$ *</$,-$B$ .*$ .<//1$ .$2@$B$23$ (22$:2C9%&D$

FF&#:27&$ **=$,-$.$ /$ <B1$ 23$ (22$:2C9%&D$

G3($AH59$ **=$,-$.$ 0$ .<*1$ 23$ (22$:2C9%&D$

I&H65%6J&$ *..$,-$.$ .B$ ++1$ 23$ (22$:2C9%&D$

I"C$6$ *.+$,-$.$ B$ .1$ 23$ 45%675(&7$

K&:(2H$H2(5(&$ *.0$,-$.$ <$ B1$ 23$ (22$:2C9%&D$

K&:(2H$1)6L$ *.0$,-$.$ <$ B1$ 23$ 45%675(&7$

K&:(2H$1:5%&$ *.0$,-$.$ <$ <01$ 23$ (22$:2C9%&D$

;211%&11$

M2C9H&1162#

$N2HC

5($

M2#4&H162#

$OH6()C&P

:$

Page 50: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Results!"#$%&'()* +"'($%*

,-'$"*("./$01#*

2/&3"(**14**56"('01#,*

78&"* 9'#/':*;%"$)*

91.":*;%"$)"(*

!"#$%&#'()$ **+$,-$.$ /$ *01$ 23$ 45%675(&7$

8#$9%5:&$!;$ *<=$,-$.$ /$ <01$ 23$ 45%675(&7$

;>//$ **+$,-$*$ 0$ .?.=1$ .$2@$*$23$ 45%675(&7$

;>A$ *<.$,-$*$ B$ .+=1$ *$2@$*$23$ (22$:2C9%&D$

E51&$0B$ *</$,-$B$ .*$ .<//1$ .$2@$B$23$ (22$:2C9%&D$

FF&#:27&$ **=$,-$.$ /$ <B1$ 23$ (22$:2C9%&D$

G3($AH59$ **=$,-$.$ 0$ .<*1$ 23$ (22$:2C9%&D$

I&H65%6J&$ *..$,-$.$ .B$ ++1$ 23$ (22$:2C9%&D$

I"C$6$ *.+$,-$.$ B$ .1$ 23$ 45%675(&7$

K&:(2H$H2(5(&$ *.0$,-$.$ <$ B1$ 23$ (22$:2C9%&D$

K&:(2H$1)6L$ *.0$,-$.$ <$ B1$ 23$ 45%675(&7$

K&:(2H$1:5%&$ *.0$,-$.$ <$ <01$ 23$ (22$:2C9%&D$

;211%&11$

M2C9H&1162#

$N2HC

5($

M2#4&H162#

$OH6()C&P

:$

PINS narrowed the valid candidates to 1 in

almost all cases

Page 51: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Results!"#$%&'()* +"'($%*

,-'$"*("./$01#*

2/&3"(**14**56"('01#,*

78&"* 9'#/':*;%"$)*

91.":*;%"$)"(*

!"#$%&#'()$ **+$,-$.$ /$ *01$ 23$ 45%675(&7$

8#$9%5:&$!;$ *<=$,-$.$ /$ <01$ 23$ 45%675(&7$

;>//$ **+$,-$*$ 0$ .?.=1$ .$2@$*$23$ 45%675(&7$

;>A$ *<.$,-$*$ B$ .+=1$ *$2@$*$23$ (22$:2C9%&D$

E51&$0B$ *</$,-$B$ .*$ .<//1$ .$2@$B$23$ (22$:2C9%&D$

FF&#:27&$ **=$,-$.$ /$ <B1$ 23$ (22$:2C9%&D$

G3($AH59$ **=$,-$.$ 0$ .<*1$ 23$ (22$:2C9%&D$

I&H65%6J&$ *..$,-$.$ .B$ ++1$ 23$ (22$:2C9%&D$

I"C$6$ *.+$,-$.$ B$ .1$ 23$ 45%675(&7$

K&:(2H$H2(5(&$ *.0$,-$.$ <$ B1$ 23$ (22$:2C9%&D$

K&:(2H$1)6L$ *.0$,-$.$ <$ B1$ 23$ 45%675(&7$

K&:(2H$1:5%&$ *.0$,-$.$ <$ <01$ 23$ (22$:2C9%&D$

;211%&11$

M2C9H&1162#

$N2HC

5($

M2#4&H162#

$OH6()C&P

:$

Directed path exploration is successful in finding a small set of paths

that prune the space

Page 52: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Results!"#$%&'()* +"'($%*

,-'$"*("./$01#*

2/&3"(**14**56"('01#,*

78&"* 9'#/':*;%"$)*

91.":*;%"$)"(*

!"#$%&#'()$ **+$,-$.$ /$ *01$ 23$ 45%675(&7$

8#$9%5:&$!;$ *<=$,-$.$ /$ <01$ 23$ 45%675(&7$

;>//$ **+$,-$*$ 0$ .?.=1$ .$2@$*$23$ 45%675(&7$

;>A$ *<.$,-$*$ B$ .+=1$ *$2@$*$23$ (22$:2C9%&D$

E51&$0B$ *</$,-$B$ .*$ .<//1$ .$2@$B$23$ (22$:2C9%&D$

FF&#:27&$ **=$,-$.$ /$ <B1$ 23$ (22$:2C9%&D$

G3($AH59$ **=$,-$.$ 0$ .<*1$ 23$ (22$:2C9%&D$

I&H65%6J&$ *..$,-$.$ .B$ ++1$ 23$ (22$:2C9%&D$

I"C$6$ *.+$,-$.$ B$ .1$ 23$ 45%675(&7$

K&:(2H$H2(5(&$ *.0$,-$.$ <$ B1$ 23$ (22$:2C9%&D$

K&:(2H$1)6L$ *.0$,-$.$ <$ B1$ 23$ 45%675(&7$

K&:(2H$1:5%&$ *.0$,-$.$ <$ <01$ 23$ (22$:2C9%&D$

;211%&11$

M2C9H&1162#

$N2HC

5($

M2#4&H162#

$OH6()C&P

:$

Symbolic execution is sometimes expensive; but mostly

the paths are explored in reasonable time

Page 53: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Results!"#$%&'()* +"'($%*

,-'$"*("./$01#*

2/&3"(**14**56"('01#,*

78&"* 9'#/':*;%"$)*

91.":*;%"$)"(*

!"#$%&#'()$ **+$,-$.$ /$ *01$ 23$ 45%675(&7$

8#$9%5:&$!;$ *<=$,-$.$ /$ <01$ 23$ 45%675(&7$

;>//$ **+$,-$*$ 0$ .?.=1$ .$2@$*$23$ 45%675(&7$

;>A$ *<.$,-$*$ B$ .+=1$ *$2@$*$23$ (22$:2C9%&D$

E51&$0B$ *</$,-$B$ .*$ .<//1$ .$2@$B$23$ (22$:2C9%&D$

FF&#:27&$ **=$,-$.$ /$ <B1$ 23$ (22$:2C9%&D$

G3($AH59$ **=$,-$.$ 0$ .<*1$ 23$ (22$:2C9%&D$

I&H65%6J&$ *..$,-$.$ .B$ ++1$ 23$ (22$:2C9%&D$

I"C$6$ *.+$,-$.$ B$ .1$ 23$ 45%675(&7$

K&:(2H$H2(5(&$ *.0$,-$.$ <$ B1$ 23$ (22$:2C9%&D$

K&:(2H$1)6L$ *.0$,-$.$ <$ B1$ 23$ 45%675(&7$

K&:(2H$1:5%&$ *.0$,-$.$ <$ <01$ 23$ (22$:2C9%&D$

;211%&11$

M2C9H&1162#

$N2HC

5($

M2#4&H162#

$OH6()C&P

:$

Either only one remained or were easily

examined

Page 54: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Results!"#$%&'()* +"'($%*

,-'$"*("./$01#*

2/&3"(**14**56"('01#,*

78&"* 9'#/':*;%"$)*

91.":*;%"$)"(*

!"#$%&#'()$ **+$,-$.$ /$ *01$ 23$ 45%675(&7$

8#$9%5:&$!;$ *<=$,-$.$ /$ <01$ 23$ 45%675(&7$

;>//$ **+$,-$*$ 0$ .?.=1$ .$2@$*$23$ 45%675(&7$

;>A$ *<.$,-$*$ B$ .+=1$ *$2@$*$23$ (22$:2C9%&D$

E51&$0B$ *</$,-$B$ .*$ .<//1$ .$2@$B$23$ (22$:2C9%&D$

FF&#:27&$ **=$,-$.$ /$ <B1$ 23$ (22$:2C9%&D$

G3($AH59$ **=$,-$.$ 0$ .<*1$ 23$ (22$:2C9%&D$

I&H65%6J&$ *..$,-$.$ .B$ ++1$ 23$ (22$:2C9%&D$

I"C$6$ *.+$,-$.$ B$ .1$ 23$ 45%675(&7$

K&:(2H$H2(5(&$ *.0$,-$.$ <$ B1$ 23$ (22$:2C9%&D$

K&:(2H$1)6L$ *.0$,-$.$ <$ B1$ 23$ 45%675(&7$

K&:(2H$1:5%&$ *.0$,-$.$ <$ <01$ 23$ (22$:2C9%&D$

;211%&11$

M2C9H&1162#

$N2HC

5($

M2#4&H162#

$OH6()C&P

:$

A testing-based approach is the only viable option, as most of the

examples are too complex for even for bounded verification

Page 55: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

Conclusions

• PINS seems very promising• First testing-based approach to program synthesis• To our knowledge, no other technique can invert these

programs with as little guidance

• Supports small path-bound hypothesis for synthesis• Makes sense, since it works for testing (approximate

verification), and we know verification and synthesis are related (see POPL’10 paper)

• PINS should be applicable to other domains too

http://www.cs.umd.edu/~saurabhs/vs3/PINS/

Page 56: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common
Page 57: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

PINS approach vs CEGAR/CEGIS

VerifierConstraint Solver

Counterexample

SATisfying Soln

Correctness checkerConstraint Solver

Evidence of correctness

k SATisfying Solns picked

Page 58: Path-based Inductive Synthesis for Program Inversion · Program Inversion as Synthesis • Task Given a program P, synthesis P-1 such that P-1(P(x)) = x • Motivation: Many common

void main(int n, BitString A) { BitString *D; int *B; int i,p,k,j,r,size,x,go;

IN(str(A,0,n-1),n); ASSUME(n >= 1);

D[0] = "0"; D[1] = "1";

i = 0; p = 2; k = 0; while (i < n) { j = i; r = 0; size=-1; while (j < n && r != -1) { x = 0; r = -1; while (x < p) { if (D[x] == substr(A,i,j)) r = x; x++; } if (r != -1) { go = r; size = j-i+1; } j++; } B[k++] = go; D[p++] = substr(A,i,j-1); i += size; }

OUT(B,k);}

LZWvoid main(int *A, int n) { int *P,*N,*C; int i,j,k,c,p,r;

IN(BOUND(A,0,n),n); ASSUME(n >= 0); i = 0; k = 0; while (i < n) { c = 0; p = 0; j = 0; while (j < i) { r = 0; while (i+r < n-1 && A[j+r] == A[i+r]) r++; if (c < r) { c = r; p = i-j; } j++; } P[k] = p; N[k] = c; C[k] = A[i+c]; i = i+1+c; k++; } OUT(P,N,C,k);}

PINS

LZW compressor LZW decompressor