synthesizing from components: building from · pdf filesynthesizing from components: building...

30
Synthesizing from Components: Building from Blocks Ashish Tiwari SRI International 333 Ravenswood Ave Menlo Park, CA 94025 Joint work with Sumit Gulwani (MSR), Vijay Anand Korthikanti (UIUC), Susmit Jha (UC Berkeley), Sanjit Seshia (UC Berkeley), Thomas Sturm (Munich), Ankur Taly (Stanford), Ramarathnam Venkatesan (MSR) MSR, Redmond Component-based Synthesis: 1

Upload: truongnhan

Post on 05-Feb-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Synthesizing from Components:

Building from Blocks

Ashish Tiwari

SRI International

333 Ravenswood Ave

Menlo Park, CA 94025

Joint work with Sumit Gulwani (MSR), Vijay Anand Korthikanti (UIUC),

Susmit Jha (UC Berkeley), Sanjit Seshia (UC Berkeley), Thomas Sturm

(Munich), Ankur Taly (Stanford), Ramarathnam Venkatesan (MSR)

MSR, Redmond Component-based Synthesis: 1

Page 2: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Component-Based Synthesis

....

Problem: How towire the components to synthesize adesiredsystem ?

MSR, Redmond Component-based Synthesis: 2

Page 3: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Concrete Examples

Desired SystemFspec Componentsfi’s

sort an array comparators

computex+y2 modulo arithmetic ops

find rightmost one bitwise ops, arithmetic ops

computex243 multiplication

acceptω-regular language Buchi automata

safe hybrid system multiple operating modes

geometry construction ruler-compass steps

deobfuscated code parts of obfuscated code

verification proof verification inference rules

Question: ∃C : ∀x : Fspec(x) = C(f1, f2, . . .)(x)

MSR, Redmond Component-based Synthesis: 3

Page 4: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Synthesis Problem Classes

“This is difficult”

“This is ill posed”

“This is too generalto be solvable”

∃C : ∀x : Fspec(x) = C(f1, f2, . . .)(x)

Parameters that define thesynthesis problem:

• composition operatorC

• class of specificationsFspec

• class of component specificationsfi

Fixing thesynthesis problem:

fix these parameters, fixrepresentationof Fspec, fi

MSR, Redmond Component-based Synthesis: 4

Page 5: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Bounded Synthesis

Thesynthesis problemis still hard

We make itfeasibleby replacing theunboundedquantifier,∃C, by abounded

quantifier

∃C : ∀x : Fspec(x) = C(f1, f2, . . .)(x)

∃c : ∀x : Fspec(x) = c(f1, f2, f3)(x), c in some finite set

Thisbounded synthesisproblem is solved by deciding the∃∀ formula

MSR, Redmond Component-based Synthesis: 5

Page 6: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Straight-Line Program Synthesis

composition operator function composition

components primitive functions

system complex function

Bounded synthesis version:

• fix length of program

• fix upper bound on number of each component

∃P : ∀x : Fspec(x) = P (x), P a straight-line program composingfi’s

∃π : ∀x : Fspec(x) = fπ(1)(fπ(2)(fπ(3)(x)))

MSR, Redmond Component-based Synthesis: 6

Page 7: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Straight-Line Program Synthesis

Specification: Evaluate polynomiala ∗ h2 + b ∗ h+ c

Budget: two multiplication andtwo addition operators

Finitesearch space

Synthesized Program:

1. o1 := a ∗ h;

2. o2 := o1 + b;

3. o3 := o2 ∗ h;

4. returno3 + c;

Correctness:(a ∗ h+ b) ∗ h+ c = a ∗ h2 + b ∗ h+ c

MSR, Redmond Component-based Synthesis: 7

Page 8: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Straight-Line Program Synthesis

Specification: Turn-off rightmost contiguous 1 bits

Example:010101100 7→ 010100000

Budget: two addition and at mostfour bitwise Boolean operators

Finitesearch space: Also need some constants

Synthesized Program:

1. o1 := x+ (−1);

2. o2 := o1|x;

3. o3 := o2 + 1;

4. returno3&x;

Correctness on sample input:

010101100 7→ 010101011 7→ 010101111 7→ 010110000 7→ 010100000

MSR, Redmond Component-based Synthesis: 8

Page 9: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Loop-free Program Synthesis

composition operator function composition

components primitive functions,if-then-else

system complex function

Bounded synthesis version:

• fix length of program

• fix upper bound on number of each component includingif-then-else

∃P : ∀x : Fspec(x) = P (x), P a straight-line program composingfi’s

∃π : ∀x : Fspec(x) = fπ(ǫ)(fπ(1)(fπ(11)(x1), fπ(12)(x2, x1)))

MSR, Redmond Component-based Synthesis: 9

Page 10: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Loop-free Program Synthesis

Specification: Obfuscated code

Example: We are given

if (h(x))

if (x*(x+1)% 2 == 1) y := f(x) else y := g(x)

else y := f(g(x))

Components Budget: f, g, h, if-then-else

Synthesized Program:

o := g(x);

if (h(x)) y := o; else y := f(o);

Correctness: Equivalence of two loop-free programs

MSR, Redmond Component-based Synthesis: 10

Page 11: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Loop-free Program Synthesis

∃π : ∀x : Fspec(x) = fπ(ǫ)(fπ(1)(fπ(11)(x1), fπ(12)(x2, x1)))

Enumerate all possible programs and check

Enumerate all permutationsπ and check

Checking if a synthesized program is the desired program is averification

problem

Bounded Synthesis:= iteratively performverification

But we canlearnfrom failures ...

MSR, Redmond Component-based Synthesis: 11

Page 12: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

∃∀φ Solvers

Bounded Synthesis7→ ∃∀ solving

How to solve∃u : ∀x : φ formulas?

A1 Counter-example guided iterative solver

A2 Distinguishing input solver

• Applies even whenφ not fully known

A3 Numerical solver

MSR, Redmond Component-based Synthesis: 12

Page 13: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

A1: Solving ∃∀φ

Counter-example guided iterative procedure for solving∃~u : ∀~x : φ(~u, ~x)

1. Guess~u0 for ~u

2. (Verification) Check if

∀~x : φ(~u0, ~x)

3. If true, then return~u0

4. Get counterexample~x0, add it toX

5. (Finite Synthesis) Find new~u0 such that

∃~u0 :∧

~x0∈X

φ(~u0, ~x0)

6. Go to Step 2

MSR, Redmond Component-based Synthesis: 13

Page 14: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

A1: Counter-example Guided Iterative∃∀ Solving

Needs a backendquantifier-free solver

That can returncounterexamples

We use anSMT solver

The structure ofφ, and additional knowledge about whatφ encodes, is used

optimize the above procedure to expediteconvergence

Related Work: Sketch, Aha

Reference: Synthesis of loop-free programs, PLDI 2011

MSR, Redmond Component-based Synthesis: 14

Page 15: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

A2: Distinguishing Input Solver

Solving∃~u : ∀~x : φ(~u, ~x)

1. X := some finite set of choices for~x

2. Findtwo programsthat work forX , butdiffer on some~x0

∃~u1, ~u2, ~x0 : (∧

~x∈X

(φ(~u1, ~x) ∧ φ(~u2, ~x))) ∧ (φ(~u1, ~x0) 6⇔ φ(~u2, ~x0))

3. If satisfiable, we add~x0 toX and go to (2)

4. If unsatisfiable, then findoneprogram that works forX

∃~u1 :∧

~x∈X

φ(~u1, ~x)

5. If satisfiable, return~u1

6. Otherwise, return “not synthesizable”

MSR, Redmond Component-based Synthesis: 15

Page 16: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

A2: Properties of the A2 Solver

The second algorithm for solving∃~u : ∀~x : φ(~u, ~x)

• Does not need thefull specificationof the desired program

• We only need the knowledge of the specification on the setX

• Does not perform theverificationstep

An interativeimplementation of A2:

1. Tool asks user for theexpected output on input~x0

2. Tool synthesizes internallytwo programsthat work correctly for

X := {~x0}, but differ on input~x1

3. Tool asks user for theexpected output on input~x1

4. Add ~x1 toX and repeat

MSR, Redmond Component-based Synthesis: 16

Page 17: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

A3: Nonsymbolic∃∀ Solver

A third algorithm for solving∃~u : ∀~x : φ(~u, ~x)

1. Findfinite setX of input-output pairsof the specification

2. Synthesizeprogram that worksfor finite setX

3. Verify the synthesized programon randomly sampled inputs

We solved Step (2) using anSMT solverpreviously

We can avoid the SMT solver and instead

1. hierarchical program synthesis: first synthesizehigh-level components

2. enumerate composition of high-level componentsguided bygoal

MSR, Redmond Component-based Synthesis: 17

Page 18: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Synthesis Without Symbolic Reasoning

Specification: Construct a triangle, given its base, a base angle and sum ofthe

other two sides.

Components: Ruler compass constructions

Formal specification: Given pointsp1, p2 and numbersa, r, find pointp

φpre := r > length(p1, p2)

φpost := Angle(p, p1, p2) = a ∧ length(p, p1) + length(p, p2) = r

Construction:

L1 := ConstructLineGivenAngleLine(L,a);

C1 := ConstructCircleGivenPointLength(p1,r);

(p3,p4) := LineCircleIntersection(L1,C1);

L2 := PerpendicularBisector2Points(p2,p3);

p5 := LineLineIntersection(L1,L2);

MSR, Redmond Component-based Synthesis: 18

Page 19: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Geometry Construction Synthesis

Step 1 find concrete input-output pair consistent with specification

L = Line(〈81.62, 99.62〉, 〈99.62, 83.62〉)

r = 88.07

a = 0.81 radians

Compute output for this input:p := 〈131.72, 103.59〉

Step 2 Start enumerating partial programs built using anextended library

Step 3 Evaluate if intermediate objects generated by the partial program are

goodand try other choices in Step (2) otherwise

MSR, Redmond Component-based Synthesis: 19

Page 20: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Geometry Construction Synthesis

Evaluting effect of making searchgoal directed

-50

0

50

100

150

200

250

-50 0 50 100 150 200 250

y

x

Points generated by goal-directed search

depth 0 (Input)depth 1depth 2depth 3depth 4

depth 5 (Output)

-50

0

50

100

-50 0 50 100 y

x

Points generated by brute-force search

depth 0 (Input)depth 1depth 2depth 3depth 4depth 5

depth 6 (Output)

Points visited in a goal-directed search (left) and a brute-force search (right).

MSR, Redmond Component-based Synthesis: 20

Page 21: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Geometry Construction Synthesis

• Extended libraryis forward search

◦ Encodes knowledge / concept taught in class

• Goal directnessis backward search

◦ Corresponds to reasoning student expected to do

• Sample input-output points generated usingnumericaltechniques

MSR, Redmond Component-based Synthesis: 21

Page 22: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Switching Logic Synthesis

Given amultimodal dynamical system

Synthesizeconditions for switching between modessuch that some

requirements are met

MSR, Redmond Component-based Synthesis: 22

Page 23: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Driving a Robot

3−3 0

10 The goal is to drive the robot starting fromInit to

Reach while remaining insideSafe:

Init := (x ∈ [−1, 1], y = 0, vx = 0, vy = 0)

Reach := (y ≥ 10)

Safe := (|x| ≤ 3)

Using the 2 modes:

• Mode 1: Force applied in(1, 1)-direction

dx

dt= vx,

dvx

dt= 1− vx,

dy

dt= vy,

dvy

dt= 1− vy

• Mode 2: Force applied in(−1, 1)-direction

dx

dt= vx,

dvx

dt= −1− vx,

dy

dt= vy,

dvy

dt= 1− vy

MSR, Redmond Component-based Synthesis: 23

Page 24: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Example: Driving a Robot

We synthesize anon-deterministic controller: a set of different possible

switchings that each satisfy the requirementSafeUReach.

Two possibletrajectories:

−3 −2 −1 0 1 2 30

2

4

6

8

10

12

Position x

Pos

ition

yPositionx=−3x=3Alt Position

How to discover the correct switching logic?

MSR, Redmond Component-based Synthesis: 24

Page 25: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Switching Logic Synthesis

∃switching conditions: ∀state variables: correctness

We can againboundthe search for switching conditions

But that is abadsolution

Need to go back toverification

MSR, Redmond Component-based Synthesis: 25

Page 26: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Verification Techniques

1. Reachability-Based Verification

2. Abstraction-Based Verification

3. Certificate-Based Verification

Key Observation: Verification = searching forright certificate

Property Witness/Certificate

Stability Lyapunov function

Safety Inductive Invariant

Liveness Ranking function

MSR, Redmond Component-based Synthesis: 26

Page 27: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Certificate-Based Verification

Verifying propertyP in systemS :=

∃C : C is a certificate forP in S

Can do aboundedsearch forC

Also known as theconstraint-based approach

Certificates for Synthesis Problem:

Property Witness/Certificate

Safety ControlledInductive Invariant

Stability ControlledLyapunov function

MSR, Redmond Component-based Synthesis: 27

Page 28: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Bounded Synthesis of Switching Logic

Given multimodal dynamical system, and propertySafe:

• Guess templates for the certificate for controlled-safety

• Generate the∃a, b, . . . : ∀x, y, . . . : φ

• Solvethe formula to get values fora, b, . . .

MSR, Redmond Component-based Synthesis: 28

Page 29: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

∃∀ Solvers

Need∃u : ∀x : φ solvers for the reals

We can use the same ideas as before

• Symbolic NumericApproach:

◦ Symbolic: Acombinationof QEPCAD, redlog, slfqto eliminate inner∀

◦ Numeric:Gradient descentto findu from resulting formula

• Iterative learning: Iterativelyprune outu values based onsimulations

MSR, Redmond Component-based Synthesis: 29

Page 30: Synthesizing from Components: Building from · PDF fileSynthesizing from Components: Building from Blocks ... verification proof ... • Extended library is forward search Encodes

'

&

$

%

Conclusion

• Synthesis: ∃∀ solving

• Bounded synthesis: Make problem tractable by making∃ a finite

quantification

• Component-based Synthesis

• Various approaches tosolve∃∀ depending on application

• Switching logic synthesis : search forcontrolled certificates

MSR, Redmond Component-based Synthesis: 30