Assertions: Checks That Travel with the Design

Write a rule of the specification as a check that holds at every clock edge. See why it finds a bug where the bug starts, and how it differs from a scoreboard.

You Will Be Able To

  • Describe an assertion as a rule that must hold at every clock edge.
  • Write a timing rule as a plain checker, and read the same rule as one assertion.
  • Explain why an assertion reports a bug at its source, and a scoreboard only at the output.
  • Choose between an assertion and a scoreboard for a given rule.
Lesson
B3.4
Time
22 min
Runs on
Your browser
Check
5 questions

The scoreboard is happy: six requests went in, six answers came out, all correct. Yet the specification says every answer must arrive within four cycles. Two of them took six, and nothing in the log says so.

A Rule Pinned to a WireStep through. A scoreboard waits at the end of the path and asks whether the right answers came out. An assertion sits on the wires themselves and asks, at every clock edge, whether a rule still holds.
  • Driver
  • DUT
  • Scoreboard
  • Property
  • Data
A Rule Pinned to a WireStep through. A scoreboard waits at the end of the path and asks whether the right answers came out. An assertion sits on the wires themselves and asks, at every clock edge, whether a rule still holds. driver Bench drives req dut responder answers each req withack scoreboard Scoreboard counts answers atthe end property Assertion on reqand ack every req: ack within4 cycles reqackwatched every edge
  1. driver Benchdrives req
    • req → responder
  2. dut responderanswers each req with ack
    • ack → Scoreboard
    • watched every edge → Assertion on req and ack
  3. scoreboard Scoreboardcounts answers at the end
  4. property Assertion on req and ackevery req: ack within 4 cycles
  1. The path

    The bench sends requests and the responder answers them.

  2. Checking at the end

    A scoreboard counts what came out. Six requests, six answers: it passes.

  3. Checking on the wire

    An assertion watches req and ack at every edge. It fails at the cycle the rule breaks, next to the cause.

Read the diagram as text
  • Bench: drives req
  • responder: answers each req with ack
  • Scoreboard: counts answers at the end
  • Assertion on req and ack: every req: ack within 4 cycles
  • Bench → responder: req
  • responder → Scoreboard: ack
  • responder → Assertion on req and ack: watched every edge

An architecture drawing of the lab. The assertion needs no stimulus of its own; it only watches.

Before You Start

Read Corner Cases and How to Think of Them first. A clock edge, a register and a cycle are assumed: Modulo-N, Up/Down and Loadable Counters is a refresher.

Five questions this page answers
Question
1What is an assertion, in one sentence?
2Why does an assertion find a bug at its source?
3What can a scoreboard miss that an assertion catches, and the other way round?
4How does one timing rule look as plain code and as an assertion?
5What does "travel with the design" mean?

The Idea: A Rule That Is Checked All the Time

A scoreboard asks one question: did the right answers come out? It waits at the end of the path. That is powerful, and it is blind to how and when. An answer that arrives late but correct passes, and so does a handshake that broke a rule on the way.

An assertion asks a different question: does this rule hold right now? It is a statement about signals, such as "every request is answered within four cycles", checked at every clock edge. When the rule breaks, it fails at that edge, on those signals. You learn where and when, not just that something somewhere went wrong.

Because an assertion needs no stimulus of its own, it can sit inside the design or beside it. Then it travels. It runs in this block's bench, in the chip-level bench, and in a formal tool that checks every input. Designers write assertions for their own logic; verification engineers write them for interfaces.

New Words

New words on this page
WordMeaning
AssertionA statement about signals that must always hold. The simulator checks it and reports each failure.
Plain checkerA checker written as ordinary bench code that watches signals for one rule. An assertion is a short way to write the same thing.
ScoreboardThe checker part that holds expected results and matches them with what came out. Here it stands for any check at the end of the path.
Formal toolA program that proves a rule with mathematics for every possible input, instead of simulating chosen inputs.
Request and acknowledgeA handshake: one side raises req to ask, the other raises ack to answer.
Bounded responseA rule with a time limit, such as "answer within four cycles".

The Smallest Example: One Rule, Checked by Hand

The responder must answer each req with ack within four clock edges. Count edges after each request and decide by hand.

Request edge, answer edge, verdict
req seen at edgeack seen at edgeEdges laterRule
363holds
11143holds
14none by edge 18more than 4breaks at edge 18

Notice where the verdict lands: at edge 18, the last edge the answer was allowed. That is the earliest moment anyone could know the rule broke. A scoreboard counting answers at the end of the test learns nothing, because the answer does arrive later.

The Rules

  1. Rule 1: Write the rule, not the scenario.

    An assertion says what must always be true. It does not drive anything, so any test can trip it.

  2. Rule 2: Check at every edge.

    The rule is tested at each clock edge, so a failure names the cycle it broke.

  3. Rule 3: Fail next to the cause.

    An assertion on a wire inside the design fails there, long before the damage reaches an output.

  4. Rule 4: Scoreboards check what; assertions check how and when.

    Use both. A late or illegal handshake passes a scoreboard; wrong data can pass a timing rule.

  5. Rule 5: Let it travel.

    A rule written once runs in every bench that holds the design, and in formal tools.

Sources for These Rules

Assertions in a verification plan, by designers for logic and by verification engineers for interfaces: Mehta, section 2.2, item 8.

Assertions as a methodology, overview: Mehta, ASIC/SoC Functional Design Verification, sections 6.2 and 6.4.

Concurrent assertions, cycle delay ranges, implication and disable iff: IEEE 1800-2023, clauses 16.5, 16.7, 16.12.7 and 16.15.

The Lab: A Plain Checker, Then the Same Rule as an Assertion

In the lab, a responder answers each request three cycles later. One line makes a request that arrives while it is still busy wait three cycles more. The bench sends six requests and counts the answers, like a scoreboard. A plain checker watches req and ack.

The checker as plain code: since counts edges after a request; -1 means no request is waiting.
always @(posedge clk) begin
  if (since >= 0 && ack) since = -1;          // answered in time
  else if (since >= 0) begin
    since++;
    if (since == 4) begin errors++; $display("cycle %0d: ERROR ...", cycle); since = -1; end
  end
  if (req) since = 0;                         // a new request starts the count
end
Printed by the lab (Icarus Verilog version 12.0).
cycle 6: ack, 3 cycles after its req
cycle 14: ack, 3 cycles after its req
cycle 18: ERROR req not answered within 4 cycles
cycle 28: ack, 3 cycles after its req
cycle 38: ack, 3 cycles after its req
cycle 43: ERROR req not answered within 4 cycles
6 requests, 6 answers, 2 checker errors

Read the last line first. Six requests, six answers: a scoreboard would pass this design. Rule 4 at work. The checker fails at cycles 18 and 43, the exact edges where the time limit ran out. Rule 3 at work: those are the two requests that arrived while the responder was busy.

Here is the same rule as one assertion. Read it left to right: a_answered is its name, printed if it fails. At every rising edge of clk, if req is 1, ack must be 1 within the next four edges. The arrow |-> is the "if, then", and ##[1:4] is "one to four edges later".

disable iff (rst) switches the check off during reset. The else part runs when the assertion fails.
a_answered: assert property (@(posedge clk) disable iff (rst) req |-> ##[1:4] ack)
  else $display("time %0t: a_answered failed", $time);
The same responder and stimulus with the assertion, recorded on Verilator 5.052, the simulator the Assertions track uses. The lab's Icarus build does not run this form.
time 175: a_answered failed
time 425: a_answered failed

The clock edges in the lab come every 10 time units, starting at 5. So time 175 is edge 18 and time 425 is edge 43: the assertion and the plain checker agree, cycle for cycle. One line replaced eight.

Why Both Assertions and Scoreboards

Why not put every check in the scoreboard? Because a scoreboard sees only the outputs, after all the logic in between. A bug deep inside may take hundreds of cycles to reach an output, or may never reach one in this test. An assertion on the inner wire fails where the bug is.

Why not use only assertions? Because many questions are about data end to end: did this packet arrive intact, in order? That needs a model and a comparison, which is a scoreboard's job. Good benches use both.

Traps

The first trap is the assertion that never really runs. A rule that starts with "if req" passes quietly in every test where req never rises. Count how often each assertion actually started, or a silent pass may mean nothing was tested.

The second trap is an assertion that copies the design. Someone writes the rule by reading the RTL and states what the code does, bugs included. Write the rule from the specification, in its own words.

The third trap is a time limit off by one. "Within four cycles" can mean four edges or five, depending on where you start counting. Settle it with the designer, write it in the plan, and test a request answered at exactly the limit.

Where This Goes Next

This lesson showed one rule. The Assertions track teaches the language in full, and the Formal track proves rules for every input.

Where each idea is taught in depth
The idea from this pageWhere it is taught
Turning specification sentences into assertionsWhy Assertions
What |-> means, and when a pass is emptyImplication and Vacuous Success
Time limits and what the end of a test meansWeak and Strong: What the End of a Test Means
Assertions inside a SystemVerilog benchAssertions and Protocol Checks
The same assertion proved with no testbenchYour First Proof: the Same SVA, No Testbench

Try It

Run it: six requests, a count of answers, and a plain checker for the four-cycle rule.

Make the busy wait shorter: change the 5 in (busy > 0) ? 5 : 2 to 3. Predict the last line.

Move the request at cycle 13 to cycle 15. Does the checker still fail at cycle 18, and why?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: cycle 6: ack, 3 cycles after its req cycle 14: ack, 3 cycles after its req cycle 18: ERROR req not answered within 4 cycles cycle 28: ack, 3 cycles after its req cycle 38: ack, 3 cycles after its req cycle 43: ERROR req not answered within 4 cycles 6 requests, 6 answers, 2 checker errors

Check Yourself

Predict the outputThe busy wait is cut so a request that arrives while the responder is busy waits one cycle more instead of three. What is the last line the lab prints?
// responder: answers each req with a one-cycle ack, three cycles later.
// A req that arrives while it is still finishing the last one waits 1 cycles more.
module responder (input logic clk, rst, req, output logic ack);
  int wait_left, busy;
  always_ff @(posedge clk)
    if (rst) begin ack <= 0; wait_left <= 0; busy <= 0; end
    else begin
      ack <= 0;
      if (busy > 0) busy <= busy - 1;
      if (wait_left == 1) begin ack <= 1; busy <= 2; end
      if (wait_left > 0) wait_left <= wait_left - 1;
      else if (req) wait_left <= (busy > 0) ? 3 : 2;
    end
endmodule

module tb;
  logic clk = 0, rst = 1, req = 0, ack;
  int cycle = 0, answers = 0, errors = 0, since = -1;
  responder dut (.clk(clk), .rst(rst), .req(req), .ack(ack));
  always #5 clk = ~clk;
  // The checker, as plain code: after each req, count cycles until ack.
  always @(posedge clk) begin
    cycle++;
    if (since >= 0 && ack) begin
      answers++; $display("cycle %0d: ack, %0d cycles after its req", cycle, since + 1); since = -1;
    end else if (since >= 0) begin
      since++;
      if (since == 4) begin errors++; $display("cycle %0d: ERROR req not answered within 4 cycles", cycle); since = -1; end
    end else if (ack) answers++;   // a late answer still counts as an answer
    if (req) since = 0;
  end
  // Requests at chosen cycles, one cycle long each.
  initial begin
    @(negedge clk) rst = 0;
    for (int t = 1; t <= 48; t++) begin
      req = (t == 2 || t == 10 || t == 13 || t == 24 || t == 34 || t == 38);
      @(negedge clk);
    end
    req = 0;
    $display("%0d requests, %0d answers, %0d checker errors", 6, answers, errors);
    $finish;
  end
endmodule
ConceptWhat is an assertion?
ConceptSix requests get six correct answers, two of them late. Which check catches the late ones?
ConceptWhy does an assertion on an inner wire find a bug faster than a scoreboard?
ConceptIn the recording, the assertion fails at time 175. Edges come at 5, 15, 25 and so on. Which edge is that?

Common Mistakes

Wrong Trust a scoreboard alone for a timing rule.

A late answer that is correct passes a scoreboard.

Fix Write the timing rule as an assertion that checks every edge.

Wrong Write an assertion by reading the RTL.

It then states what the code does, including its bugs.

Fix Write the rule from the specification.

Wrong Take a silent assertion as proof the rule holds.

If its first condition never happened, it never really checked anything.

Fix Count how often each assertion started its check.

Remember

  • An assertion is a rule about signals that is checked at every clock edge.
  • It fails at the edge the rule breaks, next to the cause, and needs no stimulus of its own.
  • Scoreboards check what came out; assertions check how and when. Use both.
  • A rule written once travels: block bench, chip bench and formal tools.

Practice

Report a problem with this page