constrain_mul!
Constrain lhs * rhs = out element-wise, one row per element. Constraints and witnesses
constrain_mul! lhs, rhs, out
Adds the R1CS row lhs[i] * rhs[i] = out[i] for every element, without materializing the product as a witness entry. Each side may be a linear combination, so many checks fit in one row, for example booleanity x * (1 - x) = 0.
Arguments
lhs- Any expression, static or witness.
rhs- Any expression of the same length, static or witness.
out- Any expression of the same length, static or witness. At least one of the three 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 bits) # each element is 0 or 1: b * (1 - b) = 0 constrain_mul! (clone! bits), [1 1 1] - (clone! bits), [0 0 0] bits
(let bits) constrain_mul! (clone! bits), [1 1 1] - (clone! bits), [0 0 0] bits
Notes
Errors if all three arguments are static or if the lengths differ. Scalars are not broadcast, so constant vectors must have the full length; the standard library functions valloc and calloc build them for a static length, as in to_bits_exact.
Used in the standard library
bits/to_bits_exact, bits/xor_bits_vec_wtns, keccak/keccak_f1600, lattice/lattice_bits, typed/typed_bytes_check, typed/typed_lex_check