Home › Practice › Formal Verification › Assume vs assert: subtract one
Assume vs assert: subtract one
EasyFormalassumeassertcombinational
Some rules are only true if the world behaves. "Take one away" never gives a bigger number, as long as you did not start from zero. How do you tell a formal tool about the "as long as"? With an assume.
Concept first. assert is a claim about the design: the tool tries to break it. assume is a promise about the inputs: the tool takes it as given and never tries inputs that break it. Example with other numbers: a design returns 100 / x. The rule assert(y <= 100) only makes sense if x is never 0, so you write assume(x != 0) first. The danger: every assume shrinks the world the tool checks. Assume too much and a broken design slips through, because the inputs that would show the bug were ruled out.
The design subtracts one from a 4-bit number (it wraps, so 0 gives 15). You want to check that the answer is smaller than the input. That is false for x = 0, which a real user may never send. Use one assume to rule it out and one assert for the rule.
module dut(input [3:0] x, output [3:0] y);
assign y = x - 4'd1;
endmodule
- Keep the module name
chkand its ports. Assume on the inputxonly, never ony. - Try submitting the assert alone first. The tool will show you the input that breaks it.
- The grader uses three broken versions. If you assume more than you need, one of them gets through.
No install and no sign-up needed. You write your answer in the editor and Nishkam checks it.