41
Automated tactics for separation logic VeriML Reconstruct Z3 Proof Safe incremental type checker Certifying code transformation Proof carrying hardware IP

Automated tactics for separation logic VeriML Reconstruct Z3 Proof Safe incremental type checker

  • Upload
    berne

  • View
    49

  • Download
    0

Embed Size (px)

DESCRIPTION

Automated tactics for separation logic VeriML Reconstruct Z3 Proof Safe incremental type checker Certifying code transformation Proof carrying hardware IP. Automated tactics for separation logic. Version 1 Certified verifier for a fragment of separation logic in Coq - PowerPoint PPT Presentation

Citation preview

Page 1: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

• Automated tactics for separation logic• VeriML

• Reconstruct Z3 Proof • Safe incremental type checker• Certifying code transformation

• Proof carrying hardware IP

Page 2: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Automated tactics for separation logic• Version 1

• Certified verifier for a fragment of separation logic in Coq• Without predicates ( list, tree … )

• Prover written in SML handle these predicates and output proof trace

• Tactic to reconstruct proof from these proof trace in Coq• Version 2

• Hard coded list and tree into the certified verifier• Use a forked version Coq which supports native arrays to speed up

the verifier• Version 3 ( Ongoing )

• More generic way to support user defined predicates

Page 3: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Reconstruct Z3 Proof• Reconstruct proof in VeriML using output from Z3

Page 4: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Start from SAT Solvers• Decide propositional satisfiablity of sets of clauses:

• Proof Witness from SAT solver:• If satisfiable: assignment of all the variables• If unsatisfiable: proof by resolution of the empty clause

• Resolution rule:

𝑥∨ 𝐴𝑥∨𝐵𝐴∨𝐵

Page 5: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example• Satisfiable:

• Unsatisfiable:

𝑥1∨¬𝑥2∨𝑥3¬𝑥3𝑥1∨¬𝑥2

𝑥1∨ 𝑥2𝑥1

¬𝑥1∨𝑥3¬ 𝑥3¬𝑥1

Page 6: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

SAT Modulo Theories(SMT solver)• Atoms can be formulas from other theories

• Congruence Closure(EUF)• Linear Arithmetic(LIA)• ….

• Proof witness• If satisfiable: assignment of all the variables• If unsatisfiable: proof by resolution of the empty clause while some

leaves are now lemmas from theories

Page 7: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example• Satisfiable :

• Unsatisfiable:

𝑥≠ 𝑦∨ 𝑓 (𝑥 )= 𝑓 (𝑦 ) 𝑥=𝑦𝑓 (𝑥 )= 𝑓 (𝑦 )

𝑓 (𝑥 )≠ 𝑓 (𝑦 )

Page 8: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Interaction between SAT and SMT

• With boolean abstraction:

• • First try: A:true, B:true, C:true, D:true, E:false

• Unsat by a multi-theory solver, thus we add a theory:

• Repeat until sat or no more model can be found

A B C D E

Page 9: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Reconstruct proof• If sat: apply the assignment and check the result is true

• If unsat: check the resolution tree• Checking resolution step (SAT solver)• Checking theory lemmas (SMT solver)• Combination of theories

Page 10: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

What we need• resolution checker • checker for each theory• checker for the resolution tree which calls these two kinds of checkers at each step

Page 11: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example𝑥1∨¬𝑥2∨𝑥3¬𝑥3

❑ 𝑥1∨ 𝑥2❑

¬𝑥1∨𝑥3¬ 𝑥3❑

Page 12: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example𝑥1∨¬𝑥2∨𝑥3¬𝑥3

𝑥1∨¬𝑥2𝑥1∨ 𝑥2

❑¬𝑥1∨𝑥3¬ 𝑥3

❑❑

Page 13: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example𝑥1∨¬𝑥2∨𝑥3¬𝑥3

𝑥1∨¬𝑥2𝑥1∨ 𝑥2

𝑥1¬𝑥1∨𝑥3¬ 𝑥3

❑❑

Page 14: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example𝑥1∨¬𝑥2∨𝑥3¬𝑥3

𝑥1∨¬𝑥2𝑥1∨ 𝑥2

𝑥1¬𝑥1∨𝑥3¬ 𝑥3

¬𝑥1❑

Page 15: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example𝑥1∨¬𝑥2∨𝑥3¬𝑥3

𝑥1∨¬𝑥2𝑥1∨ 𝑥2

𝑥1¬𝑥1∨𝑥3¬ 𝑥3

¬𝑥1∎

Page 16: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Encoding in VeriML• Only consider CNF clause• Variable

• Assignment: Nat-> Bool• Literal :

• Clause: List Literal• State: List ( clauseID * Clause )

• get : S -> clauseID -> C set: S -> clauseID -> C -> S• Proof trace: ??• A realistic Checker: State -> Trace -> Bool

Page 17: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Interpretation• Given assignment • Var: v• Literal: • Clause: • Valid state

• Soundness of checker:

Page 18: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Start from SAT solver• Resolution Chain: List Nat• Resolve : Clause->Clause->Clause

• resolution between clause C1 and C2. • Resolution checker: Resolution Chain-> Clause

• for resolution chain [n1,n2,…n] and state S,• R(..(R( S[n1], S[n2]),…),S[n])

• Proof trace: List (clauseID*Resolution Chain)• Reconstruct the proof:

• List.fold (fun (id,rc) => set s (resolution_checker rc) id) trace• After this, we have the empty clause in state which indicates the

state is not valid

Page 19: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Example𝑥1∨¬𝑥2∨𝑥3¬𝑥3

𝑥1∨¬𝑥2𝑥1∨ 𝑥2

𝑥1¬𝑥1∨𝑥3¬ 𝑥3

¬𝑥1∎

Initial State: [ [2,4], [2,5,6], [3,6], [7] ]Resolutions: [ (5,[1,3,0]) , (6,[2,3] ) , (7,[5,6]) ]Resolve two clause: [2,4] [2,5,6] [2,6] ( a modified merge sort )

Page 20: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Naïve framework for SMT solver• Certificate from different theories• Inductive cert:

• | sat_solver sat_cert• | euf_solver euf_cert• | lia_solver lia_cert• ….

• Trace might be like: List (clauseID*cert)• Checkers for each theory• And finally the checker for SMT solver

• checker s trace = • List.fold (fun (id,cert) => set s (cert_checker cert) id

Page 21: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Problem Witness

SMT

Resolution

CNF

EUF

LIA

VeriML Checker

Page 22: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Z3 Proof• Example

• 34 Axiom• 19 core rules : mostly are propositional reasoning• 5 equality rules : refl, symm, trans, …• 7 quantifier rules : quant-inst, quant-intro, …• 3 theory rules : rewrite, inconsistent, …

Page 23: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Reconstruction• Overall approach:

• one proof method for every Z3 inference rule• depth-first traversal of Z3 proof

Page 24: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Conclusion• A prototype to reconstruct zChaff(SAT solver) proof• Very slow in performance

• Ongoing with Z3 reconstruction

Page 25: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Safe Incremental Type Checker• Type checking is more and more an interaction between the programmer and the type-checker

• The richer the type system is, the more expensive type checking gets

• Example• Type inference ( unification)• Dependent types • Very large term ( proof term )• Complex language ( C++ )

Page 26: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Goal • Reuse already-computed results• Recheck only the modified part and where it affects

• Example

let f x = x + 1 in (f 2)

let f x = 2 * (x + 1) in (f 2)

let f x = (let y = true in x + 1) in (f 2)

let f x = x > 1 in (f 2)

Page 27: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

• Benefit• fast type checking modified code

• this could also be used to tactic language, and refinement?• typed version control as we always have well-typed

program and its type derivations• “undo” for free

Page 28: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

• If we simply use memorization• We can only do syntactic comparison• We can’t do

• weakening: let x = 1 and let y = 2 in x let x = 1 and let y = 2 in x

• -equivalence• other possible user extensible conversions

• it’s outside typing rule

Page 29: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Difficulties• A language to describe delta between different versions

• Slice the code into each typing step• A language to store typing derivations

• Higher order terms with meta variables• Build it up

• Repository : store type derivations• Delta: describe difference between two versions of code• Incremental checker: check : repo -> delta -> repo

• try to reduce the complexity to

Page 30: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

• A language to store typing derivations• VeriML support contextual terms in computation language, thus

possible to present typing derivations• How to make it generic?

• A language to describe delta between different versions• Got stuck here

Page 31: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Scratch

Page 32: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

• Given signature: • t1 = g a

• t2 = g (g a)

Page 33: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Certifying Code Transformation• How to certify code transformation?

• Verified Compiler• Translation Validation

• VeriML approach

Page 34: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Verified Compiler

Page 35: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Translation Validation

Page 36: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Approach with VeriML

Page 37: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Naïve Example

Page 38: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker
Page 39: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Scratch

• ImplementationLogical language• Heap implementation• Language definition and semantics

• Computation language• Symbolic execution(VCGen)• Tacitc to proof Hoare Triple• Practical Code transformation examples

Page 40: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Conclusion• The thing we need to proof isn't less than translation

validation• we can do it in a single lanuguage which easier to write proof with

and we get more proof• The whole picture is still vague

Page 41: Automated tactics for separation logic VeriML Reconstruct Z3 Proof   Safe incremental type checker

Proof Carrying Hardware• Current work

• A formalization of Intel 8051 microcontroller in Coq• RC5 hash algorithm • Proof certain ports won’t “leak” secret