From 2c88f8e41c8ec54d40dbd7fad0c5582d7dc69761 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Thu, 17 Apr 2025 16:24:02 +0000 Subject: [PATCH 1/2] feat(avm): quick n dirty memory trace --- barretenberg/cpp/pil/vm2/execution.pil | 1 + barretenberg/cpp/pil/vm2/memory.pil | 19 +++++++ .../barretenberg/vm2/common/tagged_value.cpp | 23 ++++++++ .../barretenberg/vm2/common/tagged_value.hpp | 2 + .../constraining/relations/sha256.test.cpp | 10 +--- .../barretenberg/vm2/generated/columns.hpp | 6 +- .../vm2/generated/flavor_variables.hpp | 6 +- .../vm2/generated/relations/memory.hpp | 56 +++++++++++++++++++ .../vm2/simulation/execution_components.cpp | 4 +- .../vm2/simulation/execution_components.hpp | 4 ++ .../barretenberg/vm2/simulation/memory.cpp | 19 ++++++- .../barretenberg/vm2/simulation/memory.hpp | 30 +++++++++- .../vm2/simulation/sha256.test.cpp | 4 +- .../barretenberg/vm2/simulation_helper.cpp | 3 +- .../vm2/tracegen/lib/lookup_builder.hpp | 9 +++ .../vm2/tracegen/memory_trace.cpp | 35 ++++++++++++ .../vm2/tracegen/memory_trace.hpp | 20 +++++++ .../src/barretenberg/vm2/tracegen_helper.cpp | 9 ++- 18 files changed, 240 insertions(+), 20 deletions(-) create mode 100644 barretenberg/cpp/pil/vm2/memory.pil create mode 100644 barretenberg/cpp/src/barretenberg/vm2/generated/relations/memory.hpp create mode 100644 barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp create mode 100644 barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.hpp diff --git a/barretenberg/cpp/pil/vm2/execution.pil b/barretenberg/cpp/pil/vm2/execution.pil index 31799dd33294..32bc439a7487 100644 --- a/barretenberg/cpp/pil/vm2/execution.pil +++ b/barretenberg/cpp/pil/vm2/execution.pil @@ -9,6 +9,7 @@ include "class_id_derivation.pil"; include "range_check.pil"; include "bitwise.pil"; include "merkle_check.pil"; +include "memory.pil"; include "precomputed.pil"; include "sha256.pil"; include "ecc.pil"; diff --git a/barretenberg/cpp/pil/vm2/memory.pil b/barretenberg/cpp/pil/vm2/memory.pil new file mode 100644 index 000000000000..87e7ccf3576e --- /dev/null +++ b/barretenberg/cpp/pil/vm2/memory.pil @@ -0,0 +1,19 @@ +include "range_check.pil"; + +namespace memory; + +pol commit sel; +pol commit address; +pol commit value; +pol commit tag; +pol commit rw; +pol commit space_id; + +#[skippable_if] +sel = 0; + +sel * (sel - 1) = 0; +rw * (1 - rw) = 0; + +// TODO: consider tag-value consistency checking. +// TODO: consider address range checking. diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp index 1b402d051f43..7b99554adbb9 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.cpp @@ -93,6 +93,29 @@ template struct UnaryOperationVisitor { } // namespace +uint8_t get_tag_bits(ValueTag tag) +{ + switch (tag) { + case ValueTag::U1: + return 1; + case ValueTag::U8: + return 8; + case ValueTag::U16: + return 16; + case ValueTag::U32: + return 32; + case ValueTag::U64: + return 64; + case ValueTag::U128: + return 128; + case ValueTag::FF: + return 254; + } + + assert(false && "Invalid tag"); + return 0; +} + // Constructor TaggedValue::TaggedValue(TaggedValue::value_type value_) : value(value_) diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.hpp b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.hpp index e2d62579099f..8edfccf578af 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/tagged_value.hpp @@ -41,6 +41,8 @@ template ValueTag tag_for_type() } } +uint8_t get_tag_bits(ValueTag tag); + class TaggedValue { public: // We are using variant to avoid heap allocations at the cost of a bigger memory footprint. diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp index 87c7ea1d1ed2..7ac575a03792 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/sha256.test.cpp @@ -28,9 +28,7 @@ using ::testing::ReturnRef; using ::testing::StrictMock; using simulation::EventEmitter; -using simulation::Memory; -using simulation::MemoryEvent; -using simulation::NoopEventEmitter; +using simulation::MemoryStore; using simulation::Sha256; using simulation::Sha256CompressionEvent; @@ -53,8 +51,7 @@ TEST(Sha256ConstrainingTest, EmptyRow) // TOOD: Replace this with a hardcoded test vector and write a negative test TEST(Sha256ConstrainingTest, Basic) { - NoopEventEmitter emitter; - Memory mem(/*space_id=*/0, emitter); + MemoryStore mem; StrictMock context; EXPECT_CALL(context, get_memory()).WillRepeatedly(ReturnRef(mem)); @@ -89,8 +86,7 @@ TEST(Sha256ConstrainingTest, Basic) TEST(Sha256ConstrainingTest, Interaction) { - NoopEventEmitter emitter; - Memory mem(/*space_id=*/0, emitter); + MemoryStore mem; StrictMock context; EXPECT_CALL(context, get_memory()).WillRepeatedly(ReturnRef(mem)); diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp index 503f6710a696..0e1f85696f22 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp @@ -10,7 +10,7 @@ namespace bb::avm2 { // The entities that will be used in the flavor. // clang-format off #define AVM2_PRECOMPUTED_ENTITIES precomputed_bitwise_input_a, precomputed_bitwise_input_b, precomputed_bitwise_op_id, precomputed_bitwise_output, precomputed_clk, precomputed_exec_opcode, precomputed_first_row, precomputed_instr_size, precomputed_integral_tag_length, precomputed_opcode_out_of_range, precomputed_p_decomposition_limb, precomputed_p_decomposition_limb_index, precomputed_p_decomposition_radix, precomputed_power_of_2, precomputed_sel_bitwise, precomputed_sel_has_tag, precomputed_sel_integral_tag, precomputed_sel_mem_tag_out_of_range, precomputed_sel_op_dc_0, precomputed_sel_op_dc_1, precomputed_sel_op_dc_10, precomputed_sel_op_dc_11, precomputed_sel_op_dc_12, precomputed_sel_op_dc_13, precomputed_sel_op_dc_14, precomputed_sel_op_dc_15, precomputed_sel_op_dc_16, precomputed_sel_op_dc_17, precomputed_sel_op_dc_2, precomputed_sel_op_dc_3, precomputed_sel_op_dc_4, precomputed_sel_op_dc_5, precomputed_sel_op_dc_6, precomputed_sel_op_dc_7, precomputed_sel_op_dc_8, precomputed_sel_op_dc_9, precomputed_sel_p_decomposition, precomputed_sel_range_16, precomputed_sel_range_8, precomputed_sel_sha256_compression, precomputed_sel_tag_is_op2, precomputed_sel_to_radix_safe_limbs, precomputed_sha256_compression_round_constant, precomputed_to_radix_safe_limbs, precomputed_zero -#define AVM2_WIRE_ENTITIES execution_input, address_derivation_address, address_derivation_address_y, address_derivation_class_id, address_derivation_deployer_addr, address_derivation_g1_x, address_derivation_g1_y, address_derivation_incoming_viewing_key_x, address_derivation_incoming_viewing_key_y, address_derivation_init_hash, address_derivation_nullifier_key_x, address_derivation_nullifier_key_y, address_derivation_outgoing_viewing_key_x, address_derivation_outgoing_viewing_key_y, address_derivation_partial_address, address_derivation_partial_address_domain_separator, address_derivation_preaddress, address_derivation_preaddress_domain_separator, address_derivation_preaddress_public_key_x, address_derivation_preaddress_public_key_y, address_derivation_public_keys_hash, address_derivation_public_keys_hash_domain_separator, address_derivation_salt, address_derivation_salted_init_hash, address_derivation_sel, address_derivation_tagging_key_x, address_derivation_tagging_key_y, alu_ia, alu_ib, alu_ic, alu_op, alu_sel_op_add, bc_decomposition_abs_diff, bc_decomposition_bytes, bc_decomposition_bytes_pc_plus_1, bc_decomposition_bytes_pc_plus_10, bc_decomposition_bytes_pc_plus_11, bc_decomposition_bytes_pc_plus_12, bc_decomposition_bytes_pc_plus_13, bc_decomposition_bytes_pc_plus_14, bc_decomposition_bytes_pc_plus_15, bc_decomposition_bytes_pc_plus_16, bc_decomposition_bytes_pc_plus_17, bc_decomposition_bytes_pc_plus_18, bc_decomposition_bytes_pc_plus_19, bc_decomposition_bytes_pc_plus_2, bc_decomposition_bytes_pc_plus_20, bc_decomposition_bytes_pc_plus_21, bc_decomposition_bytes_pc_plus_22, bc_decomposition_bytes_pc_plus_23, bc_decomposition_bytes_pc_plus_24, bc_decomposition_bytes_pc_plus_25, bc_decomposition_bytes_pc_plus_26, bc_decomposition_bytes_pc_plus_27, bc_decomposition_bytes_pc_plus_28, bc_decomposition_bytes_pc_plus_29, bc_decomposition_bytes_pc_plus_3, bc_decomposition_bytes_pc_plus_30, bc_decomposition_bytes_pc_plus_31, bc_decomposition_bytes_pc_plus_32, bc_decomposition_bytes_pc_plus_33, bc_decomposition_bytes_pc_plus_34, bc_decomposition_bytes_pc_plus_35, bc_decomposition_bytes_pc_plus_36, bc_decomposition_bytes_pc_plus_4, bc_decomposition_bytes_pc_plus_5, bc_decomposition_bytes_pc_plus_6, bc_decomposition_bytes_pc_plus_7, bc_decomposition_bytes_pc_plus_8, bc_decomposition_bytes_pc_plus_9, bc_decomposition_bytes_rem_inv, bc_decomposition_bytes_rem_min_one_inv, bc_decomposition_bytes_remaining, bc_decomposition_bytes_to_read, bc_decomposition_id, bc_decomposition_last_of_contract, bc_decomposition_packed_field, bc_decomposition_pc, bc_decomposition_sel, bc_decomposition_sel_overflow_correction_needed, bc_decomposition_sel_packed, bc_hashing_bytecode_id, bc_hashing_incremental_hash, bc_hashing_latch, bc_hashing_output_hash, bc_hashing_packed_field, bc_hashing_pc_index, bc_hashing_sel, bc_hashing_start, bc_retrieval_address, bc_retrieval_artifact_hash, bc_retrieval_block_number, bc_retrieval_bytecode_id, bc_retrieval_current_class_id, bc_retrieval_deployer_addr, bc_retrieval_deployer_protocol_contract_address, bc_retrieval_err, bc_retrieval_incoming_viewing_key_x, bc_retrieval_incoming_viewing_key_y, bc_retrieval_init_hash, bc_retrieval_nullifier_exists, bc_retrieval_nullifier_key_x, bc_retrieval_nullifier_key_y, bc_retrieval_nullifier_tree_root, bc_retrieval_original_class_id, bc_retrieval_outer_nullifier_domain_separator, bc_retrieval_outgoing_viewing_key_x, bc_retrieval_outgoing_viewing_key_y, bc_retrieval_private_function_root, bc_retrieval_public_bytecode_commitment, bc_retrieval_public_data_tree_root, bc_retrieval_salt, bc_retrieval_sel, bc_retrieval_siloed_address, bc_retrieval_tagging_key_x, bc_retrieval_tagging_key_y, bitwise_acc_ia, bitwise_acc_ib, bitwise_acc_ic, bitwise_ctr, bitwise_ctr_inv, bitwise_ctr_min_one_inv, bitwise_ia_byte, bitwise_ib_byte, bitwise_ic_byte, bitwise_last, bitwise_op_id, bitwise_sel, bitwise_start, bitwise_tag, class_id_derivation_artifact_hash, class_id_derivation_class_id, class_id_derivation_private_function_root, class_id_derivation_public_bytecode_commitment, class_id_derivation_sel, class_id_derivation_temp_constant_for_lookup, context_stack_context_id, context_stack_contract_address, context_stack_is_static, context_stack_msg_sender, context_stack_parent_calldata_offset_addr, context_stack_parent_calldata_size_addr, context_stack_pc, ecc_add_op, ecc_double_op, ecc_inv_2_p_y, ecc_inv_x_diff, ecc_inv_y_diff, ecc_lambda, ecc_p_is_inf, ecc_p_x, ecc_p_y, ecc_q_is_inf, ecc_q_x, ecc_q_y, ecc_r_is_inf, ecc_r_x, ecc_r_y, ecc_result_infinity, ecc_sel, ecc_x_match, ecc_y_match, execution_addressing_error_idx, execution_addressing_error_kind, execution_base_address_tag, execution_base_address_val, execution_bytecode_id, execution_clk, execution_context_id, execution_contract_address, execution_ex_opcode, execution_indirect, execution_is_static, execution_last, execution_last_child_returndata_offset_addr, execution_last_child_returndata_size_addr, execution_last_child_success, execution_msg_sender, execution_op1, execution_op1_after_relative, execution_op2, execution_op2_after_relative, execution_op3, execution_op3_after_relative, execution_op4, execution_op4_after_relative, execution_parent_calldata_offset_addr, execution_parent_calldata_size_addr, execution_pc, execution_rop1, execution_rop2, execution_rop3, execution_rop4, execution_sel, execution_sel_addressing_error, execution_sel_op1_is_address, execution_sel_op2_is_address, execution_sel_op3_is_address, execution_sel_op4_is_address, ff_gt_a, ff_gt_a_hi, ff_gt_a_lo, ff_gt_b, ff_gt_b_hi, ff_gt_b_lo, ff_gt_borrow, ff_gt_cmp_rng_ctr, ff_gt_cmp_rng_ctr_inv, ff_gt_constant_128, ff_gt_p_a_borrow, ff_gt_p_b_borrow, ff_gt_p_sub_a_hi, ff_gt_p_sub_a_lo, ff_gt_p_sub_b_hi, ff_gt_p_sub_b_lo, ff_gt_res_hi, ff_gt_res_lo, ff_gt_result, ff_gt_sel, ff_gt_sel_gt, ff_gt_sel_shift_rng, instr_fetching_bd0, instr_fetching_bd1, instr_fetching_bd10, instr_fetching_bd11, instr_fetching_bd12, instr_fetching_bd13, instr_fetching_bd14, instr_fetching_bd15, instr_fetching_bd16, instr_fetching_bd17, instr_fetching_bd18, instr_fetching_bd19, instr_fetching_bd2, instr_fetching_bd20, instr_fetching_bd21, instr_fetching_bd22, instr_fetching_bd23, instr_fetching_bd24, instr_fetching_bd25, instr_fetching_bd26, instr_fetching_bd27, instr_fetching_bd28, instr_fetching_bd29, instr_fetching_bd3, instr_fetching_bd30, instr_fetching_bd31, instr_fetching_bd32, instr_fetching_bd33, instr_fetching_bd34, instr_fetching_bd35, instr_fetching_bd36, instr_fetching_bd4, instr_fetching_bd5, instr_fetching_bd6, instr_fetching_bd7, instr_fetching_bd8, instr_fetching_bd9, instr_fetching_bytecode_id, instr_fetching_bytecode_size, instr_fetching_bytes_to_read, instr_fetching_exec_opcode, instr_fetching_indirect, instr_fetching_instr_abs_diff, instr_fetching_instr_out_of_range, instr_fetching_instr_size, instr_fetching_op1, instr_fetching_op2, instr_fetching_op3, instr_fetching_op4, instr_fetching_op5, instr_fetching_op6, instr_fetching_op7, instr_fetching_opcode_out_of_range, instr_fetching_parsing_err, instr_fetching_pc, instr_fetching_pc_abs_diff, instr_fetching_pc_out_of_range, instr_fetching_pc_size_in_bits, instr_fetching_sel, instr_fetching_sel_has_tag, instr_fetching_sel_op_dc_0, instr_fetching_sel_op_dc_1, instr_fetching_sel_op_dc_10, instr_fetching_sel_op_dc_11, instr_fetching_sel_op_dc_12, instr_fetching_sel_op_dc_13, instr_fetching_sel_op_dc_14, instr_fetching_sel_op_dc_15, instr_fetching_sel_op_dc_16, instr_fetching_sel_op_dc_17, instr_fetching_sel_op_dc_2, instr_fetching_sel_op_dc_3, instr_fetching_sel_op_dc_4, instr_fetching_sel_op_dc_5, instr_fetching_sel_op_dc_6, instr_fetching_sel_op_dc_7, instr_fetching_sel_op_dc_8, instr_fetching_sel_op_dc_9, instr_fetching_sel_pc_in_range, instr_fetching_sel_tag_is_op2, instr_fetching_tag_out_of_range, instr_fetching_tag_value, merkle_check_constant_2, merkle_check_end, merkle_check_index, merkle_check_index_is_even, merkle_check_path_len, merkle_check_read_left_node, merkle_check_read_node, merkle_check_read_output_hash, merkle_check_read_right_node, merkle_check_read_root, merkle_check_remaining_path_len_inv, merkle_check_sel, merkle_check_sibling, merkle_check_start, merkle_check_write, merkle_check_write_left_node, merkle_check_write_node, merkle_check_write_output_hash, merkle_check_write_right_node, merkle_check_write_root, nullifier_check_exists, nullifier_check_intermediate_root, nullifier_check_leaf_not_exists, nullifier_check_low_leaf_hash, nullifier_check_low_leaf_index, nullifier_check_low_leaf_next_index, nullifier_check_low_leaf_next_nullifier, nullifier_check_low_leaf_nullifier, nullifier_check_new_leaf_hash, nullifier_check_next_nullifier_inv, nullifier_check_next_nullifier_is_nonzero, nullifier_check_nullifier, nullifier_check_nullifier_low_leaf_nullifier_diff_inv, nullifier_check_one, nullifier_check_root, nullifier_check_sel, nullifier_check_tree_height, nullifier_check_tree_size_before_write, nullifier_check_updated_low_leaf_hash, nullifier_check_write, nullifier_check_write_low_leaf_next_index, nullifier_check_write_low_leaf_next_nullifier, nullifier_check_write_root, poseidon2_hash_a_0, poseidon2_hash_a_1, poseidon2_hash_a_2, poseidon2_hash_a_3, poseidon2_hash_b_0, poseidon2_hash_b_1, poseidon2_hash_b_2, poseidon2_hash_b_3, poseidon2_hash_end, poseidon2_hash_input_0, poseidon2_hash_input_1, poseidon2_hash_input_2, poseidon2_hash_input_len, poseidon2_hash_num_perm_rounds_rem, poseidon2_hash_num_perm_rounds_rem_inv, poseidon2_hash_output, poseidon2_hash_padding, poseidon2_hash_sel, poseidon2_hash_start, poseidon2_perm_B_10_0, poseidon2_perm_B_10_1, poseidon2_perm_B_10_2, poseidon2_perm_B_10_3, poseidon2_perm_B_11_0, poseidon2_perm_B_11_1, poseidon2_perm_B_11_2, poseidon2_perm_B_11_3, poseidon2_perm_B_12_0, poseidon2_perm_B_12_1, poseidon2_perm_B_12_2, poseidon2_perm_B_12_3, poseidon2_perm_B_13_0, poseidon2_perm_B_13_1, poseidon2_perm_B_13_2, poseidon2_perm_B_13_3, poseidon2_perm_B_14_0, poseidon2_perm_B_14_1, poseidon2_perm_B_14_2, poseidon2_perm_B_14_3, poseidon2_perm_B_15_0, poseidon2_perm_B_15_1, poseidon2_perm_B_15_2, poseidon2_perm_B_15_3, poseidon2_perm_B_16_0, poseidon2_perm_B_16_1, poseidon2_perm_B_16_2, poseidon2_perm_B_16_3, poseidon2_perm_B_17_0, poseidon2_perm_B_17_1, poseidon2_perm_B_17_2, poseidon2_perm_B_17_3, poseidon2_perm_B_18_0, poseidon2_perm_B_18_1, poseidon2_perm_B_18_2, poseidon2_perm_B_18_3, poseidon2_perm_B_19_0, poseidon2_perm_B_19_1, poseidon2_perm_B_19_2, poseidon2_perm_B_19_3, poseidon2_perm_B_20_0, poseidon2_perm_B_20_1, poseidon2_perm_B_20_2, poseidon2_perm_B_20_3, poseidon2_perm_B_21_0, poseidon2_perm_B_21_1, poseidon2_perm_B_21_2, poseidon2_perm_B_21_3, poseidon2_perm_B_22_0, poseidon2_perm_B_22_1, poseidon2_perm_B_22_2, poseidon2_perm_B_22_3, poseidon2_perm_B_23_0, poseidon2_perm_B_23_1, poseidon2_perm_B_23_2, poseidon2_perm_B_23_3, poseidon2_perm_B_24_0, poseidon2_perm_B_24_1, poseidon2_perm_B_24_2, poseidon2_perm_B_24_3, poseidon2_perm_B_25_0, poseidon2_perm_B_25_1, poseidon2_perm_B_25_2, poseidon2_perm_B_25_3, poseidon2_perm_B_26_0, poseidon2_perm_B_26_1, poseidon2_perm_B_26_2, poseidon2_perm_B_26_3, poseidon2_perm_B_27_0, poseidon2_perm_B_27_1, poseidon2_perm_B_27_2, poseidon2_perm_B_27_3, poseidon2_perm_B_28_0, poseidon2_perm_B_28_1, poseidon2_perm_B_28_2, poseidon2_perm_B_28_3, poseidon2_perm_B_29_0, poseidon2_perm_B_29_1, poseidon2_perm_B_29_2, poseidon2_perm_B_29_3, poseidon2_perm_B_30_0, poseidon2_perm_B_30_1, poseidon2_perm_B_30_2, poseidon2_perm_B_30_3, poseidon2_perm_B_31_0, poseidon2_perm_B_31_1, poseidon2_perm_B_31_2, poseidon2_perm_B_31_3, poseidon2_perm_B_32_0, poseidon2_perm_B_32_1, poseidon2_perm_B_32_2, poseidon2_perm_B_32_3, poseidon2_perm_B_33_0, poseidon2_perm_B_33_1, poseidon2_perm_B_33_2, poseidon2_perm_B_33_3, poseidon2_perm_B_34_0, poseidon2_perm_B_34_1, poseidon2_perm_B_34_2, poseidon2_perm_B_34_3, poseidon2_perm_B_35_0, poseidon2_perm_B_35_1, poseidon2_perm_B_35_2, poseidon2_perm_B_35_3, poseidon2_perm_B_36_0, poseidon2_perm_B_36_1, poseidon2_perm_B_36_2, poseidon2_perm_B_36_3, poseidon2_perm_B_37_0, poseidon2_perm_B_37_1, poseidon2_perm_B_37_2, poseidon2_perm_B_37_3, poseidon2_perm_B_38_0, poseidon2_perm_B_38_1, poseidon2_perm_B_38_2, poseidon2_perm_B_38_3, poseidon2_perm_B_39_0, poseidon2_perm_B_39_1, poseidon2_perm_B_39_2, poseidon2_perm_B_39_3, poseidon2_perm_B_40_0, poseidon2_perm_B_40_1, poseidon2_perm_B_40_2, poseidon2_perm_B_40_3, poseidon2_perm_B_41_0, poseidon2_perm_B_41_1, poseidon2_perm_B_41_2, poseidon2_perm_B_41_3, poseidon2_perm_B_42_0, poseidon2_perm_B_42_1, poseidon2_perm_B_42_2, poseidon2_perm_B_42_3, poseidon2_perm_B_43_0, poseidon2_perm_B_43_1, poseidon2_perm_B_43_2, poseidon2_perm_B_43_3, poseidon2_perm_B_44_0, poseidon2_perm_B_44_1, poseidon2_perm_B_44_2, poseidon2_perm_B_44_3, poseidon2_perm_B_45_0, poseidon2_perm_B_45_1, poseidon2_perm_B_45_2, poseidon2_perm_B_45_3, poseidon2_perm_B_46_0, poseidon2_perm_B_46_1, poseidon2_perm_B_46_2, poseidon2_perm_B_46_3, poseidon2_perm_B_47_0, poseidon2_perm_B_47_1, poseidon2_perm_B_47_2, poseidon2_perm_B_47_3, poseidon2_perm_B_48_0, poseidon2_perm_B_48_1, poseidon2_perm_B_48_2, poseidon2_perm_B_48_3, poseidon2_perm_B_49_0, poseidon2_perm_B_49_1, poseidon2_perm_B_49_2, poseidon2_perm_B_49_3, poseidon2_perm_B_4_0, poseidon2_perm_B_4_1, poseidon2_perm_B_4_2, poseidon2_perm_B_4_3, poseidon2_perm_B_50_0, poseidon2_perm_B_50_1, poseidon2_perm_B_50_2, poseidon2_perm_B_50_3, poseidon2_perm_B_51_0, poseidon2_perm_B_51_1, poseidon2_perm_B_51_2, poseidon2_perm_B_51_3, poseidon2_perm_B_52_0, poseidon2_perm_B_52_1, poseidon2_perm_B_52_2, poseidon2_perm_B_52_3, poseidon2_perm_B_53_0, poseidon2_perm_B_53_1, poseidon2_perm_B_53_2, poseidon2_perm_B_53_3, poseidon2_perm_B_54_0, poseidon2_perm_B_54_1, poseidon2_perm_B_54_2, poseidon2_perm_B_54_3, poseidon2_perm_B_55_0, poseidon2_perm_B_55_1, poseidon2_perm_B_55_2, poseidon2_perm_B_55_3, poseidon2_perm_B_56_0, poseidon2_perm_B_56_1, poseidon2_perm_B_56_2, poseidon2_perm_B_56_3, poseidon2_perm_B_57_0, poseidon2_perm_B_57_1, poseidon2_perm_B_57_2, poseidon2_perm_B_57_3, poseidon2_perm_B_58_0, poseidon2_perm_B_58_1, poseidon2_perm_B_58_2, poseidon2_perm_B_58_3, poseidon2_perm_B_59_0, poseidon2_perm_B_59_1, poseidon2_perm_B_59_2, poseidon2_perm_B_59_3, poseidon2_perm_B_5_0, poseidon2_perm_B_5_1, poseidon2_perm_B_5_2, poseidon2_perm_B_5_3, poseidon2_perm_B_6_0, poseidon2_perm_B_6_1, poseidon2_perm_B_6_2, poseidon2_perm_B_6_3, poseidon2_perm_B_7_0, poseidon2_perm_B_7_1, poseidon2_perm_B_7_2, poseidon2_perm_B_7_3, poseidon2_perm_B_8_0, poseidon2_perm_B_8_1, poseidon2_perm_B_8_2, poseidon2_perm_B_8_3, poseidon2_perm_B_9_0, poseidon2_perm_B_9_1, poseidon2_perm_B_9_2, poseidon2_perm_B_9_3, poseidon2_perm_EXT_LAYER_4, poseidon2_perm_EXT_LAYER_5, poseidon2_perm_EXT_LAYER_6, poseidon2_perm_EXT_LAYER_7, poseidon2_perm_T_0_4, poseidon2_perm_T_0_5, poseidon2_perm_T_0_6, poseidon2_perm_T_0_7, poseidon2_perm_T_1_4, poseidon2_perm_T_1_5, poseidon2_perm_T_1_6, poseidon2_perm_T_1_7, poseidon2_perm_T_2_4, poseidon2_perm_T_2_5, poseidon2_perm_T_2_6, poseidon2_perm_T_2_7, poseidon2_perm_T_3_4, poseidon2_perm_T_3_5, poseidon2_perm_T_3_6, poseidon2_perm_T_3_7, poseidon2_perm_T_60_4, poseidon2_perm_T_60_5, poseidon2_perm_T_60_6, poseidon2_perm_T_60_7, poseidon2_perm_T_61_4, poseidon2_perm_T_61_5, poseidon2_perm_T_61_6, poseidon2_perm_T_61_7, poseidon2_perm_T_62_4, poseidon2_perm_T_62_5, poseidon2_perm_T_62_6, poseidon2_perm_T_62_7, poseidon2_perm_T_63_4, poseidon2_perm_T_63_5, poseidon2_perm_T_63_6, poseidon2_perm_T_63_7, poseidon2_perm_a_0, poseidon2_perm_a_1, poseidon2_perm_a_2, poseidon2_perm_a_3, poseidon2_perm_b_0, poseidon2_perm_b_1, poseidon2_perm_b_2, poseidon2_perm_b_3, poseidon2_perm_sel, public_data_read_leaf_not_exists, public_data_read_low_leaf_hash, public_data_read_low_leaf_index, public_data_read_low_leaf_next_index, public_data_read_low_leaf_next_slot, public_data_read_low_leaf_slot, public_data_read_low_leaf_value, public_data_read_next_slot_inv, public_data_read_next_slot_is_nonzero, public_data_read_one, public_data_read_root, public_data_read_sel, public_data_read_slot, public_data_read_slot_low_leaf_slot_diff_inv, public_data_read_tree_height, public_data_read_value, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_rng_chk_bits, range_check_sel, range_check_sel_r0_16_bit_rng_lookup, range_check_sel_r1_16_bit_rng_lookup, range_check_sel_r2_16_bit_rng_lookup, range_check_sel_r3_16_bit_rng_lookup, range_check_sel_r4_16_bit_rng_lookup, range_check_sel_r5_16_bit_rng_lookup, range_check_sel_r6_16_bit_rng_lookup, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, scalar_mul_bit, scalar_mul_bit_idx, scalar_mul_bit_radix, scalar_mul_end, scalar_mul_not_end, scalar_mul_point_inf, scalar_mul_point_x, scalar_mul_point_y, scalar_mul_res_inf, scalar_mul_res_x, scalar_mul_res_y, scalar_mul_scalar, scalar_mul_sel, scalar_mul_should_add, scalar_mul_start, scalar_mul_temp_inf, scalar_mul_temp_x, scalar_mul_temp_y, sha256_a, sha256_a_and_b, sha256_a_and_b_xor_a_and_c, sha256_a_and_c, sha256_a_rotr_13, sha256_a_rotr_2, sha256_a_rotr_22, sha256_a_rotr_2_xor_a_rotr_13, sha256_and_sel, sha256_b, sha256_b_and_c, sha256_c, sha256_ch, sha256_clk, sha256_computed_w_lhs, sha256_computed_w_rhs, sha256_d, sha256_e, sha256_e_and_f, sha256_e_rotr_11, sha256_e_rotr_25, sha256_e_rotr_6, sha256_e_rotr_6_xor_e_rotr_11, sha256_f, sha256_g, sha256_h, sha256_helper_w0, sha256_helper_w1, sha256_helper_w10, sha256_helper_w11, sha256_helper_w12, sha256_helper_w13, sha256_helper_w14, sha256_helper_w15, sha256_helper_w2, sha256_helper_w3, sha256_helper_w4, sha256_helper_w5, sha256_helper_w6, sha256_helper_w7, sha256_helper_w8, sha256_helper_w9, sha256_init_a, sha256_init_b, sha256_init_c, sha256_init_d, sha256_init_e, sha256_init_f, sha256_init_g, sha256_init_h, sha256_input_offset, sha256_is_input_round, sha256_latch, sha256_lhs_a_13, sha256_lhs_a_2, sha256_lhs_a_22, sha256_lhs_e_11, sha256_lhs_e_25, sha256_lhs_e_6, sha256_lhs_w_10, sha256_lhs_w_17, sha256_lhs_w_18, sha256_lhs_w_19, sha256_lhs_w_3, sha256_lhs_w_7, sha256_maj, sha256_next_a_lhs, sha256_next_a_rhs, sha256_next_e_lhs, sha256_next_e_rhs, sha256_not_e, sha256_not_e_and_g, sha256_output_a_lhs, sha256_output_a_rhs, sha256_output_b_lhs, sha256_output_b_rhs, sha256_output_c_lhs, sha256_output_c_rhs, sha256_output_d_lhs, sha256_output_d_rhs, sha256_output_e_lhs, sha256_output_e_rhs, sha256_output_f_lhs, sha256_output_f_rhs, sha256_output_g_lhs, sha256_output_g_rhs, sha256_output_h_lhs, sha256_output_h_rhs, sha256_output_offset, sha256_perform_round, sha256_rhs_a_13, sha256_rhs_a_2, sha256_rhs_a_22, sha256_rhs_e_11, sha256_rhs_e_25, sha256_rhs_e_6, sha256_rhs_w_10, sha256_rhs_w_17, sha256_rhs_w_18, sha256_rhs_w_19, sha256_rhs_w_3, sha256_rhs_w_7, sha256_round_constant, sha256_round_count, sha256_rounds_remaining, sha256_rounds_remaining_inv, sha256_s_0, sha256_s_1, sha256_sel, sha256_start, sha256_state_offset, sha256_w, sha256_w_15_rotr_18, sha256_w_15_rotr_7, sha256_w_15_rotr_7_xor_w_15_rotr_18, sha256_w_15_rshift_3, sha256_w_2_rotr_17, sha256_w_2_rotr_17_xor_w_2_rotr_19, sha256_w_2_rotr_19, sha256_w_2_rshift_10, sha256_w_s_0, sha256_w_s_1, sha256_xor_sel, to_radix_acc, to_radix_acc_under_p, to_radix_end, to_radix_exponent, to_radix_found, to_radix_is_unsafe_limb, to_radix_limb, to_radix_limb_eq_p, to_radix_limb_index, to_radix_limb_lt_p, to_radix_limb_p_diff, to_radix_limb_radix_diff, to_radix_not_end, to_radix_not_padding_limb, to_radix_p_limb, to_radix_radix, to_radix_rem_inverse, to_radix_safe_limbs, to_radix_safety_diff_inverse, to_radix_sel, to_radix_start, to_radix_value, update_check_address, update_check_block_number, update_check_block_number_bit_size, update_check_block_number_is_lt_block_of_change, update_check_block_of_change_subtraction, update_check_current_class_id, update_check_deployer_protocol_contract_address, update_check_hash_not_zero, update_check_original_class_id, update_check_public_data_tree_root, update_check_public_leaf_index_domain_separator, update_check_sel, update_check_shared_mutable_hash_slot, update_check_shared_mutable_leaf_slot, update_check_shared_mutable_slot, update_check_update_block_of_change, update_check_update_hash, update_check_update_hash_inv, update_check_update_hi_metadata, update_check_update_hi_metadata_bit_size, update_check_update_post_class_id_is_zero, update_check_update_post_class_inv, update_check_update_pre_class_id_is_zero, update_check_update_pre_class_inv, update_check_update_preimage_metadata, update_check_update_preimage_post_class_id, update_check_update_preimage_pre_class_id, update_check_updated_class_ids_slot, lookup_poseidon2_hash_poseidon2_perm_counts, lookup_to_radix_limb_range_counts, lookup_to_radix_limb_less_than_radix_range_counts, lookup_to_radix_fetch_safe_limbs_counts, lookup_to_radix_fetch_p_limb_counts, lookup_to_radix_limb_p_diff_range_counts, lookup_scalar_mul_to_radix_counts, lookup_scalar_mul_double_counts, lookup_scalar_mul_add_counts, lookup_address_derivation_salted_initialization_hash_poseidon2_0_counts, lookup_address_derivation_salted_initialization_hash_poseidon2_1_counts, lookup_address_derivation_partial_address_poseidon2_counts, lookup_address_derivation_public_keys_hash_poseidon2_0_counts, lookup_address_derivation_public_keys_hash_poseidon2_1_counts, lookup_address_derivation_public_keys_hash_poseidon2_2_counts, lookup_address_derivation_public_keys_hash_poseidon2_3_counts, lookup_address_derivation_public_keys_hash_poseidon2_4_counts, lookup_address_derivation_preaddress_poseidon2_counts, lookup_address_derivation_preaddress_scalar_mul_counts, lookup_address_derivation_address_ecadd_counts, lookup_bc_decomposition_bytes_are_bytes_counts, lookup_bc_decomposition_abs_diff_is_u16_counts, lookup_bc_hashing_get_packed_field_counts, lookup_bc_hashing_iv_is_len_counts, lookup_bc_hashing_poseidon2_hash_counts, lookup_range_check_dyn_rng_chk_pow_2_counts, lookup_range_check_dyn_diff_is_u16_counts, lookup_range_check_r0_is_u16_counts, lookup_range_check_r1_is_u16_counts, lookup_range_check_r2_is_u16_counts, lookup_range_check_r3_is_u16_counts, lookup_range_check_r4_is_u16_counts, lookup_range_check_r5_is_u16_counts, lookup_range_check_r6_is_u16_counts, lookup_range_check_r7_is_u16_counts, lookup_merkle_check_merkle_poseidon2_read_counts, lookup_merkle_check_merkle_poseidon2_write_counts, lookup_ff_gt_a_lo_range_counts, lookup_ff_gt_a_hi_range_counts, lookup_public_data_read_low_leaf_poseidon2_0_counts, lookup_public_data_read_low_leaf_poseidon2_1_counts, lookup_public_data_read_low_leaf_membership_counts, lookup_public_data_read_low_leaf_slot_validation_counts, lookup_public_data_read_low_leaf_next_slot_validation_counts, lookup_update_check_shared_mutable_slot_poseidon2_counts, lookup_update_check_shared_mutable_leaf_slot_poseidon2_counts, lookup_update_check_update_hash_public_data_read_counts, lookup_update_check_update_hash_poseidon2_counts, lookup_update_check_update_hi_metadata_range_counts, lookup_update_check_update_lo_metadata_range_counts, lookup_update_check_block_of_change_cmp_range_counts, lookup_nullifier_check_low_leaf_poseidon2_counts, lookup_nullifier_check_updated_low_leaf_poseidon2_counts, lookup_nullifier_check_low_leaf_merkle_check_counts, lookup_nullifier_check_low_leaf_nullifier_validation_counts, lookup_nullifier_check_low_leaf_next_nullifier_validation_counts, lookup_nullifier_check_new_leaf_poseidon2_counts, lookup_nullifier_check_new_leaf_merkle_check_counts, lookup_bc_retrieval_silo_deployment_nullifier_poseidon2_counts, lookup_bc_retrieval_deployment_nullifier_read_counts, lookup_bc_retrieval_address_derivation_counts, lookup_bc_retrieval_update_check_counts, lookup_bc_retrieval_class_id_derivation_counts, lookup_bc_retrieval_bytecode_hash_is_correct_counts, lookup_instr_fetching_pc_abs_diff_positive_counts, lookup_instr_fetching_instr_abs_diff_positive_counts, lookup_instr_fetching_tag_value_validation_counts, lookup_instr_fetching_bytecode_size_from_bc_dec_counts, lookup_instr_fetching_bytes_from_bc_dec_counts, lookup_instr_fetching_wire_instruction_info_counts, lookup_class_id_derivation_class_id_poseidon2_0_counts, lookup_class_id_derivation_class_id_poseidon2_1_counts, lookup_bitwise_integral_tag_length_counts, lookup_bitwise_byte_operations_counts, lookup_sha256_round_constant_counts +#define AVM2_WIRE_ENTITIES execution_input, address_derivation_address, address_derivation_address_y, address_derivation_class_id, address_derivation_deployer_addr, address_derivation_g1_x, address_derivation_g1_y, address_derivation_incoming_viewing_key_x, address_derivation_incoming_viewing_key_y, address_derivation_init_hash, address_derivation_nullifier_key_x, address_derivation_nullifier_key_y, address_derivation_outgoing_viewing_key_x, address_derivation_outgoing_viewing_key_y, address_derivation_partial_address, address_derivation_partial_address_domain_separator, address_derivation_preaddress, address_derivation_preaddress_domain_separator, address_derivation_preaddress_public_key_x, address_derivation_preaddress_public_key_y, address_derivation_public_keys_hash, address_derivation_public_keys_hash_domain_separator, address_derivation_salt, address_derivation_salted_init_hash, address_derivation_sel, address_derivation_tagging_key_x, address_derivation_tagging_key_y, alu_ia, alu_ib, alu_ic, alu_op, alu_sel_op_add, bc_decomposition_abs_diff, bc_decomposition_bytes, bc_decomposition_bytes_pc_plus_1, bc_decomposition_bytes_pc_plus_10, bc_decomposition_bytes_pc_plus_11, bc_decomposition_bytes_pc_plus_12, bc_decomposition_bytes_pc_plus_13, bc_decomposition_bytes_pc_plus_14, bc_decomposition_bytes_pc_plus_15, bc_decomposition_bytes_pc_plus_16, bc_decomposition_bytes_pc_plus_17, bc_decomposition_bytes_pc_plus_18, bc_decomposition_bytes_pc_plus_19, bc_decomposition_bytes_pc_plus_2, bc_decomposition_bytes_pc_plus_20, bc_decomposition_bytes_pc_plus_21, bc_decomposition_bytes_pc_plus_22, bc_decomposition_bytes_pc_plus_23, bc_decomposition_bytes_pc_plus_24, bc_decomposition_bytes_pc_plus_25, bc_decomposition_bytes_pc_plus_26, bc_decomposition_bytes_pc_plus_27, bc_decomposition_bytes_pc_plus_28, bc_decomposition_bytes_pc_plus_29, bc_decomposition_bytes_pc_plus_3, bc_decomposition_bytes_pc_plus_30, bc_decomposition_bytes_pc_plus_31, bc_decomposition_bytes_pc_plus_32, bc_decomposition_bytes_pc_plus_33, bc_decomposition_bytes_pc_plus_34, bc_decomposition_bytes_pc_plus_35, bc_decomposition_bytes_pc_plus_36, bc_decomposition_bytes_pc_plus_4, bc_decomposition_bytes_pc_plus_5, bc_decomposition_bytes_pc_plus_6, bc_decomposition_bytes_pc_plus_7, bc_decomposition_bytes_pc_plus_8, bc_decomposition_bytes_pc_plus_9, bc_decomposition_bytes_rem_inv, bc_decomposition_bytes_rem_min_one_inv, bc_decomposition_bytes_remaining, bc_decomposition_bytes_to_read, bc_decomposition_id, bc_decomposition_last_of_contract, bc_decomposition_packed_field, bc_decomposition_pc, bc_decomposition_sel, bc_decomposition_sel_overflow_correction_needed, bc_decomposition_sel_packed, bc_hashing_bytecode_id, bc_hashing_incremental_hash, bc_hashing_latch, bc_hashing_output_hash, bc_hashing_packed_field, bc_hashing_pc_index, bc_hashing_sel, bc_hashing_start, bc_retrieval_address, bc_retrieval_artifact_hash, bc_retrieval_block_number, bc_retrieval_bytecode_id, bc_retrieval_current_class_id, bc_retrieval_deployer_addr, bc_retrieval_deployer_protocol_contract_address, bc_retrieval_err, bc_retrieval_incoming_viewing_key_x, bc_retrieval_incoming_viewing_key_y, bc_retrieval_init_hash, bc_retrieval_nullifier_exists, bc_retrieval_nullifier_key_x, bc_retrieval_nullifier_key_y, bc_retrieval_nullifier_tree_root, bc_retrieval_original_class_id, bc_retrieval_outer_nullifier_domain_separator, bc_retrieval_outgoing_viewing_key_x, bc_retrieval_outgoing_viewing_key_y, bc_retrieval_private_function_root, bc_retrieval_public_bytecode_commitment, bc_retrieval_public_data_tree_root, bc_retrieval_salt, bc_retrieval_sel, bc_retrieval_siloed_address, bc_retrieval_tagging_key_x, bc_retrieval_tagging_key_y, bitwise_acc_ia, bitwise_acc_ib, bitwise_acc_ic, bitwise_ctr, bitwise_ctr_inv, bitwise_ctr_min_one_inv, bitwise_ia_byte, bitwise_ib_byte, bitwise_ic_byte, bitwise_last, bitwise_op_id, bitwise_sel, bitwise_start, bitwise_tag, class_id_derivation_artifact_hash, class_id_derivation_class_id, class_id_derivation_private_function_root, class_id_derivation_public_bytecode_commitment, class_id_derivation_sel, class_id_derivation_temp_constant_for_lookup, context_stack_context_id, context_stack_contract_address, context_stack_is_static, context_stack_msg_sender, context_stack_parent_calldata_offset_addr, context_stack_parent_calldata_size_addr, context_stack_pc, ecc_add_op, ecc_double_op, ecc_inv_2_p_y, ecc_inv_x_diff, ecc_inv_y_diff, ecc_lambda, ecc_p_is_inf, ecc_p_x, ecc_p_y, ecc_q_is_inf, ecc_q_x, ecc_q_y, ecc_r_is_inf, ecc_r_x, ecc_r_y, ecc_result_infinity, ecc_sel, ecc_x_match, ecc_y_match, execution_addressing_error_idx, execution_addressing_error_kind, execution_base_address_tag, execution_base_address_val, execution_bytecode_id, execution_clk, execution_context_id, execution_contract_address, execution_ex_opcode, execution_indirect, execution_is_static, execution_last, execution_last_child_returndata_offset_addr, execution_last_child_returndata_size_addr, execution_last_child_success, execution_msg_sender, execution_op1, execution_op1_after_relative, execution_op2, execution_op2_after_relative, execution_op3, execution_op3_after_relative, execution_op4, execution_op4_after_relative, execution_parent_calldata_offset_addr, execution_parent_calldata_size_addr, execution_pc, execution_rop1, execution_rop2, execution_rop3, execution_rop4, execution_sel, execution_sel_addressing_error, execution_sel_op1_is_address, execution_sel_op2_is_address, execution_sel_op3_is_address, execution_sel_op4_is_address, ff_gt_a, ff_gt_a_hi, ff_gt_a_lo, ff_gt_b, ff_gt_b_hi, ff_gt_b_lo, ff_gt_borrow, ff_gt_cmp_rng_ctr, ff_gt_cmp_rng_ctr_inv, ff_gt_constant_128, ff_gt_p_a_borrow, ff_gt_p_b_borrow, ff_gt_p_sub_a_hi, ff_gt_p_sub_a_lo, ff_gt_p_sub_b_hi, ff_gt_p_sub_b_lo, ff_gt_res_hi, ff_gt_res_lo, ff_gt_result, ff_gt_sel, ff_gt_sel_gt, ff_gt_sel_shift_rng, instr_fetching_bd0, instr_fetching_bd1, instr_fetching_bd10, instr_fetching_bd11, instr_fetching_bd12, instr_fetching_bd13, instr_fetching_bd14, instr_fetching_bd15, instr_fetching_bd16, instr_fetching_bd17, instr_fetching_bd18, instr_fetching_bd19, instr_fetching_bd2, instr_fetching_bd20, instr_fetching_bd21, instr_fetching_bd22, instr_fetching_bd23, instr_fetching_bd24, instr_fetching_bd25, instr_fetching_bd26, instr_fetching_bd27, instr_fetching_bd28, instr_fetching_bd29, instr_fetching_bd3, instr_fetching_bd30, instr_fetching_bd31, instr_fetching_bd32, instr_fetching_bd33, instr_fetching_bd34, instr_fetching_bd35, instr_fetching_bd36, instr_fetching_bd4, instr_fetching_bd5, instr_fetching_bd6, instr_fetching_bd7, instr_fetching_bd8, instr_fetching_bd9, instr_fetching_bytecode_id, instr_fetching_bytecode_size, instr_fetching_bytes_to_read, instr_fetching_exec_opcode, instr_fetching_indirect, instr_fetching_instr_abs_diff, instr_fetching_instr_out_of_range, instr_fetching_instr_size, instr_fetching_op1, instr_fetching_op2, instr_fetching_op3, instr_fetching_op4, instr_fetching_op5, instr_fetching_op6, instr_fetching_op7, instr_fetching_opcode_out_of_range, instr_fetching_parsing_err, instr_fetching_pc, instr_fetching_pc_abs_diff, instr_fetching_pc_out_of_range, instr_fetching_pc_size_in_bits, instr_fetching_sel, instr_fetching_sel_has_tag, instr_fetching_sel_op_dc_0, instr_fetching_sel_op_dc_1, instr_fetching_sel_op_dc_10, instr_fetching_sel_op_dc_11, instr_fetching_sel_op_dc_12, instr_fetching_sel_op_dc_13, instr_fetching_sel_op_dc_14, instr_fetching_sel_op_dc_15, instr_fetching_sel_op_dc_16, instr_fetching_sel_op_dc_17, instr_fetching_sel_op_dc_2, instr_fetching_sel_op_dc_3, instr_fetching_sel_op_dc_4, instr_fetching_sel_op_dc_5, instr_fetching_sel_op_dc_6, instr_fetching_sel_op_dc_7, instr_fetching_sel_op_dc_8, instr_fetching_sel_op_dc_9, instr_fetching_sel_pc_in_range, instr_fetching_sel_tag_is_op2, instr_fetching_tag_out_of_range, instr_fetching_tag_value, memory_address, memory_rw, memory_sel, memory_space_id, memory_tag, memory_value, merkle_check_constant_2, merkle_check_end, merkle_check_index, merkle_check_index_is_even, merkle_check_path_len, merkle_check_read_left_node, merkle_check_read_node, merkle_check_read_output_hash, merkle_check_read_right_node, merkle_check_read_root, merkle_check_remaining_path_len_inv, merkle_check_sel, merkle_check_sibling, merkle_check_start, merkle_check_write, merkle_check_write_left_node, merkle_check_write_node, merkle_check_write_output_hash, merkle_check_write_right_node, merkle_check_write_root, nullifier_check_exists, nullifier_check_intermediate_root, nullifier_check_leaf_not_exists, nullifier_check_low_leaf_hash, nullifier_check_low_leaf_index, nullifier_check_low_leaf_next_index, nullifier_check_low_leaf_next_nullifier, nullifier_check_low_leaf_nullifier, nullifier_check_new_leaf_hash, nullifier_check_next_nullifier_inv, nullifier_check_next_nullifier_is_nonzero, nullifier_check_nullifier, nullifier_check_nullifier_low_leaf_nullifier_diff_inv, nullifier_check_one, nullifier_check_root, nullifier_check_sel, nullifier_check_tree_height, nullifier_check_tree_size_before_write, nullifier_check_updated_low_leaf_hash, nullifier_check_write, nullifier_check_write_low_leaf_next_index, nullifier_check_write_low_leaf_next_nullifier, nullifier_check_write_root, poseidon2_hash_a_0, poseidon2_hash_a_1, poseidon2_hash_a_2, poseidon2_hash_a_3, poseidon2_hash_b_0, poseidon2_hash_b_1, poseidon2_hash_b_2, poseidon2_hash_b_3, poseidon2_hash_end, poseidon2_hash_input_0, poseidon2_hash_input_1, poseidon2_hash_input_2, poseidon2_hash_input_len, poseidon2_hash_num_perm_rounds_rem, poseidon2_hash_num_perm_rounds_rem_inv, poseidon2_hash_output, poseidon2_hash_padding, poseidon2_hash_sel, poseidon2_hash_start, poseidon2_perm_B_10_0, poseidon2_perm_B_10_1, poseidon2_perm_B_10_2, poseidon2_perm_B_10_3, poseidon2_perm_B_11_0, poseidon2_perm_B_11_1, poseidon2_perm_B_11_2, poseidon2_perm_B_11_3, poseidon2_perm_B_12_0, poseidon2_perm_B_12_1, poseidon2_perm_B_12_2, poseidon2_perm_B_12_3, poseidon2_perm_B_13_0, poseidon2_perm_B_13_1, poseidon2_perm_B_13_2, poseidon2_perm_B_13_3, poseidon2_perm_B_14_0, poseidon2_perm_B_14_1, poseidon2_perm_B_14_2, poseidon2_perm_B_14_3, poseidon2_perm_B_15_0, poseidon2_perm_B_15_1, poseidon2_perm_B_15_2, poseidon2_perm_B_15_3, poseidon2_perm_B_16_0, poseidon2_perm_B_16_1, poseidon2_perm_B_16_2, poseidon2_perm_B_16_3, poseidon2_perm_B_17_0, poseidon2_perm_B_17_1, poseidon2_perm_B_17_2, poseidon2_perm_B_17_3, poseidon2_perm_B_18_0, poseidon2_perm_B_18_1, poseidon2_perm_B_18_2, poseidon2_perm_B_18_3, poseidon2_perm_B_19_0, poseidon2_perm_B_19_1, poseidon2_perm_B_19_2, poseidon2_perm_B_19_3, poseidon2_perm_B_20_0, poseidon2_perm_B_20_1, poseidon2_perm_B_20_2, poseidon2_perm_B_20_3, poseidon2_perm_B_21_0, poseidon2_perm_B_21_1, poseidon2_perm_B_21_2, poseidon2_perm_B_21_3, poseidon2_perm_B_22_0, poseidon2_perm_B_22_1, poseidon2_perm_B_22_2, poseidon2_perm_B_22_3, poseidon2_perm_B_23_0, poseidon2_perm_B_23_1, poseidon2_perm_B_23_2, poseidon2_perm_B_23_3, poseidon2_perm_B_24_0, poseidon2_perm_B_24_1, poseidon2_perm_B_24_2, poseidon2_perm_B_24_3, poseidon2_perm_B_25_0, poseidon2_perm_B_25_1, poseidon2_perm_B_25_2, poseidon2_perm_B_25_3, poseidon2_perm_B_26_0, poseidon2_perm_B_26_1, poseidon2_perm_B_26_2, poseidon2_perm_B_26_3, poseidon2_perm_B_27_0, poseidon2_perm_B_27_1, poseidon2_perm_B_27_2, poseidon2_perm_B_27_3, poseidon2_perm_B_28_0, poseidon2_perm_B_28_1, poseidon2_perm_B_28_2, poseidon2_perm_B_28_3, poseidon2_perm_B_29_0, poseidon2_perm_B_29_1, poseidon2_perm_B_29_2, poseidon2_perm_B_29_3, poseidon2_perm_B_30_0, poseidon2_perm_B_30_1, poseidon2_perm_B_30_2, poseidon2_perm_B_30_3, poseidon2_perm_B_31_0, poseidon2_perm_B_31_1, poseidon2_perm_B_31_2, poseidon2_perm_B_31_3, poseidon2_perm_B_32_0, poseidon2_perm_B_32_1, poseidon2_perm_B_32_2, poseidon2_perm_B_32_3, poseidon2_perm_B_33_0, poseidon2_perm_B_33_1, poseidon2_perm_B_33_2, poseidon2_perm_B_33_3, poseidon2_perm_B_34_0, poseidon2_perm_B_34_1, poseidon2_perm_B_34_2, poseidon2_perm_B_34_3, poseidon2_perm_B_35_0, poseidon2_perm_B_35_1, poseidon2_perm_B_35_2, poseidon2_perm_B_35_3, poseidon2_perm_B_36_0, poseidon2_perm_B_36_1, poseidon2_perm_B_36_2, poseidon2_perm_B_36_3, poseidon2_perm_B_37_0, poseidon2_perm_B_37_1, poseidon2_perm_B_37_2, poseidon2_perm_B_37_3, poseidon2_perm_B_38_0, poseidon2_perm_B_38_1, poseidon2_perm_B_38_2, poseidon2_perm_B_38_3, poseidon2_perm_B_39_0, poseidon2_perm_B_39_1, poseidon2_perm_B_39_2, poseidon2_perm_B_39_3, poseidon2_perm_B_40_0, poseidon2_perm_B_40_1, poseidon2_perm_B_40_2, poseidon2_perm_B_40_3, poseidon2_perm_B_41_0, poseidon2_perm_B_41_1, poseidon2_perm_B_41_2, poseidon2_perm_B_41_3, poseidon2_perm_B_42_0, poseidon2_perm_B_42_1, poseidon2_perm_B_42_2, poseidon2_perm_B_42_3, poseidon2_perm_B_43_0, poseidon2_perm_B_43_1, poseidon2_perm_B_43_2, poseidon2_perm_B_43_3, poseidon2_perm_B_44_0, poseidon2_perm_B_44_1, poseidon2_perm_B_44_2, poseidon2_perm_B_44_3, poseidon2_perm_B_45_0, poseidon2_perm_B_45_1, poseidon2_perm_B_45_2, poseidon2_perm_B_45_3, poseidon2_perm_B_46_0, poseidon2_perm_B_46_1, poseidon2_perm_B_46_2, poseidon2_perm_B_46_3, poseidon2_perm_B_47_0, poseidon2_perm_B_47_1, poseidon2_perm_B_47_2, poseidon2_perm_B_47_3, poseidon2_perm_B_48_0, poseidon2_perm_B_48_1, poseidon2_perm_B_48_2, poseidon2_perm_B_48_3, poseidon2_perm_B_49_0, poseidon2_perm_B_49_1, poseidon2_perm_B_49_2, poseidon2_perm_B_49_3, poseidon2_perm_B_4_0, poseidon2_perm_B_4_1, poseidon2_perm_B_4_2, poseidon2_perm_B_4_3, poseidon2_perm_B_50_0, poseidon2_perm_B_50_1, poseidon2_perm_B_50_2, poseidon2_perm_B_50_3, poseidon2_perm_B_51_0, poseidon2_perm_B_51_1, poseidon2_perm_B_51_2, poseidon2_perm_B_51_3, poseidon2_perm_B_52_0, poseidon2_perm_B_52_1, poseidon2_perm_B_52_2, poseidon2_perm_B_52_3, poseidon2_perm_B_53_0, poseidon2_perm_B_53_1, poseidon2_perm_B_53_2, poseidon2_perm_B_53_3, poseidon2_perm_B_54_0, poseidon2_perm_B_54_1, poseidon2_perm_B_54_2, poseidon2_perm_B_54_3, poseidon2_perm_B_55_0, poseidon2_perm_B_55_1, poseidon2_perm_B_55_2, poseidon2_perm_B_55_3, poseidon2_perm_B_56_0, poseidon2_perm_B_56_1, poseidon2_perm_B_56_2, poseidon2_perm_B_56_3, poseidon2_perm_B_57_0, poseidon2_perm_B_57_1, poseidon2_perm_B_57_2, poseidon2_perm_B_57_3, poseidon2_perm_B_58_0, poseidon2_perm_B_58_1, poseidon2_perm_B_58_2, poseidon2_perm_B_58_3, poseidon2_perm_B_59_0, poseidon2_perm_B_59_1, poseidon2_perm_B_59_2, poseidon2_perm_B_59_3, poseidon2_perm_B_5_0, poseidon2_perm_B_5_1, poseidon2_perm_B_5_2, poseidon2_perm_B_5_3, poseidon2_perm_B_6_0, poseidon2_perm_B_6_1, poseidon2_perm_B_6_2, poseidon2_perm_B_6_3, poseidon2_perm_B_7_0, poseidon2_perm_B_7_1, poseidon2_perm_B_7_2, poseidon2_perm_B_7_3, poseidon2_perm_B_8_0, poseidon2_perm_B_8_1, poseidon2_perm_B_8_2, poseidon2_perm_B_8_3, poseidon2_perm_B_9_0, poseidon2_perm_B_9_1, poseidon2_perm_B_9_2, poseidon2_perm_B_9_3, poseidon2_perm_EXT_LAYER_4, poseidon2_perm_EXT_LAYER_5, poseidon2_perm_EXT_LAYER_6, poseidon2_perm_EXT_LAYER_7, poseidon2_perm_T_0_4, poseidon2_perm_T_0_5, poseidon2_perm_T_0_6, poseidon2_perm_T_0_7, poseidon2_perm_T_1_4, poseidon2_perm_T_1_5, poseidon2_perm_T_1_6, poseidon2_perm_T_1_7, poseidon2_perm_T_2_4, poseidon2_perm_T_2_5, poseidon2_perm_T_2_6, poseidon2_perm_T_2_7, poseidon2_perm_T_3_4, poseidon2_perm_T_3_5, poseidon2_perm_T_3_6, poseidon2_perm_T_3_7, poseidon2_perm_T_60_4, poseidon2_perm_T_60_5, poseidon2_perm_T_60_6, poseidon2_perm_T_60_7, poseidon2_perm_T_61_4, poseidon2_perm_T_61_5, poseidon2_perm_T_61_6, poseidon2_perm_T_61_7, poseidon2_perm_T_62_4, poseidon2_perm_T_62_5, poseidon2_perm_T_62_6, poseidon2_perm_T_62_7, poseidon2_perm_T_63_4, poseidon2_perm_T_63_5, poseidon2_perm_T_63_6, poseidon2_perm_T_63_7, poseidon2_perm_a_0, poseidon2_perm_a_1, poseidon2_perm_a_2, poseidon2_perm_a_3, poseidon2_perm_b_0, poseidon2_perm_b_1, poseidon2_perm_b_2, poseidon2_perm_b_3, poseidon2_perm_sel, public_data_read_leaf_not_exists, public_data_read_low_leaf_hash, public_data_read_low_leaf_index, public_data_read_low_leaf_next_index, public_data_read_low_leaf_next_slot, public_data_read_low_leaf_slot, public_data_read_low_leaf_value, public_data_read_next_slot_inv, public_data_read_next_slot_is_nonzero, public_data_read_one, public_data_read_root, public_data_read_sel, public_data_read_slot, public_data_read_slot_low_leaf_slot_diff_inv, public_data_read_tree_height, public_data_read_value, range_check_dyn_diff, range_check_dyn_rng_chk_bits, range_check_dyn_rng_chk_pow_2, range_check_is_lte_u112, range_check_is_lte_u128, range_check_is_lte_u16, range_check_is_lte_u32, range_check_is_lte_u48, range_check_is_lte_u64, range_check_is_lte_u80, range_check_is_lte_u96, range_check_rng_chk_bits, range_check_sel, range_check_sel_r0_16_bit_rng_lookup, range_check_sel_r1_16_bit_rng_lookup, range_check_sel_r2_16_bit_rng_lookup, range_check_sel_r3_16_bit_rng_lookup, range_check_sel_r4_16_bit_rng_lookup, range_check_sel_r5_16_bit_rng_lookup, range_check_sel_r6_16_bit_rng_lookup, range_check_u16_r0, range_check_u16_r1, range_check_u16_r2, range_check_u16_r3, range_check_u16_r4, range_check_u16_r5, range_check_u16_r6, range_check_u16_r7, range_check_value, scalar_mul_bit, scalar_mul_bit_idx, scalar_mul_bit_radix, scalar_mul_end, scalar_mul_not_end, scalar_mul_point_inf, scalar_mul_point_x, scalar_mul_point_y, scalar_mul_res_inf, scalar_mul_res_x, scalar_mul_res_y, scalar_mul_scalar, scalar_mul_sel, scalar_mul_should_add, scalar_mul_start, scalar_mul_temp_inf, scalar_mul_temp_x, scalar_mul_temp_y, sha256_a, sha256_a_and_b, sha256_a_and_b_xor_a_and_c, sha256_a_and_c, sha256_a_rotr_13, sha256_a_rotr_2, sha256_a_rotr_22, sha256_a_rotr_2_xor_a_rotr_13, sha256_and_sel, sha256_b, sha256_b_and_c, sha256_c, sha256_ch, sha256_clk, sha256_computed_w_lhs, sha256_computed_w_rhs, sha256_d, sha256_e, sha256_e_and_f, sha256_e_rotr_11, sha256_e_rotr_25, sha256_e_rotr_6, sha256_e_rotr_6_xor_e_rotr_11, sha256_f, sha256_g, sha256_h, sha256_helper_w0, sha256_helper_w1, sha256_helper_w10, sha256_helper_w11, sha256_helper_w12, sha256_helper_w13, sha256_helper_w14, sha256_helper_w15, sha256_helper_w2, sha256_helper_w3, sha256_helper_w4, sha256_helper_w5, sha256_helper_w6, sha256_helper_w7, sha256_helper_w8, sha256_helper_w9, sha256_init_a, sha256_init_b, sha256_init_c, sha256_init_d, sha256_init_e, sha256_init_f, sha256_init_g, sha256_init_h, sha256_input_offset, sha256_is_input_round, sha256_latch, sha256_lhs_a_13, sha256_lhs_a_2, sha256_lhs_a_22, sha256_lhs_e_11, sha256_lhs_e_25, sha256_lhs_e_6, sha256_lhs_w_10, sha256_lhs_w_17, sha256_lhs_w_18, sha256_lhs_w_19, sha256_lhs_w_3, sha256_lhs_w_7, sha256_maj, sha256_next_a_lhs, sha256_next_a_rhs, sha256_next_e_lhs, sha256_next_e_rhs, sha256_not_e, sha256_not_e_and_g, sha256_output_a_lhs, sha256_output_a_rhs, sha256_output_b_lhs, sha256_output_b_rhs, sha256_output_c_lhs, sha256_output_c_rhs, sha256_output_d_lhs, sha256_output_d_rhs, sha256_output_e_lhs, sha256_output_e_rhs, sha256_output_f_lhs, sha256_output_f_rhs, sha256_output_g_lhs, sha256_output_g_rhs, sha256_output_h_lhs, sha256_output_h_rhs, sha256_output_offset, sha256_perform_round, sha256_rhs_a_13, sha256_rhs_a_2, sha256_rhs_a_22, sha256_rhs_e_11, sha256_rhs_e_25, sha256_rhs_e_6, sha256_rhs_w_10, sha256_rhs_w_17, sha256_rhs_w_18, sha256_rhs_w_19, sha256_rhs_w_3, sha256_rhs_w_7, sha256_round_constant, sha256_round_count, sha256_rounds_remaining, sha256_rounds_remaining_inv, sha256_s_0, sha256_s_1, sha256_sel, sha256_start, sha256_state_offset, sha256_w, sha256_w_15_rotr_18, sha256_w_15_rotr_7, sha256_w_15_rotr_7_xor_w_15_rotr_18, sha256_w_15_rshift_3, sha256_w_2_rotr_17, sha256_w_2_rotr_17_xor_w_2_rotr_19, sha256_w_2_rotr_19, sha256_w_2_rshift_10, sha256_w_s_0, sha256_w_s_1, sha256_xor_sel, to_radix_acc, to_radix_acc_under_p, to_radix_end, to_radix_exponent, to_radix_found, to_radix_is_unsafe_limb, to_radix_limb, to_radix_limb_eq_p, to_radix_limb_index, to_radix_limb_lt_p, to_radix_limb_p_diff, to_radix_limb_radix_diff, to_radix_not_end, to_radix_not_padding_limb, to_radix_p_limb, to_radix_radix, to_radix_rem_inverse, to_radix_safe_limbs, to_radix_safety_diff_inverse, to_radix_sel, to_radix_start, to_radix_value, update_check_address, update_check_block_number, update_check_block_number_bit_size, update_check_block_number_is_lt_block_of_change, update_check_block_of_change_subtraction, update_check_current_class_id, update_check_deployer_protocol_contract_address, update_check_hash_not_zero, update_check_original_class_id, update_check_public_data_tree_root, update_check_public_leaf_index_domain_separator, update_check_sel, update_check_shared_mutable_hash_slot, update_check_shared_mutable_leaf_slot, update_check_shared_mutable_slot, update_check_update_block_of_change, update_check_update_hash, update_check_update_hash_inv, update_check_update_hi_metadata, update_check_update_hi_metadata_bit_size, update_check_update_post_class_id_is_zero, update_check_update_post_class_inv, update_check_update_pre_class_id_is_zero, update_check_update_pre_class_inv, update_check_update_preimage_metadata, update_check_update_preimage_post_class_id, update_check_update_preimage_pre_class_id, update_check_updated_class_ids_slot, lookup_poseidon2_hash_poseidon2_perm_counts, lookup_to_radix_limb_range_counts, lookup_to_radix_limb_less_than_radix_range_counts, lookup_to_radix_fetch_safe_limbs_counts, lookup_to_radix_fetch_p_limb_counts, lookup_to_radix_limb_p_diff_range_counts, lookup_scalar_mul_to_radix_counts, lookup_scalar_mul_double_counts, lookup_scalar_mul_add_counts, lookup_address_derivation_salted_initialization_hash_poseidon2_0_counts, lookup_address_derivation_salted_initialization_hash_poseidon2_1_counts, lookup_address_derivation_partial_address_poseidon2_counts, lookup_address_derivation_public_keys_hash_poseidon2_0_counts, lookup_address_derivation_public_keys_hash_poseidon2_1_counts, lookup_address_derivation_public_keys_hash_poseidon2_2_counts, lookup_address_derivation_public_keys_hash_poseidon2_3_counts, lookup_address_derivation_public_keys_hash_poseidon2_4_counts, lookup_address_derivation_preaddress_poseidon2_counts, lookup_address_derivation_preaddress_scalar_mul_counts, lookup_address_derivation_address_ecadd_counts, lookup_bc_decomposition_bytes_are_bytes_counts, lookup_bc_decomposition_abs_diff_is_u16_counts, lookup_bc_hashing_get_packed_field_counts, lookup_bc_hashing_iv_is_len_counts, lookup_bc_hashing_poseidon2_hash_counts, lookup_range_check_dyn_rng_chk_pow_2_counts, lookup_range_check_dyn_diff_is_u16_counts, lookup_range_check_r0_is_u16_counts, lookup_range_check_r1_is_u16_counts, lookup_range_check_r2_is_u16_counts, lookup_range_check_r3_is_u16_counts, lookup_range_check_r4_is_u16_counts, lookup_range_check_r5_is_u16_counts, lookup_range_check_r6_is_u16_counts, lookup_range_check_r7_is_u16_counts, lookup_merkle_check_merkle_poseidon2_read_counts, lookup_merkle_check_merkle_poseidon2_write_counts, lookup_ff_gt_a_lo_range_counts, lookup_ff_gt_a_hi_range_counts, lookup_public_data_read_low_leaf_poseidon2_0_counts, lookup_public_data_read_low_leaf_poseidon2_1_counts, lookup_public_data_read_low_leaf_membership_counts, lookup_public_data_read_low_leaf_slot_validation_counts, lookup_public_data_read_low_leaf_next_slot_validation_counts, lookup_update_check_shared_mutable_slot_poseidon2_counts, lookup_update_check_shared_mutable_leaf_slot_poseidon2_counts, lookup_update_check_update_hash_public_data_read_counts, lookup_update_check_update_hash_poseidon2_counts, lookup_update_check_update_hi_metadata_range_counts, lookup_update_check_update_lo_metadata_range_counts, lookup_update_check_block_of_change_cmp_range_counts, lookup_nullifier_check_low_leaf_poseidon2_counts, lookup_nullifier_check_updated_low_leaf_poseidon2_counts, lookup_nullifier_check_low_leaf_merkle_check_counts, lookup_nullifier_check_low_leaf_nullifier_validation_counts, lookup_nullifier_check_low_leaf_next_nullifier_validation_counts, lookup_nullifier_check_new_leaf_poseidon2_counts, lookup_nullifier_check_new_leaf_merkle_check_counts, lookup_bc_retrieval_silo_deployment_nullifier_poseidon2_counts, lookup_bc_retrieval_deployment_nullifier_read_counts, lookup_bc_retrieval_address_derivation_counts, lookup_bc_retrieval_update_check_counts, lookup_bc_retrieval_class_id_derivation_counts, lookup_bc_retrieval_bytecode_hash_is_correct_counts, lookup_instr_fetching_pc_abs_diff_positive_counts, lookup_instr_fetching_instr_abs_diff_positive_counts, lookup_instr_fetching_tag_value_validation_counts, lookup_instr_fetching_bytecode_size_from_bc_dec_counts, lookup_instr_fetching_bytes_from_bc_dec_counts, lookup_instr_fetching_wire_instruction_info_counts, lookup_class_id_derivation_class_id_poseidon2_0_counts, lookup_class_id_derivation_class_id_poseidon2_1_counts, lookup_bitwise_integral_tag_length_counts, lookup_bitwise_byte_operations_counts, lookup_sha256_round_constant_counts #define AVM2_DERIVED_WITNESS_ENTITIES lookup_poseidon2_hash_poseidon2_perm_inv, lookup_to_radix_limb_range_inv, lookup_to_radix_limb_less_than_radix_range_inv, lookup_to_radix_fetch_safe_limbs_inv, lookup_to_radix_fetch_p_limb_inv, lookup_to_radix_limb_p_diff_range_inv, lookup_scalar_mul_to_radix_inv, lookup_scalar_mul_double_inv, lookup_scalar_mul_add_inv, lookup_address_derivation_salted_initialization_hash_poseidon2_0_inv, lookup_address_derivation_salted_initialization_hash_poseidon2_1_inv, lookup_address_derivation_partial_address_poseidon2_inv, lookup_address_derivation_public_keys_hash_poseidon2_0_inv, lookup_address_derivation_public_keys_hash_poseidon2_1_inv, lookup_address_derivation_public_keys_hash_poseidon2_2_inv, lookup_address_derivation_public_keys_hash_poseidon2_3_inv, lookup_address_derivation_public_keys_hash_poseidon2_4_inv, lookup_address_derivation_preaddress_poseidon2_inv, lookup_address_derivation_preaddress_scalar_mul_inv, lookup_address_derivation_address_ecadd_inv, lookup_bc_decomposition_bytes_are_bytes_inv, lookup_bc_decomposition_abs_diff_is_u16_inv, lookup_bc_hashing_get_packed_field_inv, lookup_bc_hashing_iv_is_len_inv, lookup_bc_hashing_poseidon2_hash_inv, lookup_range_check_dyn_rng_chk_pow_2_inv, lookup_range_check_dyn_diff_is_u16_inv, lookup_range_check_r0_is_u16_inv, lookup_range_check_r1_is_u16_inv, lookup_range_check_r2_is_u16_inv, lookup_range_check_r3_is_u16_inv, lookup_range_check_r4_is_u16_inv, lookup_range_check_r5_is_u16_inv, lookup_range_check_r6_is_u16_inv, lookup_range_check_r7_is_u16_inv, lookup_merkle_check_merkle_poseidon2_read_inv, lookup_merkle_check_merkle_poseidon2_write_inv, lookup_ff_gt_a_lo_range_inv, lookup_ff_gt_a_hi_range_inv, lookup_public_data_read_low_leaf_poseidon2_0_inv, lookup_public_data_read_low_leaf_poseidon2_1_inv, lookup_public_data_read_low_leaf_membership_inv, lookup_public_data_read_low_leaf_slot_validation_inv, lookup_public_data_read_low_leaf_next_slot_validation_inv, lookup_update_check_shared_mutable_slot_poseidon2_inv, lookup_update_check_shared_mutable_leaf_slot_poseidon2_inv, lookup_update_check_update_hash_public_data_read_inv, lookup_update_check_update_hash_poseidon2_inv, lookup_update_check_update_hi_metadata_range_inv, lookup_update_check_update_lo_metadata_range_inv, lookup_update_check_block_of_change_cmp_range_inv, lookup_nullifier_check_low_leaf_poseidon2_inv, lookup_nullifier_check_updated_low_leaf_poseidon2_inv, lookup_nullifier_check_low_leaf_merkle_check_inv, lookup_nullifier_check_low_leaf_nullifier_validation_inv, lookup_nullifier_check_low_leaf_next_nullifier_validation_inv, lookup_nullifier_check_new_leaf_poseidon2_inv, lookup_nullifier_check_new_leaf_merkle_check_inv, lookup_bc_retrieval_silo_deployment_nullifier_poseidon2_inv, lookup_bc_retrieval_deployment_nullifier_read_inv, lookup_bc_retrieval_address_derivation_inv, lookup_bc_retrieval_update_check_inv, lookup_bc_retrieval_class_id_derivation_inv, lookup_bc_retrieval_bytecode_hash_is_correct_inv, lookup_instr_fetching_pc_abs_diff_positive_inv, lookup_instr_fetching_instr_abs_diff_positive_inv, lookup_instr_fetching_tag_value_validation_inv, lookup_instr_fetching_bytecode_size_from_bc_dec_inv, lookup_instr_fetching_bytes_from_bc_dec_inv, lookup_instr_fetching_wire_instruction_info_inv, lookup_class_id_derivation_class_id_poseidon2_0_inv, lookup_class_id_derivation_class_id_poseidon2_1_inv, lookup_bitwise_integral_tag_length_inv, lookup_bitwise_byte_operations_inv, lookup_sha256_round_constant_inv #define AVM2_SHIFTED_ENTITIES bc_decomposition_bytes_shift, bc_decomposition_bytes_pc_plus_1_shift, bc_decomposition_bytes_pc_plus_10_shift, bc_decomposition_bytes_pc_plus_11_shift, bc_decomposition_bytes_pc_plus_12_shift, bc_decomposition_bytes_pc_plus_13_shift, bc_decomposition_bytes_pc_plus_14_shift, bc_decomposition_bytes_pc_plus_15_shift, bc_decomposition_bytes_pc_plus_16_shift, bc_decomposition_bytes_pc_plus_17_shift, bc_decomposition_bytes_pc_plus_18_shift, bc_decomposition_bytes_pc_plus_19_shift, bc_decomposition_bytes_pc_plus_2_shift, bc_decomposition_bytes_pc_plus_20_shift, bc_decomposition_bytes_pc_plus_21_shift, bc_decomposition_bytes_pc_plus_22_shift, bc_decomposition_bytes_pc_plus_23_shift, bc_decomposition_bytes_pc_plus_24_shift, bc_decomposition_bytes_pc_plus_25_shift, bc_decomposition_bytes_pc_plus_26_shift, bc_decomposition_bytes_pc_plus_27_shift, bc_decomposition_bytes_pc_plus_28_shift, bc_decomposition_bytes_pc_plus_29_shift, bc_decomposition_bytes_pc_plus_3_shift, bc_decomposition_bytes_pc_plus_30_shift, bc_decomposition_bytes_pc_plus_31_shift, bc_decomposition_bytes_pc_plus_32_shift, bc_decomposition_bytes_pc_plus_33_shift, bc_decomposition_bytes_pc_plus_34_shift, bc_decomposition_bytes_pc_plus_35_shift, bc_decomposition_bytes_pc_plus_4_shift, bc_decomposition_bytes_pc_plus_5_shift, bc_decomposition_bytes_pc_plus_6_shift, bc_decomposition_bytes_pc_plus_7_shift, bc_decomposition_bytes_pc_plus_8_shift, bc_decomposition_bytes_pc_plus_9_shift, bc_decomposition_bytes_remaining_shift, bc_decomposition_id_shift, bc_decomposition_pc_shift, bc_decomposition_sel_shift, bc_hashing_bytecode_id_shift, bc_hashing_incremental_hash_shift, bc_hashing_pc_index_shift, bc_hashing_sel_shift, bc_hashing_start_shift, bitwise_acc_ia_shift, bitwise_acc_ib_shift, bitwise_acc_ic_shift, bitwise_ctr_shift, bitwise_op_id_shift, execution_sel_shift, ff_gt_a_hi_shift, ff_gt_a_lo_shift, ff_gt_b_hi_shift, ff_gt_b_lo_shift, ff_gt_cmp_rng_ctr_shift, ff_gt_p_sub_a_hi_shift, ff_gt_p_sub_a_lo_shift, ff_gt_p_sub_b_hi_shift, ff_gt_p_sub_b_lo_shift, ff_gt_sel_shift, ff_gt_sel_gt_shift, merkle_check_index_shift, merkle_check_path_len_shift, merkle_check_read_node_shift, merkle_check_read_root_shift, merkle_check_sel_shift, merkle_check_start_shift, merkle_check_write_shift, merkle_check_write_node_shift, merkle_check_write_root_shift, poseidon2_hash_a_0_shift, poseidon2_hash_a_1_shift, poseidon2_hash_a_2_shift, poseidon2_hash_a_3_shift, poseidon2_hash_input_0_shift, poseidon2_hash_input_1_shift, poseidon2_hash_input_2_shift, poseidon2_hash_num_perm_rounds_rem_shift, poseidon2_hash_output_shift, poseidon2_hash_sel_shift, poseidon2_hash_start_shift, scalar_mul_bit_idx_shift, scalar_mul_point_inf_shift, scalar_mul_point_x_shift, scalar_mul_point_y_shift, scalar_mul_res_inf_shift, scalar_mul_res_x_shift, scalar_mul_res_y_shift, scalar_mul_scalar_shift, scalar_mul_sel_shift, scalar_mul_start_shift, scalar_mul_temp_inf_shift, scalar_mul_temp_x_shift, scalar_mul_temp_y_shift, sha256_a_shift, sha256_b_shift, sha256_c_shift, sha256_d_shift, sha256_e_shift, sha256_f_shift, sha256_g_shift, sha256_h_shift, sha256_helper_w0_shift, sha256_helper_w1_shift, sha256_helper_w10_shift, sha256_helper_w11_shift, sha256_helper_w12_shift, sha256_helper_w13_shift, sha256_helper_w14_shift, sha256_helper_w15_shift, sha256_helper_w2_shift, sha256_helper_w3_shift, sha256_helper_w4_shift, sha256_helper_w5_shift, sha256_helper_w6_shift, sha256_helper_w7_shift, sha256_helper_w8_shift, sha256_helper_w9_shift, sha256_rounds_remaining_shift, sha256_sel_shift, sha256_start_shift, to_radix_acc_shift, to_radix_acc_under_p_shift, to_radix_exponent_shift, to_radix_limb_shift, to_radix_limb_eq_p_shift, to_radix_limb_index_shift, to_radix_limb_lt_p_shift, to_radix_not_padding_limb_shift, to_radix_radix_shift, to_radix_safe_limbs_shift, to_radix_sel_shift, to_radix_start_shift, to_radix_value_shift #define AVM2_TO_BE_SHIFTED(e) e.bc_decomposition_bytes, e.bc_decomposition_bytes_pc_plus_1, e.bc_decomposition_bytes_pc_plus_10, e.bc_decomposition_bytes_pc_plus_11, e.bc_decomposition_bytes_pc_plus_12, e.bc_decomposition_bytes_pc_plus_13, e.bc_decomposition_bytes_pc_plus_14, e.bc_decomposition_bytes_pc_plus_15, e.bc_decomposition_bytes_pc_plus_16, e.bc_decomposition_bytes_pc_plus_17, e.bc_decomposition_bytes_pc_plus_18, e.bc_decomposition_bytes_pc_plus_19, e.bc_decomposition_bytes_pc_plus_2, e.bc_decomposition_bytes_pc_plus_20, e.bc_decomposition_bytes_pc_plus_21, e.bc_decomposition_bytes_pc_plus_22, e.bc_decomposition_bytes_pc_plus_23, e.bc_decomposition_bytes_pc_plus_24, e.bc_decomposition_bytes_pc_plus_25, e.bc_decomposition_bytes_pc_plus_26, e.bc_decomposition_bytes_pc_plus_27, e.bc_decomposition_bytes_pc_plus_28, e.bc_decomposition_bytes_pc_plus_29, e.bc_decomposition_bytes_pc_plus_3, e.bc_decomposition_bytes_pc_plus_30, e.bc_decomposition_bytes_pc_plus_31, e.bc_decomposition_bytes_pc_plus_32, e.bc_decomposition_bytes_pc_plus_33, e.bc_decomposition_bytes_pc_plus_34, e.bc_decomposition_bytes_pc_plus_35, e.bc_decomposition_bytes_pc_plus_4, e.bc_decomposition_bytes_pc_plus_5, e.bc_decomposition_bytes_pc_plus_6, e.bc_decomposition_bytes_pc_plus_7, e.bc_decomposition_bytes_pc_plus_8, e.bc_decomposition_bytes_pc_plus_9, e.bc_decomposition_bytes_remaining, e.bc_decomposition_id, e.bc_decomposition_pc, e.bc_decomposition_sel, e.bc_hashing_bytecode_id, e.bc_hashing_incremental_hash, e.bc_hashing_pc_index, e.bc_hashing_sel, e.bc_hashing_start, e.bitwise_acc_ia, e.bitwise_acc_ib, e.bitwise_acc_ic, e.bitwise_ctr, e.bitwise_op_id, e.execution_sel, e.ff_gt_a_hi, e.ff_gt_a_lo, e.ff_gt_b_hi, e.ff_gt_b_lo, e.ff_gt_cmp_rng_ctr, e.ff_gt_p_sub_a_hi, e.ff_gt_p_sub_a_lo, e.ff_gt_p_sub_b_hi, e.ff_gt_p_sub_b_lo, e.ff_gt_sel, e.ff_gt_sel_gt, e.merkle_check_index, e.merkle_check_path_len, e.merkle_check_read_node, e.merkle_check_read_root, e.merkle_check_sel, e.merkle_check_start, e.merkle_check_write, e.merkle_check_write_node, e.merkle_check_write_root, e.poseidon2_hash_a_0, e.poseidon2_hash_a_1, e.poseidon2_hash_a_2, e.poseidon2_hash_a_3, e.poseidon2_hash_input_0, e.poseidon2_hash_input_1, e.poseidon2_hash_input_2, e.poseidon2_hash_num_perm_rounds_rem, e.poseidon2_hash_output, e.poseidon2_hash_sel, e.poseidon2_hash_start, e.scalar_mul_bit_idx, e.scalar_mul_point_inf, e.scalar_mul_point_x, e.scalar_mul_point_y, e.scalar_mul_res_inf, e.scalar_mul_res_x, e.scalar_mul_res_y, e.scalar_mul_scalar, e.scalar_mul_sel, e.scalar_mul_start, e.scalar_mul_temp_inf, e.scalar_mul_temp_x, e.scalar_mul_temp_y, e.sha256_a, e.sha256_b, e.sha256_c, e.sha256_d, e.sha256_e, e.sha256_f, e.sha256_g, e.sha256_h, e.sha256_helper_w0, e.sha256_helper_w1, e.sha256_helper_w10, e.sha256_helper_w11, e.sha256_helper_w12, e.sha256_helper_w13, e.sha256_helper_w14, e.sha256_helper_w15, e.sha256_helper_w2, e.sha256_helper_w3, e.sha256_helper_w4, e.sha256_helper_w5, e.sha256_helper_w6, e.sha256_helper_w7, e.sha256_helper_w8, e.sha256_helper_w9, e.sha256_rounds_remaining, e.sha256_sel, e.sha256_start, e.to_radix_acc, e.to_radix_acc_under_p, e.to_radix_exponent, e.to_radix_limb, e.to_radix_limb_eq_p, e.to_radix_limb_index, e.to_radix_limb_lt_p, e.to_radix_not_padding_limb, e.to_radix_radix, e.to_radix_safe_limbs, e.to_radix_sel, e.to_radix_start, e.to_radix_value @@ -31,8 +31,8 @@ enum class ColumnAndShifts { SENTINEL_DO_NOT_USE, }; -constexpr auto NUM_COLUMNS_WITH_SHIFTS = 1200; -constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 1065; +constexpr auto NUM_COLUMNS_WITH_SHIFTS = 1206; +constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 1071; constexpr auto TO_BE_SHIFTED_COLUMNS_ARRAY = []() { return std::array{ AVM2_TO_BE_SHIFTED_COLUMNS }; }(); constexpr auto SHIFTED_COLUMNS_ARRAY = []() { return std::array{ AVM2_SHIFTED_COLUMNS }; }(); static_assert(TO_BE_SHIFTED_COLUMNS_ARRAY.size() == SHIFTED_COLUMNS_ARRAY.size()); diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/flavor_variables.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor_variables.hpp index e084188de03f..46926a182479 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/flavor_variables.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor_variables.hpp @@ -15,6 +15,7 @@ #include "relations/execution.hpp" #include "relations/ff_gt.hpp" #include "relations/instr_fetching.hpp" +#include "relations/memory.hpp" #include "relations/merkle_check.hpp" #include "relations/nullifier_check.hpp" #include "relations/poseidon2_hash.hpp" @@ -49,10 +50,10 @@ namespace bb::avm2 { struct AvmFlavorVariables { static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 45; - static constexpr size_t NUM_WITNESS_ENTITIES = 1020; + static constexpr size_t NUM_WITNESS_ENTITIES = 1026; static constexpr size_t NUM_SHIFTED_ENTITIES = 135; static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; - static constexpr size_t NUM_ALL_ENTITIES = 1200; + static constexpr size_t NUM_ALL_ENTITIES = 1206; // Need to be templated for recursive verifier template @@ -71,6 +72,7 @@ struct AvmFlavorVariables { avm2::execution, avm2::ff_gt, avm2::instr_fetching, + avm2::memory, avm2::merkle_check, avm2::nullifier_check, avm2::poseidon2_hash, diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/memory.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/memory.hpp new file mode 100644 index 000000000000..57e217524fef --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/memory.hpp @@ -0,0 +1,56 @@ +// AUTOGENERATED FILE +#pragma once + +#include + +#include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/relations/relation_types.hpp" + +namespace bb::avm2 { + +template class memoryImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3 }; + + template inline static bool skip(const AllEntities& in) + { + const auto& new_term = in; + return (new_term.memory_sel).is_zero(); + } + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + + { + using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; + auto tmp = new_term.memory_sel * (new_term.memory_sel - FF(1)); + tmp *= scaling_factor; + std::get<0>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>; + auto tmp = new_term.memory_rw * (FF(1) - new_term.memory_rw); + tmp *= scaling_factor; + std::get<1>(evals) += typename Accumulator::View(tmp); + } + } +}; + +template class memory : public Relation> { + public: + static constexpr const std::string_view NAME = "memory"; + + static std::string get_subrelation_label(size_t index) + { + switch (index) {} + return std::to_string(index); + } +}; + +} // namespace bb::avm2 diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.cpp index 63659048176e..bf0c044cd101 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.cpp @@ -19,7 +19,7 @@ std::unique_ptr ExecutionComponentsProvider::make_nested_conte msg_sender, is_static, std::make_unique(address, tx_bytecode_manager), - std::make_unique(context_id, memory_events), + std::make_unique(context_id, range_check, memory_events), parent_context, cd_offset_address, cd_size_address); @@ -37,7 +37,7 @@ std::unique_ptr ExecutionComponentsProvider::make_enqueued_con msg_sender, is_static, std::make_unique(address, tx_bytecode_manager), - std::make_unique(context_id, memory_events), + std::make_unique(context_id, range_check, memory_events), calldata); } diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.hpp index 2d1acf88c4ad..3680616df949 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/execution_components.hpp @@ -13,6 +13,7 @@ #include "barretenberg/vm2/simulation/events/event_emitter.hpp" #include "barretenberg/vm2/simulation/events/memory_event.hpp" #include "barretenberg/vm2/simulation/memory.hpp" +#include "barretenberg/vm2/simulation/range_check.hpp" namespace bb::avm2::simulation { @@ -39,9 +40,11 @@ class ExecutionComponentsProviderInterface { class ExecutionComponentsProvider : public ExecutionComponentsProviderInterface { public: ExecutionComponentsProvider(TxBytecodeManagerInterface& tx_bytecode_manager, + RangeCheckInterface& range_check, EventEmitterInterface& memory_events, const InstructionInfoDBInterface& instruction_info_db) : tx_bytecode_manager(tx_bytecode_manager) + , range_check(range_check) , memory_events(memory_events) , instruction_info_db(instruction_info_db) {} @@ -61,6 +64,7 @@ class ExecutionComponentsProvider : public ExecutionComponentsProviderInterface uint32_t next_context_id = 0; TxBytecodeManagerInterface& tx_bytecode_manager; + RangeCheckInterface& range_check; EventEmitterInterface& memory_events; const InstructionInfoDBInterface& instruction_info_db; diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.cpp index c63ed7cb8884..5ff6fa169163 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.cpp @@ -4,6 +4,7 @@ #include #include "barretenberg/common/log.hpp" +#include "barretenberg/numeric/uint128/uint128.hpp" #include "barretenberg/vm2/common/memory_types.hpp" namespace bb::avm2::simulation { @@ -21,7 +22,9 @@ bool MemoryInterface::is_valid_address(const MemoryValue& address) void Memory::set(MemoryAddress index, MemoryValue value) { - // TODO: validate tag-value makes sense. + // TODO: validate address? + // TODO: reconsider tag validation. + validate_tag(value); memory[index] = value; debug("Memory write: ", index, " <- ", value.to_string()); events.emit({ .mode = MemoryMode::WRITE, .addr = index, .value = value, .space_id = space_id }); @@ -29,6 +32,7 @@ void Memory::set(MemoryAddress index, MemoryValue value) const MemoryValue& Memory::get(MemoryAddress index) const { + // TODO: validate address? static const auto default_value = MemoryValue::from(0); auto it = memory.find(index); @@ -39,4 +43,17 @@ const MemoryValue& Memory::get(MemoryAddress index) const return vt; } +// Sadly this is circuit leaking. In simulation we know the tag-value is consistent. +// But the circuit does need to force a range check. +void Memory::validate_tag(const MemoryValue& value) const +{ + if (value.get_tag() == MemoryTag::FF) { + return; + } + + uint128_t value_as_uint128 = static_cast(value.as_ff()); + auto tag_bits = get_tag_bits(value.get_tag()); + range_check.assert_range(value_as_uint128, tag_bits); +} + } // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.hpp index 4ee72dc5267d..80213f21769f 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/memory.hpp @@ -6,6 +6,7 @@ #include "barretenberg/vm2/common/memory_types.hpp" #include "barretenberg/vm2/simulation/events/event_emitter.hpp" #include "barretenberg/vm2/simulation/events/memory_event.hpp" +#include "barretenberg/vm2/simulation/range_check.hpp" namespace bb::avm2::simulation { @@ -26,8 +27,9 @@ class MemoryInterface { class Memory : public MemoryInterface { public: - Memory(uint32_t space_id, EventEmitterInterface& event_emitter) + Memory(uint32_t space_id, RangeCheckInterface& range_check, EventEmitterInterface& event_emitter) : space_id(space_id) + , range_check(range_check) , events(event_emitter) {} @@ -39,7 +41,33 @@ class Memory : public MemoryInterface { private: uint32_t space_id; unordered_flat_map memory; + + RangeCheckInterface& range_check; + // TODO: consider a deduplicating event emitter (within the same clk). EventEmitterInterface& events; + + void validate_tag(const MemoryValue& value) const; +}; + +// Just a map that doesn't emit events or do anything else. +class MemoryStore : public MemoryInterface { + public: + MemoryStore(uint32_t space_id = 0) + : space_id(space_id) + {} + + const MemoryValue& get(MemoryAddress index) const override + { + static const auto default_value = MemoryValue::from(0); + auto it = memory.find(index); + return it != memory.end() ? it->second : default_value; + } + void set(MemoryAddress index, MemoryValue value) override { memory[index] = value; } + uint32_t get_space_id() const override { return space_id; } + + private: + uint32_t space_id; + unordered_flat_map memory; }; } // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/sha256.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/sha256.test.cpp index b5c64e65a04c..b3de626cd475 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/sha256.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/sha256.test.cpp @@ -3,6 +3,7 @@ #include #include +#include "barretenberg/crypto/merkle_tree/memory_store.hpp" #include "barretenberg/vm2/common/memory_types.hpp" #include "barretenberg/vm2/simulation/events/event_emitter.hpp" #include "barretenberg/vm2/simulation/events/memory_event.hpp" @@ -18,8 +19,7 @@ using ::testing::StrictMock; TEST(Sha256CompressionSimulationTest, Sha256Compression) { - NoopEventEmitter emitter; - Memory mem(/*space_id=*/0, emitter); + MemoryStore mem; StrictMock context; EXPECT_CALL(context, get_memory()).WillRepeatedly(ReturnRef(mem)); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp index 648853c95144..b2c1859418b8 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp @@ -124,7 +124,8 @@ template EventsContainer AvmSimulationHelper::simulate_with_setting bytecode_retrieval_emitter, bytecode_decomposition_emitter, instruction_fetching_emitter); - ExecutionComponentsProvider execution_components(bytecode_manager, memory_emitter, instruction_info_db); + ExecutionComponentsProvider execution_components( + bytecode_manager, range_check, memory_emitter, instruction_info_db); Alu alu(alu_emitter); Execution execution(alu, execution_components, instruction_info_db, execution_emitter, context_stack_emitter); diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_builder.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_builder.hpp index 15de07fb584d..6fe68ced36a0 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/lib/lookup_builder.hpp @@ -9,6 +9,7 @@ #include "barretenberg/common/utils.hpp" #include "barretenberg/vm2/common/field.hpp" #include "barretenberg/vm2/common/map.hpp" +#include "barretenberg/vm2/common/stringify.hpp" #include "barretenberg/vm2/generated/columns.hpp" #include "barretenberg/vm2/tracegen/lib/interaction_builder.hpp" #include "barretenberg/vm2/tracegen/trace_container.hpp" @@ -74,6 +75,14 @@ class LookupIntoDynamicTableGeneric : public BaseLookupTraceBuildersecond; } + vinfo( + "Failed computing counts for ", + std::string(LookupSettings::NAME), + " with src tuple: {", + [&tup](std::index_sequence) { + return ((field_to_string(tup[Is]) + ", ") + ...); + }(std::make_index_sequence()), + "}"); throw std::runtime_error("Failed computing counts for " + std::string(LookupSettings::NAME) + ". Could not find tuple in destination."); } diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp new file mode 100644 index 000000000000..97232d344910 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp @@ -0,0 +1,35 @@ +#include "barretenberg/vm2/tracegen/memory_trace.hpp" + +#include + +#include "barretenberg/vm2/common/field.hpp" +#include "barretenberg/vm2/tracegen/lib/make_jobs.hpp" + +namespace bb::avm2::tracegen { + +void MemoryTraceBuilder::process(const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace) +{ + using C = Column; + + uint32_t row = 0; + for (const auto& event : events) { + trace.set(row, + { { + { C::memory_sel, 1 }, + { C::memory_address, event.addr }, + { C::memory_value, event.value }, + { C::memory_tag, static_cast(event.value.get_tag()) }, + { C::memory_rw, event.mode == simulation::MemoryMode::WRITE ? 1 : 0 }, + { C::memory_space_id, event.space_id }, + } }); + row++; + } +} + +std::vector> MemoryTraceBuilder::lookup_jobs() +{ + return {}; +} + +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.hpp new file mode 100644 index 000000000000..22b532e4da92 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "barretenberg/vm2/generated/columns.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/events/memory_event.hpp" +#include "barretenberg/vm2/tracegen/trace_container.hpp" + +namespace bb::avm2::tracegen { + +class MemoryTraceBuilder final { + public: + void process(const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace); + + static std::vector> lookup_jobs(); +}; + +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp index 5b2ae5f1b506..60eed08a1ef9 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp @@ -23,6 +23,7 @@ #include "barretenberg/vm2/tracegen/execution_trace.hpp" #include "barretenberg/vm2/tracegen/field_gt_trace.hpp" #include "barretenberg/vm2/tracegen/lib/interaction_builder.hpp" +#include "barretenberg/vm2/tracegen/memory_trace.hpp" #include "barretenberg/vm2/tracegen/merkle_check_trace.hpp" #include "barretenberg/vm2/tracegen/nullifier_tree_check_trace.hpp" #include "barretenberg/vm2/tracegen/poseidon2_trace.hpp" @@ -273,6 +274,11 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) nullifier_tree_check_trace_builder.process(events.nullifier_tree_check_events, trace)); clear_events(events.nullifier_tree_check_events); }, + [&]() { + MemoryTraceBuilder memory_trace_builder; + AVM_TRACK_TIME("tracegen/memory", memory_trace_builder.process(events.memory, trace)); + clear_events(events.memory); + }, }); AVM_TRACK_TIME("tracegen/traces", execute_jobs(jobs)); } @@ -292,7 +298,8 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) MerkleCheckTraceBuilder::lookup_jobs(), PublicDataTreeReadTraceBuilder::lookup_jobs(), UpdateCheckTraceBuilder::lookup_jobs(), - NullifierTreeCheckTraceBuilder::lookup_jobs()); + NullifierTreeCheckTraceBuilder::lookup_jobs(), + MemoryTraceBuilder::lookup_jobs()); AVM_TRACK_TIME("tracegen/interactions", parallel_for(jobs_interactions.size(), [&](size_t i) { jobs_interactions[i]->process(trace); })); From b425fb30f8e5488207c2deaa50c63ce60196ef73 Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Thu, 17 Apr 2025 16:50:27 +0000 Subject: [PATCH 2/2] gcc --- barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp index 97232d344910..99ad7a698845 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/memory_trace.cpp @@ -3,6 +3,7 @@ #include #include "barretenberg/vm2/common/field.hpp" +#include "barretenberg/vm2/tracegen/lib/interaction_builder.hpp" #include "barretenberg/vm2/tracegen/lib/make_jobs.hpp" namespace bb::avm2::tracegen {