Index Mathematics Conjectures nbv lettuce Widgets

constrain_eq!

Constrain two vectors to be equal element-wise. Constraints and witnesses

constrain_eq! lhs, rhs

Adds an R1CS row lhs[i] * 1 = rhs[i] for every element. This is how values computed from unconstrained hints (for example to_bits_unconstrained!) are tied back to the values they claim to represent.

Arguments

lhs
Any expression, static or witness.
rhs
Any expression of the same length, static or witness. At least one of lhs and rhs must be a witness.

Returns

Nothing, it is used as a statement.

Constraints

One row per element and no witness entries. In the static VM (static_eval!) it does nothing and its arguments are not evaluated.

Example

(let x, let y)
constrain_eq! x * x, y
y

A witness that doesn't satisfy the row leaves the R1CS unsatisfied, and evaluation fails:

(let x, let y)
constrain_eq! x * x, y
y

Notes

Errors if both sides are static (use assert_eq! for compile time checks) or if the lengths differ. Equality of a product is cheaper with constrain_mul!: constrain_eq! x * x, y costs a product row, a witness entry and an equality row, constrain_mul! x, x, y a single row.

Used in the standard library

bdlop/bdlop_linear_nizk_verify, bdlop/bdlop_r1cs_verify, bits/to_bits, bits/to_bits_exact, lattice/lattice_assert_canonical, lattice/lattice_bits, mersenne61/mldsa/mldsa_reduce, milli/mldsa/mldsa_reduce, mldsa/mldsa44_finish, mldsa/mldsa_assert_below_q, mldsa/mldsa_hint_unpack, mldsa/mldsa_rej_ntt_poly, mldsa/mldsa_sample_in_ball, mldsa/mldsa_use_hint, polynomial/poly_norm_inf_lt, polynomial/poly_norm_l1, slip/slip_r1cs_arg_verify, typed/typed_bytes_check