Sound Reasoning about Integral Data Types with a Reusable SMT Solver - - PowerPoint PPT Presentation

sound reasoning about integral data types with a reusable
SMART_READER_LITE
LIVE PREVIEW

Sound Reasoning about Integral Data Types with a Reusable SMT Solver - - PowerPoint PPT Presentation

Sound Reasoning about Integral Data Types with a Reusable SMT Solver Interface R egis Blanc Viktor Kuncak Laboratory for Automated Reasoning and Analysis Ecole Polytechnique F ed erale de Lausanne June 13, 2015 The Leon


slide-1
SLIDE 1

Sound Reasoning about Integral Data Types with a Reusable SMT Solver Interface

R´ egis Blanc Viktor Kuncak

Laboratory for Automated Reasoning and Analysis ´ Ecole Polytechnique F´ ed´ erale de Lausanne

June 13, 2015

slide-2
SLIDE 2

The Leon Verification System

◮ Verifier for the Scala language. ◮ Support a well-defined subset of Scala.

◮ A functional core language. ◮ Many imperative extensions. ◮ Some ways to express non-determinism.

◮ Complete for finding counterexamples. ◮ Big project from the LARA group at EPFL, with contributions

from many present (and past) members.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 1

slide-3
SLIDE 3

Contracts

Specifications can be defined using contracts.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 2

slide-4
SLIDE 4

Contracts

Specifications can be defined using contracts.

◮ Postconditions

def abs(n: Int): Int = { if(n <= 0) -n else n } ensuring(res => res >= 0)

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 2

slide-5
SLIDE 5

Contracts

Specifications can be defined using contracts.

◮ Postconditions

def abs(n: Int): Int = { if(n <= 0) -n else n } ensuring(res => res >= 0)

◮ Preconditions

def fact(n: Int): Int = { require(n >= 0) if(n == 0) 1 else n * fact(n-1) }

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 2

slide-6
SLIDE 6

Contracts

Specifications can be defined using contracts.

◮ Postconditions

def abs(n: Int): Int = { if(n <= 0) -n else n } ensuring(res => res >= 0)

◮ Preconditions

def fact(n: Int): Int = { require(n >= 0) if(n == 0) 1 else n * fact(n-1) }

The implementation and specification languages are the same.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 2

slide-7
SLIDE 7

Architecture of Leon

Code Transformations Scala Program Core Algorithm Report Scala Compiler R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 3

slide-8
SLIDE 8

Demo

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 4

slide-9
SLIDE 9

Int and BigInt

Int Primitive integer type: bit-vector semantics BigInt Library type: mathematical integer semantics

◮ Mathematical reasoning is usually easier with integers. ◮ Most programs use Int instead of BigInt. ◮ Easy to ignore the bounded nature of Int.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 5

slide-10
SLIDE 10

A Closer Look at Leon Unrolling

Code Transformations Scala Program Core Algorithm Report Scala Compiler

Function Lifting

Functional Core Language Approximated Formula Approximation Loop

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 6

slide-11
SLIDE 11

SMT Solver

SMT Solver Input Formula Satisfiable Map Proof of Unsatisfiability R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 7

slide-12
SLIDE 12

SMT Solver Theories

Any mathematical theory with a well defined axiomatization. Of interest to programming languages: Int Mathematical, unbounded, integers: Corresponds to Scala BigInt. BitVector Fixed, finite-size, bit-vectors: Correspond to Scala Int. ADT Algebraic data types. Models a subset of case classes functionalities. Array Map from one type to another. Models Scala Array and Map. UF Uninterpreted functions. Helps with abstractions.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 8

slide-13
SLIDE 13

Many Alternative Implementations

◮ With so many theories, support varies from solver to solver. ◮ State-of-the-art algorithms: ongoing research. ◮ Good to remain as solver-agnostic as possible.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 9

slide-14
SLIDE 14

SMT-LIB Interface

◮ With so many theories, support varies from solver to solver. ◮ State-of-the-art algorithms: ongoing research. ◮ Good to remain as solver-agnostic as possible.

“SMT-LIB is an international initiative aimed at facilitating research and development in Satisfiability Modulo Theories (SMT)” http://www.smtlib.org

◮ Text-based format to standardize communication with SMT

solvers.

◮ Similar to a programming language, but declarative. Syntax

based on Lisp.

◮ Large library of benchmarks. Enable organization of the

annual SMT-COMP competition.

◮ Good support in existing solvers, including Z3 and CVC4.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 9

slide-15
SLIDE 15

Leon: Integration with SMT Solvers

◮ Leon abstracts away the backend solver. ◮ One of the implementation generate SMT-LIB commands:

get many different solvers essentially for “free”

◮ The SMT-LIB interface is exposed in a stand-alone Scala

module.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 10

slide-16
SLIDE 16

Leon: Integration with SMT Solvers

◮ Leon abstracts away the backend solver. ◮ One of the implementation generate SMT-LIB commands:

get many different solvers essentially for “free”

◮ The SMT-LIB interface is exposed in a stand-alone Scala

module. scala-smtlib is a lightweight abstraction on top of the SMT-LIB standard. https://github.com/regb/scala-smtlib

◮ Simple, type-safe, communication with SMT solvers. ◮ Support for the latest SMT-LIB 2.5 standard. ◮ Include a fully complient parser (not used in Leon) that can

help building applications with SMT-LIB as input.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 10

slide-17
SLIDE 17

Conclusion

Extensions to the Leon system

◮ Sound reasoning about integral data types: Int and BigInt. ◮ Solver-agnostic backend with the help of an open-source

SMT-LIB Scala library. Work in progress Optimization of BigInt

◮ When writing program, BigInt is often closer to the expected

meaning than Int.

◮ However can often be two order of magnitude slower. ◮ Why not proving bounds statically on code using BigInt and

compiling to equivalent and faster Int.

R´ egis Blanc, Viktor Kuncak (LARA, EPFL) Integral Data Types and Reusable SMT Solver June 2015 11