diff --git a/barretenberg/cpp/pil/avm/constants_gen.pil b/barretenberg/cpp/pil/avm/constants_gen.pil index 68caa5291474..33115798e3da 100644 --- a/barretenberg/cpp/pil/avm/constants_gen.pil +++ b/barretenberg/cpp/pil/avm/constants_gen.pil @@ -43,4 +43,13 @@ namespace constants; pol START_EMIT_NULLIFIER_WRITE_OFFSET = 207; pol START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 223; pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 225; + pol GENERATOR_INDEX__NOTE_HASH_NONCE = 2; + pol GENERATOR_INDEX__UNIQUE_NOTE_HASH = 3; + pol GENERATOR_INDEX__SILOED_NOTE_HASH = 4; + pol GENERATOR_INDEX__OUTER_NULLIFIER = 7; + pol GENERATOR_INDEX__CONTRACT_ADDRESS_V1 = 15; + pol GENERATOR_INDEX__CONTRACT_LEAF = 16; + pol GENERATOR_INDEX__PUBLIC_LEAF_INDEX = 23; + pol GENERATOR_INDEX__PARTIAL_ADDRESS = 27; + pol GENERATOR_INDEX__PUBLIC_KEYS_HASH = 52; diff --git a/barretenberg/cpp/pil/vm2/bc_retrieval.pil b/barretenberg/cpp/pil/vm2/bc_retrieval.pil index c0a67b5e955c..5330a503d41b 100644 --- a/barretenberg/cpp/pil/vm2/bc_retrieval.pil +++ b/barretenberg/cpp/pil/vm2/bc_retrieval.pil @@ -56,18 +56,18 @@ pol commit public_bytecode_commitment; // Observe the folowing also connects the class_id of the instance to the class members. // TODO: Probably some latch is also needed. // TODO: Selector needs to be guarded by error flag. -// #[LOOKUP_CLASS_ID_DERIVATION] -// sel { -// class_id, -// artifact_hash, -// private_function_root, -// public_bytecode_commitment -// } in class_id_derivation.sel { -// class_id_derivation.class_id, -// class_id_derivation.artifact_hash, -// class_id_derivation.private_function_root, -// class_id_derivation.public_bytecode_commitment -// } +#[CLASS_ID_DERIVATION] +sel { + class_id, + artifact_hash, + private_function_root, + public_bytecode_commitment +} in class_id_derivation.sel { + class_id_derivation.class_id, + class_id_derivation.artifact_hash, + class_id_derivation.private_function_root, + class_id_derivation.public_bytecode_commitment +}; // TODO: Gate by error flag. #[BYTECODE_HASH_IS_CORRECT] diff --git a/barretenberg/cpp/pil/vm2/class_id_derivation.pil b/barretenberg/cpp/pil/vm2/class_id_derivation.pil new file mode 100644 index 000000000000..c5e6d4fd8c06 --- /dev/null +++ b/barretenberg/cpp/pil/vm2/class_id_derivation.pil @@ -0,0 +1,34 @@ +include "constants_gen.pil"; +include "poseidon2_hash.pil"; +include "precomputed.pil"; +include "bc_retrieval.pil"; + +namespace class_id_derivation; + + pol commit sel; + sel * (1 - sel) = 0; + + #[skippable_if] + sel = 0; + + // Members of Contract Class Id, looked up with bc_retrieval + pol commit artifact_hash; + pol commit private_function_root; + pol commit public_bytecode_commitment; // This is constrained via bc_retrieval's lookup to bc_hashing + // The result of + // H(GENERATOR_INDEX__CONTRACT_LEAF, artifact_hash, private_function_root, public_bytecode_commitment) + pol commit class_id; + + // TODO: We need this temporarily while we dont allow for aliases in the lookup tuple, there must be a better way + pol commit temp_constant_for_lookup; + sel * (temp_constant_for_lookup - constants.GENERATOR_INDEX__CONTRACT_LEAF) = 0; + // Since the inputs to poseidon2 have to be chunks of 3, we need two lookups if we want to do this in a single row + #[CLASS_ID_POSEIDON2_0] + sel { temp_constant_for_lookup, artifact_hash, private_function_root, class_id } + in poseidon2_hash.start { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + #[CLASS_ID_POSEIDON2_1] + sel { public_bytecode_commitment, precomputed.zero, precomputed.zero, class_id} + in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + diff --git a/barretenberg/cpp/pil/vm2/constants_gen.pil b/barretenberg/cpp/pil/vm2/constants_gen.pil index 68caa5291474..33115798e3da 100644 --- a/barretenberg/cpp/pil/vm2/constants_gen.pil +++ b/barretenberg/cpp/pil/vm2/constants_gen.pil @@ -43,4 +43,13 @@ namespace constants; pol START_EMIT_NULLIFIER_WRITE_OFFSET = 207; pol START_EMIT_L2_TO_L1_MSG_WRITE_OFFSET = 223; pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 225; + pol GENERATOR_INDEX__NOTE_HASH_NONCE = 2; + pol GENERATOR_INDEX__UNIQUE_NOTE_HASH = 3; + pol GENERATOR_INDEX__SILOED_NOTE_HASH = 4; + pol GENERATOR_INDEX__OUTER_NULLIFIER = 7; + pol GENERATOR_INDEX__CONTRACT_ADDRESS_V1 = 15; + pol GENERATOR_INDEX__CONTRACT_LEAF = 16; + pol GENERATOR_INDEX__PUBLIC_LEAF_INDEX = 23; + pol GENERATOR_INDEX__PARTIAL_ADDRESS = 27; + pol GENERATOR_INDEX__PUBLIC_KEYS_HASH = 52; diff --git a/barretenberg/cpp/pil/vm2/execution.pil b/barretenberg/cpp/pil/vm2/execution.pil index 8e6b98aec8ad..2ee475d09f6c 100644 --- a/barretenberg/cpp/pil/vm2/execution.pil +++ b/barretenberg/cpp/pil/vm2/execution.pil @@ -4,6 +4,7 @@ include "bc_decomposition.pil"; include "bc_hashing.pil"; include "bc_retrieval.pil"; include "instr_fetching.pil"; +include "class_id_derivation.pil"; include "range_check.pil"; include "bitwise.pil"; include "precomputed.pil"; diff --git a/barretenberg/cpp/pil/vm2/poseidon2_hash.pil b/barretenberg/cpp/pil/vm2/poseidon2_hash.pil index 1fe116f3beeb..241a758c3438 100644 --- a/barretenberg/cpp/pil/vm2/poseidon2_hash.pil +++ b/barretenberg/cpp/pil/vm2/poseidon2_hash.pil @@ -67,21 +67,20 @@ namespace poseidon2_hash; // The permutation output values are represented by b_0, b_1, b_2, b_3 // This most definitely could be simplified to a lower degree check // The next perm input is constrained to be the previous perm output + the new values to be hashed if we - // are not at the start or the end of hashing - pol NEXT_INPUT_IS_PREV_OUTPUT_SEL = (1 - LATCH_CONDITION) * (1 - start); + // are not at the end of hashing pol commit a_0; pol commit a_1; pol commit a_2; pol commit a_3; sel * start * (a_0 - input_0) = 0; - sel * NEXT_INPUT_IS_PREV_OUTPUT_SEL * (a_0' - b_0 - input_0') = 0; + sel * (1 - LATCH_CONDITION) * (a_0' - b_0 - input_0') = 0; sel * start * (a_1 - input_1) = 0; - sel * NEXT_INPUT_IS_PREV_OUTPUT_SEL * (a_1' - b_1 - input_1') = 0; + sel * (1 - LATCH_CONDITION) * (a_1' - b_1 - input_1') = 0; sel * start * (a_2 - input_2) = 0; - sel * NEXT_INPUT_IS_PREV_OUTPUT_SEL * (a_2' - b_2 - input_2') = 0; + sel * (1 - LATCH_CONDITION) * (a_2' - b_2 - input_2') = 0; sel * start * (a_3 - IV) = 0; // IV is placed in the last slot if this is the start - sel * NEXT_INPUT_IS_PREV_OUTPUT_SEL * (a_3' - b_3) = 0; + sel * (1 - LATCH_CONDITION) * (a_3' - b_3) = 0; // The Hash output value represented by b_0 pol commit b_0; diff --git a/barretenberg/cpp/pil/vm2/precomputed.pil b/barretenberg/cpp/pil/vm2/precomputed.pil index 651608ee26ac..7067e53ea0d7 100644 --- a/barretenberg/cpp/pil/vm2/precomputed.pil +++ b/barretenberg/cpp/pil/vm2/precomputed.pil @@ -4,6 +4,9 @@ namespace precomputed; // From 0 and incrementing up to the size of the circuit (2^21). pol constant clk; +// A column of zeroes +pol constant zero; + // 1 only at row 0. pol constant first_row; @@ -76,4 +79,4 @@ pol constant exec_opcode; // Toggle the rows which index (clk) is equal to a wire opcode // Is used to lookup into the wire instruction spec table which contains the operand decomposition // selectors as well as exec_opcode -pol constant sel_range_wire_opcode; \ No newline at end of file +pol constant sel_range_wire_opcode; diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/class_id_derivation.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/class_id_derivation.test.cpp new file mode 100644 index 000000000000..97c1adb73147 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/class_id_derivation.test.cpp @@ -0,0 +1,151 @@ +#include +#include + +#include "barretenberg/vm2/constraining/testing/check_relation.hpp" +#include "barretenberg/vm2/generated/columns.hpp" +#include "barretenberg/vm2/generated/flavor_settings.hpp" +#include "barretenberg/vm2/generated/relations/class_id_derivation.hpp" +#include "barretenberg/vm2/generated/relations/lookups_bc_retrieval.hpp" +#include "barretenberg/vm2/generated/relations/lookups_class_id_derivation.hpp" +#include "barretenberg/vm2/simulation/class_id_derivation.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" +#include "barretenberg/vm2/testing/fixtures.hpp" +#include "barretenberg/vm2/tracegen/bytecode_trace.hpp" +#include "barretenberg/vm2/tracegen/class_id_derivation_trace.hpp" +#include "barretenberg/vm2/tracegen/lib/lookup_builder.hpp" +#include "barretenberg/vm2/tracegen/poseidon2_trace.hpp" +#include "barretenberg/vm2/tracegen/test_trace_container.hpp" + +namespace bb::avm2::constraining { +namespace { + +using tracegen::BytecodeTraceBuilder; +using tracegen::ClassIdDerivationTraceBuilder; +using tracegen::LookupIntoDynamicTableSequential; +using tracegen::Poseidon2TraceBuilder; +using tracegen::TestTraceContainer; + +using simulation::ClassIdDerivation; +using simulation::ClassIdDerivationEvent; +using simulation::compute_contract_class_id; +using simulation::EventEmitter; +using simulation::NoopEventEmitter; +using simulation::Poseidon2; +using simulation::Poseidon2HashEvent; +using simulation::Poseidon2PermutationEvent; + +using FF = AvmFlavorSettings::FF; +using C = Column; +using class_id_derivation_relation = bb::avm2::class_id_derivation; +using poseidon2_relation = bb::avm2::poseidon2_hash; + +using lookup_poseidon2_hash_0 = bb::avm2::lookup_class_id_derivation_class_id_poseidon2_0_relation; +using lookup_poseidon2_hash_1 = bb::avm2::lookup_class_id_derivation_class_id_poseidon2_1_relation; +using lookup_bc_retrieval = bb::avm2::lookup_bc_retrieval_class_id_derivation_relation; + +ContractClass generate_contract_class() +{ + return ContractClass{ .artifact_hash = FF::random_element(), + .private_function_root = FF::random_element(), + .public_bytecode_commitment = FF::random_element(), + .packed_bytecode = {} }; +} + +TEST(ClassIdDerivationConstrainingTest, EmptyRow) +{ + TestTraceContainer trace({ + { { C::precomputed_first_row, 1 } }, + { { C::precomputed_clk, 0 } }, + }); + + check_relation(trace); +} + +TEST(ClassIdDerivationConstrainingTest, Basic) +{ + TestTraceContainer trace; + ClassIdDerivationTraceBuilder builder; + + auto klass = generate_contract_class(); + + FF class_id = + compute_contract_class_id(klass.artifact_hash, klass.private_function_root, klass.public_bytecode_commitment); + + builder.process({ { .class_id = class_id, .klass = klass } }, trace); + + check_relation(trace); +} + +TEST(ClassIdDerivationConstrainingTest, WithHashInteraction) +{ + EventEmitter hash_event_emitter; + EventEmitter perm_event_emitter; + Poseidon2 poseidon2(hash_event_emitter, perm_event_emitter); + + EventEmitter event_emitter; + ClassIdDerivation class_id_derivation(poseidon2, event_emitter); + + auto klass = generate_contract_class(); + FF class_id = + compute_contract_class_id(klass.artifact_hash, klass.private_function_root, klass.public_bytecode_commitment); + + TestTraceContainer trace({ + { { C::precomputed_first_row, 1 } }, + }); + + ClassIdDerivationTraceBuilder builder; + Poseidon2TraceBuilder poseidon2_builder; + + class_id_derivation.assert_derivation(class_id, klass); + + poseidon2_builder.process_hash(hash_event_emitter.dump_events(), trace); + builder.process({ { .class_id = class_id, .klass = klass } }, trace); + + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + + check_interaction(trace); + check_interaction(trace); +} + +// TODO: This should probably be refined and moved to bc_retrieval test file once that exists +TEST(ClassIdDerivationConstrainingTest, WithRetrievalInteraction) +{ + NoopEventEmitter hash_event_emitter; + NoopEventEmitter perm_event_emitter; + Poseidon2 poseidon2(hash_event_emitter, perm_event_emitter); + + EventEmitter event_emitter; + ClassIdDerivation class_id_derivation(poseidon2, event_emitter); + + auto klass = generate_contract_class(); + FF class_id = + compute_contract_class_id(klass.artifact_hash, klass.private_function_root, klass.public_bytecode_commitment); + + TestTraceContainer trace({ + { { C::precomputed_first_row, 1 } }, + }); + + ClassIdDerivationTraceBuilder builder; + BytecodeTraceBuilder bc_trace_builder; + + class_id_derivation.assert_derivation(class_id, klass); + builder.process({ { .class_id = class_id, .klass = klass } }, trace); + + ContractInstance instance = {}; + instance.contract_class_id = class_id; + bc_trace_builder.process_retrieval({ { .bytecode_id = 0, + .address = 1, + .siloed_address = 2, + .contract_instance = instance, + .contract_class = klass, + .nullifier_root = 3 } }, + trace); + + LookupIntoDynamicTableSequential().process(trace); + check_interaction(trace); +} + +} // namespace +} // namespace bb::avm2::constraining diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp index 0df870e05fe2..396b9bf9aa97 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp @@ -9,9 +9,9 @@ namespace bb::avm2 { // The entities that will be used in the flavor. // clang-format off -#define AVM2_PRECOMPUTED_ENTITIES precomputed_as_unary, precomputed_bitwise_input_a, precomputed_bitwise_input_b, precomputed_bitwise_op_id, precomputed_bitwise_output, precomputed_clk, precomputed_exec_opcode, precomputed_first_row, precomputed_integral_tag_length, precomputed_power_of_2, precomputed_sel_bitwise, precomputed_sel_integral_tag, 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_range_16, precomputed_sel_range_8, precomputed_sel_range_wire_opcode, precomputed_sel_sha256_compression, precomputed_sel_unary, precomputed_sha256_compression_round_constant -#define AVM2_WIRE_ENTITIES execution_input, alu_dst_addr, alu_ia, alu_ia_addr, alu_ib, alu_ib_addr, 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_bytes_to_read_unary, 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_decomposition_sel_pc_plus_1, bc_decomposition_sel_pc_plus_10, bc_decomposition_sel_pc_plus_11, bc_decomposition_sel_pc_plus_12, bc_decomposition_sel_pc_plus_13, bc_decomposition_sel_pc_plus_14, bc_decomposition_sel_pc_plus_15, bc_decomposition_sel_pc_plus_16, bc_decomposition_sel_pc_plus_17, bc_decomposition_sel_pc_plus_18, bc_decomposition_sel_pc_plus_19, bc_decomposition_sel_pc_plus_2, bc_decomposition_sel_pc_plus_20, bc_decomposition_sel_pc_plus_21, bc_decomposition_sel_pc_plus_22, bc_decomposition_sel_pc_plus_23, bc_decomposition_sel_pc_plus_24, bc_decomposition_sel_pc_plus_25, bc_decomposition_sel_pc_plus_26, bc_decomposition_sel_pc_plus_27, bc_decomposition_sel_pc_plus_28, bc_decomposition_sel_pc_plus_29, bc_decomposition_sel_pc_plus_3, bc_decomposition_sel_pc_plus_30, bc_decomposition_sel_pc_plus_31, bc_decomposition_sel_pc_plus_32, bc_decomposition_sel_pc_plus_33, bc_decomposition_sel_pc_plus_34, bc_decomposition_sel_pc_plus_35, bc_decomposition_sel_pc_plus_36, bc_decomposition_sel_pc_plus_4, bc_decomposition_sel_pc_plus_5, bc_decomposition_sel_pc_plus_6, bc_decomposition_sel_pc_plus_7, bc_decomposition_sel_pc_plus_8, bc_decomposition_sel_pc_plus_9, 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_bytecode_id, bc_retrieval_class_id, bc_retrieval_deployer_addr, bc_retrieval_err, bc_retrieval_incoming_viewing_key_x, bc_retrieval_incoming_viewing_key_y, bc_retrieval_init_hash, bc_retrieval_nullifier_key_x, bc_retrieval_nullifier_key_y, bc_retrieval_outgoing_viewing_key_x, bc_retrieval_outgoing_viewing_key_y, bc_retrieval_private_function_root, bc_retrieval_public_bytecode_commitment, 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, 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_ex_opcode, execution_indirect, execution_last, 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_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, 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_exec_opcode, instr_fetching_indirect, instr_fetching_op1, instr_fetching_op2, instr_fetching_op3, instr_fetching_op4, instr_fetching_op5, instr_fetching_op6, instr_fetching_op7, instr_fetching_pc, instr_fetching_sel, 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, 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, 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, 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, lookup_bc_decomposition_bytes_are_bytes_counts, lookup_bc_decomposition_abs_diff_is_u16_counts, lookup_bc_decomposition_bytes_to_read_as_unary_counts, lookup_poseidon2_hash_poseidon2_perm_counts, lookup_bc_hashing_get_packed_field_counts, lookup_bc_hashing_iv_is_len_counts, lookup_bc_hashing_poseidon2_hash_counts, lookup_bc_retrieval_bytecode_hash_is_correct_counts, lookup_instr_fetching_bytes_from_bc_dec_counts, lookup_instr_fetching_wire_instruction_info_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_bitwise_integral_tag_length_counts, lookup_bitwise_byte_operations_counts, lookup_sha256_round_constant_counts -#define AVM2_DERIVED_WITNESS_ENTITIES lookup_bc_decomposition_bytes_are_bytes_inv, lookup_bc_decomposition_abs_diff_is_u16_inv, lookup_bc_decomposition_bytes_to_read_as_unary_inv, lookup_poseidon2_hash_poseidon2_perm_inv, lookup_bc_hashing_get_packed_field_inv, lookup_bc_hashing_iv_is_len_inv, lookup_bc_hashing_poseidon2_hash_inv, lookup_bc_retrieval_bytecode_hash_is_correct_inv, lookup_instr_fetching_bytes_from_bc_dec_inv, lookup_instr_fetching_wire_instruction_info_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_bitwise_integral_tag_length_inv, lookup_bitwise_byte_operations_inv, lookup_sha256_round_constant_inv +#define AVM2_PRECOMPUTED_ENTITIES precomputed_as_unary, precomputed_bitwise_input_a, precomputed_bitwise_input_b, precomputed_bitwise_op_id, precomputed_bitwise_output, precomputed_clk, precomputed_exec_opcode, precomputed_first_row, precomputed_integral_tag_length, precomputed_power_of_2, precomputed_sel_bitwise, precomputed_sel_integral_tag, 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_range_16, precomputed_sel_range_8, precomputed_sel_range_wire_opcode, precomputed_sel_sha256_compression, precomputed_sel_unary, precomputed_sha256_compression_round_constant, precomputed_zero +#define AVM2_WIRE_ENTITIES execution_input, alu_dst_addr, alu_ia, alu_ia_addr, alu_ib, alu_ib_addr, 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_bytes_to_read_unary, 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_decomposition_sel_pc_plus_1, bc_decomposition_sel_pc_plus_10, bc_decomposition_sel_pc_plus_11, bc_decomposition_sel_pc_plus_12, bc_decomposition_sel_pc_plus_13, bc_decomposition_sel_pc_plus_14, bc_decomposition_sel_pc_plus_15, bc_decomposition_sel_pc_plus_16, bc_decomposition_sel_pc_plus_17, bc_decomposition_sel_pc_plus_18, bc_decomposition_sel_pc_plus_19, bc_decomposition_sel_pc_plus_2, bc_decomposition_sel_pc_plus_20, bc_decomposition_sel_pc_plus_21, bc_decomposition_sel_pc_plus_22, bc_decomposition_sel_pc_plus_23, bc_decomposition_sel_pc_plus_24, bc_decomposition_sel_pc_plus_25, bc_decomposition_sel_pc_plus_26, bc_decomposition_sel_pc_plus_27, bc_decomposition_sel_pc_plus_28, bc_decomposition_sel_pc_plus_29, bc_decomposition_sel_pc_plus_3, bc_decomposition_sel_pc_plus_30, bc_decomposition_sel_pc_plus_31, bc_decomposition_sel_pc_plus_32, bc_decomposition_sel_pc_plus_33, bc_decomposition_sel_pc_plus_34, bc_decomposition_sel_pc_plus_35, bc_decomposition_sel_pc_plus_36, bc_decomposition_sel_pc_plus_4, bc_decomposition_sel_pc_plus_5, bc_decomposition_sel_pc_plus_6, bc_decomposition_sel_pc_plus_7, bc_decomposition_sel_pc_plus_8, bc_decomposition_sel_pc_plus_9, 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_bytecode_id, bc_retrieval_class_id, bc_retrieval_deployer_addr, bc_retrieval_err, bc_retrieval_incoming_viewing_key_x, bc_retrieval_incoming_viewing_key_y, bc_retrieval_init_hash, bc_retrieval_nullifier_key_x, bc_retrieval_nullifier_key_y, bc_retrieval_outgoing_viewing_key_x, bc_retrieval_outgoing_viewing_key_y, bc_retrieval_private_function_root, bc_retrieval_public_bytecode_commitment, 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, 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_ex_opcode, execution_indirect, execution_last, 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_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, 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_exec_opcode, instr_fetching_indirect, instr_fetching_op1, instr_fetching_op2, instr_fetching_op3, instr_fetching_op4, instr_fetching_op5, instr_fetching_op6, instr_fetching_op7, instr_fetching_pc, instr_fetching_sel, 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, 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, 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, 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, lookup_bc_decomposition_bytes_are_bytes_counts, lookup_bc_decomposition_abs_diff_is_u16_counts, lookup_bc_decomposition_bytes_to_read_as_unary_counts, lookup_poseidon2_hash_poseidon2_perm_counts, lookup_bc_hashing_get_packed_field_counts, lookup_bc_hashing_iv_is_len_counts, lookup_bc_hashing_poseidon2_hash_counts, lookup_bc_retrieval_class_id_derivation_counts, lookup_bc_retrieval_bytecode_hash_is_correct_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_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_bitwise_integral_tag_length_counts, lookup_bitwise_byte_operations_counts, lookup_sha256_round_constant_counts +#define AVM2_DERIVED_WITNESS_ENTITIES lookup_bc_decomposition_bytes_are_bytes_inv, lookup_bc_decomposition_abs_diff_is_u16_inv, lookup_bc_decomposition_bytes_to_read_as_unary_inv, lookup_poseidon2_hash_poseidon2_perm_inv, lookup_bc_hashing_get_packed_field_inv, lookup_bc_hashing_iv_is_len_inv, lookup_bc_hashing_poseidon2_hash_inv, lookup_bc_retrieval_class_id_derivation_inv, lookup_bc_retrieval_bytecode_hash_is_correct_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_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_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, 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, 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 #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.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.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 #define AVM2_ALL_ENTITIES AVM2_PRECOMPUTED_ENTITIES, AVM2_WIRE_ENTITIES, AVM2_DERIVED_WITNESS_ENTITIES, AVM2_SHIFTED_ENTITIES @@ -31,8 +31,8 @@ enum class ColumnAndShifts { SENTINEL_DO_NOT_USE, }; -constexpr auto NUM_COLUMNS_WITH_SHIFTS = 862; -constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 773; +constexpr auto NUM_COLUMNS_WITH_SHIFTS = 875; +constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 786; 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.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp index 8227e44ae3a6..22b57e3c75a1 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp @@ -23,6 +23,7 @@ #include "relations/bc_hashing.hpp" #include "relations/bc_retrieval.hpp" #include "relations/bitwise.hpp" +#include "relations/class_id_derivation.hpp" #include "relations/ecc.hpp" #include "relations/execution.hpp" #include "relations/instr_fetching.hpp" @@ -36,6 +37,7 @@ #include "relations/lookups_bc_hashing.hpp" #include "relations/lookups_bc_retrieval.hpp" #include "relations/lookups_bitwise.hpp" +#include "relations/lookups_class_id_derivation.hpp" #include "relations/lookups_instr_fetching.hpp" #include "relations/lookups_poseidon2_hash.hpp" #include "relations/lookups_range_check.hpp" @@ -81,13 +83,13 @@ class AvmFlavor { // This flavor would not be used with ZK Sumcheck static constexpr bool HasZK = false; - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 36; - static constexpr size_t NUM_WITNESS_ENTITIES = 737; + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 37; + static constexpr size_t NUM_WITNESS_ENTITIES = 749; static constexpr size_t NUM_SHIFTED_ENTITIES = 89; 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 = 862; + static constexpr size_t NUM_ALL_ENTITIES = 875; // Need to be templated for recursive verifier template @@ -98,6 +100,7 @@ class AvmFlavor { avm2::bc_hashing, avm2::bc_retrieval, avm2::bitwise, + avm2::class_id_derivation, avm2::ecc, avm2::execution, avm2::instr_fetching, @@ -119,8 +122,11 @@ class AvmFlavor { lookup_bc_hashing_iv_is_len_relation, lookup_bc_hashing_poseidon2_hash_relation, lookup_bc_retrieval_bytecode_hash_is_correct_relation, + lookup_bc_retrieval_class_id_derivation_relation, lookup_bitwise_byte_operations_relation, lookup_bitwise_integral_tag_length_relation, + lookup_class_id_derivation_class_id_poseidon2_0_relation, + lookup_class_id_derivation_class_id_poseidon2_1_relation, lookup_instr_fetching_bytes_from_bc_dec_relation, lookup_instr_fetching_wire_instruction_info_relation, lookup_poseidon2_hash_poseidon2_perm_relation, @@ -417,6 +423,7 @@ class AvmFlavor { this->precomputed_sel_unary = verification_key->precomputed_sel_unary; this->precomputed_sha256_compression_round_constant = verification_key->precomputed_sha256_compression_round_constant; + this->precomputed_zero = verification_key->precomputed_zero; } }; diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/class_id_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/class_id_derivation.hpp new file mode 100644 index 000000000000..a7c3e4e71352 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/class_id_derivation.hpp @@ -0,0 +1,58 @@ +// AUTOGENERATED FILE +#pragma once + +#include + +#include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/relations/relation_types.hpp" + +namespace bb::avm2 { + +template class class_id_derivationImpl { + 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.class_id_derivation_sel).is_zero(); + } + + template + void static accumulate(ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor) + { + const auto constants_GENERATOR_INDEX__CONTRACT_LEAF = FF(16); + + { + using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; + auto tmp = new_term.class_id_derivation_sel * (FF(1) - new_term.class_id_derivation_sel); + tmp *= scaling_factor; + std::get<0>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>; + auto tmp = new_term.class_id_derivation_sel * (new_term.class_id_derivation_temp_constant_for_lookup - + constants_GENERATOR_INDEX__CONTRACT_LEAF); + tmp *= scaling_factor; + std::get<1>(evals) += typename Accumulator::View(tmp); + } + } +}; + +template class class_id_derivation : public Relation> { + public: + static constexpr const std::string_view NAME = "class_id_derivation"; + + static std::string get_subrelation_label(size_t index) + { + switch (index) {} + return std::to_string(index); + } +}; + +} // namespace bb::avm2 \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bc_retrieval.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bc_retrieval.hpp index 515837d0d29b..232bbfacf693 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bc_retrieval.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_bc_retrieval.hpp @@ -10,6 +10,105 @@ namespace bb::avm2 { +/////////////////// lookup_bc_retrieval_class_id_derivation /////////////////// + +class lookup_bc_retrieval_class_id_derivation_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_BC_RETRIEVAL_CLASS_ID_DERIVATION"; + static constexpr std::string_view RELATION_NAME = "bc_retrieval"; + + static constexpr size_t READ_TERMS = 1; + 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 INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; + static constexpr size_t READ_TERM_DEGREE = 0; + static constexpr size_t WRITE_TERM_DEGREE = 0; + + // Columns using the Column enum. + static constexpr Column SRC_SELECTOR = Column::bc_retrieval_sel; + static constexpr Column DST_SELECTOR = Column::class_id_derivation_sel; + static constexpr Column COUNTS = Column::lookup_bc_retrieval_class_id_derivation_counts; + static constexpr Column INVERSES = Column::lookup_bc_retrieval_class_id_derivation_inv; + static constexpr std::array SRC_COLUMNS = { + Column::bc_retrieval_class_id, + Column::bc_retrieval_artifact_hash, + Column::bc_retrieval_private_function_root, + Column::bc_retrieval_public_bytecode_commitment + }; + static constexpr std::array DST_COLUMNS = { + Column::class_id_derivation_class_id, + Column::class_id_derivation_artifact_hash, + Column::class_id_derivation_private_function_root, + Column::class_id_derivation_public_bytecode_commitment + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._bc_retrieval_sel() == 1 || in._class_id_derivation_sel() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._bc_retrieval_sel()); + const auto is_table_entry = View(in._class_id_derivation_sel()); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + template static inline auto get_const_entities(const AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_nonconst_entities(AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_entities(AllEntities&& in) + { + return std::forward_as_tuple(in._lookup_bc_retrieval_class_id_derivation_inv(), + in._lookup_bc_retrieval_class_id_derivation_counts(), + in._bc_retrieval_sel(), + in._class_id_derivation_sel(), + in._bc_retrieval_class_id(), + in._bc_retrieval_artifact_hash(), + in._bc_retrieval_private_function_root(), + in._bc_retrieval_public_bytecode_commitment(), + in._class_id_derivation_class_id(), + in._class_id_derivation_artifact_hash(), + in._class_id_derivation_private_function_root(), + in._class_id_derivation_public_bytecode_commitment()); + } +}; + +template +class lookup_bc_retrieval_class_id_derivation_relation + : public GenericLookupRelation { + public: + using Settings = lookup_bc_retrieval_class_id_derivation_settings; + static constexpr std::string_view NAME = lookup_bc_retrieval_class_id_derivation_settings::NAME; + static constexpr std::string_view RELATION_NAME = lookup_bc_retrieval_class_id_derivation_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_bc_retrieval_class_id_derivation_inv.is_zero(); + } + + static std::string get_subrelation_label(size_t index) + { + if (index == 0) { + return "INVERSES_ARE_CORRECT"; + } else if (index == 1) { + return "ACCUMULATION_IS_CORRECT"; + } + return std::to_string(index); + } +}; + /////////////////// lookup_bc_retrieval_bytecode_hash_is_correct /////////////////// class lookup_bc_retrieval_bytecode_hash_is_correct_settings { diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_class_id_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_class_id_derivation.hpp new file mode 100644 index 000000000000..a8574d2277c9 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_class_id_derivation.hpp @@ -0,0 +1,209 @@ +// AUTOGENERATED FILE +#pragma once + +#include "../columns.hpp" +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" + +#include +#include +#include + +namespace bb::avm2 { + +/////////////////// lookup_class_id_derivation_class_id_poseidon2_0 /////////////////// + +class lookup_class_id_derivation_class_id_poseidon2_0_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_CLASS_ID_DERIVATION_CLASS_ID_POSEIDON2_0"; + static constexpr std::string_view RELATION_NAME = "class_id_derivation"; + + static constexpr size_t READ_TERMS = 1; + 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 INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; + static constexpr size_t READ_TERM_DEGREE = 0; + static constexpr size_t WRITE_TERM_DEGREE = 0; + + // Columns using the Column enum. + static constexpr Column SRC_SELECTOR = Column::class_id_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_start; + static constexpr Column COUNTS = Column::lookup_class_id_derivation_class_id_poseidon2_0_counts; + static constexpr Column INVERSES = Column::lookup_class_id_derivation_class_id_poseidon2_0_inv; + static constexpr std::array SRC_COLUMNS = { + Column::class_id_derivation_temp_constant_for_lookup, + Column::class_id_derivation_artifact_hash, + Column::class_id_derivation_private_function_root, + Column::class_id_derivation_class_id + }; + static constexpr std::array DST_COLUMNS = { Column::poseidon2_hash_input_0, + Column::poseidon2_hash_input_1, + Column::poseidon2_hash_input_2, + Column::poseidon2_hash_output }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._class_id_derivation_sel() == 1 || in._poseidon2_hash_start() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._class_id_derivation_sel()); + const auto is_table_entry = View(in._poseidon2_hash_start()); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + template static inline auto get_const_entities(const AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_nonconst_entities(AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_entities(AllEntities&& in) + { + return std::forward_as_tuple(in._lookup_class_id_derivation_class_id_poseidon2_0_inv(), + in._lookup_class_id_derivation_class_id_poseidon2_0_counts(), + in._class_id_derivation_sel(), + in._poseidon2_hash_start(), + in._class_id_derivation_temp_constant_for_lookup(), + in._class_id_derivation_artifact_hash(), + in._class_id_derivation_private_function_root(), + in._class_id_derivation_class_id(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_class_id_derivation_class_id_poseidon2_0_relation + : public GenericLookupRelation { + public: + using Settings = lookup_class_id_derivation_class_id_poseidon2_0_settings; + static constexpr std::string_view NAME = lookup_class_id_derivation_class_id_poseidon2_0_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_class_id_derivation_class_id_poseidon2_0_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_class_id_derivation_class_id_poseidon2_0_inv.is_zero(); + } + + static std::string get_subrelation_label(size_t index) + { + if (index == 0) { + return "INVERSES_ARE_CORRECT"; + } else if (index == 1) { + return "ACCUMULATION_IS_CORRECT"; + } + return std::to_string(index); + } +}; + +/////////////////// lookup_class_id_derivation_class_id_poseidon2_1 /////////////////// + +class lookup_class_id_derivation_class_id_poseidon2_1_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_CLASS_ID_DERIVATION_CLASS_ID_POSEIDON2_1"; + static constexpr std::string_view RELATION_NAME = "class_id_derivation"; + + static constexpr size_t READ_TERMS = 1; + 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 INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4; + static constexpr size_t READ_TERM_DEGREE = 0; + static constexpr size_t WRITE_TERM_DEGREE = 0; + + // Columns using the Column enum. + static constexpr Column SRC_SELECTOR = Column::class_id_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end; + static constexpr Column COUNTS = Column::lookup_class_id_derivation_class_id_poseidon2_1_counts; + static constexpr Column INVERSES = Column::lookup_class_id_derivation_class_id_poseidon2_1_inv; + static constexpr std::array SRC_COLUMNS = { + Column::class_id_derivation_public_bytecode_commitment, + Column::precomputed_zero, + Column::precomputed_zero, + Column::class_id_derivation_class_id + }; + static constexpr std::array DST_COLUMNS = { Column::poseidon2_hash_input_0, + Column::poseidon2_hash_input_1, + Column::poseidon2_hash_input_2, + Column::poseidon2_hash_output }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._class_id_derivation_sel() == 1 || in._poseidon2_hash_end() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._class_id_derivation_sel()); + const auto is_table_entry = View(in._poseidon2_hash_end()); + return (is_operation + is_table_entry - is_operation * is_table_entry); + } + + template static inline auto get_const_entities(const AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_nonconst_entities(AllEntities& in) + { + return get_entities(in); + } + + template static inline auto get_entities(AllEntities&& in) + { + return std::forward_as_tuple(in._lookup_class_id_derivation_class_id_poseidon2_1_inv(), + in._lookup_class_id_derivation_class_id_poseidon2_1_counts(), + in._class_id_derivation_sel(), + in._poseidon2_hash_end(), + in._class_id_derivation_public_bytecode_commitment(), + in._precomputed_zero(), + in._precomputed_zero(), + in._class_id_derivation_class_id(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_class_id_derivation_class_id_poseidon2_1_relation + : public GenericLookupRelation { + public: + using Settings = lookup_class_id_derivation_class_id_poseidon2_1_settings; + static constexpr std::string_view NAME = lookup_class_id_derivation_class_id_poseidon2_1_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_class_id_derivation_class_id_poseidon2_1_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_class_id_derivation_class_id_poseidon2_1_inv.is_zero(); + } + + static std::string get_subrelation_label(size_t index) + { + if (index == 0) { + return "INVERSES_ARE_CORRECT"; + } else if (index == 1) { + return "ACCUMULATION_IS_CORRECT"; + } + return std::to_string(index); + } +}; + +} // namespace bb::avm2 diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/poseidon2_hash.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/poseidon2_hash.hpp index dcb703064554..0fc53ff08fa4 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/poseidon2_hash.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/poseidon2_hash.hpp @@ -13,7 +13,7 @@ template class poseidon2_hashImpl { using FF = FF_; static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 4, 3, 3, 3, 3, 4, 4, 4, 5, - 4, 5, 4, 5, 4, 5, 4, 5, 4 }; + 4, 4, 4, 4, 4, 4, 4, 4, 4 }; template inline static bool skip(const AllEntities& in) { @@ -32,8 +32,6 @@ template class poseidon2_hashImpl { const auto poseidon2_hash_LATCH_CONDITION = new_term.poseidon2_hash_end + new_term.precomputed_first_row; const auto poseidon2_hash_PADDED_LEN = new_term.poseidon2_hash_input_len + new_term.poseidon2_hash_padding; const auto poseidon2_hash_NEXT_ROUND_COUNT = (new_term.poseidon2_hash_num_perm_rounds_rem - FF(1)); - const auto poseidon2_hash_NEXT_INPUT_IS_PREV_OUTPUT_SEL = - (FF(1) - poseidon2_hash_LATCH_CONDITION) * (FF(1) - new_term.poseidon2_hash_start); { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; @@ -116,7 +114,7 @@ template class poseidon2_hashImpl { } { using Accumulator = typename std::tuple_element_t<11, ContainerOverSubrelations>; - auto tmp = new_term.poseidon2_hash_sel * poseidon2_hash_NEXT_INPUT_IS_PREV_OUTPUT_SEL * + auto tmp = new_term.poseidon2_hash_sel * (FF(1) - poseidon2_hash_LATCH_CONDITION) * ((new_term.poseidon2_hash_a_0_shift - new_term.poseidon2_hash_b_0) - new_term.poseidon2_hash_input_0_shift); tmp *= scaling_factor; @@ -131,7 +129,7 @@ template class poseidon2_hashImpl { } { using Accumulator = typename std::tuple_element_t<13, ContainerOverSubrelations>; - auto tmp = new_term.poseidon2_hash_sel * poseidon2_hash_NEXT_INPUT_IS_PREV_OUTPUT_SEL * + auto tmp = new_term.poseidon2_hash_sel * (FF(1) - poseidon2_hash_LATCH_CONDITION) * ((new_term.poseidon2_hash_a_1_shift - new_term.poseidon2_hash_b_1) - new_term.poseidon2_hash_input_1_shift); tmp *= scaling_factor; @@ -146,7 +144,7 @@ template class poseidon2_hashImpl { } { using Accumulator = typename std::tuple_element_t<15, ContainerOverSubrelations>; - auto tmp = new_term.poseidon2_hash_sel * poseidon2_hash_NEXT_INPUT_IS_PREV_OUTPUT_SEL * + auto tmp = new_term.poseidon2_hash_sel * (FF(1) - poseidon2_hash_LATCH_CONDITION) * ((new_term.poseidon2_hash_a_2_shift - new_term.poseidon2_hash_b_2) - new_term.poseidon2_hash_input_2_shift); tmp *= scaling_factor; @@ -161,7 +159,7 @@ template class poseidon2_hashImpl { } { using Accumulator = typename std::tuple_element_t<17, ContainerOverSubrelations>; - auto tmp = new_term.poseidon2_hash_sel * poseidon2_hash_NEXT_INPUT_IS_PREV_OUTPUT_SEL * + auto tmp = new_term.poseidon2_hash_sel * (FF(1) - poseidon2_hash_LATCH_CONDITION) * (new_term.poseidon2_hash_a_3_shift - new_term.poseidon2_hash_b_3); tmp *= scaling_factor; std::get<17>(evals) += typename Accumulator::View(tmp); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.cpp index 8efd8115f724..68c93bb69661 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.cpp @@ -4,16 +4,19 @@ #include "barretenberg/vm/aztec_constants.hpp" #include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" +#include "barretenberg/vm2/simulation/poseidon2.hpp" namespace bb::avm2::simulation { void ClassIdDerivation::assert_derivation(const ContractClassId& class_id, const ContractClass& klass) { // TODO: Cache and deduplicate. - // TODO: Use gadget. - assert(compute_contract_class_id( - klass.artifact_hash, klass.private_function_root, klass.public_bytecode_commitment) == class_id); + FF computed_class_id = poseidon2.hash({ GENERATOR_INDEX__CONTRACT_LEAF, + klass.artifact_hash, + klass.private_function_root, + klass.public_bytecode_commitment }); + assert(computed_class_id == class_id); events.emit({ .class_id = class_id, .klass = klass }); } -} // namespace bb::avm2::simulation \ No newline at end of file +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.hpp index 6e5e960994a8..698b5e973bcf 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.hpp @@ -3,6 +3,7 @@ #include "barretenberg/vm2/common/aztec_types.hpp" #include "barretenberg/vm2/simulation/events/class_id_derivation_event.hpp" #include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/poseidon2.hpp" namespace bb::avm2::simulation { @@ -14,14 +15,16 @@ class ClassIdDerivationInterface { class ClassIdDerivation : public ClassIdDerivationInterface { public: - ClassIdDerivation(EventEmitterInterface& events) + ClassIdDerivation(Poseidon2& poseidon2, EventEmitterInterface& events) : events(events) + , poseidon2(poseidon2) {} void assert_derivation(const ContractClassId& class_id, const ContractClass& klass) override; private: EventEmitterInterface& events; + Poseidon2Interface& poseidon2; }; -} // namespace bb::avm2::simulation \ No newline at end of file +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_class_id_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_class_id_derivation.hpp new file mode 100644 index 000000000000..02a506996069 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_class_id_derivation.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "barretenberg/vm2/simulation/class_id_derivation.hpp" + +namespace bb::avm2::simulation { + +class MockClassIdDerivation : public ClassIdDerivationInterface { + public: + // https://google.github.io/googletest/gmock_cook_book.html#making-the-compilation-faster + MockClassIdDerivation(); + ~MockClassIdDerivation() override; + + MOCK_METHOD(void, assert_derivation, (const ContractClassId& class_id, const ContractClass& klass), (override)); +}; + +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_class_id_derivation.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_class_id_derivation.test.cpp new file mode 100644 index 000000000000..7f38f0afe82d --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_class_id_derivation.test.cpp @@ -0,0 +1,9 @@ +// This is not a test file but we need to use .test.cpp so that it is not included in non-test builds. +#include "barretenberg/vm2/simulation/testing/mock_class_id_derivation.hpp" + +namespace bb::avm2::simulation { + +MockClassIdDerivation::MockClassIdDerivation() = default; +MockClassIdDerivation::~MockClassIdDerivation() = default; + +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp index 566ebbffda87..b66d4aa3c9d0 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp @@ -70,14 +70,15 @@ template EventsContainer AvmSimulationHelper::simulate_with_setting typename S::template DefaultEventEmitter poseidon2_hash_emitter; typename S::template DefaultEventEmitter poseidon2_perm_emitter; + Poseidon2 poseidon2(poseidon2_hash_emitter, poseidon2_perm_emitter); + AddressDerivation address_derivation(address_derivation_emitter); - ClassIdDerivation class_id_derivation(class_id_derivation_emitter); + ClassIdDerivation class_id_derivation(poseidon2, class_id_derivation_emitter); HintedRawContractDB raw_contract_db(inputs.hints); HintedRawMerkleDB raw_merkle_db(inputs.hints); ContractDB contract_db(raw_contract_db, address_derivation, class_id_derivation); MerkleDB merkle_db(raw_merkle_db); - Poseidon2 poseidon2(poseidon2_hash_emitter, poseidon2_perm_emitter); BytecodeHasher bytecode_hasher(poseidon2, bytecode_hashing_emitter); Siloing siloing(siloing_emitter); TxBytecodeManager bytecode_manager(contract_db, diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.cpp new file mode 100644 index 000000000000..3661eab92276 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.cpp @@ -0,0 +1,32 @@ +#include "barretenberg/vm2/tracegen/class_id_derivation_trace.hpp" + +#include "barretenberg/vm/aztec_constants.hpp" +#include "barretenberg/vm2/simulation/events/class_id_derivation_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/tracegen/trace_container.hpp" + +namespace bb::avm2::tracegen { + +void ClassIdDerivationTraceBuilder::process( + const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace) +{ + using C = Column; + + uint32_t row = 0; + for (const auto& event : events) { + trace.set(row, + { { + { C::class_id_derivation_sel, 1 }, + { C::class_id_derivation_class_id, event.class_id }, + { C::class_id_derivation_artifact_hash, event.klass.artifact_hash }, + { C::class_id_derivation_private_function_root, event.klass.private_function_root }, + { C::class_id_derivation_public_bytecode_commitment, event.klass.public_bytecode_commitment }, + + // This is temp because aliasing is not allowed in lookups + { C::class_id_derivation_temp_constant_for_lookup, GENERATOR_INDEX__CONTRACT_LEAF }, + } }); + row++; + } +} +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.hpp new file mode 100644 index 000000000000..de61f0378f76 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "barretenberg/vm2/generated/columns.hpp" +#include "barretenberg/vm2/simulation/events/class_id_derivation_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/tracegen/trace_container.hpp" + +namespace bb::avm2::tracegen { + +class ClassIdDerivationTraceBuilder final { + public: + void process(const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace); +}; + +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.test.cpp new file mode 100644 index 000000000000..70a2692a04d2 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/class_id_derivation_trace.test.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include + +#include "barretenberg/vm2/generated/flavor_settings.hpp" +#include "barretenberg/vm2/generated/full_row.hpp" +#include "barretenberg/vm2/testing/macros.hpp" +#include "barretenberg/vm2/tracegen/class_id_derivation_trace.hpp" +#include "barretenberg/vm2/tracegen/test_trace_container.hpp" + +namespace bb::avm2::tracegen { +namespace { + +using testing::ElementsAre; +using testing::Field; + +using R = TestTraceContainer::Row; +using FF = R::FF; + +TEST(ClassIdDerivationTraceGenTest, TraceGeneration) +{ + TestTraceContainer trace; + ClassIdDerivationTraceBuilder builder; + + ContractClassId class_id = FF(0xdeadbeef); + ContractClass klass{ + .artifact_hash = FF(12), + .private_function_root = FF(23), + .public_bytecode_commitment = FF(45), + .packed_bytecode = {}, + }; + builder.process({ { .class_id = class_id, .klass = klass } }, trace); + + EXPECT_THAT(trace.as_rows(), + ElementsAre( + // Only one row. + AllOf(ROW_FIELD_EQ(R, class_id_derivation_sel, 1), + ROW_FIELD_EQ(R, class_id_derivation_class_id, FF(0xdeadbeef)), + ROW_FIELD_EQ(R, class_id_derivation_artifact_hash, FF(12)), + ROW_FIELD_EQ(R, class_id_derivation_private_function_root, FF(23)), + ROW_FIELD_EQ(R, class_id_derivation_public_bytecode_commitment, FF(45))))); +} + +} // namespace +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/poseidon2_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/poseidon2_trace.cpp index bb5191796b3e..1c719d1a665a 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen/poseidon2_trace.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/poseidon2_trace.cpp @@ -291,8 +291,8 @@ void Poseidon2TraceBuilder::process_hash( auto num_perm_events = (input_size / 3) + static_cast(input_size % 3 != 0); auto padded_size = 3 * ((event.inputs.size() + 2) / 3); - std::array perm_input = { 0, 0, 0 }; for (size_t i = 0; i < num_perm_events; i++) { + std::array perm_input = { 0, 0, 0 }; auto perm_state = event.intermediate_states[i]; auto perm_output = event.intermediate_states[i + 1]; size_t chunk_size = std::min(input_size, static_cast(3)); diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp index 3c346ae772fb..036720f52f49 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp @@ -17,12 +17,14 @@ #include "barretenberg/vm2/generated/relations/lookups_bc_decomposition.hpp" #include "barretenberg/vm2/generated/relations/lookups_bc_retrieval.hpp" #include "barretenberg/vm2/generated/relations/lookups_bitwise.hpp" +#include "barretenberg/vm2/generated/relations/lookups_class_id_derivation.hpp" #include "barretenberg/vm2/generated/relations/lookups_instr_fetching.hpp" #include "barretenberg/vm2/generated/relations/lookups_poseidon2_hash.hpp" #include "barretenberg/vm2/generated/relations/lookups_range_check.hpp" #include "barretenberg/vm2/generated/relations/lookups_sha256.hpp" #include "barretenberg/vm2/tracegen/alu_trace.hpp" #include "barretenberg/vm2/tracegen/bytecode_trace.hpp" +#include "barretenberg/vm2/tracegen/class_id_derivation_trace.hpp" #include "barretenberg/vm2/tracegen/ecc_trace.hpp" #include "barretenberg/vm2/tracegen/execution_trace.hpp" #include "barretenberg/vm2/tracegen/lib/interaction_builder.hpp" @@ -181,6 +183,12 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) bytecode_builder.process_hashing(events.bytecode_hashing, trace)); clear_events(events.bytecode_hashing); }, + [&]() { + ClassIdDerivationTraceBuilder class_id_builder; + AVM_TRACK_TIME("tracegen/class_id_derivation", + class_id_builder.process(events.class_id_derivation, trace)); + clear_events(events.class_id_derivation); + }, [&]() { BytecodeTraceBuilder bytecode_builder; AVM_TRACK_TIME("tracegen/bytecode_retrieval", @@ -245,8 +253,13 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) std::make_unique>(), std::make_unique>(), // Bytecode Retrieval + std::make_unique>(), + std::make_unique>(), + // Class Id Derivation + std::make_unique< + LookupIntoDynamicTableSequential>(), std::make_unique< - LookupIntoDynamicTableSequential>()); + LookupIntoDynamicTableSequential>()); AVM_TRACK_TIME("tracegen/interactions", parallel_for(jobs_interactions.size(), [&](size_t i) { jobs_interactions[i]->process(trace); })); } diff --git a/yarn-project/constants/src/scripts/constants.in.ts b/yarn-project/constants/src/scripts/constants.in.ts index 141f02dd54fa..8eb2e8cf7b44 100644 --- a/yarn-project/constants/src/scripts/constants.in.ts +++ b/yarn-project/constants/src/scripts/constants.in.ts @@ -156,6 +156,18 @@ const PIL_CONSTANTS = [ 'MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS', ]; +const PIL_GENERATORS: string[] = [ + 'PARTIAL_ADDRESS', + 'CONTRACT_ADDRESS_V1', + 'CONTRACT_LEAF', + 'PUBLIC_KEYS_HASH', + 'NOTE_HASH_NONCE', + 'UNIQUE_NOTE_HASH', + 'SILOED_NOTE_HASH', + 'OUTER_NULLIFIER', + 'PUBLIC_LEAF_INDEX', +]; + /** * Parsed content. */ @@ -217,13 +229,22 @@ function processConstantsCpp( * @param constants - An object containing key-value pairs representing constants. * @returns A string containing code that exports the constants as cpp constants. */ -function processConstantsPil(constants: { [key: string]: string }): string { +function processConstantsPil( + constants: { [key: string]: string }, + generatorIndices: { [key: string]: number }, +): string { const code: string[] = []; Object.entries(constants).forEach(([key, value]) => { if (PIL_CONSTANTS.includes(key)) { code.push(` pol ${key} = ${value};`); } }); + Object.entries(generatorIndices).forEach(([key, value]) => { + if (PIL_GENERATORS.includes(key)) { + code.push(` pol GENERATOR_INDEX__${key} = ${value};`); + } + }); + return code.join('\n'); } /** @@ -293,10 +314,10 @@ ${processConstantsCpp(constants, generatorIndexEnum)} /** * Generate the constants file in PIL. */ -function generatePilConstants({ constants }: ParsedContent, targetPath: string) { +function generatePilConstants({ constants, generatorIndexEnum }: ParsedContent, targetPath: string) { const resultPil: string = `// GENERATED FILE - DO NOT EDIT, RUN yarn remake-constants in yarn-project/constants namespace constants; -${processConstantsPil(constants)} +${processConstantsPil(constants, generatorIndexEnum)} \n`; fs.writeFileSync(targetPath, resultPil);