S3 · Lesson 26 · Formal verification
Equivalence checking, model checking, bounded proofs and why simulation can't be exhaustive
Simulation checks the cases someone thought to run. A 64-bit adder has input pairs; at a billion tests a second, trying them all would take years. Formal verification answers the question differently: it turns the design and a property into a logic problem and asks a solver whether any input sequence at all can break the property. When the solver says no, that's a proof for every case; when it says yes, it hands back the shortest failing trace. This lesson covers what the tools prove, how big their problems get, and where they stop.
- The line is the time to simulate every input combination of an n-bit block exhaustively, at the rate set by the slider ( vectors per second), in years.
- Each extra input bit doubles it: 40 bits take minutes at a billion vectors a second, 64 bits take centuries.
- No speedup rescues exhaustive simulation at real widths; proofs have to reason symbolically.
Predict
A 32 × 32 multiplier is to be verified by simulating every input pair at vectors per second. How long would that take?
Two 32-bit inputs make pairs; at a second that's seconds, 585 years. A 64-bit multiplier would take years. Formal equivalence checking settles such questions in minutes by reasoning about all inputs at once.
Name it
Equivalence checking
Two circuits (RTL and its synthesized netlist, or a netlist before and after an optimization) are joined into a miter: the same inputs drive both, and an OR of the XORs of their outputs says "they differ". A SAT solver searches for inputs making the miter 1; if none exist, the circuits are equivalent for every input. Sequential designs are matched register by register first, which is why synthesis keeps register names.
Model checking
A property written as an assertion (lesson 25) is checked against every reachable state:
- Safety: something bad never happens (the FIFO never overflows). A violation is a finite trace.
- Liveness: something good eventually happens (every request is eventually granted).
- Cover: some situation can happen at all, which guards against over-constrained setups that make every assertion trivially true.
Input assumptions restrict the environment to legal behavior; too strong an assumption hides real bugs.
Bounded model checking
Unroll the design for k cycles, a copy of its logic per cycle, and ask the solver for a trace from reset that violates the property within k steps. The problem grows linearly with k: roughly variables for F flip-flops and G gates. BMC finds shallow bugs fast, but proves the property only up to depth k; a full proof needs k at least the design's diameter (the longest shortest path between reachable states), or k-induction, or abstraction.
Why the state space matters
n flip-flops have states, usually far more than are reachable. Explicit search, visiting states one at a time, works up to tens of millions of states; symbolic methods (SAT, BDDs) handle far more, but bugs buried behind long counters remain hard.
Worked example
A block with 2000 flip-flops and 50 000 gates is unrolled 30 cycles for bounded model checking. How large is the solver's problem?
Show the solution
- Variables. Every flip-flop and gate gets a variable in each of the 30 cycles:
- Clauses. With about three clauses per gate, some 4.5 million clauses: routine for a modern SAT solver.
- Depth. Doubling the depth doubles the problem, so BMC runs are usually limited to tens or hundreds of cycles.
Answer about 1.56 million variables and 4.5 million clauses.
Worked example
A FIFO of depth 16 forgets to block a push when it's full. How deep must bounded model checking go to find the overflow, and what does a clean run to depth 10 prove?
Show the solution
- Shortest failing trace. It is 17 pushes after reset, so BMC must reach depth 17.
- What depth 10 proves. A clean run to depth 10 proves only that no overflow happens in the first 10 cycles; it says nothing about deeper states.
- Choosing the depth. That's why BMC depth is chosen from the design's structure, and why counters inside a design are often reduced (a FIFO of depth 4 behaves like one of depth 16 for most properties).
Answer depth 17; a clean run to depth 10 proves only that the first 10 cycles are safe.
Worked example
A bug fires only when a 20-bit input equals one particular value. How many random tests give 99% confidence of hitting it, and how would formal verification find it?
Show the solution
- Random tests. Each hits the value with probability :
- Formal verification. A SAT solver finds the triggering value directly, in one query, since it reasons about the condition rather than sampling inputs.
Answer 4.8 million random tests, against one solver query.
Check
A block with 40 input bits is to be simulated exhaustively at 1000000 vectors per second.
(a)
How many input vectors are there?
(b)
How long would it take?
Check
A design with 1000 flip-flops and 10000 gates is unrolled 50 cycles for bounded model checking, with about three clauses per gate.
(a)
About how many variables does the solver see?
(b)
About how many clauses?
Check
A one-hot state machine has 12 states, one flip-flop each.
(a)
How many states can its flip-flops encode?
(b)
What fraction of them are reachable from reset?
Check
Bounded model checking to depth 40 finds no violation of a safety property. What has been shown?
Check
Match each kind of property to an example.
- Athe design meets timing at 1 GHz
- Bevery request is eventually granted
- Cthe input valid signal never rises during reset
- Dthe FIFO never overflows
- Ethe FIFO can become full
Check
A bug fires only for one value of an m-bit input; random tests pick that input uniformly.
Step 1
What is the chance one test hits it?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
How many tests give confidence c of hitting it?
Step 3
What is that approximately, for large m?
Check
Write bfs(init, step, bad, inputs): explore states breadth first from init, where step(state, inp) gives the next state for each input in inputs, and return (depth, count): depth is the length of the shortest input sequence reaching a state where bad(state) is true (or None if none is reachable), and count is the number of distinct states discovered.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why can formal verification find a bug that months of random simulation missed?
Random simulation samples input sequences, and a bug that needs a rare combination, such as one particular value on a wide bus or a long, specific sequence of events, may have a chance of a billionth per test, so it's effectively never hit. A formal tool doesn't sample: it encodes the design and the negated property as a logic problem and asks a solver whether any input sequence satisfies it. The solver's search is guided by the structure of the logic, so a narrow trigger condition is no harder than a common one. If a violation exists within the explored depth, the solver finds it and returns the shortest trace, whatever its probability under random inputs.
Practice
Keep practicing
6 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.