inf5140: specification and verification of parallel systems

35
university-logo Motivation On Formal Methods Formalisms for Specification and Verification Summary INF5140: Specification and Verification of Parallel Systems Lecture 1 – Introduction: Formal Methods Gerardo Schneider Department of Informatics University of Oslo INF5140, Spring 2009 Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

Upload: others

Post on 28-Feb-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

INF5140: Specification and Verification ofParallel Systems

Lecture 1 – Introduction: Formal Methods

Gerardo Schneider

Department of InformaticsUniversity of Oslo

INF5140, Spring 2009

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

Outline

1 MotivationAn Easy ProblemHow to guarantee correctness of a system?Software Bugs

2 On Formal MethodsWhat are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

3 Formalisms for Specification and VerificationSpecificationVerification

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

The Problema

aThanks to César Muñoz (NASA, Langley) for providing the example.

Compute the value of a20 given the following definition

a0 = 112

a1 = 6111

an+2 = 111−1130− 3000

anan+1

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

A Java Implementation

class mya {

static double a(int n) {if (n==0)

return 11/2.0;if (n==1)

return 61/11.0;return 111 - (1130 - 3000/a(n-2))/a(n-1);

}

public static void main(String[] argv) {for (int i=0;i<=20;i++)

System.out.println("a("+i+") = "+a(i));}

}

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

The Solution (?)

$ java myaa(0) = 5.5a(2) = 5.5901639344262435a(4) = 5.674648620514802a(6) = 5.74912092113604a(8) = 5.81131466923334a(10) = 5.861078484508624a(12) = 5.935956716634138a(14) = 15.413043180845833a(16) = 97.13715118465481a(18) = 99.98953968869486a(20) = 99.99996275956511

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Should we Trust Software?

In fact the value of an for any n ≥ 0 may be computed by usingthe following recursive expression:

an =6n+1 + 5n+1

6n + 5n

Where

limn→∞ an = 6

We get then

a20 ≈ 6!

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Correctness

A system is correct if it meets its design requirements

Examples:System: The previous Java program computing anRequirement: For any n ≥ 0, the program should beconform with the previous recursive equation (limn→∞ an = 6)

System: A telephone systemRequirement: If user A want to call user B, then eventuallyA will manage to establish a connectionSystem: An operating systemRequirement: A deadly embrace1 will never happen

1A deadly embrace is when two processes obtain access to two mutuallydependent shared resources and each decide to wait indefinitely for the other.

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

How to Guarantee Correctness?Is it possible at all?

How to show a system is correct?It is not enough to show that it can meet its requirementWe should show that a system cannot fail to meet itsrequirementBy testing? Dijkstra wrote (1972): “Program testing can beused to show the presence of bugs, but never to show theirabsence”By other kind of “proof”? Dijkstra again (1965): “One cannever guarantee that a proof is correct, the best one cansay is: ’I have not discovered any mistakes”’What about automatic proof? It is impossible to construct ageneral proof procedure for arbitrary programs2

Any hope? In some cases it is possible to mechanicallyverify correctness; in other cases... we try to do our best

2Undecidability of the halting problem, by Turing.Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

What is Validation?

In general, validation is the process of checking ifsomething satisfies a certain criterionDo not confuse validation with verification3

The following may clarify the difference between these terms:Validation: "Are we building the right product?", i.e., does the

product do what the user really requiresVerification: "Are we building the product right?", i.e., does the

product conform to the specifications

3Some authors define verification as a validation technique, others talkabout V & V –Validation & Verification– as being complementary techniques.

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Usual Approaches for Validation

The following techniques are used in industry for validation:Testing

Check the actual system rather than a modelFocused on sampling executions according to somecoverage criteria – Not exhaustiveIt is usually informal, though there are some formalapproaches

SimulationA model of the system is written in a PL, which is run withdifferent inputs – Not exhaustive

Verification“Is the process of applying a manual or automatic techniquefor establishing whether a given system satisfies a givenproperty or behaves in accordance to some abstractdescription (specification) of the system”4

4From Peled’s book “Software reliability methods”.Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Source of Errors

Errors may arise at different stages of the Software/Hardwaredevelopment:

Specification errors (incomplete or wrong specification)Transcription from the informal to the formal specificationModeling errors (abstraction, incompleteness, etc)Translation from the specification to the actual codeHandwritten proof errorsProgramming errorsErrors in the implementation of (semi-)automatic tools /compilersWrong use of tools/programs. . .

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Source of Errors

Most errors, however, are detected quite late on thedevelopment process5

5Picture borrowed from G.Holzmann’s slides(http://spinroot.com/spin/Doc/course/index.html)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Some Famous Software Bugsa

aSource: Garfinkel’s article “History’ worst software bugs”

July 28, 1962 – Mariner I space probe The Mariner I rocket divertsfrom its intended direction and was destroyed by the missioncontrol. Software error caused the miscalculation of rocket’strajectory. Source of error: wrong transcription of ahandwritten formula into the implementation code.

1985-1987 – Therac-25 medical accelerator A radiation therapydevice deliver high radiation doses. At least 5 patients diedand many were injured. Under certain circumstances it waspossible to configure the Therac-25 so the electron beamwould fire in high-power mode but with the metal X-ray targetout of position. Source of error: a “race condition”.

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Some Famous Software Bugsa

aSource: Garfinkel’s article “History’ worst software bugs”

1988 – Buffer overflow in Berkeley Unix finger daemon AnInternet worm infected more than 6000 computers in a day.The use of a C routine gets() had no limits on its input. Alarge input allows the worm to take over any connectedmachine. Kind of error: Language design error (Bufferoverflow).

1993 – Intel Pentium floating point divide A Pentium chip mademistakes when dividing floating point numbers (errors of0.006%). Between 3 and 5 million chips of the unit has to bereplaced (estimated cost: 475 million dollars). Kind of error:Hardware error.

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

An Easy ProblemHow to guarantee correctness?Software Bugs

Some Famous Software Bugsa

aSource: Garfinkel’s article “History’ worst software bugs”

June 4, 1996 – Ariane 5 Flight 501 Error in a code converting 64-bitfloating-point numbers into 16-bit signed integer. It triggeredan overflow condition which made the rocket to disintegrate40 seconds after launch. Error: Exception handling error.

November 2000 – National Cancer Institute, Panama City Atherapy planning Sw allowed Drs. to draw some “holes” forspecifying the placement of metal shields to protect healthytissue from radiation. The Sw interpreted the “hole” indifferent ways depending on how it was drawn, exposing thepatient to twice the necessary radiation. 8 patients died; 20received overdoses. Error: Incomplete specification / wronguse.

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

What are Formal Methods?

“Formal methods are a collection of notations andtechniques for describing and analyzing systems”6

Formal means the methods used are based onmathematical theories, such as logic, automata, graph orset theoryFormal specification techniques are used tounambiguously describe the system itself or its propertiesFormal analysis/verification techniques serve to verify thata system satisfies its specification (or to help finding outwhy it is not the case)

6From D.Peled’s book “Software Reliability Methods”.Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

What are Formal Methods?Some Terminology

The term verification is used in different waysSometimes used only to refer the process of obtaining theformal correctness proof of a system (deductive verification)In other cases, used to describe any action taken for findingerrors in a program (including model checking and testing)Sometimes testing is not considered to be a verificationtechnique

We will use the following definition (reminder):

Formal verification is the process of applying a manual orautomatic formal technique for establishing whether a givensystem satisfies a given property or behaves in accordance tosome abstract description (formal specification) of the system

Saying ’a program is correct’ is only meaningful w.r.t. a given spec!Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Limitations

Software verification methods do not guarantee, in general,the correctness of the code itself but rather of an abstractmodel of itIt cannot identify fabrication faults (e.g. in digital circuits)If the specification is incomplete or wrong, the verificationresult will also be wrongThe implementation of verification tools may be faultyThe bigger the system (number of possible states) moredifficult is to analyze it (state explosion problem)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Any advantage?

OF COURSE!

Formal methods are not intended to guarantee absolutereliability but to increase the confidence on system reliability.

They help minimizing the number of errors and in many casesallow to find errors impossible to find manually

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Using Formal Methods

Formal methods are used in different stages of thedevelopment process, giving a classification of formal methods

1 We describe the system giving a formal specification2 We can then prove some properties about the specification3 We can proceed by:

Deriving a program from its specification (formal synthesis)Verifying the specification w.r.t. implementation

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Formal Specification

A specification formalism must be unambiguous: it shouldhave a precise syntax and semantics

Natural languages are not suitableA trade-off must be found between expressiveness andanalysis feasibility

More expressive the specification formalism more difficultits analysis

Do not confuse the specification of the system itself with thespecification of some of its properties

Both kinds of specifications may use the same formalismbut not necessarilyFor example:

The system specification can be given as a program or as astate machineSystem properties can be formalized using some logic

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Proving Properties about the Specification

To gain confidence about the correctness of a specification it isuseful to:

Prove some properties of the specification to check that itreally means what it is supposed toProve the equivalence of different specifications

Example

a should be true for the first two points of time, and thenoscillates

First attempt: a(0) ∧ a(1) ∧ ∀t · a(t + 1) = ¬a(t)INCORRECT! - The error may be found when trying toprove some propertiesCorrect specification:a(0) ∧ a(1) ∧ ∀t ≥ 0 · a(t + 2) = ¬a(t + 1)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Formal synthesis

It would be helpful to automatically obtain animplementation from the specification of a systemDifficult since most specifications are declarative and notconstructive

They usually describe what the system should do; not howit can be achieved

Example.1 Specify the operational semantics of a programming

language in a constructive logic (Calculus ofConstructions)

2 Prove the correctness of a given property w.r.t. theoperational semantics in Coq

3 Extract an OCAML code from the correctness proof (usingCoq’s extraction mechanism)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Verifying Specifications w.r.t. Implementations

There are mainly two approaches:

Deductive approach (automated theorem proving)Describe the specification Φspec in a formal model (logic)Describe the system’s model Φimp in the same formal modelProve that Φimp =⇒ Φspec

Algorithmic approachDescribe the specification Φspec as a formula of a logicDescribe the system as an interpretation Mimp of the givenlogic (e.g. as a finite automaton)Prove that Mimp is a “model” (in the logical sense) of Φspec

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

A Few Successful Stories

Esterel Technologies (Synchronous languages – Airbus,Avionics, Semiconductor & Telecom, ...)

Scade/LustreEsterel

Astrée (Abstract interpretation – Used in Airbus)Java PathFinder (model checking –find deadlocks onmulti-threaded Java programs)Verification of circuits design (model checking)Verification of different protocols (model checking andverification of infinite-state systems)See the Formal Methods page (http://vl.fmnet.info/)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Classification of Systems

Before discussing how to choose the right Formal Method weneed a classification of systems

Different kind of systems and not allmethodologies/techniques may be applied to all kind ofsystemsSystems may be classified depending on: 7

Their architectureThe type of interaction

7Here we follow Klaus Schneider’s book “Verification of reactive systems”.Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Classification of SystemsAccording to the System Architecture

Asynchronous vs. Synchronous HardwareAnalog vs. Digital HardwareMono- vs. Multi-processor systemsImperative vs. Functional vs. Logical vs. Object-orientedSoftwareConcurrent vs. Sequential SoftwareConventional vs. Real-time Operating SystemsEmbedded vs. Local vs. Distributed Systems

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Classification of SystemsAccording to the Type of Interaction

Transformational systems: Read inputs and produceoutputs - These systems should always terminateInteractive systems: Idem previous, but they are notassumed to terminate (unless explicitly required) –Environment has to wait till the system is readyReactive systems: Non-terminating systems. Theenvironment decides when to interact with the system -These systems must be fast enough to react to anenvironment action (real-time systems)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

Taxonomy of Properties

Many specification formalisms can be classified dependingon the kind of properties they are able to express/verifyProperties may be organized in the following categories

Functional correctness: The program for computing thesquare root really computes itTemporal behavior: The answer arrives in less than 40secondsSafety properties (“something bad never happens”): Trafficlights of crossing streets are never green simultaneouslyLiveness properties (“something good eventuallyhappens”): Process A will eventually be executedPersistence properties (stabilization): For all computationsthere is a point where process A is always enabledFairness properties (some property will hold infinitelyoften): No process is ignored infinitely often by an O.S.

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

What are Formal Methods?General RemarksClassification of Formal MethodsA Few Successful StoriesHow to Choose the Right Formal Method?

When and Which Formal Method to Use?

It depends on the problem, the underlying system and theproperty we want to proveExamples:

Digital circuits ... (BDDs, model checking)Communication protocol with unbounded number ofprocesses.... (verification of infinite-state systems)Overflow in programs (static analysis and abstractinterpretation)...

Open distributed concurrent systems with unboundednumber of processes interacting through shared variablesand with real-time constraints => VERY DIFFICULT!!Need the combination of different techniques

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

SpecificationVerification

Some Formalisms for Specification

An incomplete list of formalisms for specifying systems:Logic-based formalisms

Modal and temporal logics (E.g. LTL, CTL)Real-time temporal logics (E.g. Duration calculus, TCTL)Rewriting logic

Automata-based formalismsFinite-state automataTimed and hybrid automata

Process algebraCCS (LOTOS, ...)π-calculus

Visual formalismsMSC (Message Sequence Chart)StatechartsPetri nets

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

SpecificationVerification

Some Techniques and Methodologies for Verification

Algorithmic verificationFinite-state systems (model checking)Infinite-state systemsHybrid systemsReal-time systems

Deductive verification (theorem proving)Abstract interpretationFormal testing (black box, white box, structural, ...)Static analysis

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

Summary

Formal Methods are useful and neededWhich FM to use depends on the problem, the underlyingsystem and the property we want to proveIn real complex systems, only part of the system may beformally proved and no single FM can make the task

Our course will concentrate onTemporal logic as a specification formalismSafety, liveness and (maybe) fairness propertiesSPIN (LTL Model Checking)Few other techniques from student presentation (e.g.,abstract interpretation, CTL model checking, timedautomata)

Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

Ten Commandments of Formal Methods

From “Ten commandments revisited”, by J.P. Bowen and M.G.Hinchey (In: FMICS’05, ACM. Sept. 2005, pp.8–16)

1 Chose an appropriate notation2 Formalize but not over-formalize3 Estimate costs4 Have a formal method guru on call5 Do not abandon your traditional methods6 Document sufficiently7 Do not compromise your quality standards8 Do not be dogmatic9 Test, test and test again

10 Do reuseGerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009

university-logo

MotivationOn Formal Methods

Formalisms for Specification and VerificationSummary

Further Reading

The content of this talk was based in many different sources.The following chapter is a good survey:

Klaus Schneider: Verification of reactive systems, 2003.Springer. Chap. 1

For lecture 2 (28/01/2009):G. Andrews: Foundations of Multithreaded, Parallel, andDistributed Programming, 2000. Addison Wesley. Chap. 2Z. Manna and A. Pnueli: Temporal Verification of ReactiveSystems: Safety, Springer-Verlag, 1995. Chap. 08

8This chapter is also the base of lectures 3 and 4.Gerardo Schneider, Ifi - UiO INF5140 - Lecture 1: Formal Methods 21.01.2009