Skip to main content
Version: dev

Assert Function

Noir includes a special assert function which will explicitly constrain the predicate/comparison expression that follows to be true. If this expression is false at runtime, the program will fail to be proven. Example:

fn main(x : Field, y : Field) {
assert(x == y);
}

You can optionally provide a message to be logged when the assertion fails:

assert(x == y, "x and y are not equal");

Assertions only work for predicate operations, such as ==. If there's any ambiguity on the operation, the program will fail to compile. For example, it is unclear if assert(x + y) would check for x + y == 0 or simply would return true.