Algorithm Search⌘K

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 fail is 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 APAP be the signals and Σ=2AP\Sigma = 2^{AP} the letters, so a trace is w=w0w1…∈Σωw = w_0 w_1 \ldots \in \Sigma^\omega, and w[i..j]=wi⋯wjw[i..j] = w_i \cdots w_j. A Boolean bb matches the letter aa when a⊨ba \models b. Sequences are built from Booleans by concatenation (r ##1 r'), union (r or r') and repetition (r[*m:n], r[*1:$]). A sequence rr denotes a regular language L(r)⊆Σ+L(r) \subseteq \Sigma^+; the fragment requires ε∉L(r)\varepsilon \notin L(r) and L(s)≠∅L(s) \ne \emptyset. The assertion is

φ=always (r∣ ⁣ ⁣→s),\varphi = \texttt{always } (r \mid\!\!\to s),

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 (j,k)(j, k) with w[j..k]∈L(r)w[j..k] \in L(r); the consequent starts at cycle kk. For a word u∈Σ∗u \in \Sigma^*, call uu dead when no prefix of uu is in L(s)L(s) and uu is not a prefix of any word of L(s)L(s). A suffix v∈Σωv \in \Sigma^\omega weakly satisfies ss when some prefix of vv is in L(s)L(s), or every finite prefix of vv is a prefix of a word of L(s)L(s). Then w⊨φw \models \varphi when w[k..]w[k..] weakly satisfies ss for every attempt (j,k)(j, k).

Step 1: an NFA for the antecedent. Build an NFA Ar=(Q,q0,Δ,F)A_r = (Q, q_0, \Delta, F) without ε\varepsilon-moves whose transitions carry Booleans, for example by the Thompson construction followed by ε\varepsilon-removal, or by the position automaton. For X⊆QX \subseteq Q let Post(X,a)={q′:(q,b,q′)∈Δ, q∈X, a⊨b}\mathrm{Post}(X, a) = \{q' : (q, b, q') \in \Delta,\ q \in X,\ a \models b\}.

Step 2: a DFA for the consequent. Build an ε\varepsilon-free NFA As=(P,p0,Δs,Fs)A_s = (P, p_0, \Delta_s, F_s) for ss. Remove the transitions whose Boolean is unsatisfiable, then remove the states from which no state of FsF_s is reachable. Apply the subset construction to the trimmed NFA, with letters of Σ\Sigma, and change it in two ways: a subset that meets FsF_s becomes the sink ⊤\top (the attempt succeeded), and the empty subset becomes the sink ⊥\bot (the attempt is dead). Call the result DsD_s, with start state d0={p0}d_0 = \{p_0\} and transition function δ\delta. DFA minimization may shrink it.

Step 3: the checker. The checker has a register R⊆QR \subseteq Q (one flip-flop per NFA state) and a register SS that holds a set of states of DsD_s other than ⊤\top and ⊥\bot (one flip-flop per DFA state). Both start empty. In cycle kk, with letter ak=wka_k = w_k:

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 RR and SS 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 DsD_s 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 SS 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 mm 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 uu is dead, then uxux is dead for each letter xx.

Proof. A prefix of uxux is a prefix of uu or uxux itself. No prefix of uu is in L(s)L(s). If ux∈L(s)ux \in L(s), then uu is a prefix of a word of L(s)L(s), which is false. If uxux is a prefix of a word of L(s)L(s), then so is uu, which is false. □\square

Lemma 2. vv weakly satisfies ss if and only if no finite prefix of vv is dead.

Proof. Suppose v[0..i]∈L(s)v[0..i] \in L(s). A prefix longer than i+1i + 1 letters has a prefix in L(s)L(s), and a shorter one is a prefix of v[0..i]∈L(s)v[0..i] \in L(s), so neither is dead. If every prefix of vv is a prefix of a word of L(s)L(s), none is dead. Conversely, if no prefix is dead, then either some prefix has a prefix in L(s)L(s), or every prefix is a prefix of a word of L(s)L(s), and in both cases vv weakly satisfies ss. □\square

Lemma 3 (the DFA). For u∈Σ+u \in \Sigma^+, the run of DsD_s on uu ends in ⊤\top if some prefix of uu is in L(s)L(s), in ⊥\bot if uu is dead, and otherwise in the set XuX_u of trimmed-NFA states reachable from p0p_0 on uu, which is not empty.

Proof. In the trimmed NFA each state reaches FsF_s by transitions with satisfiable Booleans, so it reaches FsF_s on some word. If Xu≠∅X_u \ne \emptyset, pick q∈Xuq \in X_u and a word yy that leads from qq to FsF_s; then uy∈L(s)uy \in L(s). Conversely, if uy∈L(s)uy \in L(s), every state of an accepting run reaches FsF_s and every transition used has a satisfied Boolean, so the run survives the trimming and Xu≠∅X_u \ne \emptyset. So Xu≠∅X_u \ne \emptyset exactly when uu is a prefix of a word of L(s)L(s). A subset meets FsF_s exactly when the word read so far is in L(s)L(s). The sinks ⊤\top and ⊥\bot are entered at the first such event and never left. By induction on the length of uu, the run ends in ⊤\top when some prefix is in L(s)L(s), and otherwise in ⊥\bot exactly when Xu=∅X_u = \emptyset, which by the above is when uu is dead. □\square

Lemma 4 (the registers). After cycle kk: (a) q∈Rq \in R if and only if some j≤kj \le k has a run of ArA_r on w[j..k]w[j..k] from q0q_0 to qq, so m=1m = 1 exactly when some attempt (j,k)(j, k) exists; (b) S′S' is the set of states δ(d0,w[k′..k])\delta(d_0, w[k'..k]) over the attempts (j,k′)(j, k') with k′≤kk' \le k that are not dead and not in ⊤\top after w[k′..k−1]w[k'..k-1] (all attempts with k′=kk' = k count).

Proof. Induction on kk. For (a), RR after cycle kk is Post(Rk−1∪{q0},wk)\mathrm{Post}(R_{k-1} \cup \{q_0\}, w_k), and the runs that end at kk are those that start at kk from q0q_0 or extend a run that ended at k−1k - 1. For (b), the attempts that end before kk and are still open after k−1k - 1 have their states in Sk−1S_{k-1} by the hypothesis and the line that removes ⊤\top and ⊥\bot; each moves to δ(d,wk)\delta(d, w_k). The new attempts are added through d0d_0 exactly when m=1m = 1. Different attempts in the same state share one entry, which changes the set but not its elements. □\square

Theorem 1 (soundness and first detection). failk=1\mathit{fail}_k = 1 if and only if some attempt (j,k′)(j, k') with k′≤kk' \le k has w[k′..k]w[k'..k] dead and, when k′<kk' < k, w[k′..k−1]w[k'..k-1] not dead. Call w[0..t]w[0..t] refuting when some attempt (j,k′)(j, k') with k′≤tk' \le t has w[k′..t]w[k'..t] dead. Then the first cycle with fail=1\mathit{fail} = 1 is the least tt such that w[0..t]w[0..t] is refuting; w⊭φw \not\models \varphi if and only if some prefix is refuting; and every refuting prefix is a bad prefix of φ\varphi.

Proof. The first claim is Lemma 4(b) with Lemma 3. A refuting prefix at tt comes from an attempt whose word first became dead at some t′≤tt' \le t, and by Lemma 1 the word stays dead, so the least refuting tt is the first t′t' with fail=1\mathit{fail} = 1. By Lemma 2, w⊭φw \not\models \varphi if and only if some attempt has a dead prefix w[k′..t]w[k'..t], that is, some prefix is refuting. If w[0..t]w[0..t] is refuting through the attempt (j,k′)(j, k'), any infinite word w′w' with prefix w[0..t]w[0..t] has the same attempt and the same dead word w′[k′..t]w'[k'..t], so w′⊭φw' \not\models \varphi. Hence w[0..t]w[0..t] is a bad prefix. ■\blacksquare

Theorem 2 (completeness for a universal letter). Suppose some letter σ⋆\sigma^\star satisfies every Boolean that occurs in ss. Then every bad prefix of φ\varphi is refuting, so the checker reports the first bad prefix of each trace in the cycle where it ends.

Proof. Let u=w[0..t]u = w[0..t] be a prefix that is not refuting, and let w′=u (σ⋆)ωw' = u \, (\sigma^\star)^\omega. Write ss as a regular expression over its Boolean occurrences; a letter word is in L(s)L(s) when it matches some word β1⋯βn\beta_1 \cdots \beta_n of Booleans of that expression letter by letter. Take an attempt (j,k′)(j, k') of w′w'. If k′>tk' > t, then w′[k′..]=(σ⋆)ωw'[k'..] = (\sigma^\star)^\omega, and (σ⋆)n(\sigma^\star)^n matches any Boolean word of ss of length nn, which exists since L(s)≠∅L(s) \ne \emptyset; so the suffix has a prefix in L(s)L(s). If k′≤tk' \le t, then w[k′..t]w[k'..t] is not dead because uu is not refuting. Either it has a prefix in L(s)L(s), and we are done, or w[k′..t]y∈L(s)w[k'..t] y \in L(s) for some yy, matching a Boolean word β1⋯βn\beta_1 \cdots \beta_n. Replace each letter of yy by σ⋆\sigma^\star, which satisfies the same Booleans; then w[k′..t](σ⋆)∣y∣∈L(s)w[k'..t] (\sigma^\star)^{|y|} \in L(s), a prefix of w′[k′..]w'[k'..]. So w′⊨φw' \models \varphi, and uu is not a bad prefix. ■\blacksquare

The condition of Theorem 2 holds when ss uses only Booleans that one valuation can make true together, for example when every Boolean of ss 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 ∣Q∣|Q| flip-flops, linear in the number of Boolean occurrences of rr for the position automaton. The consequent register has one flip-flop per state of DsD_s, at most 2∣P∣+22^{|P|} + 2 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 nn 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 2O(∣φ∣)2^{O(|\varphi|)}, 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 rr is the Boolean req, so ArA_r has two states and m=reqkm = \mathit{req}_k. The consequent read from cycle kk is "any letter, then gnt within the next 3 letters". DsD_s has the states d0d_0, d1d_1, d2d_2, d3d_3, ⊤\top and ⊥\bot: d0d_0 goes to d1d_1 on any letter, and did_i goes to ⊤\top on gnt and to di+1d_{i+1} otherwise, with d4=⊥d_4 = \bot. d0d_0 is never stored, so SS needs three flip-flops q1,q2,q3q_1, q_2, q_3 (state did_i is open):

q1+=req,q2+=q1∧¬gnt,q3+=q2∧¬gnt,fail=q3∧¬gnt.q_1^{+} = \mathit{req}, \qquad q_2^{+} = q_1 \wedge \neg \mathit{gnt}, \qquad q_3^{+} = q_2 \wedge \neg \mathit{gnt}, \qquad \mathit{fail} = q_3 \wedge \neg \mathit{gnt}.

Run it with req at cycles 1, 2 and 5 and gnt at cycle 3. The columns q1q2q3q_1 q_2 q_3 show the register after the cycle.

cycle req gnt q1q2q3q_1 q_2 q_3 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 q1q_1 holds the attempt of cycle 2 and q2q_2 the attempt of cycle 1. The grant at cycle 3 closes both. The attempt of cycle 5 dies at cycle 8. The letter {gnt}\{\mathit{gnt}\} satisfies every Boolean of ss, so by Theorem 2 the prefix w[0..8]w[0..8] 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 r=truer = \texttt{true} and $s = $ a ##1 b, so every cycle starts an attempt, and the run {a}{a}\{a\}\{a\}. The NFA for ss is p0→ap1→bp2p_0 \xrightarrow{a} p_1 \xrightarrow{b} p_2 with p2p_2 final. A checker that keeps one union UU of NFA states over all attempts gets U={p1}U = \{p_1\} after cycle 0, and after cycle 1 gets Post({p1}∪{p0},{a})={p1}\mathrm{Post}(\{p_1\} \cup \{p_0\}, \{a\}) = \{p_1\}. UU is not empty, so it reports nothing. But the attempt of cycle 0 needed bb at cycle 1 and is dead. With DsD_s, that attempt is in the state {p1}\{p_1\}, which goes to ⊥\bot on {a}\{a\}, and fail is 1 at cycle 1.

A late report. Take always (b ##1 !b), that is r=truer = \texttt{true} and $s = $ b ##1 !b, and a run that starts with {b}\{b\}. The attempt of cycle 0 needs ¬b\neg b at cycle 1 and the attempt of cycle 1 needs bb at cycle 1, so every extension fails, and w[0..0]w[0..0] 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 bb and ¬b\neg b, 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, ArA_r has the states q0q_0, q1q_1 (after start), q2q_2 (after one or more busy) and q3q_3 (after done, final), with the loop q2→busyq2q_2 \xrightarrow{busy} q_2. The register RR needs three flip-flops for q1,q2,q3q_1, q_2, q_3, however many matches overlap, and mm is the new value of q3q_3. The consequent is "any letter, then ack". Its state d0d_0 is never stored, so SS needs one flip-flop, set when m=1m = 1, and fail is that flip-flop AND NOT ack.

Variations

  • Non-overlapping implication. r |=> s equals r ##1 true |-> s, so it adds one state to ArA_r.
  • 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 S≠∅S \ne \emptyset at the last cycle. This reports an obligation, not a bad prefix.
  • Cover goals. cover property (s) needs only the NFA of ss with a new start in every cycle, as for the antecedent: the goal is hit when R∩F≠∅R \cap F \ne \emptyset. No subset construction is needed, since cover asks whether some match exists.
  • Per-attempt copies. When every word of L(s)L(s) that matters has at most nn letters, at most nn attempts are open at once. Keeping nn copies of the NFA state set, one per open attempt, costs n ∣P∣n \, |P| flip-flops and avoids the subset construction. Which form is smaller depends on ss.
  • 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 G ¬fail\mathsf{G}\,\neg\mathit{fail}, 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 gnt in finite time. Bounded versions such as ##[1:1000] gnt are safety properties, but they state a different requirement.

Exercises

  1. Build the checker for a ##1 b |-> ##1 c. Give the flip-flops of RR and SS and their next-state functions, and run it on the letters {a}{b}{a}{b}{ }\{a\}\{b\}\{a\}\{b\}\{\,\}.
  2. Show that r |=> s and r ##1 true |-> s have the same attempts, each one cycle later, and the same failures.
  3. Prove that the union of NFA states is exact for the antecedent: R∩F≠∅R \cap F \ne \emptyset after cycle kk if and only if some w[j..k]∈L(r)w[j..k] \in L(r).
  4. For always (b ##1 !b), give the first bad prefix and the first refuting prefix of the run {b}{b}{ }\{b\}\{b\}\{\,\}.
  5. For req |-> ##[1:n] gnt, show that DsD_s minimized has n+3n + 3 states and that the checker needs nn flip-flops, however many requests overlap.

References

  1. 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)
  2. 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
  3. 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
  4. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples