15 auto replace_and_check_zero_scaling = [&](uint32_t&
index,
const FF& scaling) {
16 if (
index == bb::stdlib::IS_CONSTANT) {
18 BB_ASSERT_EQ(scaling,
FF(0),
"mul_quad_ gate with IS_CONSTANT witness index has non-zero scaling");
23 bb::stdlib::IS_CONSTANT,
24 "mul_quad_ gate cannot have IS_CONSTANT for witness a. An error here probably means a conversion "
25 "issue in acir_to_constraint_buf.");
26 replace_and_check_zero_scaling(mul_quad.
b, mul_quad.
b_scaling);
27 replace_and_check_zero_scaling(mul_quad.
c, mul_quad.
c_scaling);
28 replace_and_check_zero_scaling(mul_quad.
d, mul_quad.
d_scaling);
31template <
typename Builder>
48 builder.failure(
"mul_add_gate");
52template <
typename Builder>
62 auto value_from_witness = [&](uint32_t w) {
return builder.get_variable(w); };
66 if (bilinear_batched_eq.
mode == BilinearBatchedEqMode::Bilinear) {
67 half_1 = bilinear_batched_eq.
q_m * value_from_witness(bilinear_batched_eq.
a) *
68 value_from_witness(bilinear_batched_eq.
b) +
69 bilinear_batched_eq.
q_5 * value_from_witness(bilinear_batched_eq.
a) *
70 value_from_witness(bilinear_batched_eq.
c) +
71 bilinear_batched_eq.
q_l * value_from_witness(bilinear_batched_eq.
a) +
72 bilinear_batched_eq.
q_r * value_from_witness(bilinear_batched_eq.
b) +
73 bilinear_batched_eq.
q_o * value_from_witness(bilinear_batched_eq.
c) +
74 bilinear_batched_eq.
q_4 * value_from_witness(bilinear_batched_eq.
d) + bilinear_batched_eq.
q_c;
77 half_1 = bilinear_batched_eq.
q_l * value_from_witness(bilinear_batched_eq.
a) +
78 bilinear_batched_eq.
q_r * value_from_witness(bilinear_batched_eq.
b) + bilinear_batched_eq.
q_c;
79 half_2 = bilinear_batched_eq.
q_o * value_from_witness(bilinear_batched_eq.
c) +
80 bilinear_batched_eq.
q_4 * value_from_witness(bilinear_batched_eq.
d) + bilinear_batched_eq.
q_m;
84 builder.failure(
"bilinear_batched_eq_gate");
95 builder.create_big_mul_add_gate(mul_quad);
104 uint32_t next_w4_wire_idx = 0;
107 for (
size_t j = 0; j < big_constraint.size() - 1; ++j) {
111 builder.create_big_mul_add_gate(big_constraint[j],
true);
113 next_w4_wire_value =
builder.get_variable(big_constraint[j].
a) *
builder.get_variable(big_constraint[j].
b) *
114 big_constraint[j].mul_scaling +
115 builder.get_variable(big_constraint[j].
a) * big_constraint[j].a_scaling +
116 builder.get_variable(big_constraint[j].
b) * big_constraint[j].b_scaling +
117 builder.get_variable(big_constraint[j].c) * big_constraint[j].c_scaling +
118 builder.get_variable(big_constraint[j].d) * big_constraint[j].d_scaling +
119 big_constraint[j].const_scaling;
120 next_w4_wire_value = -next_w4_wire_value;
121 next_w4_wire_idx =
builder.add_variable(next_w4_wire_value);
125 big_constraint[j + 1].d = next_w4_wire_idx;
126 big_constraint[j + 1].d_scaling =
fr(-1);
131 builder.create_big_mul_add_gate(big_constraint.back(),
false);
141 BB_ASSERT(constraint.
a != bb::stdlib::IS_CONSTANT && constraint.
b != bb::stdlib::IS_CONSTANT &&
142 constraint.
c != bb::stdlib::IS_CONSTANT,
143 "create_bilinear_constraint: the product wires a, b, c must be real witnesses.");
144 uint32_t d = constraint.
d == bb::stdlib::IS_CONSTANT ?
builder.zero_idx() : constraint.
d;
147 .
mode = BilinearBatchedEqMode::Bilinear,
152 .q_l = constraint.
q_l,
153 .q_r = constraint.
q_r,
154 .q_o = constraint.
q_o,
155 .q_4 = constraint.
q_4,
156 .q_c = constraint.
q_c,
157 .q_m = constraint.
q_m,
158 .q_5 = constraint.
q_5,
161 builder.create_bilinear_batched_eq_gate(gate);
164template <
typename Builder>
171 BB_ASSERT(resolved.
a != bb::stdlib::IS_CONSTANT,
172 "create_batched_eq_check_constraint: wire `a` must always be a real witness index.");
173 if (resolved.
b == bb::stdlib::IS_CONSTANT) {
176 if (resolved.
c == bb::stdlib::IS_CONSTANT) {
179 if (resolved.
d == bb::stdlib::IS_CONSTANT) {
184 .
mode = BilinearBatchedEqMode::BatchedEq,
198 builder.create_bilinear_batched_eq_gate(gate);
#define BB_ASSERT(expression,...)
#define BB_ASSERT_NEQ(actual, expected,...)
#define BB_ASSERT_EQ(actual, expected,...)
typename ExecutionTrace::FF FF
field< Bn254FrParams > fr
BilinearBatchedEqMode mode
static constexpr field zero()