13.07.2015 Views

Proving the Correctness of Distributed Algorithms using TLA

Proving the Correctness of Distributed Algorithms using TLA

Proving the Correctness of Distributed Algorithms using TLA

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Proving</strong> <strong>the</strong> <strong>Correctness</strong> <strong>of</strong> <strong>Distributed</strong><strong>Algorithms</strong> <strong>using</strong> <strong>TLA</strong>Khushboo Kanjani, khush@cs.tamu.edu, Texas A & M University11 May 2007AbstractThis work is a summary <strong>of</strong> <strong>the</strong> Temporal Logic <strong>of</strong> Actions(<strong>TLA</strong>)proposed by Leslie Lamport as a language for specifying and verifyingconcurrent systems. Dijkstra’s self-stabilizing mutual exclusionalgorithm is discussed to demonstrate <strong>the</strong> use <strong>of</strong> <strong>TLA</strong>.1 IntroductionFormal methods are ma<strong>the</strong>matically-based techniques for <strong>the</strong> specification,development and verification <strong>of</strong> s<strong>of</strong>tware and hardware systems. Formal verificationis <strong>the</strong> act <strong>of</strong> proving <strong>the</strong> correctness <strong>of</strong> algorithms with respect to aproperty, <strong>using</strong> formal methods <strong>of</strong> ma<strong>the</strong>matics. There are two approachesto formal verification as defined in [1]:• Model Checking: This is a technique that relies on building a finitemodel <strong>of</strong> a system and checking that a desired property holds in thatmodel.The check is performed as an exhaustive state space search thatis guaranteed to terminate since <strong>the</strong> model is finite.• Theorem <strong>Proving</strong>: Theorem proving is <strong>the</strong> process <strong>of</strong> finding apro<strong>of</strong> <strong>of</strong> a property from <strong>the</strong> axioms <strong>of</strong> <strong>the</strong> system. It is a techniquein which <strong>the</strong> behavior <strong>of</strong> <strong>the</strong> system and its desired properties are expressedas formulas in some ma<strong>the</strong>matical logic. The temporal logic <strong>of</strong>actions(<strong>TLA</strong>) is one such logic aiming at proving correctness <strong>of</strong> multiprocessprograms.1


Khushboo KanjaniThe properties which define <strong>the</strong> correctness <strong>of</strong> a program are <strong>of</strong>ten describedin temporal logic. The following is a brief overview <strong>of</strong> <strong>the</strong> kinds <strong>of</strong> logic:1.1 Logic• Binary Logic has two boolean values True and False.• Propositional Logic adds <strong>the</strong> following operators to <strong>the</strong> binary logic.conjunction(and) ∧disjunction(or) ∨negation(not) ¬implication(implies) →equivalence ≡.• First-Order(Predicate) Logic extends propositional logic with twoquantifiers:∃ existential quantification(<strong>the</strong>re exists)∀ universal quantification (for all)• Temporal Logic quantifies in terms <strong>of</strong> time and has <strong>the</strong> following twooperators:♦ - now or sometime in future□ - now and foreverTime is viewed as a sequence <strong>of</strong> states in temporal logic.The Temporal Logic <strong>of</strong> Actions(<strong>TLA</strong>) is a combination <strong>of</strong> two logics : logic<strong>of</strong> actions and <strong>the</strong> standard temporal logic. In <strong>TLA</strong>, <strong>the</strong> program and itsproperties are written in <strong>the</strong> same language. The behavior <strong>of</strong> <strong>the</strong> programis written as a temporal formula σ. To prove that <strong>the</strong> program satisfies aproperty P, it is sufficient to prove that σ => P.1.2 Related WorkThe o<strong>the</strong>r formal methods based on temporal logic are Unity Logic [4], <strong>the</strong>logic <strong>of</strong> Manna, Pnueli [11] and Process Algebra by Hoare [2], Milner[9].Unity logic is based on assertions <strong>of</strong> <strong>the</strong> form {p}s{q}, which denotes that<strong>the</strong> execution <strong>of</strong> statement s in any state satisfying predicate p results in astate satisfying predicate q. Properties <strong>of</strong> a program are expressed in terms<strong>of</strong> <strong>the</strong> basic operators unless, invariant, ensures and → (leads-to).CPSC 689-608 Spring 2007 Report Draft


Khushboo KanjaniThe language <strong>of</strong> temporal logic defined by Manna, Pnueli [11] is built froma state language used to construct state formulas, and a set <strong>of</strong> logical andtemporal operators. By applying <strong>the</strong> logical and temporal operators to <strong>the</strong>state formulas, <strong>the</strong>y construct general temporal formulas.Process algebra provides a tool for <strong>the</strong> high-level description <strong>of</strong> interactions,communications, and synchronizations between a collection <strong>of</strong> independentprocesses. Some examples <strong>of</strong> this are Hoare’s Communicating SequentialProcesses(CSP)[2] and Milner’s Calculus <strong>of</strong> Communicating Systems(CCS)[9].2 DefinitionsThis section defines all <strong>the</strong> definitions used in <strong>the</strong> logic. The semantic meaning<strong>of</strong> every object T in <strong>the</strong> logic in denoted by [[T]]. The semantic meaning<strong>of</strong> state functions, predicates, actions etc. are stated in Figure 1 from [6] in<strong>the</strong> appendix.1. Values, Variables and States: A set Val <strong>of</strong> all possible values <strong>of</strong>variables is assumed. It includes sets like <strong>the</strong> set Nat <strong>of</strong> natural numbers.The booleans true and false do not belong to this set Val. Theset Var is an infinite set <strong>of</strong> all variable names. A state is a mappingfrom <strong>the</strong> set Var to <strong>the</strong> set Val. A state s assigns a value s[x] to avariable x. St is <strong>the</strong> collection <strong>of</strong> all possible states.2. State Functions: A non boolean expression built from variables andconstants. For example: z=x+y+3.3. State Predicate: It is a boolean expression built from variables andconstant symbols. For example x + y = 1 and x, y ∈ Nat4. Actions: An action represents an atomic operation in a concurrentprogram. It is a relation between unprimed variables(referring to oldstate) and primed variables(referring to <strong>the</strong> new state after <strong>the</strong> actionis executed). For example : y’=x+y+1. s[[A]]t is true if executing <strong>the</strong>A operation in state s produces state t.CPSC 689-608 Spring 2007 Report Draft


Khushboo Kanjani5. Validity: The formal definition <strong>of</strong> validity <strong>of</strong> an action A, denoted as|= A is:|= A ≡ ∀s, t ∈ St : s[[A]]t6. Rigid Variables: A variable whose value does not change in <strong>the</strong> execution<strong>of</strong> <strong>the</strong> program is termed as a rigid variable.7. Enabled Predicate: For any action A, Enabled A is defined as follows:s[[EnabledA]] ≡ ∃t ∈ St : s[[A]]t8. Unchanged Action: An action Unchanged f , for a state function f isdefined as a step in which <strong>the</strong> value <strong>of</strong> f does not change. Formally :Unchanged f ≡ f ′ = f3 <strong>TLA</strong>In <strong>TLA</strong>, specification <strong>of</strong> <strong>the</strong> system and <strong>the</strong> desired properties are stated by<strong>TLA</strong> formulas. A <strong>TLA</strong> formula is true or false on a behavior, which is asequence <strong>of</strong> states, where a state is an assignment <strong>of</strong> values to variables.3.1 SpecificationA specification is a formal description <strong>of</strong> <strong>the</strong> desired behavior <strong>of</strong> a program.The approach to define it can be divided into two steps:• State <strong>the</strong> variables that define <strong>the</strong> system’s state.• State <strong>the</strong> granularity <strong>of</strong> <strong>the</strong> steps that change those variables’ values.CPSC 689-608 Spring 2007 Report Draft


Khushboo KanjaniP1: while true doif x 1 = x n <strong>the</strong>nx 1 := (x 1 + 1)mod(n + 1)endendP i (i ≠ 1) :while true doifx i ≠ x i−1 <strong>the</strong>nx i := x i−1endendAlgorithm 1: Dijkstra self-stabilizing algorithm for MEExample: Here we give a <strong>TLA</strong> specification <strong>of</strong> <strong>the</strong> famous Dijkstra’s selfstabilizingalgorithm for mutual exclusion in a ring described in Algorithm1. The notations used here are explained in Figure 1. Equation 1 describes<strong>the</strong> initial condition <strong>of</strong> <strong>the</strong> variables. Equation 2 states that ∀i ∈ [0, N]i ≠ 1if <strong>the</strong> value <strong>of</strong> x i is not equal to that <strong>of</strong> its left neighbor, it is assigned thatvalue when process P i is activated. For P 1 , equation 3 states that <strong>the</strong> value<strong>of</strong> x 1 is incremented if its value is equal to x n . In equation 4, w defines<strong>the</strong> state function <strong>of</strong> all <strong>the</strong> variables in <strong>the</strong> program. These <strong>TLA</strong> formulasC 1 , C 2 , ....C n describe <strong>the</strong> behavior <strong>of</strong> <strong>the</strong> processes P 1 , P 2 , ....P n respectively.All possible executions <strong>of</strong> <strong>the</strong> program satisfy <strong>the</strong> temporal formula definedin equation 6.Init φ ≡ ∀i ∈ n, 0 ≤ x i ≤ n (1)∀i ∈ [0, N]i ≠ 1, C i ≡ (x i ≠ x i−1 ) ∧ (x ′ i = x i−1 ) ∧ Unchanged < AllBut(x i ) >(2)C 1 ≡ (x 1 = x n ) ∧ (x ′ 1 = (x 1 + 1)mod(n + 1)) ∧ Unchanged < AllBut(x 1 ) >(3)w =< x 1 , x 2 , ........., x n > (4)C ≡ C 1 ∨ C 2 ∨ ........ ∨ C n (5)φ ≡ Init φ ∧ □[C] w (6)CPSC 689-608 Spring 2007 Report Draft


Khushboo Kanjani3.2 Safety PropertiesSafety properties assert that something bad never happens. For example,for <strong>the</strong> problem <strong>of</strong> mutual exclusion, <strong>the</strong> safety property is that at mostone processor is in <strong>the</strong> critical section. For <strong>the</strong> self-stabilizing Algorithm1, mutual exclusion will be guaranteed if only one processor is allowed tochange its value. In o<strong>the</strong>r words, only one <strong>of</strong> C 1 , C 2 , ....C n is enabled. Safetyproperties are usually described as invariance properties with <strong>TLA</strong> formulas<strong>of</strong> <strong>the</strong> form □ P where P is predicate. These invariance properties are provedwith rule INV1 <strong>of</strong> Figure 1.3.3 Fairness PropertiesWeak fairness asserts that eventually <strong>the</strong> action is ei<strong>the</strong>r executed or becomeimpossible to execute- maybe only briefly. Strong fairness rules out thatlast condition. It means that ei<strong>the</strong>r <strong>the</strong> action is eventually executed, or itsexecution is eventually always impossible. For an action A and state functionf, weak fairness (WF) and strong fairness(SF) are expressed as follows:W F f (A) = (□♦〈A〉 f ) ∨ (□♦¬Enabled〈A〉 f ) (7)SF f (A) = (□♦〈A〉 f ) ∨ (♦□¬Enabled〈A〉 f ) (8)For <strong>the</strong> algorithm 1, starting with a random initial configuration, <strong>the</strong> programeventually reaches a safe configuration where only one processor changes itsvalue. The program guarantees W F 〈C〉 w .4 Verification <strong>of</strong> <strong>the</strong> Byzantine Generals algorithmIn [8], <strong>the</strong> one-traitor ”oral-message” solution to <strong>the</strong> Byzantine Generalsproblem is verified <strong>using</strong> <strong>TLA</strong>. The specification is divided into three levelsand a hierarchical pro<strong>of</strong> is presented. The high-level specification defines <strong>the</strong>problem statement. The mid-level specification captures <strong>the</strong> ”oral-message”solution to <strong>the</strong> problem that works in <strong>the</strong> presence <strong>of</strong> at most <strong>of</strong> one traitor.The underlying communication is ignored. The low-level specification models<strong>the</strong> way values are transmitted over communication channels. All <strong>the</strong>se threelevel specifications are long. So cannot be included here.CPSC 689-608 Spring 2007 Report Draft


Khushboo Kanjani5 Developments<strong>TLA</strong>+[7] provides a language for specifying <strong>TLA</strong> specifications. It can beused for a wide class <strong>of</strong> systems - from program interfaces(API) to distributedsystems. It is an extension to <strong>TLA</strong> and it contains operators for definingand manipulating data structures and syntactic structures for handling largespecifications. The syntax for expressions in <strong>TLA</strong>+ aims to capture some <strong>of</strong><strong>the</strong> richness <strong>of</strong> ordinary ma<strong>the</strong>matical notation. But a precise specificationin <strong>TLA</strong>+ gets very long and complicated. <strong>TLA</strong>+ is good for s<strong>of</strong>tware andhardware engineers and <strong>of</strong> little use to researchers concentrating on design<strong>of</strong> algorithms.6 Comments<strong>TLA</strong> is good as a formal method for verifying systems but I feel that it isnot good for proving <strong>the</strong> correctness <strong>of</strong> distributed algorithms. The designer<strong>of</strong> <strong>the</strong> algorithm has an intuition <strong>of</strong> why <strong>the</strong> algorithm is correct. <strong>TLA</strong> onlygives a language to specify <strong>the</strong> behavior <strong>of</strong> <strong>the</strong> program. If <strong>the</strong> behavior isspecified correctly, <strong>the</strong> safety and liveness pro<strong>of</strong>s are direct conclusions byapplying <strong>the</strong> <strong>TLA</strong> rules. Capturing <strong>the</strong> complete behavior <strong>of</strong> <strong>the</strong> algorithmcan get long and complicated. I believe informal pro<strong>of</strong>s give a better insight<strong>of</strong> <strong>the</strong> correctness <strong>of</strong> <strong>the</strong> algorithm.Some points to be noted about <strong>TLA</strong> :• Booleans are distinct from values <strong>of</strong> any variable and so state predicatesare different from state functions.• The variables in <strong>TLA</strong> have no types. Type-correctness is a provableproperty and not a syntactic requirement for specifying programs in<strong>TLA</strong>.• A specification <strong>of</strong> a multiprocess program can be decomposed as conjunction<strong>of</strong> its processes.• The rules stated in Figure 2 as described in [6] form a complete pro<strong>of</strong>system for reasoning programs in <strong>TLA</strong>.• There is no distinction between a program and a property in <strong>TLA</strong>.CPSC 689-608 Spring 2007 Report Draft


Khushboo KanjaniReferences[1] E.M. Clarke and J.M. Wing. Formal methods: State <strong>of</strong> <strong>the</strong> art andfuture directions. ACM Computing Surveys, 1996.[2] C.A.R. Hoare. Communicating Sequential Processes. Prentice-Hall International,London,1985.[3] Rajeev Joshi, Leslie Lamport, John Mat<strong>the</strong>ws, Serdar Tasiran, MarkTuttle, and Yuan Yu. Checking cache-cohorence protocols with tla+.Formal Methods in System Design, 2003.[4] Chandy K.M. and Misra. Parallel Program Design. Addison-Wesley,1988.[5] Leslie Lamport. <strong>Proving</strong> <strong>the</strong> correctness <strong>of</strong> multiprocess programs. IEEETransactions on S<strong>of</strong>tware Engineering, 1977.[6] Leslie Lamport. The temporal logic <strong>of</strong> actions. ACM Transactions onProgramming Languages and Systems, pages 1–52, 1993.[7] Leslie Lamport. Specifying Systems:The <strong>TLA</strong>+ Language and Tools forHardware and S<strong>of</strong>tware Engineers. Addison-Wesley, 2003.[8] Leslie Lamport and Stephan Merz. Specifying and verifying faulttolerantsystems. International Symposium on Formal Techniques inReal and Fault Tolerant Systems, 1994.[9] Robin Milner. A complete inference system for a class <strong>of</strong> regular behaviors.Journal <strong>of</strong> Computer and System Sciences, 28:439–466, 1984.[10] Joao Luis Sobrinho. An algebraic <strong>the</strong>ory <strong>of</strong> dynamic network routing.ACM Transcations on Networking, 2004.[11] Manna Z. and Pnuelli A. The temporal logic and reactive and concurrentsystems. Springer-Verlag, New York, 1991.CPSC 689-608 Spring 2007 Report Draft


Khushboo KanjaniFigure 1: Syntax <strong>of</strong> <strong>TLA</strong>CPSC 689-608 Spring 2007 Report Draft


Figure 2: Pro<strong>of</strong> Rules <strong>of</strong> <strong>TLA</strong>CPSC 689-608 Spring 2007 Report DraftKhushboo Kanjani


Khushboo KanjaniFigure 3: Quantification in <strong>TLA</strong>CPSC 689-608 Spring 2007 Report Draft

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!