<<

Core Claim in Development Computer programs/systems are subject to exact reasoning.

Wolfgang Schreiner is an exact science in that all the properties [email protected] of a program and all the consequences of executing it in any given environment can, in principle, be found out from the text of the Research Institute for Symbolic Computation (RISC) program itself by means of purely deductic reasoning. Johannes Kepler University, Linz, Austria C.A.R. Hoare, “An Axiomatic Basis for Computer Programming”, http://www.risc.uni-linz.ac.at 1969.

A strong claim; not everyone might agree to it (we will rephrase it later).

Wolfgang Schreiner http://www.risc.uni-linz.ac.at 1/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 2/18

Example Demonstration

static int sum(int[] a) class Swap { { // swap a[i] and a[j] int n = a.length; static void swap(int[] a, int i, int j) int s = 0; { {n = length(a) ∧ s =0} int t = a[i]; for (int i=0; i

This reasoning has various aspects: class Main static void init(int[] a, int n) { { Specification. State the properties that a program shall have. public static void main(String[] args) for (int i=0; i

Wolfgang Schreiner http://www.risc.uni-linz.ac.at 5/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 6/18

Properties of Reasoning Alternatives to Reasoning

Principal advantage: clarity and generality. Inspection. Let multiple people look at program and discuss it. The subjects of discussion are well defined. Actually, this is reasoning (but without a formal basis). There are clear rules for the correctness of the arguments. Advantages: reduces programmer’s “system blindness”. The arguments may apply to infinitely many situations. Disadvantage: without a formal basis, it is unclear what rules guide Example: {x ≥ 0}x = x+1{x > 0} the discussion. (for all x, to show that x is greater than zero after the execution of Testing. Run the program with sample inputs and observe the the assignment statement, it suffices to show that x is greater than or external effects (see what happens). equal to zero before). Advantage: the program is shown to work in certain situations. Principal disadvantage: abstraction. Disadvantage: you never know what happens with other inputs. We reason about models of the real world. In concurrent programs, you even do not now whether the same Questionable whether the model adequately describes the real world. behavior is always exhibited with the same input. Example: the machine code generated by the for x = x+1 Simulation/. Similar to testing, but also observe the may be wrong, or the processor may have an error in the internal behavior of the program. implementation of the + operation, or ... Advantage: consideration not limited to external effects. All reasoning is relative to the assumptions of the model. Disadvantages: same as for testing.

Wolfgang Schreiner http://www.risc.uni-linz.ac.at 7/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 8/18 The Power and Limits of Reasoning Core Claim Rephrased

Assume a correct proof that program P satisfies specification S. True interpretation of Hoare’s statement: We have shown Computer programming is an exact science in that all the properties that every model execution of P satisfies S, of a model program and all the consequences of executing it in any which is also true for all real executions of P if the model is adequate. given model environment can, in principle, be found out from the text We have not shown of the program itself by means of purely deductic reasoning. that any real execution of P satisfies S, Beware of bugs in the above code; I have only proved it correct, not tried it. Donald E. Knuth, 1977. Still a strong claim, but now everyone should be able to agree to it. that S captures your expectation of a real world behavior. On the other hand, with a successful test run we demonstrate that some real execution of P satisfies an expectation, we cannot show that this is true for all real executions of P. Program testing can be used to show the presence of bugs, but never to show their absence! E.W.Dijkstra, 1972. Reasoning and testing have both their place. Wolfgang Schreiner http://www.risc.uni-linz.ac.at 9/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 10/18

The Role of Reasoning The Role of Reasoning

Often: Post Factum Better: Pre Factum So the main role of reasoning is on program/system designs: Design a principal solution to a given problem. Argue about the correctness of the design. Specification Specification Thus find design errors; repeat process until you are satisfied. The main role of testing is on program/system implementations: Reasoning Reasoning Map the design to real computers using real programming languages. Model Model Run the implementation on sample inputs and check its behavior. System System Thus find implementation errors; repeat process until you are satisfied. Modeling Implementing This is a big difference from “proving that a program is correct”. Real Real System System

Write a specification, design a model system, reason about its correctness, then implement the design, then test the implementation.

Wolfgang Schreiner http://www.risc.uni-linz.ac.at 11/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 12/18 The Role of Reasoning The Origins: Sequential Programs

Apparently, there are various approaches/tools that seem to apply A personal selection. reasoning to real systems . . . Robert W. Floyd, 1967: Assigning Meaning to Programs. Typical goal: prevent runtime errors. C.A.R. Hoare, 1969: An Axiomatic Basis for Computer Division by zero, array index out of bounds, null pointer dereferences, Programming. memory corruptions (buffer overflows). Tool that takes program as input and detects program errors. C.A.R. Hoare, 1972: Proof of Correctness of Data Representations. Actually: operate on automatically constructed models. Edsger W. Dijkstra, 1975: Guarded Commands, Nondeterminacy Focus is on falsification (finding errors). and Formal Derivation of Programs. Investigate whether “bad” states might occur in model. Edsger W. Dijkstra, 1976: A Discipline of Programming. Detected/assumed error in model may imply error in real system. Luckham et al, 1979: Stanford PASCAL Verifier - User Manual. Application to mission-critical/important pieces of software. Airplane control software. David Gries, 1981: The Science of Programming. MS Windows device driver. Axiomatic program semantics, program verification. We alwas reason about models.

Wolfgang Schreiner http://www.risc.uni-linz.ac.at 13/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 14/18

The Origins: Concurrent Programs Later History

A personal selection. In the 1980s, program verification was considered “dead” by many. Little automation, much manual effort by programmer. Dijkstra, 1968: Cooperating Sequential Processes. Handling of toy programs only. Ashcorft and Manna, 1971: Formalization of Properties of Parallel In the 1990s, model checkers became successful. Programs. Fully automatically check (finite state) models. Owicki, Gries, 1976: An Axiomatic Proof Technique for Parallel Verification of hardware and of communication protocols. Systems with state spaces of size 10100 and beyond. Programs. Since the late 1990s, interest in software verification revived. C.A.R. Hoare, 1978: Communicating Sequential Processes. /proving of critical pieces of software. Armin Pnueli, 1979: The Temporal of Programs. Focus often more on falsification than on verification. Leslie Lamport, 1980: The “Hoare Logic” of Concurrent Programs. New applications such as proof-carrying-code (PCC). Robin Milner, 1982: A Calculus of Communicating Systems. Ship machine code together with proof that code satisfies certain safety/ properties. , /algebra, temporal logic. New issues such as security considered. Formal methods are a hot topic today (also in industry). Wolfgang Schreiner http://www.risc.uni-linz.ac.at 15/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 16/18 Languages and Systems Course Outline

Specification Languages Specifying and verifying sequential programs. Hoare style: VDM (Vienna Development Method), SPARK (SPADE Hoare calculus and predicate transformers. Ada Kernel), Larch/C++, OCL (Object Constraint Language for PVS specification and verification system. UML), JML (Java ), ... Specifying and verifying Java programs. Algebraic/axiomatic: OBJ, ACT One, CafeOBJ, Larch, CASL, . . . (JML). State-oriented: Z, ASM (Abstract State Machines), ... Extended static checking of Java programs (ESC/Java2). Concurrent: Unity, Estelle, Lotos, TLA, ... Generating verification conditions for Java programs (Krakatoa/Why). Mobile: pi-Calculus, ... Verifying Java programs (KeY). Model Checkers Spin, SMV, BLAST, Bandera, SLAM, VeriSoft, . . . Specifying and verifying concurrent systems. Automated Provers State graphs for synchronous and asynchronous systems. PVS, HOL, Isabelle, Coq, Theorema, ... Specifying properties of concurrent systems in temporal logic. Verification Environments Verifying concurrent systems (PVS). Model-checking concurrent systems (Spin). Edinburgh Concurrency Workbench, STeP (Stanford Temporal Prover), KIV (Karlsruhe Interactive Verifier), JIVE (Java Interactive Proof-Carrying Code (PCC): Hans-Wolfgang Loidl (LMU Munich) Verification Environment), LOOP, Krakatoa/Why, KeY, ... Mobile code carrying a proof of its safety.

Wolfgang Schreiner http://www.risc.uni-linz.ac.at 17/18 Wolfgang Schreiner http://www.risc.uni-linz.ac.at 18/18