Techniqueadvanced
Assertion checker synthesis
Also called monitor synthesis from assertions, assertion compilation to hardware.
Compiles temporal assertions into automata and then into synthesizable monitor circuits that run in simulation, emulation or silicon, as in Boule and Zilic's work.
Assertion checker synthesis turns a temporal assertion into a finite automaton and then into a small synchronous circuit, a checker, whose output fail goes to 1 in the clock cycle where the run of the design refutes the assertion. The checker reads the same signals as the assertion and needs no simulator, so it runs inside a simulator, in an emulator, on an FPGA prototype or on the chip itself. For the fragment always (r |-> s) with sequences r and s, this page builds the checker from an NFA for r and a DFA for s, and proves that it reports exactly the finite prefixes that refute some attempt. Every such prefix is a bad prefix, and under a condition on s every bad prefix is one.
In plain words
An assertion such as "every request is granted within three cycles" is a rule over time. A checker is a small circuit that watches the signals and raises an alarm in the cycle where the rule breaks.
The rule has a trigger (a request) and an obligation (a grant soon after). A trigger can come in any cycle while older obligations still wait, so many attempts are open at once. The checker keeps flags for where the trigger pattern may be and flags for where the open obligations stand, and updates them each cycle with a few gates.
The trick is to track obligations with a machine that never guesses. Then two attempts in the same position have the same future, and one flag stands for both. With a machine that guesses, merging attempts can hide the death of one of them.
When it applies
- The assertion is a safety property, or the part of it that a finite run can refute. A liveness property has no bad prefix, so no checker can flag its failure in finite time.
- The target is hardware or a cycle-based model: emulation, an FPGA prototype, post-silicon debug or on-line monitoring, where no simulator is present. A checker also gives a formal tool the property as a circuit: the assertion holds if and only if
failis never 1 on the product of the design and the checker, an invariant. - The operators are those that a finite automaton can express: Booleans, concatenation, union, repetition, and implications between sequences. This page treats the fragment below. Intersection adds a product of automata. Local variables of SVA carry data and need more than a finite automaton over the signal values.
The template
The fragment. Let be the signals and the letters, so a trace is , and . A Boolean matches the letter when . Sequences are built from Booleans by concatenation (r ##1 r'), union (r or r') and repetition (r[*m:n], r[*1:$]). A sequence denotes a regular language ; the fragment requires and . The assertion is
read with SVA semantics: the implication is overlapping and the consequent sequence is weak, which is the default in an assert statement. An attempt is a pair with ; the consequent starts at cycle . For a word , call dead when no prefix of is in and is not a prefix of any word of . A suffix weakly satisfies when some prefix of is in , or every finite prefix of is a prefix of a word of . Then when weakly satisfies for every attempt .
Step 1: an NFA for the antecedent. Build an NFA without -moves whose transitions carry Booleans, for example by the Thompson construction followed by -removal, or by the position automaton. For let .
Step 2: a DFA for the consequent. Build an -free NFA for . Remove the transitions whose Boolean is unsatisfiable, then remove the states from which no state of is reachable. Apply the subset construction to the trimmed NFA, with letters of , and change it in two ways: a subset that meets becomes the sink (the attempt succeeded), and the empty subset becomes the sink (the attempt is dead). Call the result , with start state and transition function . DFA minimization may shrink it.
Step 3: the checker. The checker has a register (one flip-flop per NFA state) and a register that holds a set of states of other than and (one flip-flop per DFA state). Both start empty. In cycle , with letter :
R := Post(R ∪ {q0}, a_k) -- antecedent matches in progress
m := (R ∩ F ≠ ∅) -- a match of r ends at cycle k
S' := { δ(d, a_k) : d ∈ S ∪ ({d0} if m) } -- step every open attempt
fail_k := (⊥ ∈ S')
S := S' \ {⊤, ⊥}
In hardware, each flip-flop of and has a next-state function that is an OR of ANDs of flip-flops and Booleans, one term per transition. A reset clears both registers, which is what disable iff asks for.
Why the consequent needs a DFA. Two attempts in the same state of have the same future: whether and when each dies depends only on that state and on the letters to come. So one flip-flop can stand for both, and loses nothing that fail needs. Two attempts that share an NFA state do not have this property, because the NFA state of an attempt is not one state but a set. The antecedent can stay an NFA because asks only whether some match ends, and the union of the NFA sets answers exactly that.
Why the checker is exact
Lemma 1 (deadness is closed under extension). If is dead, then is dead for each letter .
Proof. A prefix of is a prefix of or itself. No prefix of is in . If , then is a prefix of a word of , which is false. If is a prefix of a word of , then so is , which is false.
Lemma 2. weakly satisfies if and only if no finite prefix of is dead.
Proof. Suppose . A prefix longer than letters has a prefix in , and a shorter one is a prefix of , so neither is dead. If every prefix of is a prefix of a word of , none is dead. Conversely, if no prefix is dead, then either some prefix has a prefix in , or every prefix is a prefix of a word of , and in both cases weakly satisfies .
Lemma 3 (the DFA). For , the run of on ends in if some prefix of is in , in if is dead, and otherwise in the set of trimmed-NFA states reachable from on , which is not empty.
Proof. In the trimmed NFA each state reaches by transitions with satisfiable Booleans, so it reaches on some word. If , pick and a word that leads from to ; then . Conversely, if , every state of an accepting run reaches and every transition used has a satisfied Boolean, so the run survives the trimming and . So exactly when is a prefix of a word of . A subset meets exactly when the word read so far is in . The sinks and are entered at the first such event and never left. By induction on the length of , the run ends in when some prefix is in , and otherwise in exactly when , which by the above is when is dead.
Lemma 4 (the registers). After cycle : (a) if and only if some has a run of on from to , so exactly when some attempt exists; (b) is the set of states over the attempts with that are not dead and not in after (all attempts with count).
Proof. Induction on . For (a), after cycle is , and the runs that end at are those that start at from or extend a run that ended at . For (b), the attempts that end before and are still open after have their states in by the hypothesis and the line that removes and ; each moves to . The new attempts are added through exactly when . Different attempts in the same state share one entry, which changes the set but not its elements.
Theorem 1 (soundness and first detection). if and only if some attempt with has dead and, when , not dead. Call refuting when some attempt with has dead. Then the first cycle with is the least such that is refuting; if and only if some prefix is refuting; and every refuting prefix is a bad prefix of .
Proof. The first claim is Lemma 4(b) with Lemma 3. A refuting prefix at comes from an attempt whose word first became dead at some , and by Lemma 1 the word stays dead, so the least refuting is the first with . By Lemma 2, if and only if some attempt has a dead prefix , that is, some prefix is refuting. If is refuting through the attempt , any infinite word with prefix has the same attempt and the same dead word , so . Hence is a bad prefix.
Theorem 2 (completeness for a universal letter). Suppose some letter satisfies every Boolean that occurs in . Then every bad prefix of is refuting, so the checker reports the first bad prefix of each trace in the cycle where it ends.
Proof. Let be a prefix that is not refuting, and let . Write as a regular expression over its Boolean occurrences; a letter word is in when it matches some word of Booleans of that expression letter by letter. Take an attempt of . If , then , and matches any Boolean word of of length , which exists since ; so the suffix has a prefix in . If , then is not dead because is not refuting. Either it has a prefix in , and we are done, or for some , matching a Boolean word . Replace each letter of by , which satisfies the same Booleans; then , a prefix of . So , and is not a bad prefix.
The condition of Theorem 2 holds when uses only Booleans that one valuation can make true together, for example when every Boolean of is a positive signal. Without it the checker can be late, as the third example below shows. Prefixes that are bad by the letters they contain, not by an argument about all extensions, are what Kupferman and Vardi call informative; the refuting prefixes of this page play that role.
Cost. The antecedent register has at most flip-flops, linear in the number of Boolean occurrences of for the position automaton. The consequent register has one flip-flop per state of , at most states before minimization. That bound comes from the subset construction; some sequences need many fewer, and bounded delays such as ##[1:n] b give a chain of states. The logic per cycle is one AND term per transition. For general LTL safety formulas, Kupferman and Vardi give automata for the informative prefixes of size , while their construction for exactly the bad prefixes is doubly exponential.
Classic examples
A bounded handshake. assert property (@(posedge clk) req |-> ##[1:3] gnt); Here is the Boolean req, so has two states and . The consequent read from cycle is "any letter, then gnt within the next 3 letters". has the states , , , , and : goes to on any letter, and goes to on gnt and to otherwise, with . is never stored, so needs three flip-flops (state is open):
Run it with req at cycles 1, 2 and 5 and gnt at cycle 3. The columns show the register after the cycle.
| cycle | req | gnt | fail | |
|---|---|---|---|---|
| 0 | 0 | 0 | 000 | 0 |
| 1 | 1 | 0 | 100 | 0 |
| 2 | 1 | 0 | 110 | 0 |
| 3 | 0 | 1 | 000 | 0 |
| 4 | 0 | 0 | 000 | 0 |
| 5 | 1 | 0 | 100 | 0 |
| 6 | 0 | 0 | 010 | 0 |
| 7 | 0 | 0 | 001 | 0 |
| 8 | 0 | 0 | 000 | 1 |
At cycle 2, flip-flop holds the attempt of cycle 2 and the attempt of cycle 1. The grant at cycle 3 closes both. The attempt of cycle 5 dies at cycle 8. The letter satisfies every Boolean of , so by Theorem 2 the prefix is the first bad prefix: after cycle 7, a grant at cycle 8 could still save the run.
Why an NFA for the consequent is wrong. Take and $s = $ a ##1 b, so every cycle starts an attempt, and the run . The NFA for is with final. A checker that keeps one union of NFA states over all attempts gets after cycle 0, and after cycle 1 gets . is not empty, so it reports nothing. But the attempt of cycle 0 needed at cycle 1 and is dead. With , that attempt is in the state , which goes to on , and fail is 1 at cycle 1.
A late report. Take always (b ##1 !b), that is and $s = $ b ##1 !b, and a run that starts with . The attempt of cycle 0 needs at cycle 1 and the attempt of cycle 1 needs at cycle 1, so every extension fails, and is already a bad prefix. No attempt is dead after cycle 0, so the checker reports at cycle 1, one cycle late. No letter satisfies both and , so Theorem 2 does not apply. The report is still sound, and it arrives as soon as a single attempt is dead.
A sequence antecedent. For start ##1 busy[*1:$] ##1 done |-> ##1 ack, has the states , (after start), (after one or more busy) and (after done, final), with the loop . The register needs three flip-flops for , however many matches overlap, and is the new value of . The consequent is "any letter, then ack". Its state is never stored, so needs one flip-flop, set when , and fail is that flip-flop AND NOT ack.
Variations
- Non-overlapping implication.
r |=> sequalsr ##1 true |-> s, so it adds one state to . - Strong consequents and the end of a run. For a strong sequence, an attempt still open when the run ends is a failure. The checker raises an end-of-test signal when at the last cycle. This reports an obligation, not a bad prefix.
- Cover goals.
cover property (s)needs only the NFA of with a new start in every cycle, as for the antecedent: the goal is hit when . No subset construction is needed, since cover asks whether some match exists. - Per-attempt copies. When every word of that matters has at most letters, at most attempts are open at once. Keeping copies of the NFA state set, one per open attempt, costs flip-flops and avoids the subset construction. Which form is smaller depends on .
- Full PSL and SVA. Boulé and Zilic give automata for the full set of PSL operators, weak and strong, and for SVA, with rewrite rules that reduce operators to a small core. The checker of this page is a special case of that approach; the details of their construction differ.
- Formal use. The product of the design and the checker turns the assertion into the invariant , which bounded model checking, k-induction or IC3 can check. For LTL in general, the route is LTL to Büchi translation, and the checker is an automaton for (informative) bad prefixes.
Pitfalls
- Merging attempts in an NFA. One union of NFA states for all attempts of the consequent misses failures, as the second example shows. Determinize the consequent, or keep one copy per attempt.
- Assuming the report is at the first bad prefix. It is at the first refuting prefix. Without the condition of Theorem 2, the checker can be one or more cycles late, as in
always (b ##1 !b). Soundness is not affected. - Vacuous runs. A checker whose antecedent never matches never fires. Count antecedent matches, or add a cover goal on
r. - Empty matches. A sequence that can match the empty word, such as
a[*0:2], changes the meaning of the implication. The fragment here excludes it. Treat it by the rules of the standard, not by the template above. - Sampling and reset. The checker must read the values that the assertion semantics samples, the values before the clock edge, and must clear its registers on the reset of
disable iff. A checker that reads values after the edge reports a different property. - Size. The subset construction can blow up. Minimize the DFA, use per-attempt copies, or split a large consequent into several assertions.
- Liveness. No finite checker refutes
s_eventually gntin finite time. Bounded versions such as##[1:1000] gntare safety properties, but they state a different requirement.
Exercises
- Build the checker for
a ##1 b |-> ##1 c. Give the flip-flops of and and their next-state functions, and run it on the letters . - Show that
r |=> sandr ##1 true |-> shave the same attempts, each one cycle later, and the same failures. - Prove that the union of NFA states is exact for the antecedent: after cycle if and only if some .
- For
always (b ##1 !b), give the first bad prefix and the first refuting prefix of the run . - For
req |-> ##[1:n] gnt, show that minimized has states and that the checker needs flip-flops, however many requests overlap.
References
- Marc Boulé and Zeljko Zilic, Generating Hardware Assertion Checkers, For Hardware Verification, Emulation, Post-Fabrication Debugging and On-Line Monitoring, Springer, 2008, the automata for Booleans, sequences and properties, the encoding of automata as circuits, and the checkers for PSL and SVA (general locator)
- Marc Boulé and Zeljko Zilic, Automata-based assertion-checker synthesis of PSL properties, ACM Transactions on Design Automation of Electronic Systems 13(1), article 4, 1 to 21, 2008, the automaton for each PSL operator, the treatment of weak and strong operators, and the circuit form of the automata
- Orna Kupferman and Moshe Y. Vardi, Model checking of safety properties, Formal Methods in System Design 19(3), 291 to 314, 2001, bad prefixes, informative prefixes, and the size of automata that recognize them
- IEEE Standard for SystemVerilog, Unified Hardware Design, Specification, and Verification Language, IEEE Std 1800-2017, Clause 16 (sequences, the implication operators, weak and strong sequence properties, and the semantics of attempts)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag SYM1QA Edit this page History Report an error Markdown