diff --git a/barretenberg/cpp/pil/avm/kernel.pil b/barretenberg/cpp/pil/avm/kernel.pil index 9763bcaaa428..d04a5fa13ffd 100644 --- a/barretenberg/cpp/pil/avm/kernel.pil +++ b/barretenberg/cpp/pil/avm/kernel.pil @@ -164,8 +164,8 @@ namespace main(256); // When we encounter a state writing opcode // We increment the side effect counter by 1 - #[SIDE_EFFECT_COUNTER_INCREMENT] - KERNEL_OUTPUT_SELECTORS * (side_effect_counter' - (side_effect_counter + 1)) = 0; + //#[SIDE_EFFECT_COUNTER_INCREMENT] + //KERNEL_OUTPUT_SELECTORS * (side_effect_counter' - (side_effect_counter + 1)) = 0; //===== LOOKUPS INTO THE PUBLIC INPUTS =========================================== pol KERNEL_INPUT_SELECTORS = sel_op_address + sel_op_storage_address + sel_op_sender @@ -182,8 +182,9 @@ namespace main(256); #[KERNEL_OUTPUT_ACTIVE_CHECK] KERNEL_OUTPUT_SELECTORS * (1 - sel_q_kernel_output_lookup) = 0; + // TODO(#8287): Reintroduce constraints #[KERNEL_OUTPUT_LOOKUP] - sel_q_kernel_output_lookup {kernel_out_offset, ia, side_effect_counter, ib} in sel_kernel_out {clk, kernel_value_out, kernel_side_effect_out, kernel_metadata_out}; + sel_q_kernel_output_lookup {kernel_out_offset, /*ia,*/ /*side_effect_counter,*/ ib } in sel_kernel_out {clk, /*kernel_value_out,*/ /*kernel_side_effect_out,*/ kernel_metadata_out}; #[LOOKUP_INTO_KERNEL] sel_q_kernel_lookup { main.ia, kernel_in_offset } in sel_kernel_inputs { kernel_inputs, clk }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp index 02c17d98dec1..4f1bed50327c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.cpp @@ -774,24 +774,23 @@ AvmFlavor::AllConstRefValues::AllConstRefValues( , main_nullifier_non_exists_write_offset_shift(il[766]) , main_pc_shift(il[767]) , main_sel_execution_row_shift(il[768]) - , main_side_effect_counter_shift(il[769]) - , main_sload_write_offset_shift(il[770]) - , main_sstore_write_offset_shift(il[771]) - , mem_glob_addr_shift(il[772]) - , mem_rw_shift(il[773]) - , mem_sel_mem_shift(il[774]) - , mem_tag_shift(il[775]) - , mem_tsp_shift(il[776]) - , mem_val_shift(il[777]) - , slice_addr_shift(il[778]) - , slice_clk_shift(il[779]) - , slice_cnt_shift(il[780]) - , slice_col_offset_shift(il[781]) - , slice_sel_cd_cpy_shift(il[782]) - , slice_sel_mem_active_shift(il[783]) - , slice_sel_return_shift(il[784]) - , slice_sel_start_shift(il[785]) - , slice_space_id_shift(il[786]) + , main_sload_write_offset_shift(il[769]) + , main_sstore_write_offset_shift(il[770]) + , mem_glob_addr_shift(il[771]) + , mem_rw_shift(il[772]) + , mem_sel_mem_shift(il[773]) + , mem_tag_shift(il[774]) + , mem_tsp_shift(il[775]) + , mem_val_shift(il[776]) + , slice_addr_shift(il[777]) + , slice_clk_shift(il[778]) + , slice_cnt_shift(il[779]) + , slice_col_offset_shift(il[780]) + , slice_sel_cd_cpy_shift(il[781]) + , slice_sel_mem_active_shift(il[782]) + , slice_sel_return_shift(il[783]) + , slice_sel_start_shift(il[784]) + , slice_space_id_shift(il[785]) {} AvmFlavor::ProverPolynomials::ProverPolynomials(ProvingKey& proving_key) @@ -1577,7 +1576,6 @@ AvmFlavor::AllConstRefValues AvmFlavor::ProverPolynomials::get_row(size_t row_id main_nullifier_non_exists_write_offset_shift[row_idx], main_pc_shift[row_idx], main_sel_execution_row_shift[row_idx], - main_side_effect_counter_shift[row_idx], main_sload_write_offset_shift[row_idx], main_sstore_write_offset_shift[row_idx], mem_glob_addr_shift[row_idx], diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index da57edf4b8d4..87bc3c0ee436 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -104,8 +104,8 @@ template using tuple_cat_t = decltype(std::tuple_cat(std:: #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_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 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_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_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 // clang-format on @@ -132,11 +132,11 @@ class AvmFlavor { static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 16; static constexpr size_t NUM_WITNESS_ENTITIES = 696; - static constexpr size_t NUM_SHIFTED_ENTITIES = 75; + static constexpr size_t NUM_SHIFTED_ENTITIES = 74; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for // the unshifted and one for the shifted - static constexpr size_t NUM_ALL_ENTITIES = 787; + static constexpr size_t NUM_ALL_ENTITIES = 786; // The total number of witnesses including shifts and derived entities. static constexpr size_t NUM_ALL_WITNESS_ENTITIES = NUM_WITNESS_ENTITIES + NUM_SHIFTED_ENTITIES; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp index 6fa15bbad85b..4ac010e71715 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel.hpp @@ -10,9 +10,9 @@ template class kernelImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3, 3, 3, - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }; template void static accumulate(ContainerOverSubrelations& evals, @@ -363,22 +363,15 @@ template class kernelImpl { } { using Accumulator = typename std::tuple_element_t<41, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_OUTPUT_SELECTORS * - (new_term.main_side_effect_counter_shift - (new_term.main_side_effect_counter + FF(1)))); + auto tmp = (main_KERNEL_INPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_lookup)); tmp *= scaling_factor; std::get<41>(evals) += typename Accumulator::View(tmp); } { using Accumulator = typename std::tuple_element_t<42, ContainerOverSubrelations>; - auto tmp = (main_KERNEL_INPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_lookup)); - tmp *= scaling_factor; - std::get<42>(evals) += typename Accumulator::View(tmp); - } - { - using Accumulator = typename std::tuple_element_t<43, ContainerOverSubrelations>; auto tmp = (main_KERNEL_OUTPUT_SELECTORS * (FF(1) - new_term.main_sel_q_kernel_output_lookup)); tmp *= scaling_factor; - std::get<43>(evals) += typename Accumulator::View(tmp); + std::get<42>(evals) += typename Accumulator::View(tmp); } } }; @@ -453,10 +446,8 @@ template class kernel : public Relation> { case 39: return "SSTORE_KERNEL_OUTPUT"; case 41: - return "SIDE_EFFECT_COUNTER_INCREMENT"; - case 42: return "KERNEL_INPUT_ACTIVE_CHECK"; - case 43: + case 42: return "KERNEL_OUTPUT_ACTIVE_CHECK"; } return std::to_string(index); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp index 27ab2deb718a..72a11d0e50fc 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/relations/kernel_output_lookup.hpp @@ -14,7 +14,7 @@ class kernel_output_lookup_lookup_settings { static constexpr size_t WRITE_TERMS = 1; static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 }; static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 }; - static constexpr size_t LOOKUP_TUPLE_SIZE = 4; + static constexpr size_t LOOKUP_TUPLE_SIZE = 2; static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; static constexpr size_t READ_TERM_DEGREE = 0; static constexpr size_t WRITE_TERM_DEGREE = 0; @@ -40,12 +40,8 @@ class kernel_output_lookup_lookup_settings { in.main_sel_q_kernel_output_lookup, in.main_sel_kernel_out, in.main_kernel_out_offset, - in.main_ia, - in.main_side_effect_counter, in.main_ib, in.main_clk, - in.main_kernel_value_out, - in.main_kernel_side_effect_out, in.main_kernel_metadata_out); } @@ -56,12 +52,8 @@ class kernel_output_lookup_lookup_settings { in.main_sel_q_kernel_output_lookup, in.main_sel_kernel_out, in.main_kernel_out_offset, - in.main_ia, - in.main_side_effect_counter, in.main_ib, in.main_clk, - in.main_kernel_value_out, - in.main_kernel_side_effect_out, in.main_kernel_metadata_out); } }; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp index 43f95355e80b..558f05409c7c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/execution.test.cpp @@ -1771,7 +1771,8 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) auto emit_note_hash_kernel_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_note_hash_out_offset; }); EXPECT_EQ(emit_note_hash_kernel_out_row->main_kernel_value_out, 1); - EXPECT_EQ(emit_note_hash_kernel_out_row->main_kernel_side_effect_out, 0); + // TODO(#8287) + // EXPECT_EQ(emit_note_hash_kernel_out_row->main_kernel_side_effect_out, 0); feed_output(emit_note_hash_out_offset, 1, 0, 0); // CHECK EMIT NULLIFIER @@ -2174,7 +2175,9 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) std::vector returndata = {}; // Generate Hint for hash exists operation - auto execution_hints = ExecutionHints().with_storage_value_hints({ { 0, 1 }, { 1, 1 }, { 2, 1 } }); + auto execution_hints = ExecutionHints() + .with_storage_value_hints({ { 0, 1 }, { 1, 1 }, { 2, 1 } }) + .with_note_hash_exists_hints({ { 0, 1 }, { 1, 1 }, { 2, 1 } }); auto trace = Execution::gen_trace(instructions, returndata, calldata, public_inputs_vec, execution_hints); @@ -2202,7 +2205,8 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) auto nullifier_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == START_NULLIFIER_EXISTS_OFFSET; }); EXPECT_EQ(nullifier_out_row->main_kernel_value_out, 1); // value - EXPECT_EQ(nullifier_out_row->main_kernel_side_effect_out, 1); + // TODO(#8287) + // EXPECT_EQ(nullifier_out_row->main_kernel_side_effect_out, 1); EXPECT_EQ(nullifier_out_row->main_kernel_metadata_out, 1); // exists feed_output(START_NULLIFIER_EXISTS_OFFSET, 1, 1, 1); @@ -2216,7 +2220,8 @@ TEST_F(AvmExecutionTests, kernelOutputHashExistsOpcodes) auto msg_out_row = std::ranges::find_if( trace.begin(), trace.end(), [&](Row r) { return r.main_clk == START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET; }); EXPECT_EQ(msg_out_row->main_kernel_value_out, 1); // value - EXPECT_EQ(msg_out_row->main_kernel_side_effect_out, 2); + // TODO(#8287) + // EXPECT_EQ(msg_out_row->main_kernel_side_effect_out, 2); EXPECT_EQ(msg_out_row->main_kernel_metadata_out, 1); // exists feed_output(START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET, 1, 2, 1); diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp index 15277be8c489..77cc1a5e59fa 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/tests/kernel.test.cpp @@ -1217,14 +1217,16 @@ TEST_F(AvmKernelOutputPositiveTests, kernelNoteHashExists) auto direct_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); - trace_builder.op_note_hash_exists(/*indirect*/ false, value_offset, metadata_offset); + // TODO(#8287): Leaf index isnt constrained properly so we just set it to 0 + trace_builder.op_note_hash_exists(/*indirect*/ false, value_offset, 0, metadata_offset); }; // TODO: fix auto indirect_apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); trace_builder.op_set(0, value_offset, indirect_value_offset, AvmMemoryTag::U32); trace_builder.op_set(0, metadata_offset, indirect_metadata_offset, AvmMemoryTag::U32); - trace_builder.op_note_hash_exists(/*indirect*/ 3, indirect_value_offset, indirect_metadata_offset); + // TODO(#8287): Leaf index isnt constrained properly so we just set it to 0 + trace_builder.op_note_hash_exists(/*indirect*/ 3, indirect_value_offset, 0, indirect_metadata_offset); }; auto checks = [=](bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( @@ -1343,7 +1345,8 @@ TEST_F(AvmKernelOutputPositiveTests, kernelL1ToL2MsgExists) auto apply_opcodes = [=](AvmTraceBuilder& trace_builder) { trace_builder.op_set(0, static_cast(value), value_offset, AvmMemoryTag::FF); - trace_builder.op_l1_to_l2_msg_exists(/*indirect*/ false, value_offset, metadata_offset); + // TODO(#8287): Leaf index isnt constrained properly so we just set it to 0 + trace_builder.op_l1_to_l2_msg_exists(/*indirect*/ false, value_offset, 0, metadata_offset); }; auto checks = [=]([[maybe_unused]] bool indirect, const std::vector& trace) { auto row = std::ranges::find_if( diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp index 36e0aba65a3e..abe7f8f40b27 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp @@ -650,8 +650,7 @@ std::vector Execution::gen_trace(std::vector const& instructio case OpCode::NOTEHASHEXISTS: trace_builder.op_note_hash_exists(std::get(inst.operands.at(0)), std::get(inst.operands.at(1)), - // TODO: leaf offset exists - // std::get(inst.operands.at(2)) + std::get(inst.operands.at(2)), std::get(inst.operands.at(3))); break; case OpCode::EMITNOTEHASH: @@ -673,8 +672,7 @@ std::vector Execution::gen_trace(std::vector const& instructio case OpCode::L1TOL2MSGEXISTS: trace_builder.op_l1_to_l2_msg_exists(std::get(inst.operands.at(0)), std::get(inst.operands.at(1)), - // TODO: leaf offset exists - // std::get(inst.operands.at(2)) + std::get(inst.operands.at(2)), std::get(inst.operands.at(3))); break; case OpCode::GETCONTRACTINSTANCE: diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp index df54b770f059..5bda7055d85d 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/execution_hints.hpp @@ -105,8 +105,15 @@ struct ExecutionHints { { std::unordered_map hints_map; push_vec_into_map(hints_map, storage_value_hints); - push_vec_into_map(hints_map, note_hash_exists_hints); push_vec_into_map(hints_map, nullifier_exists_hints); + return hints_map; + } + + // Leaf index -> exists + std::unordered_map get_leaf_index_hints() const + { + std::unordered_map hints_map; + push_vec_into_map(hints_map, note_hash_exists_hints); push_vec_into_map(hints_map, l1_to_l2_message_exists_hints); return hints_map; } @@ -161,4 +168,4 @@ struct ExecutionHints { {} }; -} // namespace bb::avm_trace \ No newline at end of file +} // namespace bb::avm_trace diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp index 8564a7eed2b3..f953f7b84897 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/kernel_trace.cpp @@ -173,7 +173,16 @@ void AvmKernelTraceBuilder::op_note_hash_exists(uint32_t clk, { uint32_t offset = START_NOTE_HASH_EXISTS_WRITE_OFFSET + note_hash_exists_offset; - perform_kernel_output_lookup(offset, side_effect_counter, note_hash, FF(result)); + // TODO(#8287)Lookups are heavily underconstrained atm + if (result == 1) { + perform_kernel_output_lookup(offset, side_effect_counter, note_hash, FF(result)); + } else { + // if the note_hash does NOT exist, the public inputs already contains the correct output value (i.e. the + // actual value at the index), so we don't try to overwrite the value + std::get(public_inputs)[offset] = side_effect_counter; + std::get(public_inputs)[offset] = FF(result); + kernel_output_selector_counter[offset]++; + } note_hash_exists_offset++; KernelTraceEntry entry = { @@ -245,7 +254,16 @@ void AvmKernelTraceBuilder::op_l1_to_l2_msg_exists(uint32_t clk, uint32_t result) { uint32_t offset = START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + l1_to_l2_msg_exists_offset; - perform_kernel_output_lookup(offset, side_effect_counter, message, FF(result)); + // TODO(#8287)Lookups are heavily underconstrained atm + if (result == 1) { + perform_kernel_output_lookup(offset, side_effect_counter, message, FF(result)); + } else { + // if the l1_to_l2_msg_exists is false, the public inputs already contains the correct output value (i.e. the + // actual value at the index), so we don't try to overwrite the value + std::get(public_inputs)[offset] = side_effect_counter; + std::get(public_inputs)[offset] = FF(result); + kernel_output_selector_counter[offset]++; + } l1_to_l2_msg_exists_offset++; KernelTraceEntry entry = { diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp index 006d06bf937a..b3b345e3e934 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp @@ -2114,6 +2114,44 @@ Row AvmTraceBuilder::create_kernel_output_opcode_with_set_metadata_output_from_h }; } +// Specifically for handling the L1TOL2MSGEXISTS and NOTEHASHEXISTS opcodes +Row AvmTraceBuilder::create_kernel_output_opcode_for_leaf_index( + uint8_t indirect, uint32_t clk, uint32_t data_offset, uint32_t metadata_offset, uint32_t leaf_index) +{ + // If doesnt exist, should not read_a, but instead get from public inputs + FF exists = execution_hints.get_leaf_index_hints().at(leaf_index); + + auto [resolved_data, resolved_metadata] = unpack_indirects<2>(indirect, { data_offset, metadata_offset }); + auto read_a = constrained_read_from_memory( + call_ptr, clk, resolved_data, AvmMemoryTag::FF, AvmMemoryTag::U8, IntermRegister::IA); + + auto write_b = constrained_write_to_memory( + call_ptr, clk, resolved_metadata, exists, AvmMemoryTag::FF, AvmMemoryTag::U8, IntermRegister::IB); + bool tag_match = read_a.tag_match && write_b.tag_match; + + return Row{ + .main_clk = clk, + .main_ia = read_a.val, + .main_ib = write_b.val, + .main_ind_addr_a = FF(read_a.indirect_address), + .main_ind_addr_b = FF(write_b.indirect_address), + .main_internal_return_ptr = internal_return_ptr, + .main_mem_addr_a = FF(read_a.direct_address), + .main_mem_addr_b = FF(write_b.direct_address), + .main_pc = pc++, + .main_r_in_tag = static_cast(AvmMemoryTag::FF), + .main_rwa = 0, + .main_rwb = 1, + .main_sel_mem_op_a = 1, + .main_sel_mem_op_b = 1, + .main_sel_q_kernel_output_lookup = 1, + .main_sel_resolve_ind_addr_a = FF(static_cast(read_a.is_indirect)), + .main_sel_resolve_ind_addr_b = FF(static_cast(write_b.is_indirect)), + .main_tag_err = static_cast(!tag_match), + .main_w_in_tag = static_cast(AvmMemoryTag::U8), + }; +} + /** * @brief Create a kernel output opcode with set metadata output object * @@ -2322,14 +2360,20 @@ void AvmTraceBuilder::op_sstore(uint8_t indirect, uint32_t src_offset, uint32_t op_jump(old_pc + 1); } -void AvmTraceBuilder::op_note_hash_exists(uint8_t indirect, uint32_t note_hash_offset, uint32_t dest_offset) +void AvmTraceBuilder::op_note_hash_exists(uint8_t indirect, + uint32_t note_hash_offset, + uint32_t leaf_index_offset, + uint32_t dest_offset) { auto const clk = static_cast(main_trace.size()) + 1; + auto leaf_index = unconstrained_read_from_memory(leaf_index_offset); Row row = - create_kernel_output_opcode_with_set_metadata_output_from_hint(indirect, clk, note_hash_offset, dest_offset); - kernel_trace_builder.op_note_hash_exists( - clk, side_effect_counter, row.main_ia, /*safe*/ static_cast(row.main_ib)); + create_kernel_output_opcode_for_leaf_index(indirect, clk, note_hash_offset, dest_offset, uint32_t(leaf_index)); + kernel_trace_builder.op_note_hash_exists(clk, + /*side_effect_counter*/ uint32_t(leaf_index), + row.main_ia, + /*safe*/ static_cast(row.main_ib)); row.main_sel_op_note_hash_exists = FF(1); // Constrain gas cost @@ -2338,7 +2382,6 @@ void AvmTraceBuilder::op_note_hash_exists(uint8_t indirect, uint32_t note_hash_o main_trace.push_back(row); debug("note_hash_exists side-effect cnt: ", side_effect_counter); - side_effect_counter++; } void AvmTraceBuilder::op_emit_note_hash(uint8_t indirect, uint32_t note_hash_offset) @@ -2394,13 +2437,17 @@ void AvmTraceBuilder::op_emit_nullifier(uint8_t indirect, uint32_t nullifier_off side_effect_counter++; } -void AvmTraceBuilder::op_l1_to_l2_msg_exists(uint8_t indirect, uint32_t log_offset, uint32_t dest_offset) +void AvmTraceBuilder::op_l1_to_l2_msg_exists(uint8_t indirect, + uint32_t log_offset, + uint32_t leaf_index_offset, + uint32_t dest_offset) { auto const clk = static_cast(main_trace.size()) + 1; - Row row = create_kernel_output_opcode_with_set_metadata_output_from_hint(indirect, clk, log_offset, dest_offset); + auto leaf_index = unconstrained_read_from_memory(leaf_index_offset); + Row row = create_kernel_output_opcode_for_leaf_index(indirect, clk, log_offset, dest_offset, uint32_t(leaf_index)); kernel_trace_builder.op_l1_to_l2_msg_exists( - clk, side_effect_counter, row.main_ia, /*safe*/ static_cast(row.main_ib)); + clk, uint32_t(leaf_index) /*side_effect_counter*/, row.main_ia, /*safe*/ static_cast(row.main_ib)); row.main_sel_op_l1_to_l2_msg_exists = FF(1); // Constrain gas cost @@ -2409,7 +2456,6 @@ void AvmTraceBuilder::op_l1_to_l2_msg_exists(uint8_t indirect, uint32_t log_offs main_trace.push_back(row); debug("l1_to_l2_msg_exists side-effect cnt: ", side_effect_counter); - side_effect_counter++; } void AvmTraceBuilder::op_get_contract_instance(uint8_t indirect, uint32_t address_offset, uint32_t dst_offset) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp index 5e5c3fdec2e7..22f446931d90 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp @@ -121,11 +121,17 @@ class AvmTraceBuilder { // World State void op_sload(uint8_t indirect, uint32_t slot_offset, uint32_t size, uint32_t dest_offset); void op_sstore(uint8_t indirect, uint32_t src_offset, uint32_t size, uint32_t slot_offset); - void op_note_hash_exists(uint8_t indirect, uint32_t note_hash_offset, uint32_t dest_offset); + void op_note_hash_exists(uint8_t indirect, + uint32_t note_hash_offset, + uint32_t leaf_index_offset, + uint32_t dest_offset); void op_emit_note_hash(uint8_t indirect, uint32_t note_hash_offset); void op_nullifier_exists(uint8_t indirect, uint32_t nullifier_offset, uint32_t dest_offset); void op_emit_nullifier(uint8_t indirect, uint32_t nullifier_offset); - void op_l1_to_l2_msg_exists(uint8_t indirect, uint32_t log_offset, uint32_t dest_offset); + void op_l1_to_l2_msg_exists(uint8_t indirect, + uint32_t log_offset, + uint32_t leaf_index_offset, + uint32_t dest_offset); void op_get_contract_instance(uint8_t indirect, uint32_t address_offset, uint32_t dst_offset); // Accrued Substate @@ -231,6 +237,9 @@ class AvmTraceBuilder { uint32_t data_offset, uint32_t metadata_offset); + Row create_kernel_output_opcode_for_leaf_index( + uint8_t indirect, uint32_t clk, uint32_t data_offset, uint32_t metadata_offset, uint32_t leaf_index); + Row create_kernel_output_opcode_with_set_value_from_hint(uint8_t indirect, uint32_t clk, uint32_t data_offset, diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 7e7dc09ab630..3e906aff1b68 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -151,6 +151,11 @@ export class SimulatorOracle implements DBOracle { return await this.aztecNode.findLeafIndex('latest', MerkleTreeId.NOTE_HASH_TREE, commitment); } + // We need this in public as part of the EXISTS calls - but isn't used in private + public getCommitmentValue(_leafIndex: bigint): Promise { + throw new Error('Unimplemented in private!'); + } + async getNullifierIndex(nullifier: Fr) { return await this.aztecNode.findLeafIndex('latest', MerkleTreeId.NULLIFIER_TREE, nullifier); } diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index 7118684483dc..48c658325a26 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -401,11 +401,11 @@ describe('AVM simulator: transpiled Noir contracts', () => { const results = await new AvmSimulator(context).executeBytecode(bytecode); expect(results.reverted).toBe(false); expect(results.output).toEqual([expectFound ? Fr.ONE : Fr.ZERO]); - + const expectedValue = results.output[0].toNumber() === 1 ? value0 : Fr.ZERO; expect(trace.traceNoteHashCheck).toHaveBeenCalledTimes(1); expect(trace.traceNoteHashCheck).toHaveBeenCalledWith( storageAddress, - /*noteHash=*/ value0, + /*noteHash=*/ expectedValue, leafIndex, /*exists=*/ expectFound, ); @@ -467,9 +467,13 @@ describe('AVM simulator: transpiled Noir contracts', () => { expect(results.output).toEqual([expectFound ? Fr.ONE : Fr.ZERO]); expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledTimes(1); + let expectedValue = results.output[0].toNumber() === 1 ? value0 : value1; + if (mockAtLeafIndex === undefined) { + expectedValue = Fr.ZERO; + } expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledWith( address, - /*msgHash=*/ value0, + /*msgHash=*/ expectedValue, leafIndex, /*exists=*/ expectFound, ); diff --git a/yarn-project/simulator/src/avm/journal/journal.test.ts b/yarn-project/simulator/src/avm/journal/journal.test.ts index 9818c42be4b6..f3c18188d129 100644 --- a/yarn-project/simulator/src/avm/journal/journal.test.ts +++ b/yarn-project/simulator/src/avm/journal/journal.test.ts @@ -79,7 +79,7 @@ describe('journal', () => { const exists = await persistableState.checkNoteHashExists(address, utxo, leafIndex); expect(exists).toEqual(false); expect(trace.traceNoteHashCheck).toHaveBeenCalledTimes(1); - expect(trace.traceNoteHashCheck).toHaveBeenCalledWith(address, utxo, leafIndex, exists); + expect(trace.traceNoteHashCheck).toHaveBeenCalledWith(address, Fr.ZERO, leafIndex, exists); }); it('checkNoteHashExists works for existing note hashes', async () => { @@ -126,7 +126,7 @@ describe('journal', () => { const exists = await persistableState.checkL1ToL2MessageExists(address, utxo, leafIndex); expect(exists).toEqual(false); expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledTimes(1); - expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledWith(address, utxo, leafIndex, exists); + expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledWith(address, Fr.ZERO, leafIndex, exists); }); it('checkL1ToL2MessageExists works for existing message', async () => { diff --git a/yarn-project/simulator/src/avm/journal/journal.ts b/yarn-project/simulator/src/avm/journal/journal.ts index f34a2832edd7..2f869c76a7b8 100644 --- a/yarn-project/simulator/src/avm/journal/journal.ts +++ b/yarn-project/simulator/src/avm/journal/journal.ts @@ -1,5 +1,5 @@ import { AztecAddress, type FunctionSelector, type Gas } from '@aztec/circuits.js'; -import { type Fr } from '@aztec/foundation/fields'; +import { Fr } from '@aztec/foundation/fields'; import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log'; import { SerializableContractInstance } from '@aztec/types/contracts'; @@ -122,10 +122,14 @@ export class AvmPersistableStateManager { * @returns true if the note hash exists at the given leaf index, false otherwise */ public async checkNoteHashExists(storageAddress: Fr, noteHash: Fr, leafIndex: Fr): Promise { - const gotLeafIndex = await this.hostStorage.commitmentsDb.getCommitmentIndex(noteHash); - const exists = gotLeafIndex === leafIndex.toBigInt(); - this.log.debug(`noteHashes(${storageAddress})@${noteHash} ?? leafIndex: ${leafIndex}, exists: ${exists}.`); - this.trace.traceNoteHashCheck(storageAddress, noteHash, leafIndex, exists); + const gotLeafValue = (await this.hostStorage.commitmentsDb.getCommitmentValue(leafIndex.toBigInt())) ?? Fr.ZERO; + const exists = gotLeafValue.equals(noteHash); + this.log.debug( + `noteHashes(${storageAddress})@${noteHash} ?? leafIndex: ${leafIndex} | gotLeafValue: ${gotLeafValue}, exists: ${exists}.`, + ); + // TODO(8287): We still return exists here, but we need to transmit both the requested noteHash and the gotLeafValue + // such that the VM can constrain the equality and decide on exists based on that. + this.trace.traceNoteHashCheck(storageAddress, gotLeafValue, leafIndex, exists); return Promise.resolve(exists); } @@ -173,12 +177,14 @@ export class AvmPersistableStateManager { * @returns exists - whether the message exists in the L1 to L2 Messages tree */ public async checkL1ToL2MessageExists(contractAddress: Fr, msgHash: Fr, msgLeafIndex: Fr): Promise { - const valueAtIndex = await this.hostStorage.commitmentsDb.getL1ToL2LeafValue(msgLeafIndex.toBigInt()); - const exists = valueAtIndex?.equals(msgHash) ?? false; + const valueAtIndex = (await this.hostStorage.commitmentsDb.getL1ToL2LeafValue(msgLeafIndex.toBigInt())) ?? Fr.ZERO; + const exists = valueAtIndex.equals(msgHash); this.log.debug( `l1ToL2Messages(@${msgLeafIndex}) ?? exists: ${exists}, expected: ${msgHash}, found: ${valueAtIndex}.`, ); - this.trace.traceL1ToL2MessageCheck(contractAddress, msgHash, msgLeafIndex, exists); + // TODO(8287): We still return exists here, but we need to transmit both the requested msgHash and the value + // such that the VM can constrain the equality and decide on exists based on that. + this.trace.traceL1ToL2MessageCheck(contractAddress, valueAtIndex, msgLeafIndex, exists); return Promise.resolve(exists); } diff --git a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts index dd1e638d6a49..aab2ae6efa6c 100644 --- a/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/accrued_substate.test.ts @@ -98,10 +98,11 @@ describe('Accrued Substate', () => { const gotExists = context.machineState.memory.getAs(existsOffset); expect(gotExists).toEqual(new Uint8(expectFound ? 1 : 0)); + const expectedValue = gotExists.toNumber() === 1 ? value0 : Fr.ZERO; expect(trace.traceNoteHashCheck).toHaveBeenCalledTimes(1); expect(trace.traceNoteHashCheck).toHaveBeenCalledWith( storageAddress, - /*noteHash=*/ value0, + /*noteHash=*/ expectedValue, leafIndex, /*exists=*/ expectFound, ); @@ -290,9 +291,14 @@ describe('Accrued Substate', () => { expect(gotExists).toEqual(new Uint8(expectFound ? 1 : 0)); expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledTimes(1); + // The expected value to trace depends on a) if we found it and b) if it is undefined + let expectedValue = gotExists.toNumber() === 1 ? value0 : value1; + if (mockAtLeafIndex === undefined) { + expectedValue = Fr.ZERO; + } expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledWith( address, - /*msgHash=*/ value0, + /*msgHash=*/ expectedValue, leafIndex, /*exists=*/ expectFound, ); diff --git a/yarn-project/simulator/src/avm/test_utils.ts b/yarn-project/simulator/src/avm/test_utils.ts index ce65116d5b87..f7dda9f6593d 100644 --- a/yarn-project/simulator/src/avm/test_utils.ts +++ b/yarn-project/simulator/src/avm/test_utils.ts @@ -28,8 +28,15 @@ export function mockStorageReadWithMap(hs: HostStorage, mockedStorage: Map).getCommitmentIndex.mockResolvedValue(leafIndex.toBigInt()); +export function mockNoteHashExists(hs: HostStorage, _leafIndex: Fr, value?: Fr) { + (hs.commitmentsDb as jest.Mocked).getCommitmentValue.mockImplementation((index: bigint) => { + if (index == _leafIndex.toBigInt()) { + return Promise.resolve(value); + } else { + // This is ok for now since the traceing functions handle it + return Promise.resolve(undefined); + } + }); } export function mockNullifierExists(hs: HostStorage, leafIndex: Fr, _value?: Fr) { diff --git a/yarn-project/simulator/src/public/db_interfaces.ts b/yarn-project/simulator/src/public/db_interfaces.ts index ca44044de82d..dfa168b66bbf 100644 --- a/yarn-project/simulator/src/public/db_interfaces.ts +++ b/yarn-project/simulator/src/public/db_interfaces.ts @@ -100,6 +100,13 @@ export interface CommitmentsDB { */ getCommitmentIndex(commitment: Fr): Promise; + /** + * Gets commitment in the note hash tree given a leaf index. + * @param leafIndex - the leaf to look up. + * @returns - The commitment at that index. Undefined if leaf index is not found. + */ + getCommitmentValue(leafIndex: bigint): Promise; + /** * Gets the index of a nullifier in the nullifier tree. * @param nullifier - The nullifier. diff --git a/yarn-project/simulator/src/public/public_db_sources.ts b/yarn-project/simulator/src/public/public_db_sources.ts index da99bb02d4ec..662ccae10c3a 100644 --- a/yarn-project/simulator/src/public/public_db_sources.ts +++ b/yarn-project/simulator/src/public/public_db_sources.ts @@ -308,6 +308,17 @@ export class WorldStateDB implements CommitmentsDB { return index; } + public async getCommitmentValue(leafIndex: bigint): Promise { + const timer = new Timer(); + const leafValue = await this.db.getLeafValue(MerkleTreeId.NOTE_HASH_TREE, leafIndex); + this.log.debug(`[DB] Fetched commitment leaf value`, { + eventName: 'public-db-access', + duration: timer.ms(), + operation: 'get-commitment-leaf-value', + } satisfies PublicDBAccessStats); + return leafValue; + } + public async getNullifierIndex(nullifier: Fr): Promise { const timer = new Timer(); const index = await this.db.findLeafIndex(MerkleTreeId.NULLIFIER_TREE, nullifier.toBuffer()); diff --git a/yarn-project/simulator/src/public/side_effect_trace.test.ts b/yarn-project/simulator/src/public/side_effect_trace.test.ts index 8ea72de14931..5ee1469f1615 100644 --- a/yarn-project/simulator/src/public/side_effect_trace.test.ts +++ b/yarn-project/simulator/src/public/side_effect_trace.test.ts @@ -94,7 +94,6 @@ describe('Side Effect Trace', () => { it('Should trace note hash checks', () => { const exists = true; trace.traceNoteHashCheck(address, utxo, leafIndex, exists); - expect(trace.getCounter()).toBe(startCounterPlus1); const pxResult = toPxResult(trace); expect(pxResult.noteHashReadRequests).toEqual([ @@ -106,7 +105,7 @@ describe('Side Effect Trace', () => { leafIndex, }, ]); - expect(pxResult.avmCircuitHints.noteHashExists.items).toEqual([{ key: startCounterFr, value: new Fr(exists) }]); + expect(pxResult.avmCircuitHints.noteHashExists.items).toEqual([{ key: leafIndex, value: new Fr(exists) }]); }); it('Should trace note hashes', () => { @@ -174,7 +173,6 @@ describe('Side Effect Trace', () => { it('Should trace L1ToL2 Message checks', () => { const exists = true; trace.traceL1ToL2MessageCheck(address, utxo, leafIndex, exists); - expect(trace.getCounter()).toBe(startCounterPlus1); const pxResult = toPxResult(trace); expect(pxResult.l1ToL2MsgReadRequests).toEqual([ @@ -185,7 +183,7 @@ describe('Side Effect Trace', () => { ]); expect(pxResult.avmCircuitHints.l1ToL2MessageExists.items).toEqual([ { - key: startCounterFr, + key: leafIndex, value: new Fr(exists), }, ]); @@ -246,7 +244,6 @@ describe('Side Effect Trace', () => { nestedTrace.tracePublicStorageWrite(address, slot, value); testCounter++; nestedTrace.traceNoteHashCheck(address, utxo, leafIndex, existsDefault); - testCounter++; nestedTrace.traceNewNoteHash(address, utxo); testCounter++; nestedTrace.traceNullifierCheck(address, utxo, leafIndex, /*exists=*/ true, isPending); @@ -256,7 +253,6 @@ describe('Side Effect Trace', () => { nestedTrace.traceNewNullifier(address, utxo); testCounter++; nestedTrace.traceL1ToL2MessageCheck(address, utxo, leafIndex, existsDefault); - testCounter++; nestedTrace.traceNewL2ToL1Message(recipient, content); testCounter++; nestedTrace.traceUnencryptedLog(address, log); diff --git a/yarn-project/simulator/src/public/side_effect_trace.ts b/yarn-project/simulator/src/public/side_effect_trace.ts index c26c5fdd53b6..5d7b0a33a70c 100644 --- a/yarn-project/simulator/src/public/side_effect_trace.ts +++ b/yarn-project/simulator/src/public/side_effect_trace.ts @@ -105,6 +105,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { this.incrementSideEffectCounter(); } + // TODO(8287): _exists can be removed once we have the vm properly handling the equality check public traceNoteHashCheck(_storageAddress: Fr, noteHash: Fr, leafIndex: Fr, exists: boolean) { // TODO(4805): check if some threshold is reached for max note hash checks // NOTE: storageAddress is unused but will be important when an AVM circuit processes an entire enqueued call @@ -112,10 +113,8 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { // is in fact checking the leaf indicated by the user this.noteHashReadRequests.push(new TreeLeafReadRequest(noteHash, leafIndex)); this.avmCircuitHints.noteHashExists.items.push( - new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ new Fr(exists ? 1 : 0)), + new AvmKeyValueHint(/*key=*/ new Fr(leafIndex), /*value=*/ exists ? Fr.ONE : Fr.ZERO), ); - this.logger.debug(`NOTE_HASH_CHECK cnt: ${this.sideEffectCounter}`); - this.incrementSideEffectCounter(); } public traceNewNoteHash(_storageAddress: Fr, noteHash: Fr) { @@ -155,6 +154,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { this.incrementSideEffectCounter(); } + // TODO(8287): _exists can be removed once we have the vm properly handling the equality check public traceL1ToL2MessageCheck(_contractAddress: Fr, msgHash: Fr, msgLeafIndex: Fr, exists: boolean) { // TODO(4805): check if some threshold is reached for max message reads // NOTE: contractAddress is unused but will be important when an AVM circuit processes an entire enqueued call @@ -162,10 +162,8 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { // is in fact checking the leaf indicated by the user this.l1ToL2MsgReadRequests.push(new TreeLeafReadRequest(msgHash, msgLeafIndex)); this.avmCircuitHints.l1ToL2MessageExists.items.push( - new AvmKeyValueHint(/*key=*/ new Fr(this.sideEffectCounter), /*value=*/ new Fr(exists ? 1 : 0)), + new AvmKeyValueHint(/*key=*/ new Fr(msgLeafIndex), /*value=*/ exists ? Fr.ONE : Fr.ZERO), ); - this.logger.debug(`L1_TO_L2_MSG_CHECK cnt: ${this.sideEffectCounter}`); - this.incrementSideEffectCounter(); } public traceNewL2ToL1Message(recipient: Fr, content: Fr) {