automating relatively complete verification of higher-order functional programs
DESCRIPTION
Automating Relatively Complete Verification of Higher-Order Functional Programs. Hiroshi Unno (University of Tsukuba) Tachio Terauchi (Nagoya University) Naoki Kobayashi (University of Tokyo). Path-Sensitive Verifier for Functional Programs (cf. SLAM, BLAST, โฆ for Imperative Programs). - PowerPoint PPT PresentationTRANSCRIPT
Automating Relatively Complete Verification of Higher-Order Functional Programs
Hiroshi Unno (University of Tsukuba)Tachio Terauchi (Nagoya University)
Naoki Kobayashi (University of Tokyo)
2013/1/23 POPL 2013 1
Path-Sensitive Verifier for Functional Programs(cf. SLAM, BLAST, โฆ for Imperative Programs)
2013/1/23 POPL 2013 2
let rec mc x = if x > 100 then x โ 10 else mc (mc (x + 11))inlet n = randi() inif n ยท 101 then assert (mc n = 91) Verifier
Program & Spec.Result
Certificateor
Counterexample
All these verifiers are based on refinement type system
(cf. Hoare logic for first-orderimperative programs)
Demo
โข Refinement type inference by Horn clause solving [Unno and Kobayashi 2008, 2009]
โข Liquid Types [Rondon, Kawaguchi and Jhala 2008, โฆ]โข Depcegar [Terauchi 2010]โข MoCHi [Sato, Unno and Kobayashi 2011, 2013]โข HMC [Jhala, Majumdar and Rybalchenko 2011]
Refinement Types
Non-negative integers
Functions that take an integer andreturn an integer not less than
2013/1/23 POPL 2013 3
FOL formulas for refinement
Soundness of refinement type system : is safe (i.e., )if is well-typed (i.e., )
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐ ๐= ๐ ๐
Example: Typing Safe Program under
2013/1/23 POPL 2013 4
๐ : ๐ข๐ง๐ญโ {๐โจ๐=๐ }โ๐ฎ๐ง๐ข๐ญ
{๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ
๐ : ๐ข๐ง๐ญโ ( {๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ )โ๐ฎ๐ง๐ข๐ญ
( {๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ )โ๐ฎ๐ง๐ข๐ญ( {๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ )โ๐ฎ๐ง๐ข๐ญWell-typed!
Automated Verification viaRefinement Type Inference
โข Input a program โข Infer a type environment such that
(cf. invariant inference for Hoare logic)
2013/1/23 POPL 2013 5
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐ ๐= ๐ ๐๐ช={๐๐ฉ๐ฉ๐ฅ๐ฒโฆ๐ : ๐ข๐ง๐ญโ ( {๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ )โ๐ฎ๐ง๐ข๐ญ
๐๐ก๐๐๐คโฆ๐ :๐ข๐ง๐ญโ {๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ ,๐ฆ๐๐ข๐งโฆ๐ข๐ง๐ญโ๐ฎ๐ง๐ข๐ญ }
Limitation of Refinement Type System
Incompleteness: There is a safe but untypable program
2013/1/23 POPL 2013 6
whereas Hoare logic is relatively complete
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐
Example: Safe but Untypable Program
2013/1/23 POPL 2013 7
{๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ
( {๐|๐ท (๐ )}โ๐ฎ๐ง๐ข๐ญ )โ ๐ : {๐|๐ธ(๐)}โ๐ฎ๐ง๐ข๐ญ( {๐|๐ท (๐ )}โ๐ฎ๐ง๐ข๐ญ )โ ๐ : {๐|๐ธ(๐)}โ๐ฎ๐ง๐ข๐ญCannot
depend on
Untypable because:
Refinement predicate for
Refinement predicate for the 1st arg. of
Our Contributions
โข Relatively complete extension ofordinary refinement type system
โข Type inference method for
2013/1/23 POPL 2013 8
Our Contributions
โข Relatively complete extension ofordinary refinement type system
โข Type inference method for
2013/1/23 POPL 2013 9
for any safe programgiven an oracle to decide the validity of
formulas of Peano arithmetic
Our Design Goal of
โข Easy to automate type checking & inferenceโ By exploiting techniques from first-order
automated theorem proving (e.g., interpolation, SMT)โข Rejected alternative designs:โ Refinement predicates on functions (cf. Coq)
โ Unrestricted use of quantification (cf. Dependent ML)
2013/1/23 POPL 2013 10
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐
Our Approach: RestrictedUse of Quantification
โข Add one universal quantifier over integerjust before each function parameter[Goerdt 1985, German, Clarke, and Halpern 1983, 1989]
2013/1/23 POPL 2013 11
โ๐ . ( {๐|๐ท (๐ ,๐) }โ๐ฎ๐ง๐ข๐ญ )โ {๐|๐ธ (๐ ,๐)}โ๐ฎ๐ง๐ข๐ญ
A quantifier instantiation for
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐
Example: Typing under
2013/1/23 POPL 2013 12
{๐|๐=๐ }โ๐ฎ๐ง๐ข๐ญ {๐|๐=๐ }
โ๐ . ( {๐|๐ท (๐ ,๐) }โ๐ฎ๐ง๐ข๐ญ )โ {๐|๐ธ (๐ ,๐)}โ๐ฎ๐ง๐ข๐ญ{๐โจ๐=๐} {๐|๐=๐ }
[๐]Well-typed!
Theorem: Relative Completeness of
2013/1/23 POPL 2013 13
A program is safe
There exists a substitution for โ?โs such that
Our Contributions
โข Relatively complete extension ofordinary refinement type system
โข Type inference method for
2013/1/23 POPL 2013 14
Type Inference for
โข Find a substitution as well asa type environment such that
2013/1/23 POPL 2013 15
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐
Our Approach
โข Counterexample guided inference of and (cf. CEGAR in software model checking for imperative programs)โ For inference of a type environment :โข Use existing refinement type inference methods for
[Terauchi 2010, Kobayashi, Sato, Unno 2011]
โ For inference of a substitution for โ?โs: โข Use a new method based on non-linear constraint solving
2013/1/23 POPL 2013 16
Our Approach
โข Counterexample guided inference of and (cf. CEGAR in software model checking for imperative programs)โ For inference of a type environment :โข Use existing refinement type inference methods for
[Terauchi 2010, Kobayashi, Sato, Unno 2011]
โ For inference of a substitution for โ?โs: โข Use a new method based on non-linear constraint solving
2013/1/23 POPL 2013 17
Counterexample GuidedRefinement Type Inference
2013/1/23 POPL 2013 18
Input Program
unsafe
Step 1: Fixed-PointType Inference [1,2]
Step 3: Refinement [1,2]
safe
Counter-example s.t.
CandidateType Envs.
yes
โ๐ช .๐ชโข๐
โ๐ชโ๐ซ .๐ชโข๐ท
Step 2: SafetyCheck of [2]
no
unknown
ยฌโ๐ชโ๐ซ .๐ชโข๐ท
ยฌโ๐ช .๐ชโข๐
New CandidateType Envs.
s.t.
[1] Terauchi POPL 2010 [2] Kobayashi, Sato, Unno PLDI 2011
Our Approach
โข Counterexample guided inference of and (cf. CEGAR in software model checking for imperative programs)โ For inference of a type environment :โข Use existing refinement type inference methods for
[Terauchi 2010, Kobayashi, Sato, Unno 2011]
โ For inference of a substitution for โ?โs: โข Use a new method based on non-linear constraint solving
2013/1/23 POPL 2013 19
Candidate Substitution
Counterexample GuidedSubstitution Inference
2013/1/23 POPL 2013 20
Input Program
unsafe
Step 1: Fixed-PointType Inference [1,2]
safe
Counter-example s.t.
CandidateType Envs.
yes
โ๐ช .๐ชโข๐ ๐
โ๐ชโ๐ซ .๐ชโข๐๐ท
Step 2: SafetyCheck of [2]
no
ยฌโ๐ชโ๐ซ .๐ชโข๐ ๐ท
ยฌโ๐ช .๐ชโข๐๐
New CandidateType Envs.
s.t.
[1] Terauchi POPL 2010 [2] Kobayashi, Sato, Unno PLDI 2011
Instantiated Program
New Candidate Substitution
s.t.
Step 3: Refinement [1,2]
Finding New Candidate Substitution
โข Input:a safe non-recursive fragment such that
โข Output: such that
2013/1/23 POPL 2013 21
By reduction to non-linear constraint solving using linear expression templates for
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐
Example: Reduction to Non-Linear Constraint Solving
2013/1/23 POPL 2013 22
โ๐๐ ,๐๐ ,๐ท ,๐ธ
. (โ๐ ,๐ , ๐ .๐=๐๐+๐๐ โ ๐โง๐=๐โ๐ธ (๐ , ๐ )โ๐ ,๐ ,๐ .๐ธ (๐ ,๐ )โง๐=๐โ ๐ท (๐ ,๐)โ๐ ,๐ , ๐ .๐ท (๐ ,๐ )โง๐=๐๐+๐๐โ ๐โ๐=๐)
โ๐ .( {๐|๐ท (๐ ,๐ ) }โ๐ฎ๐ง๐ข๐ญ )โ {๐โจ {๐ธ (๐ , ๐ ) }โ๐ฎ๐ง๐ข๐ญ
Example: Non-linearConstraint Solving (1/2)
2013/1/23 POPL 2013 23
โ๐๐ ,๐๐ .โ ๐ , ๐ , ๐ .๐=๐๐+๐๐โ ๐โง
๐=๐๐+๐๐โ ๐โ ๐= ๐
โ๐๐ ,๐๐ ,๐ท ,๐ธ
. (โ๐ ,๐ , ๐ .๐=๐๐+๐๐ โ ๐โง๐=๐โ๐ธ (๐ , ๐ )โ๐ ,๐ ,๐ .๐ธ (๐ ,๐ )โง๐=๐โ ๐ท (๐ ,๐)โ๐ ,๐ , ๐ .๐ท (๐ ,๐ )โง๐=๐๐+๐๐โ ๐โ๐=๐)
Elim.
Elim.
โ๐๐ ,๐๐ ,๐ธ
. (โ๐ ,๐ , ๐ .๐=๐๐+๐๐ โ ๐โง๐=๐โ๐ธ (๐ , ๐ )
โ๐ ,๐ ,๐ , ๐ . ๐ธ (๐ , ๐ )โง๐=๐โง๐=๐๐+๐๐โ ๐โ๐=๐ )
iff
Example: Non-linearConstraint Solving (2/2)
2013/1/23 POPL 2013 24
โ๐๐ ,๐๐ .โ ๐ , ๐ , ๐ .๐=๐๐+๐๐โ ๐โง๐=๐๐+๐๐โ ๐โ ๐= ๐
โ๐๐ ,๐๐ .โ๐๐ ,๐๐ .๐๐+๐๐=๐โง
๐๐โ ๐๐=๐โง๐๐โ ๐๐=โ๐
๐๐=๐ ,๐๐=๐
๐ฅ๐๐ญ ๐๐ฉ๐ฉ๐ฅ๐ฒ๐ฌ๐ฐ ๐ ๐= ๐ ๐๐
to
Bit-vector modeling & SMT [Gulwani, Srivastava, Venkatesan 2008]
Farkasโ lemma: iff
Implementation
โข Extended MoCHi [Sato, Unno and Kobayashi 2011, 2013]
with the type inference method for
2013/1/23 POPL 2013 25
let rec mc x = if x > 100 then x โ 10 else mc (mc (x + 11))inlet n = randi() inif n ยท 101 then assert (mc n = 91) MoCHi
Program & Spec.Result
Certificateor
Counterexample
Conclusion
โข Relatively complete refinement type system โ Restricted use of quantificationโข Add one universal quantifier over integer
just before each function parameter
โข Type inference method for โ Counterexample guided inference of and โข inference by application of existing refinement type
inference methods [Terauchi 2010, Kobayashi, Sato, Unno 2011]
โข Inference by reduction to non-linear constraint solving
2013/1/23 POPL 2013 26