Index Mathematics Conjectures nbv lettuce Widgets

assert_eq!

Fail compilation unless two static vectors are equal. Assertions

assert_eq! lhs, rhs[, "message"]

Compares two static vectors element by element while the program is compiled and stops compilation with an error at the first index where they differ. It is a check on values known at compile time, not a constraint: nothing is added to the R1CS. To require equality of witness values use constrain_eq!.

Arguments

lhs, rhs
Static vectors (or scalars) of equal length. A witness value, including a let variable that was assigned a static (it is lifted to a witness constant, see variables), is an error.
"message"
Optional string literal appended to the error. Any other expression is an error.

Returns

lhs, unchanged and static. assert_eq! is in both grammar lists, so it can be used as a statement or as an expression, e.g. static n = assert_eq! (len! a), 4.

Constraints

None.

Example

(let x)
static n = len! x
assert_eq! n, 3, "expected three inputs"
static same = assert_eq! [1 2], [1 2]
n
static a = [1 2 3]
assert_eq! a, [1 5 3], "a has changed"

Notes

Vectors of different lengths fail with a dimension error. Both arguments are evaluated, so named vectors passed in are moved; use clone! to keep them. See also assert_ne!, assert_lt! and assert_lte!.

Used in the standard library

bdlop/bdlop_linear_nizk_verify, bdlop/bdlop_milli_config, bits/add32_bits, bits/lt_bits, bits/lte_bits, bits/lte_negone, bits/to_bits, bits/to_bits_exact, bits/to_bits_exact_static, blake3/blake3_compress, blake3/blake3_core, chacha/chacha_block, chacha/chacha_quarter_round, dilithium/lattice/lattice_permutation, dilithium/mldsa/mldsa44_verify_static, dilithium/mldsa/mldsa44_w_approx, dilithium/mldsa/mldsa44_w_approx_static, ext/ext_eq_eval, ext/ext_from_base, ext/ext_mul, ext/ext_mul_base, ext/ext_poly_eval, ext/ext_sum, ext/ext_vec_mul, fields/assert_dilithium, fields/assert_mersenne61, fields/assert_milli32, inner_prod, keccak/keccak_f1600, keccak/keccak_sponge_shake, lattice/lattice_absorb, lattice/lattice_assert_canonical, lattice/lattice_bits, lattice/lattice_expand, mat_vec_mul, mersenne61/mldsa/mldsa_pointwise, mersenne61/poseidon/poseidon_mersenne61, mersenne61/poseidon/poseidon_mersenne61_state, milli/mldsa/mldsa_intt_sub, milli/mldsa/mldsa_ntt_z, milli/mldsa/mldsa_pointwise, milli/mldsa/mldsa_reduce, milli/poseidon/poseidon_milli, milli/poseidon/poseidon_milli_state, mldsa/mldsa44_parse, mldsa/mldsa44_parse_sig, mldsa/mldsa_assert_below_q, mldsa/mldsa_expand_a, mldsa/mldsa_hint_unpack, mldsa/mldsa_sample_in_ball, mldsa/mldsa_use_hint, oraccle/oraccle_sample_ternary_vec, oraccle/oraccle_squeeze, polynomial/mat_poly_compose_horizontal, polynomial/mat_poly_compose_vertical, polynomial/mat_poly_mul_vec, polynomial/ntt, polynomial/ntt_negacyclic_mat, polynomial/poly_norm_inf, polynomial/poly_norm_inf_lt, polynomial/poly_norm_l1, polynomial/polynomial_coef_mul, polynomial/vec_poly_scalar_mul, polynomial/vec_polynomial_coef_mul, r1cs/r1cs_assert_field, r1cs/r1cs_compose_vertical, r1cs/r1cs_from_output, r1cs/r1cs_from_vec, r1cs/r1cs_into_output, slip/slip_r1cs_arg_verify, sym_mat_index, typed/typed_bytes_check, typed/typed_lex_chacha, typed/typed_lex_check, typed/typed_lex_width, typed/typed_width