Section 19.2.3

Finite-state hardware versus unbounded computation models

Definition

Finite-state hardware is a real processor with its memory: it holds a fixed number of bits, so it has only finitely many states. An unbounded computation model, such as the Turing machine (a mathematical computer with unlimited tape memory) or a program over integers of unlimited size, lets the state grow without limit. Whether such a finite model can reach a bad state is decidable §19.2.1: an exhaustive search always stops with the correct answer, though it may take infeasibly long. In an unbounded model the question is undecidable in general.

The idea

A processor with its memory is a machine of fixed size. If the machine has bb bits of state, it can be in at most 2b2^b states, and the theorems of the halting problem §19.2.2 entry, which assume unlimited memory, do not apply to it. So it seems that any property of a real processor could be checked by trying everything. The catch is size: each bit doubles the number of states, and a search through the states of a single 64-bit register, at one billion states per second, would take centuries.

A maze is a good picture. In a maze with finitely many rooms, chalk-marking each room on entry guarantees that the walk finishes: after at most as many visits as there are rooms, every reachable room is marked. In a maze that keeps growing, the marking never finishes. A real processor is the finite maze, but with 2b2^b rooms for bb in the hundreds of thousands. The picture stops in one respect: some methods reason about whole groups of rooms at once instead of visiting them one by one, and that is how large and infinite models are verified in practice.

A second catch is the model. “Every state” means every state of the model that was searched. A search over a model that leaves out an interrupt §6.11, a peripheral or a fault proves a property of that model, not of the device.

How it works

Exhaustive verification of a finite model has four steps.

  1. Choose the state. List every bit that can influence future behavior: processor registers, memory, the registers of the relevant peripherals (the hardware units around the processor, such as timers and radios), pending-interrupt flags, and any state of the environment the model includes. Let bb be the total number of these bits.

  2. Define the steps. For each state, the transition rule gives the possible next states. A deterministic machine without inputs has exactly one next state. Each input the environment can supply at that step, such as a received byte or an arriving interrupt, can give one more possible next state.

  3. Search. Start from the initial states. Keep a set of visited states and a queue of states still to expand. Take a state from the queue, compute its next states, check each against the property, and add each one not yet visited to both the set and the queue. Stop when the queue is empty or a bad state is found. With a first in, first out §14.14 queue this is breadth-first search §14.18.

  4. Conclude. Each state enters the queue at most once, and there are at most 2b2^b states, so the search stops. If it found no bad state, no bad state is reachable in the model.

Halting is decidable too, for a deterministic finite machine that receives no input. Run it for 2b2^b steps. If it has not stopped, it has passed through 2b+12^b + 1 states, counting the initial one, but only 2b2^b distinct states exist, so some state occurred twice. This counting argument is the pigeonhole principle. From the repeated state, the deterministic machine repeats the same steps again and again, so it never stops.

Properties about infinite behavior, such as liveness properties §1.12 (something good eventually happens), are also decidable on a finite model. An infinite execution of a finite machine must eventually go round a cycle of states, so a search can look for a reachable cycle on which the good event never occurs.

In an unbounded model the search can go on forever, because new states keep appearing. Very little unboundedness is needed for undecidability. A program with just two integer counters of unlimited size, which can only add 1, subtract 1 and test for 0, can simulate any Turing machine; Marvin Minsky proved this in the 1960s [437]. Whether such a program stops, or reaches a given instruction, is therefore undecidable.

Practical tools avoid listing states one by one. Symbolic model checking §3.30 represents large sets of states by formulas, using binary decision diagrams (compact graphs that represent true-or-false functions of many bits) or satisfiability solvers (programs that search for bit values that make a formula true). Bounded model checking §3.29 checks every execution up to a fixed number of steps kk. Abstraction merges many states into one. An inductive invariant §19.2.4, a property that holds initially and is preserved by every step, covers all reachable states §3.21 without visiting them. Each of these succeeds on many real designs, and no known method avoids exponential cost in the worst case.

Worked example

A 3-bit counter xx starts at 0, and each step sets xx to (x+2)mod8(x + 2) \bmod 8, the remainder after dividing x+2x + 2 by 8. The property to verify is that xx is never odd. The model has 23=82^3 = 8 possible states, 0 to 7. The search runs as follows.

  1. Visited: 0. Expand 0: 0+2=20 + 2 = 2, new.

  2. Expand 2: 2+2=42 + 2 = 4, new.

  3. Expand 4: 4+2=64 + 2 = 6, new.

  4. Expand 6: (6+2)mod8=0(6 + 2) \bmod 8 = 0, already visited.

The queue is empty after 4 expansions. The reachable states are 0, 2, 4 and 6, none of them odd, so the property holds for this model. The search visited 4 of the 8 possible states.

Replace the 3-bit counter by an integer of unlimited size with the step x←x+2x \leftarrow x + 2. The reachable states are 0,2,4,6,…0, 2, 4, 6, \dots, and the search never ends, because every expansion produces a new state. The property still holds, but a different argument shows it: xx is even at the start, and adding 2 to an even number gives an even number, so every reachable state is even. That argument is an inductive invariant.

Each added bit doubles the number of states. A 10-bit model has 210=1,0242^{10} = 1{,}024 states, and a 20-bit model has 220=1,048,5762^{20} = 1{,}048{,}576, which is 210=1,0242^{10} = 1{,}024 times as many. One 64-bit register has 264=18,446,744,073,709,551,6162^{64} = 18{,}446{,}744{,}073{,}709{,}551{,}616 values. At 10910^9 states per second the search takes about 1.84×10101.84 \times 10^{10} seconds, and with 365.25×86,400=31,557,600365.25 \times 86{,}400 = 31{,}557{,}600 seconds in a year, that is about 585 years. A microcontroller §6.1 with 64 KiB of RAM has 65,536×8=524,28865{,}536 \times 8 = 524{,}288 bits of RAM alone, so up to 2524,2882^{524{,}288} memory states. That number has 157,827 decimal digits, because 524,288×log102≈157,826.4524{,}288 \times \log_{10} 2 \approx 157{,}826.4.

A complete search can still prove the wrong thing. A main loop appends a record to a 16-entry buffer, with positions 0 to 15, only when the index ii is below 16: it compares ii with 16, then stores the record at position ii and adds 1 to ii. A model that contains only the main loop never stores outside positions 0 to 15, and an exhaustive search of that model confirms it. On the device, an interrupt handler §6.12 that appends records with the same code can run between the main loop’s comparison and its store. With i=15i = 15: the main loop compares 15 with 16 and passes; the handler runs, stores at position 15 and sets ii to 16; the main loop resumes, stores at position ii, which is now 16 and outside the buffer, and sets ii to 17. The search was exhaustive over a model that lacked the interrupt.

Stated precisely

A transition system is a triple M=(S,I,T)M = (S, I, T): SS is the set of states, I⊆SI \subseteq S is the set of initial states, and T⊆S×ST \subseteq S \times S is the transition relation, where (s,s′)∈T(s, s') \in T means that state s′s' can follow state ss in one step. Let B⊆SB \subseteq S be the set of bad states. The reachable set Reach(M)\mathrm{Reach}(M) is the smallest set that contains II and contains s′s' whenever it contains ss and (s,s′)∈T(s, s') \in T. The safety property §1.11 holds exactly when Reach(M)∩B=∅\mathrm{Reach}(M) \cap B = \emptyset.

Write |X||X| for the number of elements of a set XX. If SS is finite, and the next states of each state can be computed, the search computes Reach(M)\mathrm{Reach}(M) and stops, with work proportional to |S|+|T||S| + |T|. A machine with bb bits of state has |S|≤2b|S| \le 2^b, and the visited set may need up to 2b×b2^b \times b bits of memory. A deterministic machine without inputs stops by itself if and only if it stops within |S||S| steps.

The conclusion transfers to the real device only under three assumptions, each of which must be argued separately.

  1. Faithful state. Every bit that can influence the property is part of the state.

  2. Faithful steps. TT contains every step the device can take, including interrupts, peripherals acting on their own, other processors, faults and power loss, as far as the property depends on them.

  3. Bounded environment. The environment offers a finite set of choices at each step, and nothing about it needs unbounded memory to describe, such as an unbounded queue of pending messages.

If the state can grow without bound, SS is infinite, and reachability is undecidable in general.

Limits and common mistakes

Finite means decidable, not feasible. The bound 2b2^b counts the possible states; the reachable set can be much smaller, but nothing guarantees that it is. This is the state explosion §3.26 problem.

“Exhaustive” refers to the model. A missing interrupt, peripheral, second processor, fault or power-loss path makes a complete search prove a property of a different machine.

A bit-level model assumes that every step follows the processor’s specification. Physical effects lie outside it: a voltage glitch or a laser pulse that an attacker uses to skip an instruction, a bit flipped by radiation, or a signal sampled while it is changing. Fault injection §10.28 and an explicit fault model §1.30 address them.

An environment can make a model infinite even when the hardware is finite, for example a peer that may send any number of messages whose count matters. Designers then bound the environment, for example to at most 3 outstanding messages, and the conclusion covers only that bound.

An unbounded model is sometimes the better choice, because an inductive argument covers all sizes at once. It can also hide behavior that the real machine has: a model with integers of unlimited size never shows a 32-bit counter wrapping from its largest value back to 0.

Halting being decidable for a finite machine does not contradict the halting theorem, which assumes unlimited memory. Nor does it help in practice, because the bound is 2b2^b steps.

Questions answered

Can we exhaustively verify any real processor because its bits are finite?

Only in principle. Because a real processor and its memory hold a fixed number bb of bits, the processor has at most 2b2^b states, so whether a bad state is reachable is decidable: an exhaustive search that marks visited states always stops. Two obstacles remain. The first is size. One 64-bit register has 264≈1.8×10192^{64} \approx 1.8 \times 10^{19} values, about 585 years of search at one billion states per second, and 64 KiB of memory has 2524,2882^{524{,}288} possible contents. Each added bit doubles the count: 10 bits give 1,024 states, 20 bits give 1,048,576. The second is fidelity. The search covers the model, so registers, memory, interrupt and control state, the relevant peripherals, faults and the environment’s possible inputs must all be in it; leaving one out lets a complete search prove a property of the wrong machine.

What makes real processors verifiable in practice is not finiteness alone but methods that avoid listing states: symbolic model checking, bounded model checking up to a fixed number of steps, abstraction, and inductive invariants, applied to chosen properties of chosen parts of the design.

Related entries: State explosion (§3.26), Reachability (§3.21), Decidability and semidecidability (§19.2.1), Halting problem, Rice’s theorem, and restricted verifiers (§19.2.2), Model checking (§3.30), Finite-state machine (§8.33), Graph reachability search (§14.18). Further reading: [437].