30 const auto constants_AVM_EXEC_OP_ID_ALU_NOT =
FF(256);
31 const auto constants_AVM_EXEC_OP_ID_ALU_SHL =
FF(512);
32 const auto constants_AVM_EXEC_OP_ID_ALU_SHR =
FF(1024);
33 const auto constants_AVM_EXEC_OP_ID_ALU_TRUNCATE =
FF(2048);
34 const auto alu_IS_NOT_FF = (
FF(1) - in.get(C::alu_sel_is_ff));
35 const auto alu_IS_NOT_U128 = (
FF(1) - in.get(C::alu_sel_is_u128));
36 const auto alu_CHECK_TAG_FF = in.get(C::alu_sel_op_div) + in.get(C::alu_sel_op_fdiv) + in.get(C::alu_sel_op_lt) +
37 in.get(C::alu_sel_op_lte) + in.get(C::alu_sel_op_not) + in.get(C::alu_sel_shift_ops);
38 const auto alu_TAG_FF_DIFF = (in.get(C::alu_ia_tag) - constants_MEM_TAG_FF);
39 const auto alu_CHECK_TAG_U128 = in.get(C::alu_sel_op_mul) + in.get(C::alu_sel_op_div);
40 const auto alu_TAG_U128_DIFF = (in.get(C::alu_ia_tag) - constants_MEM_TAG_U128);
41 const auto alu_EXPECTED_C_TAG =
42 (in.get(C::alu_sel_op_add) + in.get(C::alu_sel_op_sub) + in.get(C::alu_sel_op_mul) + in.get(C::alu_sel_op_div) +
43 in.get(C::alu_sel_op_truncate) + in.get(C::alu_sel_shift_ops)) *
44 in.get(C::alu_ia_tag) +
45 (in.get(C::alu_sel_op_eq) + in.get(C::alu_sel_op_lt) + in.get(C::alu_sel_op_lte)) * constants_MEM_TAG_U1 +
46 in.get(C::alu_sel_op_fdiv) * constants_MEM_TAG_FF;
47 const auto alu_FF_TAG_ERR = (in.get(C::alu_sel_op_div) + in.get(C::alu_sel_op_not) + in.get(C::alu_sel_shift_ops)) *
48 in.get(C::alu_sel_is_ff) +
49 in.get(C::alu_sel_op_fdiv) * alu_IS_NOT_FF;
50 const auto alu_CHECK_AB_TAGS =
51 ((
FF(1) - in.get(C::alu_sel_op_not) * in.get(C::alu_sel_is_ff)) - in.get(C::alu_sel_op_truncate));
52 const auto alu_AB_TAGS_EQ = (
FF(1) - in.get(C::alu_sel_ab_tag_mismatch));
53 const auto alu_TWO_POW_64 =
FF(
uint256_t{ 0UL, 1UL, 0UL, 0UL });
54 const auto alu_DECOMPOSED_A =
55 (in.get(C::alu_sel_mul_u128) + in.get(C::alu_sel_shift_ops_no_overflow)) * in.get(C::alu_ia) +
56 (in.get(C::alu_sel_shift_ops) - in.get(C::alu_sel_shift_ops_no_overflow)) *
57 (in.get(C::alu_ib) - in.get(C::alu_max_bits)) +
58 in.get(C::alu_sel_is_u128) * in.get(C::alu_sel_op_div) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
60 const auto alu_DECOMPOSED_B = in.get(C::alu_ib);
61 const auto alu_LIMB_SIZE = in.get(C::alu_sel_mul_div_u128) * alu_TWO_POW_64 +
62 in.get(C::alu_sel_shift_ops) * in.get(C::alu_two_pow_shift_lo_bits);
63 const auto alu_DIV_OPS = in.get(C::alu_sel_op_div) + in.get(C::alu_sel_op_fdiv);
64 const auto alu_DIV_OPS_NON_U128 =
65 (
FF(1) - in.get(C::alu_sel_err)) * (in.get(C::alu_sel_op_fdiv) + in.get(C::alu_sel_op_div) * alu_IS_NOT_U128);
66 const auto alu_DIFF = (in.get(C::alu_ia) - in.get(C::alu_ib));
67 const auto alu_SHIFT_OVERFLOW = in.get(C::alu_sel_shift_ops) * (
FF(1) - in.get(C::alu_sel_shift_ops_no_overflow));
68 const auto alu_SHIFT_HI_BITS =
69 (in.get(C::alu_max_bits) - in.get(C::alu_sel_shift_ops_no_overflow) * in.get(C::alu_shift_lo_bits));
73 auto tmp = in.get(C::alu_sel) * (
FF(1) - in.get(C::alu_sel));
74 tmp *= scaling_factor;
75 std::get<0>(evals) +=
typename Accumulator::View(tmp);
79 auto tmp = in.get(C::alu_cf) * (
FF(1) - in.get(C::alu_cf));
80 tmp *= scaling_factor;
81 std::get<1>(evals) +=
typename Accumulator::View(tmp);
85 auto tmp = in.get(C::alu_sel_is_ff) * (
FF(1) - in.get(C::alu_sel_is_ff));
86 tmp *= scaling_factor;
87 std::get<2>(evals) +=
typename Accumulator::View(tmp);
91 auto tmp = in.get(C::alu_sel_is_u128) * (
FF(1) - in.get(C::alu_sel_is_u128));
92 tmp *= scaling_factor;
93 std::get<3>(evals) +=
typename Accumulator::View(tmp);
97 auto tmp = (in.get(C::alu_sel_err) - ((in.get(C::alu_sel_tag_err) + in.get(C::alu_sel_div_0_err)) -
98 in.get(C::alu_sel_tag_err) * in.get(C::alu_sel_div_0_err)));
99 tmp *= scaling_factor;
100 std::get<4>(evals) +=
typename Accumulator::View(tmp);
104 auto tmp = (in.get(C::alu_op_id) - (in.get(C::alu_sel_op_add) * constants_AVM_EXEC_OP_ID_ALU_ADD +
105 in.get(C::alu_sel_op_sub) * constants_AVM_EXEC_OP_ID_ALU_SUB +
106 in.get(C::alu_sel_op_mul) * constants_AVM_EXEC_OP_ID_ALU_MUL +
107 in.get(C::alu_sel_op_div) * constants_AVM_EXEC_OP_ID_ALU_DIV +
108 in.get(C::alu_sel_op_fdiv) * constants_AVM_EXEC_OP_ID_ALU_FDIV +
109 in.get(C::alu_sel_op_eq) * constants_AVM_EXEC_OP_ID_ALU_EQ +
110 in.get(C::alu_sel_op_lt) * constants_AVM_EXEC_OP_ID_ALU_LT +
111 in.get(C::alu_sel_op_lte) * constants_AVM_EXEC_OP_ID_ALU_LTE +
112 in.get(C::alu_sel_op_not) * constants_AVM_EXEC_OP_ID_ALU_NOT +
113 in.get(C::alu_sel_op_shl) * constants_AVM_EXEC_OP_ID_ALU_SHL +
114 in.get(C::alu_sel_op_shr) * constants_AVM_EXEC_OP_ID_ALU_SHR +
115 in.get(C::alu_sel_op_truncate) * constants_AVM_EXEC_OP_ID_ALU_TRUNCATE));
116 tmp *= scaling_factor;
117 std::get<5>(evals) +=
typename Accumulator::View(tmp);
121 auto tmp = alu_CHECK_TAG_FF *
122 ((alu_TAG_FF_DIFF * (in.get(C::alu_sel_is_ff) * (
FF(1) - in.get(C::alu_tag_ff_diff_inv)) +
123 in.get(C::alu_tag_ff_diff_inv)) +
124 in.get(C::alu_sel_is_ff)) -
126 tmp *= scaling_factor;
127 std::get<6>(evals) +=
typename Accumulator::View(tmp);
131 auto tmp = alu_CHECK_TAG_U128 *
132 ((alu_TAG_U128_DIFF * (in.get(C::alu_sel_is_u128) * (
FF(1) - in.get(C::alu_tag_u128_diff_inv)) +
133 in.get(C::alu_tag_u128_diff_inv)) +
134 in.get(C::alu_sel_is_u128)) -
136 tmp *= scaling_factor;
137 std::get<7>(evals) +=
typename Accumulator::View(tmp);
141 auto tmp = (
FF(1) - in.get(C::alu_sel_err)) * (alu_EXPECTED_C_TAG - in.get(C::alu_ic_tag));
142 tmp *= scaling_factor;
143 std::get<8>(evals) +=
typename Accumulator::View(tmp);
147 auto tmp = in.get(C::alu_sel_tag_err) * (
FF(1) - in.get(C::alu_sel_tag_err));
148 tmp *= scaling_factor;
149 std::get<9>(evals) +=
typename Accumulator::View(tmp);
153 auto tmp = in.get(C::alu_sel_ab_tag_mismatch) * (
FF(1) - in.get(C::alu_sel_ab_tag_mismatch));
154 tmp *= scaling_factor;
159 auto tmp = (in.get(C::alu_sel_tag_err) - ((in.get(C::alu_sel_ab_tag_mismatch) + alu_FF_TAG_ERR) -
160 in.get(C::alu_sel_ab_tag_mismatch) * alu_FF_TAG_ERR));
161 tmp *= scaling_factor;
168 (((in.get(C::alu_ia_tag) - in.get(C::alu_ib_tag)) *
169 (alu_AB_TAGS_EQ * (
FF(1) - in.get(C::alu_ab_tags_diff_inv)) + in.get(C::alu_ab_tags_diff_inv)) -
172 tmp *= scaling_factor;
177 auto tmp = (in.get(C::alu_sel_decompose_a) -
178 (in.get(C::alu_sel_mul_div_u128) + in.get(C::alu_sel_shift_ops) * alu_IS_NOT_FF));
179 tmp *= scaling_factor;
184 auto tmp = in.get(C::alu_sel_decompose_a) *
185 (alu_DECOMPOSED_A - (in.get(C::alu_a_lo) + alu_LIMB_SIZE * in.get(C::alu_a_hi)));
186 tmp *= scaling_factor;
191 auto tmp = in.get(C::alu_sel_mul_div_u128) *
192 (alu_DECOMPOSED_B - (in.get(C::alu_b_lo) + alu_LIMB_SIZE * in.get(C::alu_b_hi)));
193 tmp *= scaling_factor;
198 auto tmp = in.get(C::alu_sel_mul_div_u128) * (
FF(64) - in.get(C::alu_constant_64));
199 tmp *= scaling_factor;
204 auto tmp = ((in.get(C::alu_a_lo_bits) - in.get(C::alu_sel_mul_div_u128) * in.get(C::alu_constant_64)) -
205 in.get(C::alu_sel_shift_ops) * in.get(C::alu_shift_lo_bits));
206 tmp *= scaling_factor;
211 auto tmp = ((in.get(C::alu_a_hi_bits) - in.get(C::alu_sel_mul_div_u128) * in.get(C::alu_constant_64)) -
212 in.get(C::alu_sel_shift_ops) * alu_SHIFT_HI_BITS);
213 tmp *= scaling_factor;
218 auto tmp = in.get(C::alu_sel_op_add) * (
FF(1) - in.get(C::alu_sel_op_add));
219 tmp *= scaling_factor;
224 auto tmp = in.get(C::alu_sel_op_sub) * (
FF(1) - in.get(C::alu_sel_op_sub));
225 tmp *= scaling_factor;
230 auto tmp = (in.get(C::alu_sel_op_add) + in.get(C::alu_sel_op_sub)) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
231 ((in.get(C::alu_ia) - in.get(C::alu_ic)) +
232 (in.get(C::alu_sel_op_add) - in.get(C::alu_sel_op_sub)) *
233 (in.get(C::alu_ib) - in.get(C::alu_cf) * (in.get(C::alu_max_value) +
FF(1))));
234 tmp *= scaling_factor;
239 auto tmp = in.get(C::alu_sel_op_mul) * (
FF(1) - in.get(C::alu_sel_op_mul));
240 tmp *= scaling_factor;
245 auto tmp = in.get(C::alu_sel_op_mul) * alu_IS_NOT_U128 * (
FF(1) - in.get(C::alu_sel_tag_err)) *
246 ((in.get(C::alu_ia) * in.get(C::alu_ib) - in.get(C::alu_ic)) -
247 (in.get(C::alu_max_value) +
FF(1)) * in.get(C::alu_c_hi));
248 tmp *= scaling_factor;
253 auto tmp = (in.get(C::alu_sel_mul_u128) - in.get(C::alu_sel_is_u128) * in.get(C::alu_sel_op_mul));
254 tmp *= scaling_factor;
260 in.get(C::alu_sel_mul_u128) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
261 (((in.get(C::alu_ia) * in.get(C::alu_b_lo) + in.get(C::alu_a_lo) * in.get(C::alu_b_hi) * alu_TWO_POW_64) -
263 (in.get(C::alu_max_value) +
FF(1)) * (in.get(C::alu_cf) * alu_TWO_POW_64 + in.get(C::alu_c_hi)));
264 tmp *= scaling_factor;
269 auto tmp = in.get(C::alu_sel_op_div) * (
FF(1) - in.get(C::alu_sel_op_div));
270 tmp *= scaling_factor;
276 (in.get(C::alu_sel_div_no_0_err) - in.get(C::alu_sel_op_div) * (
FF(1) - in.get(C::alu_sel_div_0_err)));
277 tmp *= scaling_factor;
282 auto tmp = (in.get(C::alu_sel_mul_div_u128) -
283 (in.get(C::alu_sel_mul_u128) + in.get(C::alu_sel_is_u128) * in.get(C::alu_sel_op_div)));
284 tmp *= scaling_factor;
289 auto tmp = in.get(C::alu_sel_is_u128) * in.get(C::alu_sel_op_div) * (
FF(1) - in.get(C::alu_sel_err)) *
290 in.get(C::alu_a_hi) * in.get(C::alu_b_hi);
291 tmp *= scaling_factor;
297 in.get(C::alu_sel_is_u128) * in.get(C::alu_sel_op_div) * (
FF(1) - in.get(C::alu_sel_err)) *
298 ((in.get(C::alu_ic) * in.get(C::alu_b_lo) + in.get(C::alu_a_lo) * in.get(C::alu_b_hi) * alu_TWO_POW_64) -
299 (in.get(C::alu_ia) - in.get(C::alu_helper1)));
300 tmp *= scaling_factor;
305 auto tmp = in.get(C::alu_sel_op_fdiv) * (
FF(1) - in.get(C::alu_sel_op_fdiv));
306 tmp *= scaling_factor;
311 auto tmp = in.get(C::alu_sel_div_0_err) * (
FF(1) - in.get(C::alu_sel_div_0_err));
312 tmp *= scaling_factor;
317 auto tmp = (alu_DIV_OPS * ((in.get(C::alu_ib) * (in.get(C::alu_sel_div_0_err) * (
FF(1) - in.get(C::alu_b_inv)) +
318 in.get(C::alu_b_inv)) +
319 in.get(C::alu_sel_div_0_err)) -
321 in.get(C::alu_sel_div_0_err) * (in.get(C::alu_sel_div_0_err) - alu_DIV_OPS));
322 tmp *= scaling_factor;
327 auto tmp = alu_DIV_OPS_NON_U128 * (in.get(C::alu_ib) * in.get(C::alu_ic) -
328 (in.get(C::alu_ia) - in.get(C::alu_sel_op_div) * in.get(C::alu_helper1)));
329 tmp *= scaling_factor;
334 auto tmp = in.get(C::alu_sel_op_eq) * (
FF(1) - in.get(C::alu_sel_op_eq));
335 tmp *= scaling_factor;
341 in.get(C::alu_sel_op_eq) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
342 ((alu_DIFF * (in.get(C::alu_ic) * (
FF(1) - in.get(C::alu_helper1)) + in.get(C::alu_helper1)) -
FF(1)) +
344 tmp *= scaling_factor;
349 auto tmp = in.get(C::alu_sel_op_lt) * (
FF(1) - in.get(C::alu_sel_op_lt));
350 tmp *= scaling_factor;
355 auto tmp = in.get(C::alu_sel_op_lte) * (
FF(1) - in.get(C::alu_sel_op_lte));
356 tmp *= scaling_factor;
361 auto tmp = (in.get(C::alu_sel_lt_ops) -
362 (
FF(1) - in.get(C::alu_sel_tag_err)) * (in.get(C::alu_sel_op_lt) + in.get(C::alu_sel_op_lte)));
363 tmp *= scaling_factor;
368 auto tmp = (in.get(C::alu_sel_ff_lt_ops) - in.get(C::alu_sel_is_ff) * in.get(C::alu_sel_lt_ops));
369 tmp *= scaling_factor;
374 auto tmp = (in.get(C::alu_sel_int_lt_ops) - alu_IS_NOT_FF * in.get(C::alu_sel_lt_ops));
375 tmp *= scaling_factor;
380 auto tmp = (in.get(C::alu_sel_op_lt) * (in.get(C::alu_lt_ops_input_a) - in.get(C::alu_ib)) +
381 in.get(C::alu_sel_op_lte) * (in.get(C::alu_lt_ops_input_a) - in.get(C::alu_ia)));
382 tmp *= scaling_factor;
387 auto tmp = (in.get(C::alu_sel_op_lt) * (in.get(C::alu_lt_ops_input_b) - in.get(C::alu_ia)) +
388 in.get(C::alu_sel_op_lte) * (in.get(C::alu_lt_ops_input_b) - in.get(C::alu_ib)));
389 tmp *= scaling_factor;
394 auto tmp = (in.get(C::alu_sel_op_lt) * (in.get(C::alu_lt_ops_result_c) - in.get(C::alu_ic)) +
395 in.get(C::alu_sel_op_lte) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
396 ((
FF(1) - in.get(C::alu_lt_ops_result_c)) - in.get(C::alu_ic)));
397 tmp *= scaling_factor;
402 auto tmp = in.get(C::alu_sel_op_not) * (
FF(1) - in.get(C::alu_sel_op_not));
403 tmp *= scaling_factor;
408 auto tmp = in.get(C::alu_sel_op_not) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
409 ((in.get(C::alu_ia) + in.get(C::alu_ib)) - in.get(C::alu_max_value));
410 tmp *= scaling_factor;
415 auto tmp = in.get(C::alu_sel_op_shl) * in.get(C::alu_sel_shift_ops_no_overflow) *
416 (
FF(1) - in.get(C::alu_sel_tag_err)) *
417 ((in.get(C::alu_max_value) +
FF(1)) - in.get(C::alu_two_pow_shift_lo_bits) * in.get(C::alu_helper1));
418 tmp *= scaling_factor;
423 auto tmp = in.get(C::alu_sel_op_shl) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
425 in.get(C::alu_sel_shift_ops_no_overflow) * in.get(C::alu_a_lo) * in.get(C::alu_helper1));
426 tmp *= scaling_factor;
431 auto tmp = in.get(C::alu_sel_op_shr) * (
FF(1) - in.get(C::alu_sel_tag_err)) *
432 (in.get(C::alu_ic) - in.get(C::alu_sel_shift_ops_no_overflow) * in.get(C::alu_a_hi));
433 tmp *= scaling_factor;
438 auto tmp = (in.get(C::alu_sel_shift_ops) - (in.get(C::alu_sel_op_shl) + in.get(C::alu_sel_op_shr)));
439 tmp *= scaling_factor;
444 auto tmp = in.get(C::alu_sel_shift_ops_no_overflow) * (
FF(1) - in.get(C::alu_sel_shift_ops));
445 tmp *= scaling_factor;
450 auto tmp = ((in.get(C::alu_shift_lo_bits) -
451 in.get(C::alu_sel_shift_ops_no_overflow) *
452 (in.get(C::alu_sel_op_shl) * (in.get(C::alu_max_bits) - in.get(C::alu_ib)) +
453 in.get(C::alu_sel_op_shr) * in.get(C::alu_ib))) -
454 alu_SHIFT_OVERFLOW * in.get(C::alu_max_bits));
455 tmp *= scaling_factor;
460 auto tmp = in.get(C::alu_sel_op_truncate) * (
FF(1) - in.get(C::alu_sel_op_truncate));
461 tmp *= scaling_factor;
466 auto tmp = in.get(C::alu_sel_trunc_trivial) * (
FF(1) - in.get(C::alu_sel_trunc_trivial));
467 tmp *= scaling_factor;
472 auto tmp = in.get(C::alu_sel_trunc_gte_128) * (
FF(1) - in.get(C::alu_sel_trunc_gte_128));
473 tmp *= scaling_factor;
478 auto tmp = in.get(C::alu_sel_trunc_lt_128) * (
FF(1) - in.get(C::alu_sel_trunc_lt_128));
479 tmp *= scaling_factor;
484 auto tmp = (in.get(C::alu_sel_trunc_non_trivial) -
485 (in.get(C::alu_sel_trunc_gte_128) + in.get(C::alu_sel_trunc_lt_128)));
486 tmp *= scaling_factor;
491 auto tmp = (in.get(C::alu_sel_op_truncate) -
492 (in.get(C::alu_sel_trunc_non_trivial) + in.get(C::alu_sel_trunc_trivial)));
493 tmp *= scaling_factor;
498 auto tmp = in.get(C::alu_sel_trunc_trivial) * (in.get(C::alu_ia) - in.get(C::alu_ic));
499 tmp *= scaling_factor;
504 auto tmp = in.get(C::alu_sel_trunc_lt_128) * (in.get(C::alu_a_lo) - in.get(C::alu_ia));
505 tmp *= scaling_factor;
511 in.get(C::alu_sel_trunc_non_trivial) *
512 ((in.get(C::alu_ic) + in.get(C::alu_mid) * (in.get(C::alu_max_value) +
FF(1))) - in.get(C::alu_a_lo));
513 tmp *= scaling_factor;
519 (in.get(C::alu_mid_bits) - in.get(C::alu_sel_trunc_non_trivial) * (
FF(128) - in.get(C::alu_max_bits)));
520 tmp *= scaling_factor;