Formal Verification – Robust and Efficient Code Lecture 1

Slides:



Advertisements
Similar presentations
Copyright 2000 Cadence Design Systems. Permission is granted to reproduce without modification. Introduction An overview of formal methods for hardware.
Advertisements

Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Synthesis, Analysis, and Verification Lecture 04c Lectures: Viktor Kuncak VC Generation for Programs with Data Structures “Beyond Integers”
50.530: Software Engineering
Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
50.530: Software Engineering Sun Jun SUTD. Week 10: Invariant Generation.
Verification of Functional Programs in Scala Philippe Suter (joint work w/ Ali Sinan Köksal and Viktor Kuncak) ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE,
Hoare’s Correctness Triplets Dijkstra’s Predicate Transformers
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
1 University of Toronto Department of Computer Science © 2001, Steve Easterbrook Lecture 10: Formal Verification Formal Methods Basics of Logic first order.
Functional Design and Programming Lecture 11: Functional reasoning.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Axiomatic Semantics.
ISBN Chapter 3 Describing Syntax and Semantics.
Formal Specification and Verification. Specifications Imprecise specifications can cause serious problems downstream Lots of interpretations even with.
1 Semantic Description of Programming languages. 2 Static versus Dynamic Semantics n Static Semantics represents legal forms of programs that cannot be.
1/22 Programs : Semantics and Verification Charngki PSWLAB Programs: Semantics and Verification Mordechai Ben-Ari Mathematical Logic for Computer.
CS 355 – Programming Languages
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor Formal Methods in Software Engineering1.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der Humboldt.
CPSC 322, Lecture 19Slide 1 Propositional Logic Intro, Syntax Computer Science cpsc322, Lecture 19 (Textbook Chpt ) February, 23, 2009.
Invariant Based Programming, March 20101/ Teaching the construction of correct programs using invariant based programming Ralph-Johan Back Johannes Eriksson.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Embedded Systems Laboratory Department of Computer and Information Science Linköping University Sweden Formal Verification and Model Checking Traian Pop.
Review: forward E { P } { P && E } TF { P && ! E } { P 1 } { P 2 } { P 1 || P 2 } x = E { P } { \exists … }
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Software Verification Bertrand Meyer Chair of Software Engineering Lecture 2: Axiomatic semantics.
Program Verification using Templates over Predicate Abstraction Saurabh Srivastava University of Maryland, College Park Sumit Gulwani Microsoft Research,
Describing Syntax and Semantics
School of Computer ScienceG53FSP Formal Specification1 Dr. Rong Qu Introduction to Formal Specification
MCA –Software Engineering Kantipur City College. Topics include  Formal Methods Concept  Formal Specification Language Test plan creation Test-case.
Formal Methods 1. Software Engineering and Formal Methods  Every software engineering methodology is based on a recommended development process  proceeding.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Murali Sitaraman
Pre/Post Condition Logic 03/06/2013. Agenda Hoare’s Logic Overview Application to Pre/Post Conditions.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Static program checking and verification Slides: Based.
Reading and Writing Mathematical Proofs
Empirical Explorations with The Logical Theory Machine: A Case Study in Heuristics by Allen Newell, J. C. Shaw, & H. A. Simon by Allen Newell, J. C. Shaw,
1 Program Correctness CIS 375 Bruce R. Maxim UM-Dearborn.
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
Overview of Formal Methods. Topics Introduction and terminology FM and Software Engineering Applications of FM Propositional and Predicate Logic Program.
CSI 3125, Axiomatic Semantics, page 1 Axiomatic semantics The assignment statement Statement composition The "if-then-else" statement The "while" statement.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
Formal Verification Lecture 9. Formal Verification Formal verification relies on Descriptions of the properties or requirements Descriptions of systems.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.5 Application: Correctness of Algorithms 1 [P]rogramming reliability – must be an activity.
Reasoning about programs March CSE 403, Winter 2011, Brun.
Program Analysis and Verification Spring 2014 Program Analysis and Verification Lecture 4: Axiomatic Semantics I Roman Manevich Ben-Gurion University.
Chapter 3 Part II Describing Syntax and Semantics.
COP4020 Programming Languages Introduction to Axiomatic Semantics Prof. Robert van Engelen.
CS6133 Software Specification and Verification
An Axiomatic Basis for Computer Programming Robert Stewart.
Lecture 5 1 CSP tools for verification of Sec Prot Overview of the lecture The Casper interface Refinement checking and FDR Model checking Theorem proving.
Principle of Programming Lanugages 3: Compilation of statements Statements in C Assertion Hoare logic Department of Information Science and Engineering.
DEDUCTION PRINCIPLES AND STRATEGIES FOR SEMANTIC WEB Chain resolution and its fuzzyfication Dr. Hashim Habiballa University of Ostrava.
Static Techniques for V&V. Hierarchy of V&V techniques Static Analysis V&V Dynamic Techniques Model Checking Simulation Symbolic Execution Testing Informal.
1 Section 8.2 Program Correctness (for imperative programs) A theory of program correctness needs wffs, axioms, and inference rules. Wffs (called Hoare.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
Formal Verification – Robust and Efficient Code 1 iCSC2016, Kim Albertsson, LTU Formal Verification – Robust and Efficient Code Lecture 2 Why FV? Kim Albertsson.
Formal Methods: Model Checkers and Theorem Provers
Formal Methods in Software Engineering 1
Lecture 5 Floyd-Hoare Style Verification
Axiomatic semantics Points to discuss: The assignment statement
Programming Languages 2nd edition Tucker and Noonan
Program correctness Axiomatic semantics
Program Verification with Hoare Logic
Programming Languages 2nd edition Tucker and Noonan
COP4020 Programming Languages
Presentation transcript:

Formal Verification – Robust and Efficient Code Lecture 1 Introduction to FV Kim Albertsson Luleå University of Technology Inverted CERN School of Computing, 29 February – 2 March 2016

Introduction Luleå You are here Kim Albertsson Research interests M.Sc. Engineering Physics and Electrical Engineering Currently studying for M.Sc. Computer Science Research interests Automation Machine learning Formal methods Great way to automate tedious tasks Luleå You are here Image from Wikimedia Commons, the free media repository

Formal Methods Managing complexity “…mathematically based languages, techniques, and tools for specifying and verifying … systems.” Edmund M. Clarke et al. Reveals inconsistencies and ambiguities

Formal Methods Specification + Model + Implementation enables verification Proving properties for a system Will my algorithm sort the input? Will my soda pop be delivered in time? Can the LHC interlock system end up in an inconsistent state?

Overview Series Approaches Application Model Checking and Theorem Proving Logic and automation How to build an ecosystem Application Robust code Robust and Efficient code

Introduction Lecture 1 Introduction Methods of Formal Verification Practical examples Specification Testing vs. Proving Contracts Methods of Formal Verification Model Checking Theorem Proving In-depth Theorem Proving First Order Logic Satisfiability Modulo Theories Verification Platforms

Introduction Lecture 1 Errors discovered late FV requires FV gives Expensive FV requires More effort for specification FV gives Feedback on inconsistencies Reduces late errors Reduces total time

Overview Introduction Methods of Formal Verification Practical examples Specification Testing vs. Proving Contracts Methods of Formal Verification Model Checking Theorem Proving In-depth Theorem Proving First Order Logic Satisfiability Modulo Theories Verification Platforms

Practical Examples Space flight, Ariane 5 - 501 Avionics, Lockheed

Ariane 5 - 501 Ariane 5 Expensive bug discovery Reused inertial reference system of Ariane 4 Greater horizontal acceleration 64-bit float cast to 16-bit integer overflowed Expensive bug discovery Image from Wikimedia Commons, the free media repository

Image from Wikimedia Commons, the free media repository Lockheed C130J C130J Hercules Secure low-level flight control code Review concluded Improved quality of product Decreased cost of development Image from Wikimedia Commons, the free media repository

Specification Concise, high level description of behaviour Varying degree of rigour Informal; written English Formal; using standardised syntax Required for verification

A verified program has demonstrated that specification is consistent with implementation

Specification Example in whyML let bubblesort (a: array int) = requires { … } ensures { sorted a } …

Testing vs. Proving Testing Proving Limited to particular point in input space Proving Reason about complete input space

Contract A contract consists of Weakest precondition pre-condition, that must hold before execution post-condition, that must hold after execution Weakest precondition The set of least restrictive of pre-conditions that still ensure the post-condition

System Composition

System Composition

Overview Introduction Methods of Formal Verification Practical examples Specification Testing vs. Proving Contracts Methods of Formal Verification Model Checking Theorem Proving In-depth Theorem Proving First Order Logic Satisfiability Modulo Theories Verification Platforms

Methods of FV Model Checking Theorem Proving General tool Tricky problem Theorem Proving

Model Checking Verifies that property holds for all states Explores all model states Suitable for finite state models Program verification Model program as a graph

Model Checking Pros Cons Easy start-up with when applicable Requires clever algorithms Must start anew each time

Theorem Proving Define a formal logic system With inference rules Proofs are derived by applying rules By hand or by machine Turns out full automation is a tricky problem Interactive provers, or proof assistants

Overview Introduction Methods of Formal Verification Practical examples Specification Testing vs. Proving Contracts Methods of Formal Verification Model Checking Theorem Proving In-depth Theorem Proving First Order Logic Satisfiability Modulo Theories Verification Platforms

First Order Logic Functions Object variables Predicates Sentence Refers to a unique object Names like x, jim, 1 Predicates Relations like =, <, AtHome Connectives ∧,∨,→,= Functions Complex names mother(jim) head(x) 1+1 Sentence Combination of the above mother(jim) = kimberly head(x) < 1

First Order Logic

First Order Logic Quantifiers Usage ∀ — for all ∃ — existence ∀x. Programmer(x) → Happy(x) ∃x. Programmer(x) → ProducesBugs(x) ∃x∀y. Loves(x, y)

Hoare Logic P, Precondition Q, Postcondition C, Command When C is executed under P, Q is guaranteed Rules required for each action of a language

Hoare Logic Composition While rule Allows commands to be executed in sequence While rule Models while-statement P is called loop invariant Can be extended to prove termination

Theories Theory Axiom Theorem Example Set of sentences that are assumed to be true, T Axiom Each element in T Theorem Any sentence that can be concluded from the theory Example Peano arithmetic, theory of lists…

Satisfiability Modulo Theories Hoare logic To reason about programs Reasoning expressed First order logic Verification conditions (VC)

Satisfiability Modulo Theories Similar to Binary Satisfiability problem, SAT One of the first problems to be shown to be NP-complete Find assignment of x, y, z … so that the expression is satisfied SAT variables are boolean SMTs are extended to handle FOL constructs Verifying a proof is easy Check each step for validity assuming our logic system

Satisfiability Modulo Theories Formulas are considered w.r.t background theory For formula F, assume ¬F F is valid when ¬F is not satisfiable under T Modern solvers use heuristics Improves performance for specific theories At the cost of general performance

Satisfiability Modulo Theories Example in alt-ergo Try for yourself https://alt-ergo.ocamlpro.com/try.php logic x, y, z: prop axiom a_1: (x and not y) -> (y or z) axiom a_2: y -> not x axiom a_3: x goal g_1: z # [answer] Valid (0.0060 seconds) (3 steps)

Verification Platforms Unified interface for provers Generates verification conditions (VCs) Discharged by any compliant prover, interactive or automatic Examples why3, boogie

Example let insertion_sort (a: array int) = for i = 1 to length a - 1 do let v = a[i] in let j = ref i in while !j > 0 && a[!j - 1] > v do a[!j] <- a[!j - 1]; j := !j - 1 done; a[!j] <- v done end

Example let insertion_sort (a: array int) = ensures { sorted a } for i = 1 to length a - 1 do invariant { sorted_sub a 0 i } let v = a[i] in let j = ref i in while !j > 0 && a[!j - 1] > v do invariant { 0 <= !j <= i } invariant { forall k1 k2: int. 0 <= k1 <= k2 <= i -> k1 <> !j -> k2 <> !j -> a[k1] <= a[k2] } invariant { forall k: int. !j+1 <= k <= i -> v < a[k] } a[!j] <- a[!j - 1]; j := !j - 1 done; a[!j] <- v done end

Example let insertion_sort (a: array int) = ensures { sorted a } for i = 1 to length a - 1 do invariant { sorted_sub a 0 i } let v = a[i] in let j = ref i in while !j > 0 && a[!j - 1] > v do invariant { 0 <= !j <= i } invariant { forall k1 k2: int. 0 <= k1 <= k2 <= i -> k1 <> !j -> k2 <> !j -> a[k1] <= a[k2] } invariant { forall k: int. !j+1 <= k <= i -> v < a[k] } a[!j] <- a[!j - 1]; j := !j - 1 done; a[!j] <- v done end

Example let insertion_sort (a: array int) = ensures { sorted a } for i = 1 to length a - 1 do invariant { sorted_sub a 0 i } let v = a[i] in let j = ref i in while !j > 0 && a[!j - 1] > v do invariant { 0 <= !j <= i } invariant { forall k1 k2: int. 0 <= k1 <= k2 <= i -> k1 <> !j -> k2 <> !j -> a[k1] <= a[k2] } invariant { forall k: int. !j+1 <= k <= i -> v < a[k] } a[!j] <- a[!j - 1]; j := !j - 1 done; a[!j] <- v done end

Example i, j are loop variables v holds the current element We are sorting subsegment [0, i]

Example let insertion_sort (a: array int) = ensures { sorted a } for i = 1 to length a - 1 do invariant { sorted_sub a 0 i } let v = a[i] in let j = ref i in while !j > 0 && a[!j - 1] > v do invariant { 0 <= !j <= i } invariant { forall k1 k2: int. 0 <= k1 <= k2 <= i -> k1 <> !j -> k2 <> !j -> a[k1] <= a[k2] } invariant { forall k: int. !j+1 <= k <= i -> v < a[k] } a[!j] <- a[!j - 1]; j := !j - 1 done; a[!j] <- v done end

Recap of Lecture 1 FV manages complexity Finds errors early Save money, time and possibly life Proof is a demonstration Consistency of specification and implementation Image from Wikimedia Commons, the free media repository

Recap of Lecture 1 Proving properties about your system Model Checking Exhaustive search of state space Theorem Proving Deductive approach

Recap of Lecture 1 Theorem Proving Based on First Order Logic Satisfiability Modulo Theories (SMT) solvers to find application of rules IVT platforms front-end with many SMT backends

Thank you