12-06

Chapter 12 · Taming the state space, choosing your evidence

Choosing your evidence

  • 43 min core
  • Core track
  • Skills: evidence

00Recall

One card from 12-05 on the induction check, and two cards from chapters 10 and 11 that put an AI summary next to a TLC result. This lesson is about matching a claim to the evidence that can carry it, and those two cards were the same question in miniature.

12-05-a from Reachable versus inductive

What makes an invariant inductive, and how do you check that with TLC?

Show answer

It holds initially and every step from any state satisfying it leads to a state satisfying it. Define IndInit == TypeOK /\ Inv and check INIT IndInit, NEXT Next and INVARIANT Inv: a breadth-first search from every typed state that satisfies Inv. If Inv is inductive (and steps keep the types), every successor is one of those starting states, so the search ends after one step; if it is not, the violation is one step from the start.

11-05-b from When no mapping exists

An AI summary says "TLC confirms AlternatingBit refines ReliableChannel, so every message is eventually delivered." The cfg checked ChanInit and ChanStep on Spec. Is the summary accurate?

Show answer

No. Those properties are the safety half. The protocol's Spec has no fairness and allows it to stop, so delivery was not checked; checking Chan!Liveness on Spec fails. It passes only on a spec that adds enough of the protocol's own fairness, and the summary should say which.

10-04-b from Fairness hides liveness bugs, never safety bugs

An AI summary says "with strong fairness on every action, TLC finds no violation of NoStarvation, so the design is starvation-free." What should you check before accepting it?

Show answer

What each fairness conjunct promises and who keeps that promise. SF on a lock or on a user's action is an assumption the real system may not meet; under the fairness a real scheduler gives, the same design may starve.

Skip recall Recall is never required.

01Commit

specs/proofs/HourClock.tla is a clock that shows only the hour. specs/proofs/HourClockProof.tla next to it is a short proof, written for TLAPS, the TLA+ proof system, that every behavior of the clock satisfies TypeOK in every state. The course ships a cfg for the proof module too.

Commit a

What does ./tla report for HourClockProof.cfg?

  1. A pass: TLC checks the proof's steps.
  2. A parse error: the proof needs a module that only TLAPS ships.
  3. A pass: TLC skips the proof steps and checks TypeOK on the clock, as for HourClock.cfg.

Answer A parse error: the proof needs a module that only TLAPS ships.

specs/apalache/BankTransferTyped.tla moves money between two accounts in two steps, a debit and then a credit. MoneyConserved says the two balances plus the money in flight always add up to the opening total. Here is a claim you would like to make in a design review: "MoneyConserved holds for every opening balance and every transfer limit."

Commit b

Which evidence can support the claim "MoneyConserved holds for every opening balance and every transfer limit" as worded?

  1. TLC breadth-first search of the model with an opening balance of two and a limit of two, every action firing and the witness reached.
  2. Apalache, checking every behavior of up to ten steps, with the opening balance and the limit left open instead of fixed.
  3. A TLAPS proof, checked by the prover, of Spec => []MoneyConserved through an inductive invariant, with the constants left open.
  4. Simulation with a large opening balance and a million random behaviors, every one of which kept the money conserved.

Answer A TLAPS proof, checked by the prover, of Spec => []MoneyConserved through an inductive invariant, with the constants left open.

02Lab

shell
./tla check chapters/12-state-space-and-evidence/specs/proofs/HourClockProof.cfg
./tla check chapters/12-state-space-and-evidence/specs/proofs/HourClock.cfg
./tla check chapters/12-state-space-and-evidence/specs/apalache/BankTransferTyped.cfg
Expected output 12-state-space-and-evidence/specs/proofs/HourClockProof
12-state-space-and-evidence/specs/proofs/HourClockProof  HourClockProof.cfg
parse error: cannot find module TLAPS (only this folder and the standard modules are searched)
  chapters/12-state-space-and-evidence/specs/proofs/HourClockProof.tla:0:0: cannot find module TLAPS (only this folder and the standard modules are searched)
expected outcome met: parse-error TLAPS
Expected output 12-state-space-and-evidence/specs/proofs/HourClock
12-state-space-and-evidence/specs/proofs/HourClock  HourClock.cfg
parse ok
model check: no violation found in 12 distinct states (13 generated, depth 12)
expected outcome met: pass
coverage: all 1 actions fired
witness AtTwelve reached (trace of 12 states)

Reveal for commit a

A parse error: SANY cannot find the module TLAPS. That is what the cfg expects, and it is all ./tla can say about the proof. Whether the proof is accepted is a question for TLAPS, which this course does not run.

Reveal for commit b

Of these four options, only the proof can carry "every opening balance and every limit", and only a proof of the shape 12-05 taught: Init => Inv, Inv /\ [Next]_vars => Inv' and Inv => MoneyConserved, every step accepted by the prover, for every value of the constants that the module's ASSUME allows. A proof of the last implication alone says nothing about the behaviors. Each of the other options can carry a narrower claim, and the evidence table below says which.

03Reason

If you picked the TLC run, you are in the habit this chapter has been building, and it is a good habit: run the model, read the numbers. This lesson adds the last question: which kind of evidence can even support the claim I want to make?

Write something before openingis the proof broken?

The message says nothing about the proof. It says the TLA+ parser bundled with TLC cannot find a module that ships with TLAPS. Install TLAPS and the module is there; whether the proof steps then go through is the prover's verdict. A tool that cannot read your evidence has neither refuted it nor checked it.

Every :::did-not-show box draws on this evidence table.

MethodWhat it coversBound it leaves
TLC BFSevery reachable state of one finite modelconstants, constraints, symmetry
TLC simulationsampled behaviorscoverage (unknown)
Apalachesymbolic, boundedbehavior length, data types
TLAPSunbounded proof of what is statednone in the claim, but high effort and the spec may still be wrong
Trace validationobserved runs conform to the speconly the runs and logged variables observed

Read each row as a sentence: "this method covers X, and leaves Y unchecked". Every claim you write should be able to name its row. A TLC claim also names any view whose soundness you argued, and the fingerprint estimate of 12-01. The Apalache row is its bounded run: it considers only behaviors up to its length, and only values of the types its @type annotations declare. Its one-step induction check of 12-05 (--init=IndInv --length=1) depends on no length, and leaves only the constants it was given.

Start with the proof. It has the shape 12-05 taught you.

TLA+chapters/12-state-space-and-evidence/specs/proofs/HourClockProof.tla
LEMMA InitTyped is defined as Init implies TypeOK
  BY DEF Init, TypeOK
TLA+chapters/12-state-space-and-evidence/specs/proofs/HourClockProof.tla
LEMMA StepTyped is defined as TypeOK and [Next]_hour implies TypeOKprime
  BY DEF TypeOK, Next, Tick
TLA+chapters/12-state-space-and-evidence/specs/proofs/HourClockProof.tla
THEOREM AlwaysTyped is defined as Spec implies alwaysTypeOK
  BY InitTyped, StepTyped, PTL DEF Spec

The first lemma is the base case, the second is the induction step, and the theorem puts them together with PTL, a back-end decision procedure for propositional temporal logic. StepTyped is exactly the one-step check of 12-05, stated as a theorem. Here TLC could check the same 12 states, because the clock has no open constants; a proof pays off when constants or types are unbounded.

So a proof leaves no bound in its claim, but it proves exactly the theorem you wrote, about exactly the spec you wrote. If the spec abstracts away the bug, or the theorem is weaker than the requirement, the proof is perfect and the system is still wrong.

Write something before openingchange Tick to a clock that never moves, hour' = hour. Which of the three statements in the proof stop being true?

None of them. The initial hour is still in range, and a step that leaves it alone keeps it in range, so both lemmas and the theorem stay true of the stopped clock. A typing theorem cannot tell a working clock from a broken one: that is what "what is stated" means in the TLAPS row. To catch the stopped clock you need a property that says the hour keeps changing, and the fairness that makes a working clock satisfy it.

Write something before openingthe Warm-up asks you to run the induction step for MoneyConserved with TLC before anyone writes a proof. Why do that first?

If MoneyConserved is not inductive, its induction step is false and the prover will fail, with a message far harder to read than TLC's. MoneyConserved can still be proved, through a stronger invariant; the Warm-up finds it. TLC prints a two-state counterexample to induction in a second, and it tells you which conjunct the proof is missing.

Apalache sits between TLC and TLAPS. It translates the spec and a bounded number of steps into constraints for an SMT solver, so it can reason about whole sets of values at once instead of enumerating them. It needs the type of every variable and constant: the @type comments in BankTransferTyped.tla, which TLC reads as comments.

TLA+chapters/12-state-space-and-evidence/specs/apalache/BankTransferTyped.tla
VARIABLES
    \* @type: Str -> Int;
    balance,    \* balance[a]: money in account a
    \* @type: Int;
    inFlight,   \* money debited and not yet credited
    \* @type: Str;
    payee       \* the account the money in flight is going to, or "none"

A bounded Apalache run looks like this. ConstInit gives it the constants that the TLC cfg gives TLC.

shell
apalache-mc check --cinit=ConstInit --inv=MoneyConserved --length=10 BankTransferTyped.tla

Apalache and TLAPS are optional tools: the course's checks do not run them. Output not shown: run it yourself, or see the optional-tools workflow. What the course does run is TLC on the same module, BankTransferTyped.cfg, which finds no violation of MoneyConserved or NoOverdraft in 19 distinct states, with both actions firing and the witness reached.

The last row, trace validation, is chapter 14: it checks logs of real runs against the spec, and it is the only row that touches the code.

Try the table on three sentences about the bank. "No transfer overdraws an account", from a cfg with an opening balance of two: TLC BFS, bounded by those constants. "No overdraft in ten thousand random transfers": simulation, bounded by coverage nobody can measure. "No overdraft for any balance, proved": TLAPS, bounded by what the theorem states, and honest only if the proof was checked, which in this course it is not.

None of these rows is "the best". A strong review packet can combine three: an exhaustive TLC run of small models, a simulation or bounded run of larger ones, and, for the one invariant everything depends on, an induction check, then perhaps a proof.

04In your editor

Check this lesson's exercises with:

shell
./tla check 12-06

05Practice

Warm-up. Before anyone tries to prove MoneyConserved, run the induction step with TLC, read the counterexample, and add the conjunct the proof would need.

Core. A teammate's bounded check of a help desk's ticket numbers is "deep enough for any real bug". Make it deep enough for this one, and say which row of the table the teammate's run belongs to.

12-06-ex1Warm-up5 min

12-06-ex1 · Before you prove it

Tier: warm-up. Time: about 5 minutes.

BankTransferTyped.tla is the module from specs/apalache/. A teammate plans to prove MoneyConserved with TLAPS, by induction like HourClockProof.tla. Before anyone spends an afternoon in the prover, run the induction step with TLC.

  1. Run ./tla check 12-06-ex1. MCBankTransferTyped.cfg starts from every typed state where StepInv holds and takes one step. With StepInv == MoneyConserved, it finds a counterexample to induction. Read its first state: what is in flight, and who is it going to?
  2. Fill gap g1 in MCBankTransferTyped.tla: add the conjunct a proof would need.
  3. Run again. Both cfgs must pass.

Leave BankTransferTyped.tla and both cfgs as they are.

Hints: HINTS.md, under "12-06-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/12-state-space-and-evidence/exercises/06-ex1-before-you-prove-it/.

Both cfgs must meet their goals, MCBankTransferTyped.cfg and MCBankTransferTyped.reach.cfg: the line below appears once for each.

Done when: ./tla check 12-06-ex1 prints "goal met: pass".

./tla check 12-06-ex1

Repo chapters/12-state-space-and-evidence/exercises/06-ex1-before-you-prove-it/

Hints

Hint 1

Read the counterexample's first state: how much is in flight, and what is the payee?

Hint 2

In every reachable state, money in flight always has a payee: Debit sets both at once and Credit clears both. MoneyConserved alone does not know that.

Hint 3 (nearly the answer)

Add one conjunct: an implication from "no payee" to "nothing in flight".

12-06-ex2Core8 min

12-06-ex2 · Deep enough

Tier: core. Time: about 8 minutes.

TicketIds.tla numbers help desk tickets from a counter that wraps around after MaxId numbers. Nothing stops it from handing out a number that is still in use. A teammate checks it the way a bounded tool would: CONSTRAINT Shallow stops TLC from exploring past level Bound, much as Apalache's --length stops at a number of steps. The check passes, and the teammate writes "deep enough for any real bug".

  1. Run ./tla check 12-06-ex2. It passes, every action fires, and two tickets are open at once.
  2. Before you change anything, work out on paper how many tickets must be opened, with none closed, before a number is reused.
  3. Fill gap g1 in TicketIds.cfg: raise Bound until the check meets the bug. Predict the smallest value first; Shallow's comment says how TLC counts.
  4. Read the trace, and in NOTES.md write the smallest Bound that meets the bug and why, which row of the evidence table the teammate's run belongs to, and the claim it really supported. The grader accepts any bound that meets the bug; the smallest one is your job.

Do not remove the constraint or fix Open. The point is the bound.

Hints: HINTS.md, under "12-06-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/12-state-space-and-evidence/exercises/06-ex2-deep-enough/.

Done when: ./tla check 12-06-ex2 prints "goal met: violation UniqueIds".

./tla check 12-06-ex2

Repo chapters/12-state-space-and-evidence/exercises/06-ex2-deep-enough/

Hints

Hint 1

Count the tickets: with MaxId numbers, after how many openings does the counter hand out number 0 again, if none is closed?

Hint 2

The bug needs one more opening than there are numbers. Then count states, not steps, and read how Shallow counts levels and what TLC checks one level past the bound.

Hint 3 (nearly the answer)

The bug's trace has one state more than the number of openings it needs. TLC checks invariants one level past the bound, so the smallest Bound is one less than that trace's length.

06Explain it

Open NOTES.md and answer the three prompts under 12-06, about the Core exercise.

output
What I built, and why it is correct:
Which assumption, if false, breaks it:
What TLC did not check here:

Compare your answers with "12-06 check your explanation" in HINTS.md.

After you writeCheck your explanation

A good answer: "A bound of seven meets the bug: the counter reuses a number on the seventh ticket opened, a trace of eight states, and TLC checks invariants one level past the bound. The teammate's run belongs to the bounded row of the evidence table, like Apalache: it explored states up to level four and checked their successors, so it covered every behavior of at most five states (four steps) and nothing longer. Neither run says anything about a counter of another size."

A weak answer: "I raised the bound until it failed." It does not say how deep the bug is or which kind of evidence the original run was.

Done?