diff --git a/barretenberg/cpp/pil/avm/alu.pil b/barretenberg/cpp/pil/avm/alu.pil index cae0003f39f..cb20b528252 100644 --- a/barretenberg/cpp/pil/avm/alu.pil +++ b/barretenberg/cpp/pil/avm/alu.pil @@ -733,3 +733,94 @@ namespace alu(256); pol NEXT_SUM_128_HI = u16_r3' + u16_r4' * 2**16 + u16_r5' * 2**32 + u16_r6' * 2**48; partial_prod_lo = op_div_std * NEXT_SUM_64_LO; partial_prod_hi = op_div_std * NEXT_SUM_128_HI; + + //====== Inter-table Shift Constraints (Lookups) ============================================ + // Currently only used for shift operations but can be generalised for other uses. + + // Lookup for 2**(ib) + #[LOOKUP_POW_2_0] + sel_shift_which {ib, two_pow_s} in main.sel_rng_8 {main.clk, powers.power_of_2}; + + // Lookup for 2**(t-ib) + #[LOOKUP_POW_2_1] + sel_shift_which {t_sub_s_bits ,two_pow_t_sub_s} in main.sel_rng_8 {main.clk, powers.power_of_2}; + + //====== Inter-table Constraints (Range Checks) ============================================ + // TODO: Investigate optimising these range checks. Handling non-FF elements should require less range checks. + // One can increase the granularity based on the operation and tag. In the most extreme case, + // a specific selector per register might be introduced. + #[LOOKUP_U8_0] + sel_rng_chk_lookup { u8_r0 } in main.sel_rng_8 { main.clk }; + + #[LOOKUP_U8_1] + sel_rng_chk_lookup { u8_r1 } in main.sel_rng_8 { main.clk }; + + #[LOOKUP_U16_0] + sel_rng_chk_lookup { u16_r0 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_1] + sel_rng_chk_lookup { u16_r1 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_2] + sel_rng_chk_lookup { u16_r2 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_3] + sel_rng_chk_lookup { u16_r3 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_4] + sel_rng_chk_lookup { u16_r4 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_5] + sel_rng_chk_lookup { u16_r5 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_6] + sel_rng_chk_lookup { u16_r6 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_7] + sel_rng_chk_lookup { u16_r7 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_8] + sel_rng_chk_lookup { u16_r8 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_9] + sel_rng_chk_lookup { u16_r9 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_10] + sel_rng_chk_lookup { u16_r10 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_11] + sel_rng_chk_lookup { u16_r11 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_12] + sel_rng_chk_lookup { u16_r12 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_13] + sel_rng_chk_lookup { u16_r13 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_U16_14] + sel_rng_chk_lookup { u16_r14 } in main.sel_rng_16 { main.clk }; + + // ==== Additional row range checks for division + #[LOOKUP_DIV_U16_0] + sel_div_rng_chk { div_u16_r0 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_1] + sel_div_rng_chk { div_u16_r1 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_2] + sel_div_rng_chk { div_u16_r2 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_3] + sel_div_rng_chk { div_u16_r3 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_4] + sel_div_rng_chk { div_u16_r4 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_5] + sel_div_rng_chk { div_u16_r5 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_6] + sel_div_rng_chk { div_u16_r6 } in main.sel_rng_16 { main.clk }; + + #[LOOKUP_DIV_U16_7] + sel_div_rng_chk { div_u16_r7 } in main.sel_rng_16 { main.clk }; diff --git a/barretenberg/cpp/pil/avm/main.pil b/barretenberg/cpp/pil/avm/main.pil index f1b03e37c3a..dcb5b7db4f9 100644 --- a/barretenberg/cpp/pil/avm/main.pil +++ b/barretenberg/cpp/pil/avm/main.pil @@ -628,94 +628,3 @@ namespace main(256); #[LOOKUP_MEM_RNG_CHK_HI] mem.sel_rng_chk {mem.diff_hi} in sel_rng_8 {clk}; - - //====== Inter-table Shift Constraints (Lookups) ============================================ - // Currently only used for shift operations but can be generalised for other uses. - - // Lookup for 2**(ib) - #[LOOKUP_POW_2_0] - alu.sel_shift_which {alu.ib, alu.two_pow_s} in sel_rng_8 {clk, powers.power_of_2}; - - // Lookup for 2**(t-ib) - #[LOOKUP_POW_2_1] - alu.sel_shift_which {alu.t_sub_s_bits , alu.two_pow_t_sub_s} in sel_rng_8 {clk, powers.power_of_2}; - - //====== Inter-table Constraints (Range Checks) ============================================ - // TODO: Investigate optimising these range checks. Handling non-FF elements should require less range checks. - // One can increase the granularity based on the operation and tag. In the most extreme case, - // a specific selector per register might be introduced. - #[LOOKUP_U8_0] - alu.sel_rng_chk_lookup { alu.u8_r0 } in sel_rng_8 { clk }; - - #[LOOKUP_U8_1] - alu.sel_rng_chk_lookup { alu.u8_r1 } in sel_rng_8 { clk }; - - #[LOOKUP_U16_0] - alu.sel_rng_chk_lookup { alu.u16_r0 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_1] - alu.sel_rng_chk_lookup { alu.u16_r1 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_2] - alu.sel_rng_chk_lookup { alu.u16_r2 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_3] - alu.sel_rng_chk_lookup { alu.u16_r3 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_4] - alu.sel_rng_chk_lookup { alu.u16_r4 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_5] - alu.sel_rng_chk_lookup { alu.u16_r5 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_6] - alu.sel_rng_chk_lookup { alu.u16_r6 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_7] - alu.sel_rng_chk_lookup { alu.u16_r7 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_8] - alu.sel_rng_chk_lookup { alu.u16_r8 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_9] - alu.sel_rng_chk_lookup { alu.u16_r9 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_10] - alu.sel_rng_chk_lookup { alu.u16_r10 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_11] - alu.sel_rng_chk_lookup { alu.u16_r11 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_12] - alu.sel_rng_chk_lookup { alu.u16_r12 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_13] - alu.sel_rng_chk_lookup { alu.u16_r13 } in sel_rng_16 { clk }; - - #[LOOKUP_U16_14] - alu.sel_rng_chk_lookup { alu.u16_r14 } in sel_rng_16 { clk }; - - // ==== Additional row range checks for division - #[LOOKUP_DIV_U16_0] - alu.sel_div_rng_chk { alu.div_u16_r0 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_1] - alu.sel_div_rng_chk { alu.div_u16_r1 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_2] - alu.sel_div_rng_chk { alu.div_u16_r2 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_3] - alu.sel_div_rng_chk { alu.div_u16_r3 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_4] - alu.sel_div_rng_chk { alu.div_u16_r4 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_5] - alu.sel_div_rng_chk { alu.div_u16_r5 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_6] - alu.sel_div_rng_chk { alu.div_u16_r6 } in sel_rng_16 { clk }; - - #[LOOKUP_DIV_U16_7] - alu.sel_div_rng_chk { alu.div_u16_r7 } in sel_rng_16 { clk }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp index 7db313939c4..ec768c0055b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/circuit_builder.cpp @@ -627,22 +627,6 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.slice_sel_start[i] = rows[i].slice_sel_start; polys.slice_space_id[i] = rows[i].slice_space_id; polys.slice_val[i] = rows[i].slice_val; - polys.lookup_byte_lengths_counts[i] = rows[i].lookup_byte_lengths_counts; - polys.lookup_byte_operations_counts[i] = rows[i].lookup_byte_operations_counts; - polys.lookup_opcode_gas_counts[i] = rows[i].lookup_opcode_gas_counts; - polys.range_check_l2_gas_hi_counts[i] = rows[i].range_check_l2_gas_hi_counts; - polys.range_check_l2_gas_lo_counts[i] = rows[i].range_check_l2_gas_lo_counts; - polys.range_check_da_gas_hi_counts[i] = rows[i].range_check_da_gas_hi_counts; - polys.range_check_da_gas_lo_counts[i] = rows[i].range_check_da_gas_lo_counts; - polys.kernel_output_lookup_counts[i] = rows[i].kernel_output_lookup_counts; - polys.lookup_into_kernel_counts[i] = rows[i].lookup_into_kernel_counts; - polys.lookup_cd_value_counts[i] = rows[i].lookup_cd_value_counts; - polys.lookup_ret_value_counts[i] = rows[i].lookup_ret_value_counts; - polys.incl_main_tag_err_counts[i] = rows[i].incl_main_tag_err_counts; - polys.incl_mem_tag_err_counts[i] = rows[i].incl_mem_tag_err_counts; - polys.lookup_mem_rng_chk_lo_counts[i] = rows[i].lookup_mem_rng_chk_lo_counts; - polys.lookup_mem_rng_chk_mid_counts[i] = rows[i].lookup_mem_rng_chk_mid_counts; - polys.lookup_mem_rng_chk_hi_counts[i] = rows[i].lookup_mem_rng_chk_hi_counts; polys.lookup_pow_2_0_counts[i] = rows[i].lookup_pow_2_0_counts; polys.lookup_pow_2_1_counts[i] = rows[i].lookup_pow_2_1_counts; polys.lookup_u8_0_counts[i] = rows[i].lookup_u8_0_counts; @@ -670,6 +654,22 @@ AvmCircuitBuilder::ProverPolynomials AvmCircuitBuilder::compute_polynomials() co polys.lookup_div_u16_5_counts[i] = rows[i].lookup_div_u16_5_counts; polys.lookup_div_u16_6_counts[i] = rows[i].lookup_div_u16_6_counts; polys.lookup_div_u16_7_counts[i] = rows[i].lookup_div_u16_7_counts; + polys.lookup_byte_lengths_counts[i] = rows[i].lookup_byte_lengths_counts; + polys.lookup_byte_operations_counts[i] = rows[i].lookup_byte_operations_counts; + polys.lookup_opcode_gas_counts[i] = rows[i].lookup_opcode_gas_counts; + polys.range_check_l2_gas_hi_counts[i] = rows[i].range_check_l2_gas_hi_counts; + polys.range_check_l2_gas_lo_counts[i] = rows[i].range_check_l2_gas_lo_counts; + polys.range_check_da_gas_hi_counts[i] = rows[i].range_check_da_gas_hi_counts; + polys.range_check_da_gas_lo_counts[i] = rows[i].range_check_da_gas_lo_counts; + polys.kernel_output_lookup_counts[i] = rows[i].kernel_output_lookup_counts; + polys.lookup_into_kernel_counts[i] = rows[i].lookup_into_kernel_counts; + polys.lookup_cd_value_counts[i] = rows[i].lookup_cd_value_counts; + polys.lookup_ret_value_counts[i] = rows[i].lookup_ret_value_counts; + polys.incl_main_tag_err_counts[i] = rows[i].incl_main_tag_err_counts; + polys.incl_mem_tag_err_counts[i] = rows[i].incl_mem_tag_err_counts; + polys.lookup_mem_rng_chk_lo_counts[i] = rows[i].lookup_mem_rng_chk_lo_counts; + polys.lookup_mem_rng_chk_mid_counts[i] = rows[i].lookup_mem_rng_chk_mid_counts; + polys.lookup_mem_rng_chk_hi_counts[i] = rows[i].lookup_mem_rng_chk_hi_counts; } for (auto [shifted, to_be_shifted] : zip_view(polys.get_shifted(), polys.get_to_be_shifted())) { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index 9cf8f248f46..02c17d98dec 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -608,49 +608,49 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , slice_sel_start(il[600]) , slice_space_id(il[601]) , slice_val(il[602]) - , lookup_byte_lengths_counts(il[603]) - , lookup_byte_operations_counts(il[604]) - , lookup_opcode_gas_counts(il[605]) - , range_check_l2_gas_hi_counts(il[606]) - , range_check_l2_gas_lo_counts(il[607]) - , range_check_da_gas_hi_counts(il[608]) - , range_check_da_gas_lo_counts(il[609]) - , kernel_output_lookup_counts(il[610]) - , lookup_into_kernel_counts(il[611]) - , lookup_cd_value_counts(il[612]) - , lookup_ret_value_counts(il[613]) - , incl_main_tag_err_counts(il[614]) - , incl_mem_tag_err_counts(il[615]) - , lookup_mem_rng_chk_lo_counts(il[616]) - , lookup_mem_rng_chk_mid_counts(il[617]) - , lookup_mem_rng_chk_hi_counts(il[618]) - , lookup_pow_2_0_counts(il[619]) - , lookup_pow_2_1_counts(il[620]) - , lookup_u8_0_counts(il[621]) - , lookup_u8_1_counts(il[622]) - , lookup_u16_0_counts(il[623]) - , lookup_u16_1_counts(il[624]) - , lookup_u16_2_counts(il[625]) - , lookup_u16_3_counts(il[626]) - , lookup_u16_4_counts(il[627]) - , lookup_u16_5_counts(il[628]) - , lookup_u16_6_counts(il[629]) - , lookup_u16_7_counts(il[630]) - , lookup_u16_8_counts(il[631]) - , lookup_u16_9_counts(il[632]) - , lookup_u16_10_counts(il[633]) - , lookup_u16_11_counts(il[634]) - , lookup_u16_12_counts(il[635]) - , lookup_u16_13_counts(il[636]) - , lookup_u16_14_counts(il[637]) - , lookup_div_u16_0_counts(il[638]) - , lookup_div_u16_1_counts(il[639]) - , lookup_div_u16_2_counts(il[640]) - , lookup_div_u16_3_counts(il[641]) - , lookup_div_u16_4_counts(il[642]) - , lookup_div_u16_5_counts(il[643]) - , lookup_div_u16_6_counts(il[644]) - , lookup_div_u16_7_counts(il[645]) + , lookup_pow_2_0_counts(il[603]) + , lookup_pow_2_1_counts(il[604]) + , lookup_u8_0_counts(il[605]) + , lookup_u8_1_counts(il[606]) + , lookup_u16_0_counts(il[607]) + , lookup_u16_1_counts(il[608]) + , lookup_u16_2_counts(il[609]) + , lookup_u16_3_counts(il[610]) + , lookup_u16_4_counts(il[611]) + , lookup_u16_5_counts(il[612]) + , lookup_u16_6_counts(il[613]) + , lookup_u16_7_counts(il[614]) + , lookup_u16_8_counts(il[615]) + , lookup_u16_9_counts(il[616]) + , lookup_u16_10_counts(il[617]) + , lookup_u16_11_counts(il[618]) + , lookup_u16_12_counts(il[619]) + , lookup_u16_13_counts(il[620]) + , lookup_u16_14_counts(il[621]) + , lookup_div_u16_0_counts(il[622]) + , lookup_div_u16_1_counts(il[623]) + , lookup_div_u16_2_counts(il[624]) + , lookup_div_u16_3_counts(il[625]) + , lookup_div_u16_4_counts(il[626]) + , lookup_div_u16_5_counts(il[627]) + , lookup_div_u16_6_counts(il[628]) + , lookup_div_u16_7_counts(il[629]) + , lookup_byte_lengths_counts(il[630]) + , lookup_byte_operations_counts(il[631]) + , lookup_opcode_gas_counts(il[632]) + , range_check_l2_gas_hi_counts(il[633]) + , range_check_l2_gas_lo_counts(il[634]) + , range_check_da_gas_hi_counts(il[635]) + , range_check_da_gas_lo_counts(il[636]) + , kernel_output_lookup_counts(il[637]) + , lookup_into_kernel_counts(il[638]) + , lookup_cd_value_counts(il[639]) + , lookup_ret_value_counts(il[640]) + , incl_main_tag_err_counts(il[641]) + , incl_mem_tag_err_counts(il[642]) + , lookup_mem_rng_chk_lo_counts(il[643]) + , lookup_mem_rng_chk_mid_counts(il[644]) + , lookup_mem_rng_chk_hi_counts(il[645]) , perm_pos_mem_read_a_inv(il[646]) , perm_pos_mem_read_b_inv(il[647]) , perm_pos_mem_read_c_inv(il[648]) @@ -674,49 +674,49 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , perm_main_mem_ind_addr_b_inv(il[666]) , perm_main_mem_ind_addr_c_inv(il[667]) , perm_main_mem_ind_addr_d_inv(il[668]) - , lookup_byte_lengths_inv(il[669]) - , lookup_byte_operations_inv(il[670]) - , lookup_opcode_gas_inv(il[671]) - , range_check_l2_gas_hi_inv(il[672]) - , range_check_l2_gas_lo_inv(il[673]) - , range_check_da_gas_hi_inv(il[674]) - , range_check_da_gas_lo_inv(il[675]) - , kernel_output_lookup_inv(il[676]) - , lookup_into_kernel_inv(il[677]) - , lookup_cd_value_inv(il[678]) - , lookup_ret_value_inv(il[679]) - , incl_main_tag_err_inv(il[680]) - , incl_mem_tag_err_inv(il[681]) - , lookup_mem_rng_chk_lo_inv(il[682]) - , lookup_mem_rng_chk_mid_inv(il[683]) - , lookup_mem_rng_chk_hi_inv(il[684]) - , lookup_pow_2_0_inv(il[685]) - , lookup_pow_2_1_inv(il[686]) - , lookup_u8_0_inv(il[687]) - , lookup_u8_1_inv(il[688]) - , lookup_u16_0_inv(il[689]) - , lookup_u16_1_inv(il[690]) - , lookup_u16_2_inv(il[691]) - , lookup_u16_3_inv(il[692]) - , lookup_u16_4_inv(il[693]) - , lookup_u16_5_inv(il[694]) - , lookup_u16_6_inv(il[695]) - , lookup_u16_7_inv(il[696]) - , lookup_u16_8_inv(il[697]) - , lookup_u16_9_inv(il[698]) - , lookup_u16_10_inv(il[699]) - , lookup_u16_11_inv(il[700]) - , lookup_u16_12_inv(il[701]) - , lookup_u16_13_inv(il[702]) - , lookup_u16_14_inv(il[703]) - , lookup_div_u16_0_inv(il[704]) - , lookup_div_u16_1_inv(il[705]) - , lookup_div_u16_2_inv(il[706]) - , lookup_div_u16_3_inv(il[707]) - , lookup_div_u16_4_inv(il[708]) - , lookup_div_u16_5_inv(il[709]) - , lookup_div_u16_6_inv(il[710]) - , lookup_div_u16_7_inv(il[711]) + , lookup_pow_2_0_inv(il[669]) + , lookup_pow_2_1_inv(il[670]) + , lookup_u8_0_inv(il[671]) + , lookup_u8_1_inv(il[672]) + , lookup_u16_0_inv(il[673]) + , lookup_u16_1_inv(il[674]) + , lookup_u16_2_inv(il[675]) + , lookup_u16_3_inv(il[676]) + , lookup_u16_4_inv(il[677]) + , lookup_u16_5_inv(il[678]) + , lookup_u16_6_inv(il[679]) + , lookup_u16_7_inv(il[680]) + , lookup_u16_8_inv(il[681]) + , lookup_u16_9_inv(il[682]) + , lookup_u16_10_inv(il[683]) + , lookup_u16_11_inv(il[684]) + , lookup_u16_12_inv(il[685]) + , lookup_u16_13_inv(il[686]) + , lookup_u16_14_inv(il[687]) + , lookup_div_u16_0_inv(il[688]) + , lookup_div_u16_1_inv(il[689]) + , lookup_div_u16_2_inv(il[690]) + , lookup_div_u16_3_inv(il[691]) + , lookup_div_u16_4_inv(il[692]) + , lookup_div_u16_5_inv(il[693]) + , lookup_div_u16_6_inv(il[694]) + , lookup_div_u16_7_inv(il[695]) + , lookup_byte_lengths_inv(il[696]) + , lookup_byte_operations_inv(il[697]) + , lookup_opcode_gas_inv(il[698]) + , range_check_l2_gas_hi_inv(il[699]) + , range_check_l2_gas_lo_inv(il[700]) + , range_check_da_gas_hi_inv(il[701]) + , range_check_da_gas_lo_inv(il[702]) + , kernel_output_lookup_inv(il[703]) + , lookup_into_kernel_inv(il[704]) + , lookup_cd_value_inv(il[705]) + , lookup_ret_value_inv(il[706]) + , incl_main_tag_err_inv(il[707]) + , incl_mem_tag_err_inv(il[708]) + , lookup_mem_rng_chk_lo_inv(il[709]) + , lookup_mem_rng_chk_mid_inv(il[710]) + , lookup_mem_rng_chk_hi_inv(il[711]) , alu_a_hi_shift(il[712]) , alu_a_lo_shift(il[713]) , alu_b_hi_shift(il[714]) @@ -1411,22 +1411,6 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id slice_sel_start[row_idx], slice_space_id[row_idx], slice_val[row_idx], - lookup_byte_lengths_counts[row_idx], - lookup_byte_operations_counts[row_idx], - lookup_opcode_gas_counts[row_idx], - range_check_l2_gas_hi_counts[row_idx], - range_check_l2_gas_lo_counts[row_idx], - range_check_da_gas_hi_counts[row_idx], - range_check_da_gas_lo_counts[row_idx], - kernel_output_lookup_counts[row_idx], - lookup_into_kernel_counts[row_idx], - lookup_cd_value_counts[row_idx], - lookup_ret_value_counts[row_idx], - incl_main_tag_err_counts[row_idx], - incl_mem_tag_err_counts[row_idx], - lookup_mem_rng_chk_lo_counts[row_idx], - lookup_mem_rng_chk_mid_counts[row_idx], - lookup_mem_rng_chk_hi_counts[row_idx], lookup_pow_2_0_counts[row_idx], lookup_pow_2_1_counts[row_idx], lookup_u8_0_counts[row_idx], @@ -1454,6 +1438,22 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id lookup_div_u16_5_counts[row_idx], lookup_div_u16_6_counts[row_idx], lookup_div_u16_7_counts[row_idx], + lookup_byte_lengths_counts[row_idx], + lookup_byte_operations_counts[row_idx], + lookup_opcode_gas_counts[row_idx], + range_check_l2_gas_hi_counts[row_idx], + range_check_l2_gas_lo_counts[row_idx], + range_check_da_gas_hi_counts[row_idx], + range_check_da_gas_lo_counts[row_idx], + kernel_output_lookup_counts[row_idx], + lookup_into_kernel_counts[row_idx], + lookup_cd_value_counts[row_idx], + lookup_ret_value_counts[row_idx], + incl_main_tag_err_counts[row_idx], + incl_mem_tag_err_counts[row_idx], + lookup_mem_rng_chk_lo_counts[row_idx], + lookup_mem_rng_chk_mid_counts[row_idx], + lookup_mem_rng_chk_hi_counts[row_idx], perm_pos_mem_read_a_inv[row_idx], perm_pos_mem_read_b_inv[row_idx], perm_pos_mem_read_c_inv[row_idx], @@ -1477,22 +1477,6 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id perm_main_mem_ind_addr_b_inv[row_idx], perm_main_mem_ind_addr_c_inv[row_idx], perm_main_mem_ind_addr_d_inv[row_idx], - lookup_byte_lengths_inv[row_idx], - lookup_byte_operations_inv[row_idx], - lookup_opcode_gas_inv[row_idx], - range_check_l2_gas_hi_inv[row_idx], - range_check_l2_gas_lo_inv[row_idx], - range_check_da_gas_hi_inv[row_idx], - range_check_da_gas_lo_inv[row_idx], - kernel_output_lookup_inv[row_idx], - lookup_into_kernel_inv[row_idx], - lookup_cd_value_inv[row_idx], - lookup_ret_value_inv[row_idx], - incl_main_tag_err_inv[row_idx], - incl_mem_tag_err_inv[row_idx], - lookup_mem_rng_chk_lo_inv[row_idx], - lookup_mem_rng_chk_mid_inv[row_idx], - lookup_mem_rng_chk_hi_inv[row_idx], lookup_pow_2_0_inv[row_idx], lookup_pow_2_1_inv[row_idx], lookup_u8_0_inv[row_idx], @@ -1520,6 +1504,22 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id lookup_div_u16_5_inv[row_idx], lookup_div_u16_6_inv[row_idx], lookup_div_u16_7_inv[row_idx], + lookup_byte_lengths_inv[row_idx], + lookup_byte_operations_inv[row_idx], + lookup_opcode_gas_inv[row_idx], + range_check_l2_gas_hi_inv[row_idx], + range_check_l2_gas_lo_inv[row_idx], + range_check_da_gas_hi_inv[row_idx], + range_check_da_gas_lo_inv[row_idx], + kernel_output_lookup_inv[row_idx], + lookup_into_kernel_inv[row_idx], + lookup_cd_value_inv[row_idx], + lookup_ret_value_inv[row_idx], + incl_main_tag_err_inv[row_idx], + incl_mem_tag_err_inv[row_idx], + lookup_mem_rng_chk_lo_inv[row_idx], + lookup_mem_rng_chk_mid_inv[row_idx], + lookup_mem_rng_chk_hi_inv[row_idx], alu_a_hi_shift[row_idx], alu_a_lo_shift[row_idx], alu_b_hi_shift[row_idx], @@ -2225,22 +2225,6 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::perm_main_mem_ind_addr_b_inv = "PERM_MAIN_MEM_IND_ADDR_B_INV"; Base::perm_main_mem_ind_addr_c_inv = "PERM_MAIN_MEM_IND_ADDR_C_INV"; Base::perm_main_mem_ind_addr_d_inv = "PERM_MAIN_MEM_IND_ADDR_D_INV"; - Base::lookup_byte_lengths_inv = "LOOKUP_BYTE_LENGTHS_INV"; - Base::lookup_byte_operations_inv = "LOOKUP_BYTE_OPERATIONS_INV"; - Base::lookup_opcode_gas_inv = "LOOKUP_OPCODE_GAS_INV"; - Base::range_check_l2_gas_hi_inv = "RANGE_CHECK_L2_GAS_HI_INV"; - Base::range_check_l2_gas_lo_inv = "RANGE_CHECK_L2_GAS_LO_INV"; - Base::range_check_da_gas_hi_inv = "RANGE_CHECK_DA_GAS_HI_INV"; - Base::range_check_da_gas_lo_inv = "RANGE_CHECK_DA_GAS_LO_INV"; - Base::kernel_output_lookup_inv = "KERNEL_OUTPUT_LOOKUP_INV"; - Base::lookup_into_kernel_inv = "LOOKUP_INTO_KERNEL_INV"; - Base::lookup_cd_value_inv = "LOOKUP_CD_VALUE_INV"; - Base::lookup_ret_value_inv = "LOOKUP_RET_VALUE_INV"; - Base::incl_main_tag_err_inv = "INCL_MAIN_TAG_ERR_INV"; - Base::incl_mem_tag_err_inv = "INCL_MEM_TAG_ERR_INV"; - Base::lookup_mem_rng_chk_lo_inv = "LOOKUP_MEM_RNG_CHK_LO_INV"; - Base::lookup_mem_rng_chk_mid_inv = "LOOKUP_MEM_RNG_CHK_MID_INV"; - Base::lookup_mem_rng_chk_hi_inv = "LOOKUP_MEM_RNG_CHK_HI_INV"; Base::lookup_pow_2_0_inv = "LOOKUP_POW_2_0_INV"; Base::lookup_pow_2_1_inv = "LOOKUP_POW_2_1_INV"; Base::lookup_u8_0_inv = "LOOKUP_U8_0_INV"; @@ -2268,22 +2252,22 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::lookup_div_u16_5_inv = "LOOKUP_DIV_U16_5_INV"; Base::lookup_div_u16_6_inv = "LOOKUP_DIV_U16_6_INV"; Base::lookup_div_u16_7_inv = "LOOKUP_DIV_U16_7_INV"; - Base::lookup_byte_lengths_counts = "LOOKUP_BYTE_LENGTHS_COUNTS"; - Base::lookup_byte_operations_counts = "LOOKUP_BYTE_OPERATIONS_COUNTS"; - Base::lookup_opcode_gas_counts = "LOOKUP_OPCODE_GAS_COUNTS"; - Base::range_check_l2_gas_hi_counts = "RANGE_CHECK_L2_GAS_HI_COUNTS"; - Base::range_check_l2_gas_lo_counts = "RANGE_CHECK_L2_GAS_LO_COUNTS"; - Base::range_check_da_gas_hi_counts = "RANGE_CHECK_DA_GAS_HI_COUNTS"; - Base::range_check_da_gas_lo_counts = "RANGE_CHECK_DA_GAS_LO_COUNTS"; - Base::kernel_output_lookup_counts = "KERNEL_OUTPUT_LOOKUP_COUNTS"; - Base::lookup_into_kernel_counts = "LOOKUP_INTO_KERNEL_COUNTS"; - Base::lookup_cd_value_counts = "LOOKUP_CD_VALUE_COUNTS"; - Base::lookup_ret_value_counts = "LOOKUP_RET_VALUE_COUNTS"; - Base::incl_main_tag_err_counts = "INCL_MAIN_TAG_ERR_COUNTS"; - Base::incl_mem_tag_err_counts = "INCL_MEM_TAG_ERR_COUNTS"; - Base::lookup_mem_rng_chk_lo_counts = "LOOKUP_MEM_RNG_CHK_LO_COUNTS"; - Base::lookup_mem_rng_chk_mid_counts = "LOOKUP_MEM_RNG_CHK_MID_COUNTS"; - Base::lookup_mem_rng_chk_hi_counts = "LOOKUP_MEM_RNG_CHK_HI_COUNTS"; + Base::lookup_byte_lengths_inv = "LOOKUP_BYTE_LENGTHS_INV"; + Base::lookup_byte_operations_inv = "LOOKUP_BYTE_OPERATIONS_INV"; + Base::lookup_opcode_gas_inv = "LOOKUP_OPCODE_GAS_INV"; + Base::range_check_l2_gas_hi_inv = "RANGE_CHECK_L2_GAS_HI_INV"; + Base::range_check_l2_gas_lo_inv = "RANGE_CHECK_L2_GAS_LO_INV"; + Base::range_check_da_gas_hi_inv = "RANGE_CHECK_DA_GAS_HI_INV"; + Base::range_check_da_gas_lo_inv = "RANGE_CHECK_DA_GAS_LO_INV"; + Base::kernel_output_lookup_inv = "KERNEL_OUTPUT_LOOKUP_INV"; + Base::lookup_into_kernel_inv = "LOOKUP_INTO_KERNEL_INV"; + Base::lookup_cd_value_inv = "LOOKUP_CD_VALUE_INV"; + Base::lookup_ret_value_inv = "LOOKUP_RET_VALUE_INV"; + Base::incl_main_tag_err_inv = "INCL_MAIN_TAG_ERR_INV"; + Base::incl_mem_tag_err_inv = "INCL_MEM_TAG_ERR_INV"; + Base::lookup_mem_rng_chk_lo_inv = "LOOKUP_MEM_RNG_CHK_LO_INV"; + Base::lookup_mem_rng_chk_mid_inv = "LOOKUP_MEM_RNG_CHK_MID_INV"; + Base::lookup_mem_rng_chk_hi_inv = "LOOKUP_MEM_RNG_CHK_HI_INV"; Base::lookup_pow_2_0_counts = "LOOKUP_POW_2_0_COUNTS"; Base::lookup_pow_2_1_counts = "LOOKUP_POW_2_1_COUNTS"; Base::lookup_u8_0_counts = "LOOKUP_U8_0_COUNTS"; @@ -2311,6 +2295,22 @@ AvmFlavor::CommitmentLabels::CommitmentLabels() Base::lookup_div_u16_5_counts = "LOOKUP_DIV_U16_5_COUNTS"; Base::lookup_div_u16_6_counts = "LOOKUP_DIV_U16_6_COUNTS"; Base::lookup_div_u16_7_counts = "LOOKUP_DIV_U16_7_COUNTS"; + Base::lookup_byte_lengths_counts = "LOOKUP_BYTE_LENGTHS_COUNTS"; + Base::lookup_byte_operations_counts = "LOOKUP_BYTE_OPERATIONS_COUNTS"; + Base::lookup_opcode_gas_counts = "LOOKUP_OPCODE_GAS_COUNTS"; + Base::range_check_l2_gas_hi_counts = "RANGE_CHECK_L2_GAS_HI_COUNTS"; + Base::range_check_l2_gas_lo_counts = "RANGE_CHECK_L2_GAS_LO_COUNTS"; + Base::range_check_da_gas_hi_counts = "RANGE_CHECK_DA_GAS_HI_COUNTS"; + Base::range_check_da_gas_lo_counts = "RANGE_CHECK_DA_GAS_LO_COUNTS"; + Base::kernel_output_lookup_counts = "KERNEL_OUTPUT_LOOKUP_COUNTS"; + Base::lookup_into_kernel_counts = "LOOKUP_INTO_KERNEL_COUNTS"; + Base::lookup_cd_value_counts = "LOOKUP_CD_VALUE_COUNTS"; + Base::lookup_ret_value_counts = "LOOKUP_RET_VALUE_COUNTS"; + Base::incl_main_tag_err_counts = "INCL_MAIN_TAG_ERR_COUNTS"; + Base::incl_mem_tag_err_counts = "INCL_MEM_TAG_ERR_COUNTS"; + Base::lookup_mem_rng_chk_lo_counts = "LOOKUP_MEM_RNG_CHK_LO_COUNTS"; + Base::lookup_mem_rng_chk_mid_counts = "LOOKUP_MEM_RNG_CHK_MID_COUNTS"; + Base::lookup_mem_rng_chk_hi_counts = "LOOKUP_MEM_RNG_CHK_HI_COUNTS"; }; AvmFlavor::VerifierCommitments::VerifierCommitments(const std::shared_ptr& verification_key) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index a88d98f21a2..0e7bb68207b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -102,8 +102,8 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: // The entities that will be used in the flavor. // clang-format off #define PRECOMPUTED_ENTITIES byte_lookup_sel_bin, byte_lookup_table_byte_lengths, byte_lookup_table_in_tags, byte_lookup_table_input_a, byte_lookup_table_input_b, byte_lookup_table_op_id, byte_lookup_table_output, gas_base_da_gas_fixed_table, gas_base_l2_gas_fixed_table, gas_dyn_da_gas_fixed_table, gas_dyn_l2_gas_fixed_table, gas_sel_gas_cost, main_clk, main_sel_first, main_zeroes, powers_power_of_2 -#define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_borrow, alu_cf, alu_clk, alu_cmp_rng_ctr, alu_div_u16_r0, alu_div_u16_r1, alu_div_u16_r2, alu_div_u16_r3, alu_div_u16_r4, alu_div_u16_r5, alu_div_u16_r6, alu_div_u16_r7, alu_divisor_hi, alu_divisor_lo, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_op_add, alu_op_cast, alu_op_cast_prev, alu_op_div, alu_op_div_a_lt_b, alu_op_div_std, alu_op_eq, alu_op_eq_diff_inv, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_p_a_borrow, alu_p_b_borrow, alu_p_sub_a_hi, alu_p_sub_a_lo, alu_p_sub_b_hi, alu_p_sub_b_lo, alu_partial_prod_hi, alu_partial_prod_lo, alu_quotient_hi, alu_quotient_lo, alu_remainder, alu_res_hi, alu_res_lo, alu_sel_alu, alu_sel_cmp, alu_sel_div_rng_chk, alu_sel_rng_chk, alu_sel_rng_chk_lookup, alu_sel_shift_which, alu_shift_lt_bit_len, alu_t_sub_s_bits, alu_two_pow_s, alu_two_pow_t_sub_s, alu_u128_tag, alu_u16_r0, alu_u16_r1, alu_u16_r10, alu_u16_r11, alu_u16_r12, alu_u16_r13, alu_u16_r14, alu_u16_r2, alu_u16_r3, alu_u16_r4, alu_u16_r5, alu_u16_r6, alu_u16_r7, alu_u16_r8, alu_u16_r9, alu_u16_tag, alu_u32_tag, alu_u64_tag, alu_u8_r0, alu_u8_r1, alu_u8_tag, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, conversion_clk, conversion_input, conversion_num_limbs, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, main_abs_l2_rem_gas_lo, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_coinbase, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_pedersen_commit, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff_hi, mem_diff_lo, mem_diff_mid, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, range_check_l2_gas_hi_counts, range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, lookup_mem_rng_chk_mid_counts, lookup_mem_rng_chk_hi_counts, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, lookup_u8_1_counts, lookup_u16_0_counts, lookup_u16_1_counts, lookup_u16_2_counts, lookup_u16_3_counts, lookup_u16_4_counts, lookup_u16_5_counts, lookup_u16_6_counts, lookup_u16_7_counts, lookup_u16_8_counts, lookup_u16_9_counts, lookup_u16_10_counts, lookup_u16_11_counts, lookup_u16_12_counts, lookup_u16_13_counts, lookup_u16_14_counts, lookup_div_u16_0_counts, lookup_div_u16_1_counts, lookup_div_u16_2_counts, lookup_div_u16_3_counts, lookup_div_u16_4_counts, lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts -#define DERIVED_WITNESS_ENTITIES perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_slice_mem_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_pos2_perm_inv, perm_main_pedersen_inv, perm_main_slice_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, range_check_l2_gas_hi_inv, range_check_l2_gas_lo_inv, range_check_da_gas_hi_inv, range_check_da_gas_lo_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv, lookup_mem_rng_chk_lo_inv, lookup_mem_rng_chk_mid_inv, lookup_mem_rng_chk_hi_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_u8_0_inv, lookup_u8_1_inv, lookup_u16_0_inv, lookup_u16_1_inv, lookup_u16_2_inv, lookup_u16_3_inv, lookup_u16_4_inv, lookup_u16_5_inv, lookup_u16_6_inv, lookup_u16_7_inv, lookup_u16_8_inv, lookup_u16_9_inv, lookup_u16_10_inv, lookup_u16_11_inv, lookup_u16_12_inv, lookup_u16_13_inv, lookup_u16_14_inv, lookup_div_u16_0_inv, lookup_div_u16_1_inv, lookup_div_u16_2_inv, lookup_div_u16_3_inv, lookup_div_u16_4_inv, lookup_div_u16_5_inv, lookup_div_u16_6_inv, lookup_div_u16_7_inv +#define WIRE_ENTITIES main_kernel_inputs, main_kernel_value_out, main_kernel_side_effect_out, main_kernel_metadata_out, main_calldata, main_returndata, alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, alu_borrow, alu_cf, alu_clk, alu_cmp_rng_ctr, alu_div_u16_r0, alu_div_u16_r1, alu_div_u16_r2, alu_div_u16_r3, alu_div_u16_r4, alu_div_u16_r5, alu_div_u16_r6, alu_div_u16_r7, alu_divisor_hi, alu_divisor_lo, alu_ff_tag, alu_ia, alu_ib, alu_ic, alu_in_tag, alu_op_add, alu_op_cast, alu_op_cast_prev, alu_op_div, alu_op_div_a_lt_b, alu_op_div_std, alu_op_eq, alu_op_eq_diff_inv, alu_op_lt, alu_op_lte, alu_op_mul, alu_op_not, alu_op_shl, alu_op_shr, alu_op_sub, alu_p_a_borrow, alu_p_b_borrow, alu_p_sub_a_hi, alu_p_sub_a_lo, alu_p_sub_b_hi, alu_p_sub_b_lo, alu_partial_prod_hi, alu_partial_prod_lo, alu_quotient_hi, alu_quotient_lo, alu_remainder, alu_res_hi, alu_res_lo, alu_sel_alu, alu_sel_cmp, alu_sel_div_rng_chk, alu_sel_rng_chk, alu_sel_rng_chk_lookup, alu_sel_shift_which, alu_shift_lt_bit_len, alu_t_sub_s_bits, alu_two_pow_s, alu_two_pow_t_sub_s, alu_u128_tag, alu_u16_r0, alu_u16_r1, alu_u16_r10, alu_u16_r11, alu_u16_r12, alu_u16_r13, alu_u16_r14, alu_u16_r2, alu_u16_r3, alu_u16_r4, alu_u16_r5, alu_u16_r6, alu_u16_r7, alu_u16_r8, alu_u16_r9, alu_u16_tag, alu_u32_tag, alu_u64_tag, alu_u8_r0, alu_u8_r1, alu_u8_tag, binary_acc_ia, binary_acc_ib, binary_acc_ic, binary_clk, binary_ia_bytes, binary_ib_bytes, binary_ic_bytes, binary_in_tag, binary_mem_tag_ctr, binary_mem_tag_ctr_inv, binary_op_id, binary_sel_bin, binary_start, conversion_clk, conversion_input, conversion_num_limbs, conversion_radix, conversion_sel_to_radix_le, keccakf1600_clk, keccakf1600_input, keccakf1600_output, keccakf1600_sel_keccakf1600, main_abs_da_rem_gas_hi, main_abs_da_rem_gas_lo, main_abs_l2_rem_gas_hi, main_abs_l2_rem_gas_lo, main_alu_in_tag, main_base_da_gas_op_cost, main_base_l2_gas_op_cost, main_bin_op_id, main_call_ptr, main_da_gas_remaining, main_da_out_of_gas, main_dyn_da_gas_op_cost, main_dyn_gas_multiplier, main_dyn_l2_gas_op_cost, main_emit_l2_to_l1_msg_write_offset, main_emit_note_hash_write_offset, main_emit_nullifier_write_offset, main_emit_unencrypted_log_write_offset, main_ia, main_ib, main_ic, main_id, main_id_zero, main_ind_addr_a, main_ind_addr_b, main_ind_addr_c, main_ind_addr_d, main_internal_return_ptr, main_inv, main_kernel_in_offset, main_kernel_out_offset, main_l1_to_l2_msg_exists_write_offset, main_l2_gas_remaining, main_l2_out_of_gas, main_mem_addr_a, main_mem_addr_b, main_mem_addr_c, main_mem_addr_d, main_note_hash_exist_write_offset, main_nullifier_exists_write_offset, main_nullifier_non_exists_write_offset, main_op_err, main_opcode_val, main_pc, main_r_in_tag, main_rwa, main_rwb, main_rwc, main_rwd, main_sel_alu, main_sel_bin, main_sel_calldata, main_sel_execution_row, main_sel_kernel_inputs, main_sel_kernel_out, main_sel_last, main_sel_mem_op_a, main_sel_mem_op_b, main_sel_mem_op_c, main_sel_mem_op_d, main_sel_mov_ia_to_ic, main_sel_mov_ib_to_ic, main_sel_op_add, main_sel_op_address, main_sel_op_and, main_sel_op_block_number, main_sel_op_calldata_copy, main_sel_op_cast, main_sel_op_chain_id, main_sel_op_cmov, main_sel_op_coinbase, main_sel_op_dagasleft, main_sel_op_div, main_sel_op_ecadd, main_sel_op_emit_l2_to_l1_msg, main_sel_op_emit_note_hash, main_sel_op_emit_nullifier, main_sel_op_emit_unencrypted_log, main_sel_op_eq, main_sel_op_external_call, main_sel_op_external_return, main_sel_op_external_revert, main_sel_op_fdiv, main_sel_op_fee_per_da_gas, main_sel_op_fee_per_l2_gas, main_sel_op_function_selector, main_sel_op_get_contract_instance, main_sel_op_internal_call, main_sel_op_internal_return, main_sel_op_jump, main_sel_op_jumpi, main_sel_op_keccak, main_sel_op_l1_to_l2_msg_exists, main_sel_op_l2gasleft, main_sel_op_lt, main_sel_op_lte, main_sel_op_mov, main_sel_op_msm, main_sel_op_mul, main_sel_op_not, main_sel_op_note_hash_exists, main_sel_op_nullifier_exists, main_sel_op_or, main_sel_op_pedersen, main_sel_op_pedersen_commit, main_sel_op_poseidon2, main_sel_op_radix_le, main_sel_op_sender, main_sel_op_set, main_sel_op_sha256, main_sel_op_shl, main_sel_op_shr, main_sel_op_sload, main_sel_op_sstore, main_sel_op_storage_address, main_sel_op_sub, main_sel_op_timestamp, main_sel_op_transaction_fee, main_sel_op_version, main_sel_op_xor, main_sel_q_kernel_lookup, main_sel_q_kernel_output_lookup, main_sel_resolve_ind_addr_a, main_sel_resolve_ind_addr_b, main_sel_resolve_ind_addr_c, main_sel_resolve_ind_addr_d, main_sel_returndata, main_sel_rng_16, main_sel_rng_8, main_sel_slice_gadget, main_side_effect_counter, main_sload_write_offset, main_space_id, main_sstore_write_offset, main_tag_err, main_w_in_tag, mem_addr, mem_clk, mem_diff_hi, mem_diff_lo, mem_diff_mid, mem_glob_addr, mem_last, mem_lastAccess, mem_one_min_inv, mem_r_in_tag, mem_rw, mem_sel_mem, mem_sel_mov_ia_to_ic, mem_sel_mov_ib_to_ic, mem_sel_op_a, mem_sel_op_b, mem_sel_op_c, mem_sel_op_cmov, mem_sel_op_d, mem_sel_op_poseidon_read_a, mem_sel_op_poseidon_read_b, mem_sel_op_poseidon_read_c, mem_sel_op_poseidon_read_d, mem_sel_op_poseidon_write_a, mem_sel_op_poseidon_write_b, mem_sel_op_poseidon_write_c, mem_sel_op_poseidon_write_d, mem_sel_op_slice, mem_sel_resolve_ind_addr_a, mem_sel_resolve_ind_addr_b, mem_sel_resolve_ind_addr_c, mem_sel_resolve_ind_addr_d, mem_sel_rng_chk, mem_skip_check_tag, mem_space_id, mem_tag, mem_tag_err, mem_tsp, mem_val, mem_w_in_tag, pedersen_clk, pedersen_input, pedersen_output, pedersen_sel_pedersen, poseidon2_B_10_0, poseidon2_B_10_1, poseidon2_B_10_2, poseidon2_B_10_3, poseidon2_B_11_0, poseidon2_B_11_1, poseidon2_B_11_2, poseidon2_B_11_3, poseidon2_B_12_0, poseidon2_B_12_1, poseidon2_B_12_2, poseidon2_B_12_3, poseidon2_B_13_0, poseidon2_B_13_1, poseidon2_B_13_2, poseidon2_B_13_3, poseidon2_B_14_0, poseidon2_B_14_1, poseidon2_B_14_2, poseidon2_B_14_3, poseidon2_B_15_0, poseidon2_B_15_1, poseidon2_B_15_2, poseidon2_B_15_3, poseidon2_B_16_0, poseidon2_B_16_1, poseidon2_B_16_2, poseidon2_B_16_3, poseidon2_B_17_0, poseidon2_B_17_1, poseidon2_B_17_2, poseidon2_B_17_3, poseidon2_B_18_0, poseidon2_B_18_1, poseidon2_B_18_2, poseidon2_B_18_3, poseidon2_B_19_0, poseidon2_B_19_1, poseidon2_B_19_2, poseidon2_B_19_3, poseidon2_B_20_0, poseidon2_B_20_1, poseidon2_B_20_2, poseidon2_B_20_3, poseidon2_B_21_0, poseidon2_B_21_1, poseidon2_B_21_2, poseidon2_B_21_3, poseidon2_B_22_0, poseidon2_B_22_1, poseidon2_B_22_2, poseidon2_B_22_3, poseidon2_B_23_0, poseidon2_B_23_1, poseidon2_B_23_2, poseidon2_B_23_3, poseidon2_B_24_0, poseidon2_B_24_1, poseidon2_B_24_2, poseidon2_B_24_3, poseidon2_B_25_0, poseidon2_B_25_1, poseidon2_B_25_2, poseidon2_B_25_3, poseidon2_B_26_0, poseidon2_B_26_1, poseidon2_B_26_2, poseidon2_B_26_3, poseidon2_B_27_0, poseidon2_B_27_1, poseidon2_B_27_2, poseidon2_B_27_3, poseidon2_B_28_0, poseidon2_B_28_1, poseidon2_B_28_2, poseidon2_B_28_3, poseidon2_B_29_0, poseidon2_B_29_1, poseidon2_B_29_2, poseidon2_B_29_3, poseidon2_B_30_0, poseidon2_B_30_1, poseidon2_B_30_2, poseidon2_B_30_3, poseidon2_B_31_0, poseidon2_B_31_1, poseidon2_B_31_2, poseidon2_B_31_3, poseidon2_B_32_0, poseidon2_B_32_1, poseidon2_B_32_2, poseidon2_B_32_3, poseidon2_B_33_0, poseidon2_B_33_1, poseidon2_B_33_2, poseidon2_B_33_3, poseidon2_B_34_0, poseidon2_B_34_1, poseidon2_B_34_2, poseidon2_B_34_3, poseidon2_B_35_0, poseidon2_B_35_1, poseidon2_B_35_2, poseidon2_B_35_3, poseidon2_B_36_0, poseidon2_B_36_1, poseidon2_B_36_2, poseidon2_B_36_3, poseidon2_B_37_0, poseidon2_B_37_1, poseidon2_B_37_2, poseidon2_B_37_3, poseidon2_B_38_0, poseidon2_B_38_1, poseidon2_B_38_2, poseidon2_B_38_3, poseidon2_B_39_0, poseidon2_B_39_1, poseidon2_B_39_2, poseidon2_B_39_3, poseidon2_B_40_0, poseidon2_B_40_1, poseidon2_B_40_2, poseidon2_B_40_3, poseidon2_B_41_0, poseidon2_B_41_1, poseidon2_B_41_2, poseidon2_B_41_3, poseidon2_B_42_0, poseidon2_B_42_1, poseidon2_B_42_2, poseidon2_B_42_3, poseidon2_B_43_0, poseidon2_B_43_1, poseidon2_B_43_2, poseidon2_B_43_3, poseidon2_B_44_0, poseidon2_B_44_1, poseidon2_B_44_2, poseidon2_B_44_3, poseidon2_B_45_0, poseidon2_B_45_1, poseidon2_B_45_2, poseidon2_B_45_3, poseidon2_B_46_0, poseidon2_B_46_1, poseidon2_B_46_2, poseidon2_B_46_3, poseidon2_B_47_0, poseidon2_B_47_1, poseidon2_B_47_2, poseidon2_B_47_3, poseidon2_B_48_0, poseidon2_B_48_1, poseidon2_B_48_2, poseidon2_B_48_3, poseidon2_B_49_0, poseidon2_B_49_1, poseidon2_B_49_2, poseidon2_B_49_3, poseidon2_B_4_0, poseidon2_B_4_1, poseidon2_B_4_2, poseidon2_B_4_3, poseidon2_B_50_0, poseidon2_B_50_1, poseidon2_B_50_2, poseidon2_B_50_3, poseidon2_B_51_0, poseidon2_B_51_1, poseidon2_B_51_2, poseidon2_B_51_3, poseidon2_B_52_0, poseidon2_B_52_1, poseidon2_B_52_2, poseidon2_B_52_3, poseidon2_B_53_0, poseidon2_B_53_1, poseidon2_B_53_2, poseidon2_B_53_3, poseidon2_B_54_0, poseidon2_B_54_1, poseidon2_B_54_2, poseidon2_B_54_3, poseidon2_B_55_0, poseidon2_B_55_1, poseidon2_B_55_2, poseidon2_B_55_3, poseidon2_B_56_0, poseidon2_B_56_1, poseidon2_B_56_2, poseidon2_B_56_3, poseidon2_B_57_0, poseidon2_B_57_1, poseidon2_B_57_2, poseidon2_B_57_3, poseidon2_B_58_0, poseidon2_B_58_1, poseidon2_B_58_2, poseidon2_B_58_3, poseidon2_B_59_0, poseidon2_B_59_1, poseidon2_B_59_2, poseidon2_B_59_3, poseidon2_B_5_0, poseidon2_B_5_1, poseidon2_B_5_2, poseidon2_B_5_3, poseidon2_B_6_0, poseidon2_B_6_1, poseidon2_B_6_2, poseidon2_B_6_3, poseidon2_B_7_0, poseidon2_B_7_1, poseidon2_B_7_2, poseidon2_B_7_3, poseidon2_B_8_0, poseidon2_B_8_1, poseidon2_B_8_2, poseidon2_B_8_3, poseidon2_B_9_0, poseidon2_B_9_1, poseidon2_B_9_2, poseidon2_B_9_3, poseidon2_EXT_LAYER_4, poseidon2_EXT_LAYER_5, poseidon2_EXT_LAYER_6, poseidon2_EXT_LAYER_7, poseidon2_T_0_4, poseidon2_T_0_5, poseidon2_T_0_6, poseidon2_T_0_7, poseidon2_T_1_4, poseidon2_T_1_5, poseidon2_T_1_6, poseidon2_T_1_7, poseidon2_T_2_4, poseidon2_T_2_5, poseidon2_T_2_6, poseidon2_T_2_7, poseidon2_T_3_4, poseidon2_T_3_5, poseidon2_T_3_6, poseidon2_T_3_7, poseidon2_T_60_4, poseidon2_T_60_5, poseidon2_T_60_6, poseidon2_T_60_7, poseidon2_T_61_4, poseidon2_T_61_5, poseidon2_T_61_6, poseidon2_T_61_7, poseidon2_T_62_4, poseidon2_T_62_5, poseidon2_T_62_6, poseidon2_T_62_7, poseidon2_T_63_4, poseidon2_T_63_5, poseidon2_T_63_6, poseidon2_T_63_7, poseidon2_a_0, poseidon2_a_1, poseidon2_a_2, poseidon2_a_3, poseidon2_b_0, poseidon2_b_1, poseidon2_b_2, poseidon2_b_3, poseidon2_clk, poseidon2_input_addr, poseidon2_mem_addr_read_a, poseidon2_mem_addr_read_b, poseidon2_mem_addr_read_c, poseidon2_mem_addr_read_d, poseidon2_mem_addr_write_a, poseidon2_mem_addr_write_b, poseidon2_mem_addr_write_c, poseidon2_mem_addr_write_d, poseidon2_output_addr, poseidon2_sel_poseidon_perm, sha256_clk, sha256_input, sha256_output, sha256_sel_sha256_compression, sha256_state, slice_addr, slice_clk, slice_cnt, slice_col_offset, slice_one_min_inv, slice_sel_cd_cpy, slice_sel_mem_active, slice_sel_return, slice_sel_start, slice_space_id, slice_val, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, lookup_u8_1_counts, lookup_u16_0_counts, lookup_u16_1_counts, lookup_u16_2_counts, lookup_u16_3_counts, lookup_u16_4_counts, lookup_u16_5_counts, lookup_u16_6_counts, lookup_u16_7_counts, lookup_u16_8_counts, lookup_u16_9_counts, lookup_u16_10_counts, lookup_u16_11_counts, lookup_u16_12_counts, lookup_u16_13_counts, lookup_u16_14_counts, lookup_div_u16_0_counts, lookup_div_u16_1_counts, lookup_div_u16_2_counts, lookup_div_u16_3_counts, lookup_div_u16_4_counts, lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts, lookup_byte_lengths_counts, lookup_byte_operations_counts, lookup_opcode_gas_counts, range_check_l2_gas_hi_counts, range_check_l2_gas_lo_counts, range_check_da_gas_hi_counts, range_check_da_gas_lo_counts, kernel_output_lookup_counts, lookup_into_kernel_counts, lookup_cd_value_counts, lookup_ret_value_counts, incl_main_tag_err_counts, incl_mem_tag_err_counts, lookup_mem_rng_chk_lo_counts, lookup_mem_rng_chk_mid_counts, lookup_mem_rng_chk_hi_counts +#define DERIVED_WITNESS_ENTITIES perm_pos_mem_read_a_inv, perm_pos_mem_read_b_inv, perm_pos_mem_read_c_inv, perm_pos_mem_read_d_inv, perm_pos_mem_write_a_inv, perm_pos_mem_write_b_inv, perm_pos_mem_write_c_inv, perm_pos_mem_write_d_inv, perm_slice_mem_inv, perm_main_alu_inv, perm_main_bin_inv, perm_main_conv_inv, perm_main_pos2_perm_inv, perm_main_pedersen_inv, perm_main_slice_inv, perm_main_mem_a_inv, perm_main_mem_b_inv, perm_main_mem_c_inv, perm_main_mem_d_inv, perm_main_mem_ind_addr_a_inv, perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_u8_0_inv, lookup_u8_1_inv, lookup_u16_0_inv, lookup_u16_1_inv, lookup_u16_2_inv, lookup_u16_3_inv, lookup_u16_4_inv, lookup_u16_5_inv, lookup_u16_6_inv, lookup_u16_7_inv, lookup_u16_8_inv, lookup_u16_9_inv, lookup_u16_10_inv, lookup_u16_11_inv, lookup_u16_12_inv, lookup_u16_13_inv, lookup_u16_14_inv, lookup_div_u16_0_inv, lookup_div_u16_1_inv, lookup_div_u16_2_inv, lookup_div_u16_3_inv, lookup_div_u16_4_inv, lookup_div_u16_5_inv, lookup_div_u16_6_inv, lookup_div_u16_7_inv, lookup_byte_lengths_inv, lookup_byte_operations_inv, lookup_opcode_gas_inv, range_check_l2_gas_hi_inv, range_check_l2_gas_lo_inv, range_check_da_gas_hi_inv, range_check_da_gas_lo_inv, kernel_output_lookup_inv, lookup_into_kernel_inv, lookup_cd_value_inv, lookup_ret_value_inv, incl_main_tag_err_inv, incl_mem_tag_err_inv, lookup_mem_rng_chk_lo_inv, lookup_mem_rng_chk_mid_inv, lookup_mem_rng_chk_hi_inv #define SHIFTED_ENTITIES alu_a_hi_shift, alu_a_lo_shift, alu_b_hi_shift, alu_b_lo_shift, alu_cmp_rng_ctr_shift, alu_div_u16_r0_shift, alu_div_u16_r1_shift, alu_div_u16_r2_shift, alu_div_u16_r3_shift, alu_div_u16_r4_shift, alu_div_u16_r5_shift, alu_div_u16_r6_shift, alu_div_u16_r7_shift, alu_op_add_shift, alu_op_cast_shift, alu_op_cast_prev_shift, alu_op_div_shift, alu_op_mul_shift, alu_op_shl_shift, alu_op_shr_shift, alu_op_sub_shift, alu_p_sub_a_hi_shift, alu_p_sub_a_lo_shift, alu_p_sub_b_hi_shift, alu_p_sub_b_lo_shift, alu_sel_alu_shift, alu_sel_cmp_shift, alu_sel_div_rng_chk_shift, alu_sel_rng_chk_shift, alu_sel_rng_chk_lookup_shift, alu_u16_r0_shift, alu_u16_r1_shift, alu_u16_r2_shift, alu_u16_r3_shift, alu_u16_r4_shift, alu_u16_r5_shift, alu_u16_r6_shift, alu_u8_r0_shift, alu_u8_r1_shift, binary_acc_ia_shift, binary_acc_ib_shift, binary_acc_ic_shift, binary_mem_tag_ctr_shift, binary_op_id_shift, main_da_gas_remaining_shift, main_emit_l2_to_l1_msg_write_offset_shift, main_emit_note_hash_write_offset_shift, main_emit_nullifier_write_offset_shift, main_emit_unencrypted_log_write_offset_shift, main_internal_return_ptr_shift, main_l1_to_l2_msg_exists_write_offset_shift, main_l2_gas_remaining_shift, main_note_hash_exist_write_offset_shift, main_nullifier_exists_write_offset_shift, main_nullifier_non_exists_write_offset_shift, main_pc_shift, main_sel_execution_row_shift, main_side_effect_counter_shift, main_sload_write_offset_shift, main_sstore_write_offset_shift, mem_glob_addr_shift, mem_rw_shift, mem_sel_mem_shift, mem_tag_shift, mem_tsp_shift, mem_val_shift, slice_addr_shift, slice_clk_shift, slice_cnt_shift, slice_col_offset_shift, slice_sel_cd_cpy_shift, slice_sel_mem_active_shift, slice_sel_return_shift, slice_sel_start_shift, slice_space_id_shift #define TO_BE_SHIFTED(e) e.alu_a_hi, e.alu_a_lo, e.alu_b_hi, e.alu_b_lo, e.alu_cmp_rng_ctr, e.alu_div_u16_r0, e.alu_div_u16_r1, e.alu_div_u16_r2, e.alu_div_u16_r3, e.alu_div_u16_r4, e.alu_div_u16_r5, e.alu_div_u16_r6, e.alu_div_u16_r7, e.alu_op_add, e.alu_op_cast, e.alu_op_cast_prev, e.alu_op_div, e.alu_op_mul, e.alu_op_shl, e.alu_op_shr, e.alu_op_sub, e.alu_p_sub_a_hi, e.alu_p_sub_a_lo, e.alu_p_sub_b_hi, e.alu_p_sub_b_lo, e.alu_sel_alu, e.alu_sel_cmp, e.alu_sel_div_rng_chk, e.alu_sel_rng_chk, e.alu_sel_rng_chk_lookup, e.alu_u16_r0, e.alu_u16_r1, e.alu_u16_r2, e.alu_u16_r3, e.alu_u16_r4, e.alu_u16_r5, e.alu_u16_r6, e.alu_u8_r0, e.alu_u8_r1, e.binary_acc_ia, e.binary_acc_ib, e.binary_acc_ic, e.binary_mem_tag_ctr, e.binary_op_id, e.main_da_gas_remaining, e.main_emit_l2_to_l1_msg_write_offset, e.main_emit_note_hash_write_offset, e.main_emit_nullifier_write_offset, e.main_emit_unencrypted_log_write_offset, e.main_internal_return_ptr, e.main_l1_to_l2_msg_exists_write_offset, e.main_l2_gas_remaining, e.main_note_hash_exist_write_offset, e.main_nullifier_exists_write_offset, e.main_nullifier_non_exists_write_offset, e.main_pc, e.main_sel_execution_row, e.main_side_effect_counter, e.main_sload_write_offset, e.main_sstore_write_offset, e.mem_glob_addr, e.mem_rw, e.mem_sel_mem, e.mem_tag, e.mem_tsp, e.mem_val, e.slice_addr, e.slice_clk, e.slice_cnt, e.slice_col_offset, e.slice_sel_cd_cpy, e.slice_sel_mem_active, e.slice_sel_return, e.slice_sel_start, e.slice_space_id #define ALL_ENTITIES PRECOMPUTED_ENTITIES, WIRE_ENTITIES, DERIVED_WITNESS_ENTITIES, SHIFTED_ENTITIES diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp index 8a9e2d32c81..25dc4756728 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.cpp @@ -645,22 +645,6 @@ template std::vector AvmFullRow::names() "perm_main_mem_ind_addr_b_inv", "perm_main_mem_ind_addr_c_inv", "perm_main_mem_ind_addr_d_inv", - "lookup_byte_lengths_inv", - "lookup_byte_operations_inv", - "lookup_opcode_gas_inv", - "range_check_l2_gas_hi_inv", - "range_check_l2_gas_lo_inv", - "range_check_da_gas_hi_inv", - "range_check_da_gas_lo_inv", - "kernel_output_lookup_inv", - "lookup_into_kernel_inv", - "lookup_cd_value_inv", - "lookup_ret_value_inv", - "incl_main_tag_err_inv", - "incl_mem_tag_err_inv", - "lookup_mem_rng_chk_lo_inv", - "lookup_mem_rng_chk_mid_inv", - "lookup_mem_rng_chk_hi_inv", "lookup_pow_2_0_inv", "lookup_pow_2_1_inv", "lookup_u8_0_inv", @@ -688,22 +672,22 @@ template std::vector AvmFullRow::names() "lookup_div_u16_5_inv", "lookup_div_u16_6_inv", "lookup_div_u16_7_inv", - "lookup_byte_lengths_counts", - "lookup_byte_operations_counts", - "lookup_opcode_gas_counts", - "range_check_l2_gas_hi_counts", - "range_check_l2_gas_lo_counts", - "range_check_da_gas_hi_counts", - "range_check_da_gas_lo_counts", - "kernel_output_lookup_counts", - "lookup_into_kernel_counts", - "lookup_cd_value_counts", - "lookup_ret_value_counts", - "incl_main_tag_err_counts", - "incl_mem_tag_err_counts", - "lookup_mem_rng_chk_lo_counts", - "lookup_mem_rng_chk_mid_counts", - "lookup_mem_rng_chk_hi_counts", + "lookup_byte_lengths_inv", + "lookup_byte_operations_inv", + "lookup_opcode_gas_inv", + "range_check_l2_gas_hi_inv", + "range_check_l2_gas_lo_inv", + "range_check_da_gas_hi_inv", + "range_check_da_gas_lo_inv", + "kernel_output_lookup_inv", + "lookup_into_kernel_inv", + "lookup_cd_value_inv", + "lookup_ret_value_inv", + "incl_main_tag_err_inv", + "incl_mem_tag_err_inv", + "lookup_mem_rng_chk_lo_inv", + "lookup_mem_rng_chk_mid_inv", + "lookup_mem_rng_chk_hi_inv", "lookup_pow_2_0_counts", "lookup_pow_2_1_counts", "lookup_u8_0_counts", @@ -730,7 +714,23 @@ template std::vector AvmFullRow::names() "lookup_div_u16_4_counts", "lookup_div_u16_5_counts", "lookup_div_u16_6_counts", - "lookup_div_u16_7_counts" }; + "lookup_div_u16_7_counts", + "lookup_byte_lengths_counts", + "lookup_byte_operations_counts", + "lookup_opcode_gas_counts", + "range_check_l2_gas_hi_counts", + "range_check_l2_gas_lo_counts", + "range_check_da_gas_hi_counts", + "range_check_da_gas_lo_counts", + "kernel_output_lookup_counts", + "lookup_into_kernel_counts", + "lookup_cd_value_counts", + "lookup_ret_value_counts", + "incl_main_tag_err_counts", + "incl_mem_tag_err_counts", + "lookup_mem_rng_chk_lo_counts", + "lookup_mem_rng_chk_mid_counts", + "lookup_mem_rng_chk_hi_counts" }; } template RefVector AvmFullRow::as_vector() const @@ -1362,22 +1362,6 @@ template RefVector AvmFullRow::as_vector() const perm_main_mem_ind_addr_b_inv, perm_main_mem_ind_addr_c_inv, perm_main_mem_ind_addr_d_inv, - lookup_byte_lengths_inv, - lookup_byte_operations_inv, - lookup_opcode_gas_inv, - range_check_l2_gas_hi_inv, - range_check_l2_gas_lo_inv, - range_check_da_gas_hi_inv, - range_check_da_gas_lo_inv, - kernel_output_lookup_inv, - lookup_into_kernel_inv, - lookup_cd_value_inv, - lookup_ret_value_inv, - incl_main_tag_err_inv, - incl_mem_tag_err_inv, - lookup_mem_rng_chk_lo_inv, - lookup_mem_rng_chk_mid_inv, - lookup_mem_rng_chk_hi_inv, lookup_pow_2_0_inv, lookup_pow_2_1_inv, lookup_u8_0_inv, @@ -1405,22 +1389,22 @@ template RefVector AvmFullRow::as_vector() const lookup_div_u16_5_inv, lookup_div_u16_6_inv, lookup_div_u16_7_inv, - lookup_byte_lengths_counts, - lookup_byte_operations_counts, - lookup_opcode_gas_counts, - range_check_l2_gas_hi_counts, - range_check_l2_gas_lo_counts, - range_check_da_gas_hi_counts, - range_check_da_gas_lo_counts, - kernel_output_lookup_counts, - lookup_into_kernel_counts, - lookup_cd_value_counts, - lookup_ret_value_counts, - incl_main_tag_err_counts, - incl_mem_tag_err_counts, - lookup_mem_rng_chk_lo_counts, - lookup_mem_rng_chk_mid_counts, - lookup_mem_rng_chk_hi_counts, + lookup_byte_lengths_inv, + lookup_byte_operations_inv, + lookup_opcode_gas_inv, + range_check_l2_gas_hi_inv, + range_check_l2_gas_lo_inv, + range_check_da_gas_hi_inv, + range_check_da_gas_lo_inv, + kernel_output_lookup_inv, + lookup_into_kernel_inv, + lookup_cd_value_inv, + lookup_ret_value_inv, + incl_main_tag_err_inv, + incl_mem_tag_err_inv, + lookup_mem_rng_chk_lo_inv, + lookup_mem_rng_chk_mid_inv, + lookup_mem_rng_chk_hi_inv, lookup_pow_2_0_counts, lookup_pow_2_1_counts, lookup_u8_0_counts, @@ -1448,6 +1432,22 @@ template RefVector AvmFullRow::as_vector() const lookup_div_u16_5_counts, lookup_div_u16_6_counts, lookup_div_u16_7_counts, + lookup_byte_lengths_counts, + lookup_byte_operations_counts, + lookup_opcode_gas_counts, + range_check_l2_gas_hi_counts, + range_check_l2_gas_lo_counts, + range_check_da_gas_hi_counts, + range_check_da_gas_lo_counts, + kernel_output_lookup_counts, + lookup_into_kernel_counts, + lookup_cd_value_counts, + lookup_ret_value_counts, + incl_main_tag_err_counts, + incl_mem_tag_err_counts, + lookup_mem_rng_chk_lo_counts, + lookup_mem_rng_chk_mid_counts, + lookup_mem_rng_chk_hi_counts, }; } diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp index 07e82e9798f..4c8e36640e3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/full_row.hpp @@ -636,22 +636,6 @@ template struct AvmFullRow { FF perm_main_mem_ind_addr_b_inv{}; FF perm_main_mem_ind_addr_c_inv{}; FF perm_main_mem_ind_addr_d_inv{}; - FF lookup_byte_lengths_inv{}; - FF lookup_byte_operations_inv{}; - FF lookup_opcode_gas_inv{}; - FF range_check_l2_gas_hi_inv{}; - FF range_check_l2_gas_lo_inv{}; - FF range_check_da_gas_hi_inv{}; - FF range_check_da_gas_lo_inv{}; - FF kernel_output_lookup_inv{}; - FF lookup_into_kernel_inv{}; - FF lookup_cd_value_inv{}; - FF lookup_ret_value_inv{}; - FF incl_main_tag_err_inv{}; - FF incl_mem_tag_err_inv{}; - FF lookup_mem_rng_chk_lo_inv{}; - FF lookup_mem_rng_chk_mid_inv{}; - FF lookup_mem_rng_chk_hi_inv{}; FF lookup_pow_2_0_inv{}; FF lookup_pow_2_1_inv{}; FF lookup_u8_0_inv{}; @@ -679,22 +663,22 @@ template struct AvmFullRow { FF lookup_div_u16_5_inv{}; FF lookup_div_u16_6_inv{}; FF lookup_div_u16_7_inv{}; - FF lookup_byte_lengths_counts{}; - FF lookup_byte_operations_counts{}; - FF lookup_opcode_gas_counts{}; - FF range_check_l2_gas_hi_counts{}; - FF range_check_l2_gas_lo_counts{}; - FF range_check_da_gas_hi_counts{}; - FF range_check_da_gas_lo_counts{}; - FF kernel_output_lookup_counts{}; - FF lookup_into_kernel_counts{}; - FF lookup_cd_value_counts{}; - FF lookup_ret_value_counts{}; - FF incl_main_tag_err_counts{}; - FF incl_mem_tag_err_counts{}; - FF lookup_mem_rng_chk_lo_counts{}; - FF lookup_mem_rng_chk_mid_counts{}; - FF lookup_mem_rng_chk_hi_counts{}; + FF lookup_byte_lengths_inv{}; + FF lookup_byte_operations_inv{}; + FF lookup_opcode_gas_inv{}; + FF range_check_l2_gas_hi_inv{}; + FF range_check_l2_gas_lo_inv{}; + FF range_check_da_gas_hi_inv{}; + FF range_check_da_gas_lo_inv{}; + FF kernel_output_lookup_inv{}; + FF lookup_into_kernel_inv{}; + FF lookup_cd_value_inv{}; + FF lookup_ret_value_inv{}; + FF incl_main_tag_err_inv{}; + FF incl_mem_tag_err_inv{}; + FF lookup_mem_rng_chk_lo_inv{}; + FF lookup_mem_rng_chk_mid_inv{}; + FF lookup_mem_rng_chk_hi_inv{}; FF lookup_pow_2_0_counts{}; FF lookup_pow_2_1_counts{}; FF lookup_u8_0_counts{}; @@ -722,6 +706,22 @@ template struct AvmFullRow { FF lookup_div_u16_5_counts{}; FF lookup_div_u16_6_counts{}; FF lookup_div_u16_7_counts{}; + FF lookup_byte_lengths_counts{}; + FF lookup_byte_operations_counts{}; + FF lookup_opcode_gas_counts{}; + FF range_check_l2_gas_hi_counts{}; + FF range_check_l2_gas_lo_counts{}; + FF range_check_da_gas_hi_counts{}; + FF range_check_da_gas_lo_counts{}; + FF kernel_output_lookup_counts{}; + FF lookup_into_kernel_counts{}; + FF lookup_cd_value_counts{}; + FF lookup_ret_value_counts{}; + FF incl_main_tag_err_counts{}; + FF incl_mem_tag_err_counts{}; + FF lookup_mem_rng_chk_lo_counts{}; + FF lookup_mem_rng_chk_mid_counts{}; + FF lookup_mem_rng_chk_hi_counts{}; RefVector as_vector() const; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.cpp index a0ee918a418..f7ff34984b3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.cpp @@ -73,7 +73,8 @@ uint8_t mem_tag_bits(AvmMemoryTag in_tag) } return 0; } -} // Anonymous namespace + +} // namespace /************************************************************************************************** * PRIVATE HELPERS @@ -149,10 +150,6 @@ std::vector AvmAluTraceBuilder::cmp_range_che return rows; } -/************************************************************************************************** - * RESET/FINALIZE - **************************************************************************************************/ - /** * @brief Resetting the internal state so that a new Alu trace can be rebuilt using the same object. * @@ -163,16 +160,6 @@ void AvmAluTraceBuilder::reset() range_checked_required = false; } -/** - * @brief Prepare the Alu trace to be incorporated into the main trace. - * - * @return The Alu trace (which is moved). - */ -std::vector AvmAluTraceBuilder::finalize() -{ - return std::move(alu_trace); -} - /************************************************************************************************** * COMPUTE - ARITHMETIC **************************************************************************************************/ @@ -243,13 +230,8 @@ FF AvmAluTraceBuilder::op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, uin alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_add = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::ADD, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -327,13 +309,8 @@ FF AvmAluTraceBuilder::op_sub(FF const& a, FF const& b, AvmMemoryTag in_tag, uin alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_sub = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::SUB, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -427,8 +404,8 @@ FF AvmAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uin alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_mul = true, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::MUL, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -459,14 +436,11 @@ FF AvmAluTraceBuilder::op_mul(FF const& a, FF const& b, AvmMemoryTag in_tag, uin alu_u16_reg = u16_reg; // Following code executed for: ff, u8, u16, u32, u64 (u128 returned handled specifically) + ASSERT(in_tag != AvmMemoryTag::U128); alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_mul = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, + .opcode = OpCode::MUL, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -497,12 +471,8 @@ FF AvmAluTraceBuilder::op_div(FF const& a, FF const& b, AvmMemoryTag in_tag, uin auto [u8_r0, u8_r1, u16_reg] = to_alu_slice_registers(rng_chk_lo); alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry({ .alu_clk = clk, - .alu_op_div = true, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::DIV, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = 0, @@ -549,12 +519,8 @@ FF AvmAluTraceBuilder::op_div(FF const& a, FF const& b, AvmMemoryTag in_tag, uin auto hi_lo_limbs = std::vector{ a_lo, a_hi, partial_prod, b_hi, p_sub_a_lo, p_sub_a_hi }; AvmAluTraceBuilder::AluTraceEntry row{ .alu_clk = clk, - .alu_op_div = true, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::DIV, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = FF{ c_u256 }, @@ -601,13 +567,8 @@ FF AvmAluTraceBuilder::op_eq(FF const& a, FF const& b, AvmMemoryTag in_tag, uint alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_eq = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::EQ, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = res, @@ -653,13 +614,8 @@ FF AvmAluTraceBuilder::op_lt(FF const& a, FF const& b, AvmMemoryTag in_tag, uint AvmAluTraceBuilder::AluTraceEntry row{ .alu_clk = clk, - .alu_op_lt = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::LT, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = FF(static_cast(c)), @@ -708,13 +664,8 @@ FF AvmAluTraceBuilder::op_lte(FF const& a, FF const& b, AvmMemoryTag in_tag, uin // Construct the row that performs the lte check AvmAluTraceBuilder::AluTraceEntry row{ .alu_clk = clk, - .alu_op_lte = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::LTE, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = FF(static_cast(c)), @@ -771,12 +722,8 @@ FF AvmAluTraceBuilder::op_not(FF const& a, AvmMemoryTag in_tag, uint32_t const c alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_not = true, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::NOT, + .tag = in_tag, .alu_ia = a, .alu_ic = c, }); @@ -816,13 +763,8 @@ FF AvmAluTraceBuilder::op_shl(FF const& a, FF const& b, AvmMemoryTag in_tag, uin [[maybe_unused]] auto [alu_u8_r0, alu_u8_r1, alu_u16_reg] = AvmAluTraceBuilder::to_alu_slice_registers(0); alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_shl = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::SHL, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = 0, @@ -873,13 +815,8 @@ FF AvmAluTraceBuilder::op_shl(FF const& a, FF const& b, AvmMemoryTag in_tag, uin alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_shl = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::SHL, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = c, @@ -926,13 +863,8 @@ FF AvmAluTraceBuilder::op_shr(FF const& a, FF const& b, AvmMemoryTag in_tag, uin [[maybe_unused]] auto [alu_u8_r0, alu_u8_r1, alu_u16_reg] = AvmAluTraceBuilder::to_alu_slice_registers(0); alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_shr = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::SHR, + .tag = in_tag, .alu_ia = a, .alu_ib = b, .alu_ic = 0, @@ -961,12 +893,8 @@ FF AvmAluTraceBuilder::op_shr(FF const& a, FF const& b, AvmMemoryTag in_tag, uin alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_shr = true, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::SHR, + .tag = in_tag, .alu_ia = a, .alu_ib = b, // Could be replaced with x_hi but nice to have 2 ways of calculating the result @@ -1031,13 +959,8 @@ FF AvmAluTraceBuilder::op_cast(FF const& a, AvmMemoryTag in_tag, uint32_t clk) alu_trace.push_back(AvmAluTraceBuilder::AluTraceEntry{ .alu_clk = clk, - .alu_op_cast = true, - .alu_ff_tag = in_tag == AvmMemoryTag::FF, - .alu_u8_tag = in_tag == AvmMemoryTag::U8, - .alu_u16_tag = in_tag == AvmMemoryTag::U16, - .alu_u32_tag = in_tag == AvmMemoryTag::U32, - .alu_u64_tag = in_tag == AvmMemoryTag::U64, - .alu_u128_tag = in_tag == AvmMemoryTag::U128, + .opcode = OpCode::CAST, + .tag = in_tag, .alu_ia = a, .alu_ic = c, .alu_u8_r0 = u8_r0, @@ -1075,12 +998,171 @@ bool AvmAluTraceBuilder::is_range_check_required() const * @brief Helper function that returns a boolean if this entry is an alu operation. * This is helpful to filter out range check rows or the second row in the 128-bit multiply. * - * @return A boolean telling whether range check is required. + * @return A boolean telling whether the ALU is enabled for the row. */ -bool AvmAluTraceBuilder::is_alu_row_enabled(AvmAluTraceBuilder::AluTraceEntry const& r) +bool AvmAluTraceBuilder::is_alu_row_enabled(const AvmAluTraceBuilder::AluTraceEntry& r) { - return (r.alu_op_add || r.alu_op_sub || r.alu_op_mul || r.alu_op_eq || r.alu_op_not || r.alu_op_lt || - r.alu_op_lte || r.alu_op_shr || r.alu_op_shl || r.alu_op_cast || r.alu_op_div); + return (r.opcode == OpCode::ADD || r.opcode == OpCode::SUB || r.opcode == OpCode::MUL || r.opcode == OpCode::EQ || + r.opcode == OpCode::NOT || r.opcode == OpCode::LT || r.opcode == OpCode::LTE || r.opcode == OpCode::SHR || + r.opcode == OpCode::SHL || r.opcode == OpCode::CAST || r.opcode == OpCode::DIV); +} + +/** + * @brief Incorporates the ALU trace in the main trace. + */ +void AvmAluTraceBuilder::finalize(std::vector>& main_trace) +{ + // This embeds the ALU information into the main trace. + for (size_t i = 0; i < alu_trace.size(); i++) { + auto const& src = alu_trace.at(i); + auto& dest = main_trace.at(i); + + dest.alu_clk = FF(static_cast(src.alu_clk)); + + if (src.opcode.has_value()) { + dest.alu_op_add = FF(src.opcode == OpCode::ADD ? 1 : 0); + dest.alu_op_sub = FF(src.opcode == OpCode::SUB ? 1 : 0); + dest.alu_op_mul = FF(src.opcode == OpCode::MUL ? 1 : 0); + dest.alu_op_not = FF(src.opcode == OpCode::NOT ? 1 : 0); + dest.alu_op_eq = FF(src.opcode == OpCode::EQ ? 1 : 0); + dest.alu_op_lt = FF(src.opcode == OpCode::LT ? 1 : 0); + dest.alu_op_lte = FF(src.opcode == OpCode::LTE ? 1 : 0); + dest.alu_op_cast = FF(src.opcode == OpCode::CAST ? 1 : 0); + dest.alu_op_shr = FF(src.opcode == OpCode::SHR ? 1 : 0); + dest.alu_op_shl = FF(src.opcode == OpCode::SHL ? 1 : 0); + dest.alu_op_div = FF(src.opcode == OpCode::DIV ? 1 : 0); + } + + dest.alu_sel_rng_chk = FF(src.rng_chk_sel ? 1 : 0); + dest.alu_op_cast_prev = FF(src.alu_op_cast_prev ? 1 : 0); + dest.alu_sel_cmp = dest.alu_op_lt + dest.alu_op_lte; + + if (src.tag.has_value()) { + dest.alu_ff_tag = FF(src.tag == AvmMemoryTag::FF ? 1 : 0); + dest.alu_u8_tag = FF(src.tag == AvmMemoryTag::U8 ? 1 : 0); + dest.alu_u16_tag = FF(src.tag == AvmMemoryTag::U16 ? 1 : 0); + dest.alu_u32_tag = FF(src.tag == AvmMemoryTag::U32 ? 1 : 0); + dest.alu_u64_tag = FF(src.tag == AvmMemoryTag::U64 ? 1 : 0); + dest.alu_u128_tag = FF(src.tag == AvmMemoryTag::U128 ? 1 : 0); + dest.alu_in_tag = FF(static_cast(src.tag.value())); + } + + dest.alu_ia = src.alu_ia; + dest.alu_ib = src.alu_ib; + dest.alu_ic = src.alu_ic; + + dest.alu_cf = FF(static_cast(src.alu_cf)); + + dest.alu_u8_r0 = FF(src.alu_u8_r0); + dest.alu_u8_r1 = FF(src.alu_u8_r1); + + dest.alu_u16_r0 = FF(src.alu_u16_reg.at(0)); + dest.alu_u16_r1 = FF(src.alu_u16_reg.at(1)); + dest.alu_u16_r2 = FF(src.alu_u16_reg.at(2)); + dest.alu_u16_r3 = FF(src.alu_u16_reg.at(3)); + dest.alu_u16_r4 = FF(src.alu_u16_reg.at(4)); + dest.alu_u16_r5 = FF(src.alu_u16_reg.at(5)); + dest.alu_u16_r6 = FF(src.alu_u16_reg.at(6)); + dest.alu_u16_r7 = FF(src.alu_u16_reg.at(7)); + dest.alu_u16_r8 = FF(src.alu_u16_reg.at(8)); + dest.alu_u16_r9 = FF(src.alu_u16_reg.at(9)); + dest.alu_u16_r10 = FF(src.alu_u16_reg.at(10)); + dest.alu_u16_r11 = FF(src.alu_u16_reg.at(11)); + dest.alu_u16_r12 = FF(src.alu_u16_reg.at(12)); + dest.alu_u16_r13 = FF(src.alu_u16_reg.at(13)); + dest.alu_u16_r14 = FF(src.alu_u16_reg.at(14)); + + dest.alu_sel_div_rng_chk = FF(static_cast(src.div_u64_range_chk_sel)); + dest.alu_div_u16_r0 = FF(src.div_u64_range_chk.at(0)); + dest.alu_div_u16_r1 = FF(src.div_u64_range_chk.at(1)); + dest.alu_div_u16_r2 = FF(src.div_u64_range_chk.at(2)); + dest.alu_div_u16_r3 = FF(src.div_u64_range_chk.at(3)); + dest.alu_div_u16_r4 = FF(src.div_u64_range_chk.at(4)); + dest.alu_div_u16_r5 = FF(src.div_u64_range_chk.at(5)); + dest.alu_div_u16_r6 = FF(src.div_u64_range_chk.at(6)); + dest.alu_div_u16_r7 = FF(src.div_u64_range_chk.at(7)); + dest.alu_op_eq_diff_inv = FF(src.alu_op_eq_diff_inv); + + // Not all rows in ALU are enabled with a selector. For instance, + // multiplication over u128 and cast is taking two lines. + if (is_alu_row_enabled(src)) { + dest.alu_sel_alu = FF(1); + } + + if (dest.alu_sel_cmp == FF(1) || dest.alu_sel_rng_chk == FF(1)) { + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_b_lo = FF(src.hi_lo_limbs.at(2)); + dest.alu_b_hi = FF(src.hi_lo_limbs.at(3)); + dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); + dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); + dest.alu_p_sub_b_lo = FF(src.hi_lo_limbs.at(6)); + dest.alu_p_sub_b_hi = FF(src.hi_lo_limbs.at(7)); + dest.alu_res_lo = FF(src.hi_lo_limbs.at(8)); + dest.alu_res_hi = FF(src.hi_lo_limbs.at(9)); + dest.alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); + dest.alu_p_b_borrow = FF(static_cast(src.p_b_borrow)); + dest.alu_borrow = FF(static_cast(src.borrow)); + dest.alu_cmp_rng_ctr = FF(static_cast(src.cmp_rng_ctr)); + dest.alu_sel_rng_chk_lookup = FF(1); + } + if (dest.alu_op_div == FF(1)) { + dest.alu_op_div_std = uint256_t(src.alu_ia) >= uint256_t(src.alu_ib); + dest.alu_op_div_a_lt_b = uint256_t(src.alu_ia) < uint256_t(src.alu_ib); + dest.alu_sel_rng_chk_lookup = FF(1); + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_b_lo = FF(src.hi_lo_limbs.at(2)); + dest.alu_b_hi = FF(src.hi_lo_limbs.at(3)); + dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); + dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); + dest.alu_remainder = src.remainder; + dest.alu_divisor_lo = src.divisor_lo; + dest.alu_divisor_hi = src.divisor_hi; + dest.alu_quotient_lo = src.quotient_lo; + dest.alu_quotient_hi = src.quotient_hi; + dest.alu_partial_prod_lo = src.partial_prod_lo; + dest.alu_partial_prod_hi = src.partial_prod_hi; + } + + if (dest.alu_op_add == FF(1) || dest.alu_op_sub == FF(1) || dest.alu_op_mul == FF(1)) { + dest.alu_sel_rng_chk_lookup = FF(1); + } + + if (dest.alu_op_cast == FF(1)) { + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(2)); + dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(3)); + dest.alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); + dest.alu_sel_rng_chk_lookup = FF(1); + } + + if (dest.alu_op_cast_prev == FF(1)) { + dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); + dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); + dest.alu_sel_rng_chk_lookup = FF(1); + } + + // Multiplication over u128 expands over two rows. + if (dest.alu_op_mul == FF(1) && dest.alu_u128_tag) { + main_trace.at(i + 1).alu_sel_rng_chk_lookup = FF(1); + } + if (dest.alu_op_shr || dest.alu_op_shl) { + dest.alu_a_lo = FF(src.hi_lo_limbs[0]); + dest.alu_a_hi = FF(src.hi_lo_limbs[1]); + dest.alu_b_lo = FF(src.hi_lo_limbs[2]); + dest.alu_b_hi = FF(src.hi_lo_limbs[3]); + dest.alu_sel_shift_which = FF(1); + dest.alu_shift_lt_bit_len = FF(static_cast(src.shift_lt_bit_len)); + dest.alu_t_sub_s_bits = FF(src.mem_tag_sub_shift); + dest.alu_two_pow_s = FF(uint256_t(1) << dest.alu_ib); + dest.alu_two_pow_t_sub_s = FF(uint256_t(1) << uint256_t(dest.alu_t_sub_s_bits)); + dest.alu_sel_rng_chk_lookup = FF(1); + } + } + + reset(); } } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.hpp index f21d762a20d..8cda2a4e271 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/alu_trace.hpp @@ -1,9 +1,13 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" +#include "barretenberg/vm/avm/generated/full_row.hpp" #include "barretenberg/vm/avm/trace/common.hpp" +#include "barretenberg/vm/avm/trace/opcode.hpp" + #include #include +#include #include #include @@ -13,39 +17,20 @@ class AvmAluTraceBuilder { public: struct AluTraceEntry { - uint32_t alu_clk{}; - - bool alu_op_add = false; - bool alu_op_sub = false; - bool alu_op_mul = false; - bool alu_op_div = false; - - bool alu_op_eq = false; - bool alu_op_lt = false; - bool alu_op_lte = false; + uint32_t alu_clk = 0; - bool alu_op_not = false; - bool alu_op_shl = false; - bool alu_op_shr = false; - - bool alu_op_cast = false; + std::optional opcode = std::nullopt; + std::optional tag = std::nullopt; bool alu_op_cast_prev = false; - bool alu_ff_tag = false; - bool alu_u8_tag = false; - bool alu_u16_tag = false; - bool alu_u32_tag = false; - bool alu_u64_tag = false; - bool alu_u128_tag = false; - FF alu_ia{}; FF alu_ib{}; FF alu_ic{}; bool alu_cf = false; - uint8_t alu_u8_r0{}; - uint8_t alu_u8_r1{}; + uint8_t alu_u8_r0 = 0; + uint8_t alu_u8_r1 = 0; std::array alu_u16_reg{}; @@ -85,8 +70,9 @@ class AvmAluTraceBuilder { std::array, 8> div_u64_range_chk_counters; AvmAluTraceBuilder() = default; + size_t size() const { return alu_trace.size(); } void reset(); - std::vector finalize(); + void finalize(std::vector>& main_trace); // Compute - Arithmetic FF op_add(FF const& a, FF const& b, AvmMemoryTag in_tag, uint32_t clk); @@ -107,15 +93,15 @@ class AvmAluTraceBuilder { // Compute - Type Conversions FF op_cast(FF const& a, AvmMemoryTag in_tag, uint32_t clk); - bool is_range_check_required() const; - static bool is_alu_row_enabled(AvmAluTraceBuilder::AluTraceEntry const& r); - private: std::vector alu_trace; bool range_checked_required = false; template std::tuple> to_alu_slice_registers(T a); std::vector cmp_range_check_helper(AluTraceEntry row, std::vector hi_lo_limbs); + + bool is_range_check_required() const; + static bool is_alu_row_enabled(AvmAluTraceBuilder::AluTraceEntry const& r); }; } // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index a1bcdb2b3c1..006d06bf937 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -3413,7 +3413,6 @@ void AvmTraceBuilder::op_keccakf1600(uint8_t indirect, std::vector AvmTraceBuilder::finalize(bool range_check_required) { auto mem_trace = mem_trace_builder.finalize(); - auto alu_trace = alu_trace_builder.finalize(); auto conv_trace = conversion_trace_builder.finalize(); auto sha256_trace = sha256_trace_builder.finalize(); auto poseidon2_trace = poseidon2_trace_builder.finalize(); @@ -3423,7 +3422,7 @@ std::vector AvmTraceBuilder::finalize(bool range_check_required) const auto& fixed_gas_table = FixedGasTable::get(); size_t mem_trace_size = mem_trace.size(); size_t main_trace_size = main_trace.size(); - size_t alu_trace_size = alu_trace.size(); + size_t alu_trace_size = alu_trace_builder.size(); size_t conv_trace_size = conv_trace.size(); size_t sha256_trace_size = sha256_trace.size(); size_t poseidon2_trace_size = poseidon2_trace.size(); @@ -3612,151 +3611,7 @@ std::vector AvmTraceBuilder::finalize(bool range_check_required) * ALU TRACE INCLUSION **********************************************************************************************/ - for (size_t i = 0; i < alu_trace_size; i++) { - auto const& src = alu_trace.at(i); - auto& dest = main_trace.at(i); - - dest.alu_clk = FF(static_cast(src.alu_clk)); - - dest.alu_op_add = FF(static_cast(src.alu_op_add)); - dest.alu_op_sub = FF(static_cast(src.alu_op_sub)); - dest.alu_op_mul = FF(static_cast(src.alu_op_mul)); - dest.alu_op_not = FF(static_cast(src.alu_op_not)); - dest.alu_op_eq = FF(static_cast(src.alu_op_eq)); - dest.alu_op_lt = FF(static_cast(src.alu_op_lt)); - dest.alu_op_lte = FF(static_cast(src.alu_op_lte)); - dest.alu_op_cast = FF(static_cast(src.alu_op_cast)); - dest.alu_op_cast_prev = FF(static_cast(src.alu_op_cast_prev)); - dest.alu_sel_cmp = FF(static_cast(src.alu_op_lt) + static_cast(src.alu_op_lte)); - dest.alu_sel_rng_chk = FF(static_cast(src.rng_chk_sel)); - dest.alu_op_shr = FF(static_cast(src.alu_op_shr)); - dest.alu_op_shl = FF(static_cast(src.alu_op_shl)); - dest.alu_op_div = FF(static_cast(src.alu_op_div)); - - dest.alu_ff_tag = FF(static_cast(src.alu_ff_tag)); - dest.alu_u8_tag = FF(static_cast(src.alu_u8_tag)); - dest.alu_u16_tag = FF(static_cast(src.alu_u16_tag)); - dest.alu_u32_tag = FF(static_cast(src.alu_u32_tag)); - dest.alu_u64_tag = FF(static_cast(src.alu_u64_tag)); - dest.alu_u128_tag = FF(static_cast(src.alu_u128_tag)); - - dest.alu_in_tag = dest.alu_u8_tag + FF(2) * dest.alu_u16_tag + FF(3) * dest.alu_u32_tag + - FF(4) * dest.alu_u64_tag + FF(5) * dest.alu_u128_tag + FF(6) * dest.alu_ff_tag; - - dest.alu_ia = src.alu_ia; - dest.alu_ib = src.alu_ib; - dest.alu_ic = src.alu_ic; - - dest.alu_cf = FF(static_cast(src.alu_cf)); - - dest.alu_u8_r0 = FF(src.alu_u8_r0); - dest.alu_u8_r1 = FF(src.alu_u8_r1); - - dest.alu_u16_r0 = FF(src.alu_u16_reg.at(0)); - dest.alu_u16_r1 = FF(src.alu_u16_reg.at(1)); - dest.alu_u16_r2 = FF(src.alu_u16_reg.at(2)); - dest.alu_u16_r3 = FF(src.alu_u16_reg.at(3)); - dest.alu_u16_r4 = FF(src.alu_u16_reg.at(4)); - dest.alu_u16_r5 = FF(src.alu_u16_reg.at(5)); - dest.alu_u16_r6 = FF(src.alu_u16_reg.at(6)); - dest.alu_u16_r7 = FF(src.alu_u16_reg.at(7)); - dest.alu_u16_r8 = FF(src.alu_u16_reg.at(8)); - dest.alu_u16_r9 = FF(src.alu_u16_reg.at(9)); - dest.alu_u16_r10 = FF(src.alu_u16_reg.at(10)); - dest.alu_u16_r11 = FF(src.alu_u16_reg.at(11)); - dest.alu_u16_r12 = FF(src.alu_u16_reg.at(12)); - dest.alu_u16_r13 = FF(src.alu_u16_reg.at(13)); - dest.alu_u16_r14 = FF(src.alu_u16_reg.at(14)); - - dest.alu_sel_div_rng_chk = FF(static_cast(src.div_u64_range_chk_sel)); - dest.alu_div_u16_r0 = FF(src.div_u64_range_chk.at(0)); - dest.alu_div_u16_r1 = FF(src.div_u64_range_chk.at(1)); - dest.alu_div_u16_r2 = FF(src.div_u64_range_chk.at(2)); - dest.alu_div_u16_r3 = FF(src.div_u64_range_chk.at(3)); - dest.alu_div_u16_r4 = FF(src.div_u64_range_chk.at(4)); - dest.alu_div_u16_r5 = FF(src.div_u64_range_chk.at(5)); - dest.alu_div_u16_r6 = FF(src.div_u64_range_chk.at(6)); - dest.alu_div_u16_r7 = FF(src.div_u64_range_chk.at(7)); - dest.alu_op_eq_diff_inv = FF(src.alu_op_eq_diff_inv); - - // Not all rows in ALU are enabled with a selector. For instance, - // multiplication over u128 and cast is taking two lines. - if (AvmAluTraceBuilder::is_alu_row_enabled(src)) { - dest.alu_sel_alu = FF(1); - } - - if (dest.alu_sel_cmp == FF(1) || dest.alu_sel_rng_chk == FF(1)) { - dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.alu_b_lo = FF(src.hi_lo_limbs.at(2)); - dest.alu_b_hi = FF(src.hi_lo_limbs.at(3)); - dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); - dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); - dest.alu_p_sub_b_lo = FF(src.hi_lo_limbs.at(6)); - dest.alu_p_sub_b_hi = FF(src.hi_lo_limbs.at(7)); - dest.alu_res_lo = FF(src.hi_lo_limbs.at(8)); - dest.alu_res_hi = FF(src.hi_lo_limbs.at(9)); - dest.alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); - dest.alu_p_b_borrow = FF(static_cast(src.p_b_borrow)); - dest.alu_borrow = FF(static_cast(src.borrow)); - dest.alu_cmp_rng_ctr = FF(static_cast(src.cmp_rng_ctr)); - dest.alu_sel_rng_chk_lookup = FF(1); - } - if (dest.alu_op_div == FF(1)) { - dest.alu_op_div_std = uint256_t(src.alu_ia) >= uint256_t(src.alu_ib); - dest.alu_op_div_a_lt_b = uint256_t(src.alu_ia) < uint256_t(src.alu_ib); - dest.alu_sel_rng_chk_lookup = FF(1); - dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.alu_b_lo = FF(src.hi_lo_limbs.at(2)); - dest.alu_b_hi = FF(src.hi_lo_limbs.at(3)); - dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(4)); - dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(5)); - dest.alu_remainder = src.remainder; - dest.alu_divisor_lo = src.divisor_lo; - dest.alu_divisor_hi = src.divisor_hi; - dest.alu_quotient_lo = src.quotient_lo; - dest.alu_quotient_hi = src.quotient_hi; - dest.alu_partial_prod_lo = src.partial_prod_lo; - dest.alu_partial_prod_hi = src.partial_prod_hi; - } - - if (dest.alu_op_add == FF(1) || dest.alu_op_sub == FF(1) || dest.alu_op_mul == FF(1)) { - dest.alu_sel_rng_chk_lookup = FF(1); - } - - if (dest.alu_op_cast == FF(1)) { - dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.alu_p_sub_a_lo = FF(src.hi_lo_limbs.at(2)); - dest.alu_p_sub_a_hi = FF(src.hi_lo_limbs.at(3)); - dest.alu_p_a_borrow = FF(static_cast(src.p_a_borrow)); - dest.alu_sel_rng_chk_lookup = FF(1); - } - - if (dest.alu_op_cast_prev == FF(1)) { - dest.alu_a_lo = FF(src.hi_lo_limbs.at(0)); - dest.alu_a_hi = FF(src.hi_lo_limbs.at(1)); - dest.alu_sel_rng_chk_lookup = FF(1); - } - - // Multiplication over u128 expands over two rows. - if (dest.alu_op_mul == FF(1) && dest.alu_u128_tag) { - main_trace.at(i + 1).alu_sel_rng_chk_lookup = FF(1); - } - if (src.alu_op_shr || src.alu_op_shl) { - dest.alu_a_lo = FF(src.hi_lo_limbs[0]); - dest.alu_a_hi = FF(src.hi_lo_limbs[1]); - dest.alu_b_lo = FF(src.hi_lo_limbs[2]); - dest.alu_b_hi = FF(src.hi_lo_limbs[3]); - dest.alu_sel_shift_which = FF(1); - dest.alu_shift_lt_bit_len = FF(static_cast(src.shift_lt_bit_len)); - dest.alu_t_sub_s_bits = FF(src.mem_tag_sub_shift); - dest.alu_two_pow_s = FF(uint256_t(1) << dest.alu_ib); - dest.alu_two_pow_t_sub_s = FF(uint256_t(1) << uint256_t(dest.alu_t_sub_s_bits)); - dest.alu_sel_rng_chk_lookup = FF(1); - } - } + alu_trace_builder.finalize(main_trace); /********************************************************************************************** * GADGET TABLES INCLUSION