diff --git a/barretenberg/cpp/pil/avm/constants_gen.pil b/barretenberg/cpp/pil/avm/constants_gen.pil index 33115798e3da..699f679ad95c 100644 --- a/barretenberg/cpp/pil/avm/constants_gen.pil +++ b/barretenberg/cpp/pil/avm/constants_gen.pil @@ -43,6 +43,8 @@ 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 GRUMPKIN_ONE_X = 1; + pol GRUMPKIN_ONE_Y = 17631683881184975370165255887551781615748388533673675138860; pol GENERATOR_INDEX__NOTE_HASH_NONCE = 2; pol GENERATOR_INDEX__UNIQUE_NOTE_HASH = 3; pol GENERATOR_INDEX__SILOED_NOTE_HASH = 4; diff --git a/barretenberg/cpp/pil/vm2/address_derivation.pil b/barretenberg/cpp/pil/vm2/address_derivation.pil new file mode 100644 index 000000000000..4f167b589cfd --- /dev/null +++ b/barretenberg/cpp/pil/vm2/address_derivation.pil @@ -0,0 +1,143 @@ +include "constants_gen.pil"; +include "ecc.pil"; +include "poseidon2_hash.pil"; +include "precomputed.pil"; +include "scalar_mul.pil"; + +namespace address_derivation; + + pol commit sel; + sel * (1 - sel) = 0; + + #[skippable_if] + sel = 0; + + // Address preimage components + pol commit salt; + pol commit deployer_addr; + pol commit class_id; + pol commit init_hash; + pol commit nullifier_key_x; + pol commit nullifier_key_y; + pol commit incoming_viewing_key_x; + pol commit incoming_viewing_key_y; + pol commit outgoing_viewing_key_x; + pol commit outgoing_viewing_key_y; + pol commit tagging_key_x; + pol commit tagging_key_y; + + // Expected derived address + pol commit address; + + + // Computation of salted initialization hash + + pol commit salted_init_hash; + + // It's reused between the partial address and salted initialization hash. Weird. + // TODO: We need this temporarily while we dont allow for aliases in the lookup tuple + pol commit partial_address_domain_separator; + sel * (partial_address_domain_separator - constants.GENERATOR_INDEX__PARTIAL_ADDRESS) = 0; + + #[SALTED_INITIALIZATION_HASH_POSEIDON2_0] + sel { partial_address_domain_separator, salt, init_hash, salted_init_hash } + in poseidon2_hash.start { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + #[SALTED_INITIALIZATION_HASH_POSEIDON2_1] + sel { deployer_addr, precomputed.zero, precomputed.zero, salted_init_hash} + in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + + // Computation of partial address + + pol commit partial_address; + + #[PARTIAL_ADDRESS_POSEIDON2] + sel { partial_address_domain_separator, class_id, salted_init_hash, partial_address } + in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + + // Hash the public keys + + pol commit public_keys_hash; + + // TODO: We need this temporarily while we dont allow for aliases in the lookup tuple + pol commit public_keys_hash_domain_separator; + sel * (public_keys_hash_domain_separator - constants.GENERATOR_INDEX__PUBLIC_KEYS_HASH) = 0; + + // Remove all the 0s for is_infinite when removed from public_keys.nr + // https://github.com/AztecProtocol/aztec-packages/issues/7529 + #[PUBLIC_KEYS_HASH_POSEIDON2_0] + sel { public_keys_hash_domain_separator, nullifier_key_x, nullifier_key_y, public_keys_hash } + in poseidon2_hash.start { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + #[PUBLIC_KEYS_HASH_POSEIDON2_1] + sel { precomputed.zero, incoming_viewing_key_x, incoming_viewing_key_y, public_keys_hash } + in poseidon2_hash.sel { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + #[PUBLIC_KEYS_HASH_POSEIDON2_2] + sel { precomputed.zero, outgoing_viewing_key_x, outgoing_viewing_key_y, public_keys_hash } + in poseidon2_hash.sel { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + #[PUBLIC_KEYS_HASH_POSEIDON2_3] + sel { precomputed.zero, tagging_key_x, tagging_key_y, public_keys_hash } + in poseidon2_hash.sel { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + #[PUBLIC_KEYS_HASH_POSEIDON2_4] + sel { precomputed.zero, precomputed.zero, precomputed.zero, public_keys_hash } + in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + + // Compute the preaddress + + pol commit preaddress; + + // TODO: We need this temporarily while we dont allow for aliases in the lookup tuple + pol commit preaddress_domain_separator; + sel * (preaddress_domain_separator - constants.GENERATOR_INDEX__CONTRACT_ADDRESS_V1) = 0; + + #[PREADDRESS_POSEIDON2] + sel { preaddress_domain_separator, public_keys_hash, partial_address, preaddress } + in poseidon2_hash.end { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output }; + + + // Derive preaddress public key + + pol commit preaddress_public_key_x; + pol commit preaddress_public_key_y; + + // TODO: We need this temporarily while we dont allow for aliases in the lookup tuple + pol commit g1_x; + sel * (g1_x - constants.GRUMPKIN_ONE_X) = 0; + + pol commit g1_y; + sel * (g1_y - constants.GRUMPKIN_ONE_Y) = 0; + + #[PREADDRESS_SCALAR_MUL] + sel { + preaddress, + g1_x, g1_y, precomputed.zero, + preaddress_public_key_x, preaddress_public_key_y, precomputed.zero + } in scalar_mul.start { + scalar_mul.scalar, + scalar_mul.point_x, scalar_mul.point_y, scalar_mul.point_inf, + scalar_mul.res_x, scalar_mul.res_y, scalar_mul.res_inf + }; + + + // Finally, the address must be the x coordinate of preaddress_public_key + incoming_viewing_key + + pol commit address_y; + + #[ADDRESS_ECADD] + sel { + preaddress_public_key_x, preaddress_public_key_y, precomputed.zero, + incoming_viewing_key_x, incoming_viewing_key_y, precomputed.zero, + address, address_y, precomputed.zero + } in ecc.sel { + ecc.p_x, ecc.p_y, ecc.p_is_inf, + ecc.q_x, ecc.q_y, ecc.q_is_inf, + ecc.r_x, ecc.r_y, ecc.r_is_inf + }; + + diff --git a/barretenberg/cpp/pil/vm2/constants_gen.pil b/barretenberg/cpp/pil/vm2/constants_gen.pil index 33115798e3da..699f679ad95c 100644 --- a/barretenberg/cpp/pil/vm2/constants_gen.pil +++ b/barretenberg/cpp/pil/vm2/constants_gen.pil @@ -43,6 +43,8 @@ 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 GRUMPKIN_ONE_X = 1; + pol GRUMPKIN_ONE_Y = 17631683881184975370165255887551781615748388533673675138860; pol GENERATOR_INDEX__NOTE_HASH_NONCE = 2; pol GENERATOR_INDEX__UNIQUE_NOTE_HASH = 3; pol GENERATOR_INDEX__SILOED_NOTE_HASH = 4; diff --git a/barretenberg/cpp/pil/vm2/execution.pil b/barretenberg/cpp/pil/vm2/execution.pil index e358df327bc3..2d03fe9cac38 100644 --- a/barretenberg/cpp/pil/vm2/execution.pil +++ b/barretenberg/cpp/pil/vm2/execution.pil @@ -1,5 +1,6 @@ include "alu.pil"; include "addressing.pil"; +include "address_derivation.pil"; include "bc_decomposition.pil"; include "bc_hashing.pil"; include "bc_retrieval.pil"; diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/aztec_types.hpp b/barretenberg/cpp/src/barretenberg/vm2/common/aztec_types.hpp index c1a4f872b2f0..ea1e8f370cc2 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/aztec_types.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/aztec_types.hpp @@ -22,15 +22,18 @@ struct PublicKeys { return { nullifier_key.x, nullifier_key.y, incoming_viewing_key.x, incoming_viewing_key.y, outgoing_viewing_key.x, outgoing_viewing_key.y, tagging_key.x, tagging_key.y }; } + + bool operator==(const PublicKeys& other) const = default; }; struct ContractInstance { - AztecAddress address; FF salt; AztecAddress deployer_addr; ContractClassId contract_class_id; FF initialisation_hash; PublicKeys public_keys; + + bool operator==(const ContractInstance& other) const = default; }; struct ContractClass { diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/standard_affine_point.hpp b/barretenberg/cpp/src/barretenberg/vm2/common/standard_affine_point.hpp index 54fca66462d5..2ec8908fc3bf 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/standard_affine_point.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/standard_affine_point.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include namespace bb::avm2 { @@ -51,15 +52,27 @@ template class StandardAffinePoint { constexpr const BaseField& y() const noexcept { return point.is_point_at_infinity() ? zero : point.y; } - static StandardAffinePoint& infinity() + static const StandardAffinePoint& infinity() { static auto infinity = StandardAffinePoint(AffinePoint::infinity()); return infinity; } + static const StandardAffinePoint& one() + { + static auto one = StandardAffinePoint(AffinePoint::one()); + return one; + } + private: AffinePoint point; static constexpr const auto zero = BaseField::zero(); }; +template std::ostream& operator<<(std::ostream& os, const StandardAffinePoint& point) +{ + os << "StandardAffinePoint(" << point.x() << ", " << point.y() << ", " << point.is_infinity() << ")"; + return os; +} + } // namespace bb::avm2 diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/address_derivation.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/address_derivation.test.cpp new file mode 100644 index 000000000000..4aeba05e7cbb --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/address_derivation.test.cpp @@ -0,0 +1,174 @@ +#include +#include + +#include "barretenberg/crypto/poseidon2/poseidon2.hpp" +#include "barretenberg/crypto/poseidon2/poseidon2_params.hpp" +#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/address_derivation.hpp" +#include "barretenberg/vm2/generated/relations/lookups_address_derivation.hpp" +#include "barretenberg/vm2/simulation/address_derivation.hpp" +#include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" +#include "barretenberg/vm2/simulation/events/ecc_events.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" +#include "barretenberg/vm2/simulation/to_radix.hpp" +#include "barretenberg/vm2/testing/fixtures.hpp" +#include "barretenberg/vm2/tracegen/address_derivation_trace.hpp" +#include "barretenberg/vm2/tracegen/ecc_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" +#include "barretenberg/vm2/tracegen/to_radix_trace.hpp" + +namespace bb::avm2::constraining { +namespace { + +using tracegen::AddressDerivationTraceBuilder; +using tracegen::EccTraceBuilder; +using tracegen::LookupIntoDynamicTableSequential; +using tracegen::Poseidon2TraceBuilder; +using tracegen::TestTraceContainer; + +using simulation::AddressDerivation; +using simulation::AddressDerivationEvent; +using simulation::compute_contract_address; +using simulation::Ecc; +using simulation::EccAddEvent; +using simulation::EventEmitter; +using simulation::hash_public_keys; +using simulation::NoopEventEmitter; +using simulation::Poseidon2; +using simulation::Poseidon2HashEvent; +using simulation::Poseidon2PermutationEvent; +using simulation::ScalarMulEvent; +using simulation::ToRadix; +using simulation::ToRadixEvent; + +using FF = AvmFlavorSettings::FF; +using C = Column; +using address_derivation_relation = bb::avm2::address_derivation; +using poseidon2_relation = bb::avm2::poseidon2_hash; +using ecadd_relation = bb::avm2::ecc; +using scalar_mul_relation = bb::avm2::scalar_mul; +using poseidon2 = crypto::Poseidon2; + +using lookup_salted_initialization_hash_poseidon2_0 = + bb::avm2::lookup_address_derivation_salted_initialization_hash_poseidon2_0_relation; +using lookup_salted_initialization_hash_poseidon2_1 = + bb::avm2::lookup_address_derivation_salted_initialization_hash_poseidon2_1_relation; +using lookup_partial_address_poseidon2 = bb::avm2::lookup_address_derivation_partial_address_poseidon2_relation; +using lookup_public_keys_hash_poseidon2_0 = + bb::avm2::lookup_address_derivation_public_keys_hash_poseidon2_0_relation; +using lookup_public_keys_hash_poseidon2_1 = + bb::avm2::lookup_address_derivation_public_keys_hash_poseidon2_1_relation; +using lookup_public_keys_hash_poseidon2_2 = + bb::avm2::lookup_address_derivation_public_keys_hash_poseidon2_2_relation; +using lookup_public_keys_hash_poseidon2_3 = + bb::avm2::lookup_address_derivation_public_keys_hash_poseidon2_3_relation; +using lookup_public_keys_hash_poseidon2_4 = + bb::avm2::lookup_address_derivation_public_keys_hash_poseidon2_4_relation; +using lookup_public_preaddress_poseidon2 = bb::avm2::lookup_address_derivation_preaddress_poseidon2_relation; +using lookup_public_preaddress_scalar_mul = bb::avm2::lookup_address_derivation_preaddress_scalar_mul_relation; +using lookup_address_ecadd = bb::avm2::lookup_address_derivation_address_ecadd_relation; + +TEST(AddressDerivationConstrainingTest, EmptyRow) +{ + check_relation(testing::empty_trace()); +} + +TEST(AddressDerivationConstrainingTest, Basic) +{ + TestTraceContainer trace; + AddressDerivationTraceBuilder builder; + + auto instance = testing::random_contract_instance(); + + FF salted_initialization_hash = poseidon2::hash( + { GENERATOR_INDEX__PARTIAL_ADDRESS, instance.salt, instance.initialisation_hash, instance.deployer_addr }); + + FF partial_address = + poseidon2::hash({ GENERATOR_INDEX__PARTIAL_ADDRESS, instance.contract_class_id, salted_initialization_hash }); + + FF public_keys_hash = hash_public_keys(instance.public_keys); + FF preaddress = poseidon2::hash({ GENERATOR_INDEX__CONTRACT_ADDRESS_V1, public_keys_hash, partial_address }); + + EmbeddedCurvePoint g1 = EmbeddedCurvePoint::one(); + EmbeddedCurvePoint preaddress_public_key = g1 * Fq(preaddress); + EmbeddedCurvePoint address_point = preaddress_public_key + instance.public_keys.incoming_viewing_key; + + builder.process({ { .address = address_point.x(), + .instance = instance, + .salted_initialization_hash = salted_initialization_hash, + .partial_address = partial_address, + .public_keys_hash = public_keys_hash, + .preaddress = preaddress, + .preaddress_public_key = preaddress_public_key, + .address_point = address_point } }, + trace); + + EXPECT_EQ(trace.get_num_rows(), 1); + check_relation(trace); +} + +TEST(AddressDerivationConstrainingTest, WithInteractions) +{ + NoopEventEmitter to_radix_event_emitter; + EventEmitter ecadd_event_emitter; + EventEmitter scalar_mul_event_emitter; + EventEmitter hash_event_emitter; + NoopEventEmitter perm_event_emitter; + EventEmitter address_derivation_event_emitter; + + ToRadix to_radix_simulator(to_radix_event_emitter); + Ecc ecc_simulator(to_radix_simulator, ecadd_event_emitter, scalar_mul_event_emitter); + Poseidon2 poseidon2_simulator(hash_event_emitter, perm_event_emitter); + + AddressDerivation address_derivation(poseidon2_simulator, ecc_simulator, address_derivation_event_emitter); + + TestTraceContainer trace = TestTraceContainer::from_rows({ + { .precomputed_first_row = 1 }, + }); + + AddressDerivationTraceBuilder builder; + Poseidon2TraceBuilder poseidon2_builder; + EccTraceBuilder ecc_builder; + + ContractInstance instance = testing::random_contract_instance(); + AztecAddress address = compute_contract_address(instance); + address_derivation.assert_derivation(address, instance); + + builder.process(address_derivation_event_emitter.dump_events(), trace); + poseidon2_builder.process_hash(hash_event_emitter.dump_events(), trace); + ecc_builder.process_add(ecadd_event_emitter.dump_events(), trace); + ecc_builder.process_scalar_mul(scalar_mul_event_emitter.dump_events(), trace); + + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + LookupIntoDynamicTableSequential().process(trace); + + check_relation(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(trace); + check_interaction(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 87555864890a..6627a3a833d2 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp @@ -10,8 +10,8 @@ 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_instr_size_in_bytes, precomputed_integral_tag_length, precomputed_p_decomposition_limb, precomputed_p_decomposition_limb_index, precomputed_p_decomposition_radix, 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_p_decomposition, precomputed_sel_range_16, precomputed_sel_range_8, precomputed_sel_range_wire_opcode, precomputed_sel_sha256_compression, precomputed_sel_to_radix_safe_limbs, precomputed_sel_unary, precomputed_sha256_compression_round_constant, precomputed_to_radix_safe_limbs, 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_instr_size_in_bytes, 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, 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, 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, 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 -#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, 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 +#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_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_instr_size_in_bytes, 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, 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, lookup_poseidon2_hash_poseidon2_perm_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_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_decomposition_bytes_to_read_as_unary_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_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_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_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_decomposition_bytes_to_read_as_unary_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_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, 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.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 #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 = 965; -constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 850; +constexpr auto NUM_COLUMNS_WITH_SHIFTS = 1013; +constexpr auto NUM_COLUMNS_WITHOUT_SHIFTS = 898; 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 2c489ca1c378..8ef02ec75c02 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp @@ -18,6 +18,7 @@ #include "flavor_settings.hpp" // Relations +#include "relations/address_derivation.hpp" #include "relations/alu.hpp" #include "relations/bc_decomposition.hpp" #include "relations/bc_hashing.hpp" @@ -35,6 +36,7 @@ #include "relations/to_radix.hpp" // Lookup and permutation relations +#include "relations/lookups_address_derivation.hpp" #include "relations/lookups_bc_decomposition.hpp" #include "relations/lookups_bc_hashing.hpp" #include "relations/lookups_bc_retrieval.hpp" @@ -88,17 +90,18 @@ class AvmFlavor { static constexpr bool HasZK = false; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 44; - static constexpr size_t NUM_WITNESS_ENTITIES = 806; + static constexpr size_t NUM_WITNESS_ENTITIES = 854; static constexpr size_t NUM_SHIFTED_ENTITIES = 115; 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 = 965; + static constexpr size_t NUM_ALL_ENTITIES = 1013; // Need to be templated for recursive verifier template using MainRelations_ = std::tuple< // Relations + avm2::address_derivation, avm2::alu, avm2::bc_decomposition, avm2::bc_hashing, @@ -121,6 +124,17 @@ class AvmFlavor { template using LookupRelations_ = std::tuple< // Lookups + lookup_address_derivation_address_ecadd_relation, + lookup_address_derivation_partial_address_poseidon2_relation, + lookup_address_derivation_preaddress_poseidon2_relation, + lookup_address_derivation_preaddress_scalar_mul_relation, + lookup_address_derivation_public_keys_hash_poseidon2_0_relation, + lookup_address_derivation_public_keys_hash_poseidon2_1_relation, + lookup_address_derivation_public_keys_hash_poseidon2_2_relation, + lookup_address_derivation_public_keys_hash_poseidon2_3_relation, + lookup_address_derivation_public_keys_hash_poseidon2_4_relation, + lookup_address_derivation_salted_initialization_hash_poseidon2_0_relation, + lookup_address_derivation_salted_initialization_hash_poseidon2_1_relation, lookup_bc_decomposition_abs_diff_is_u16_relation, lookup_bc_decomposition_bytes_are_bytes_relation, lookup_bc_decomposition_bytes_to_read_as_unary_relation, diff --git a/barretenberg/cpp/src/barretenberg/vm2/generated/relations/address_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/address_derivation.hpp new file mode 100644 index 000000000000..ab599c098ae1 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/address_derivation.hpp @@ -0,0 +1,90 @@ +// AUTOGENERATED FILE +#pragma once + +#include + +#include "barretenberg/relations/relation_parameters.hpp" +#include "barretenberg/relations/relation_types.hpp" + +namespace bb::avm2 { + +template class address_derivationImpl { + public: + using FF = FF_; + + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 3, 3, 3 }; + + template inline static bool skip(const AllEntities& in) + { + const auto& new_term = in; + return (new_term.address_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_GRUMPKIN_ONE_X = FF(1); + const auto constants_GRUMPKIN_ONE_Y = + FF(uint256_t{ 9457493854555940652UL, 3253583849847263892UL, 14921373847124204899UL, 2UL }); + const auto constants_GENERATOR_INDEX__CONTRACT_ADDRESS_V1 = FF(15); + const auto constants_GENERATOR_INDEX__PARTIAL_ADDRESS = FF(27); + const auto constants_GENERATOR_INDEX__PUBLIC_KEYS_HASH = FF(52); + + { + using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; + auto tmp = new_term.address_derivation_sel * (FF(1) - new_term.address_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.address_derivation_sel * (new_term.address_derivation_partial_address_domain_separator - + constants_GENERATOR_INDEX__PARTIAL_ADDRESS); + tmp *= scaling_factor; + std::get<1>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<2, ContainerOverSubrelations>; + auto tmp = + new_term.address_derivation_sel * (new_term.address_derivation_public_keys_hash_domain_separator - + constants_GENERATOR_INDEX__PUBLIC_KEYS_HASH); + tmp *= scaling_factor; + std::get<2>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>; + auto tmp = new_term.address_derivation_sel * (new_term.address_derivation_preaddress_domain_separator - + constants_GENERATOR_INDEX__CONTRACT_ADDRESS_V1); + tmp *= scaling_factor; + std::get<3>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<4, ContainerOverSubrelations>; + auto tmp = new_term.address_derivation_sel * (new_term.address_derivation_g1_x - constants_GRUMPKIN_ONE_X); + tmp *= scaling_factor; + std::get<4>(evals) += typename Accumulator::View(tmp); + } + { + using Accumulator = typename std::tuple_element_t<5, ContainerOverSubrelations>; + auto tmp = new_term.address_derivation_sel * (new_term.address_derivation_g1_y - constants_GRUMPKIN_ONE_Y); + tmp *= scaling_factor; + std::get<5>(evals) += typename Accumulator::View(tmp); + } + } +}; + +template class address_derivation : public Relation> { + public: + static constexpr const std::string_view NAME = "address_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_address_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_address_derivation.hpp new file mode 100644 index 000000000000..7284b666a2a2 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/generated/relations/lookups_address_derivation.hpp @@ -0,0 +1,1136 @@ +// AUTOGENERATED FILE +#pragma once + +#include "../columns.hpp" +#include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" + +#include +#include +#include + +namespace bb::avm2 { + +/////////////////// lookup_address_derivation_salted_initialization_hash_poseidon2_0 /////////////////// + +class lookup_address_derivation_salted_initialization_hash_poseidon2_0_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_SALTED_INITIALIZATION_HASH_POSEIDON2_0"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_start; + static constexpr Column COUNTS = Column::lookup_address_derivation_salted_initialization_hash_poseidon2_0_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_salted_initialization_hash_poseidon2_0_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_partial_address_domain_separator, + ColumnAndShifts::address_derivation_salt, + ColumnAndShifts::address_derivation_init_hash, + ColumnAndShifts::address_derivation_salted_init_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_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._address_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_address_derivation_salted_initialization_hash_poseidon2_0_inv(), + in._lookup_address_derivation_salted_initialization_hash_poseidon2_0_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_start(), + in._address_derivation_partial_address_domain_separator(), + in._address_derivation_salt(), + in._address_derivation_init_hash(), + in._address_derivation_salted_init_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_salted_initialization_hash_poseidon2_0_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_salted_initialization_hash_poseidon2_0_settings; + static constexpr std::string_view NAME = + lookup_address_derivation_salted_initialization_hash_poseidon2_0_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_salted_initialization_hash_poseidon2_0_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_salted_initialization_hash_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_address_derivation_salted_initialization_hash_poseidon2_1 /////////////////// + +class lookup_address_derivation_salted_initialization_hash_poseidon2_1_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_SALTED_INITIALIZATION_HASH_POSEIDON2_1"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end; + static constexpr Column COUNTS = Column::lookup_address_derivation_salted_initialization_hash_poseidon2_1_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_salted_initialization_hash_poseidon2_1_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_deployer_addr, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_salted_init_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_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._address_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_address_derivation_salted_initialization_hash_poseidon2_1_inv(), + in._lookup_address_derivation_salted_initialization_hash_poseidon2_1_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_end(), + in._address_derivation_deployer_addr(), + in._precomputed_zero(), + in._precomputed_zero(), + in._address_derivation_salted_init_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_salted_initialization_hash_poseidon2_1_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_salted_initialization_hash_poseidon2_1_settings; + static constexpr std::string_view NAME = + lookup_address_derivation_salted_initialization_hash_poseidon2_1_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_salted_initialization_hash_poseidon2_1_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_salted_initialization_hash_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); + } +}; + +/////////////////// lookup_address_derivation_partial_address_poseidon2 /////////////////// + +class lookup_address_derivation_partial_address_poseidon2_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PARTIAL_ADDRESS_POSEIDON2"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end; + static constexpr Column COUNTS = Column::lookup_address_derivation_partial_address_poseidon2_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_partial_address_poseidon2_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_partial_address_domain_separator, + ColumnAndShifts::address_derivation_class_id, + ColumnAndShifts::address_derivation_salted_init_hash, + ColumnAndShifts::address_derivation_partial_address + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_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._address_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_address_derivation_partial_address_poseidon2_inv(), + in._lookup_address_derivation_partial_address_poseidon2_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_end(), + in._address_derivation_partial_address_domain_separator(), + in._address_derivation_class_id(), + in._address_derivation_salted_init_hash(), + in._address_derivation_partial_address(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_partial_address_poseidon2_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_partial_address_poseidon2_settings; + static constexpr std::string_view NAME = lookup_address_derivation_partial_address_poseidon2_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_partial_address_poseidon2_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_partial_address_poseidon2_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_address_derivation_public_keys_hash_poseidon2_0 /////////////////// + +class lookup_address_derivation_public_keys_hash_poseidon2_0_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PUBLIC_KEYS_HASH_POSEIDON2_0"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_start; + static constexpr Column COUNTS = Column::lookup_address_derivation_public_keys_hash_poseidon2_0_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_public_keys_hash_poseidon2_0_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_public_keys_hash_domain_separator, + ColumnAndShifts::address_derivation_nullifier_key_x, + ColumnAndShifts::address_derivation_nullifier_key_y, + ColumnAndShifts::address_derivation_public_keys_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_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._address_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_address_derivation_public_keys_hash_poseidon2_0_inv(), + in._lookup_address_derivation_public_keys_hash_poseidon2_0_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_start(), + in._address_derivation_public_keys_hash_domain_separator(), + in._address_derivation_nullifier_key_x(), + in._address_derivation_nullifier_key_y(), + in._address_derivation_public_keys_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_public_keys_hash_poseidon2_0_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_public_keys_hash_poseidon2_0_settings; + static constexpr std::string_view NAME = lookup_address_derivation_public_keys_hash_poseidon2_0_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_public_keys_hash_poseidon2_0_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_public_keys_hash_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_address_derivation_public_keys_hash_poseidon2_1 /////////////////// + +class lookup_address_derivation_public_keys_hash_poseidon2_1_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PUBLIC_KEYS_HASH_POSEIDON2_1"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_sel; + static constexpr Column COUNTS = Column::lookup_address_derivation_public_keys_hash_poseidon2_1_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_public_keys_hash_poseidon2_1_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_incoming_viewing_key_x, + ColumnAndShifts::address_derivation_incoming_viewing_key_y, + ColumnAndShifts::address_derivation_public_keys_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_derivation_sel() == 1 || in._poseidon2_hash_sel() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._address_derivation_sel()); + const auto is_table_entry = View(in._poseidon2_hash_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_address_derivation_public_keys_hash_poseidon2_1_inv(), + in._lookup_address_derivation_public_keys_hash_poseidon2_1_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_sel(), + in._precomputed_zero(), + in._address_derivation_incoming_viewing_key_x(), + in._address_derivation_incoming_viewing_key_y(), + in._address_derivation_public_keys_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_public_keys_hash_poseidon2_1_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_public_keys_hash_poseidon2_1_settings; + static constexpr std::string_view NAME = lookup_address_derivation_public_keys_hash_poseidon2_1_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_public_keys_hash_poseidon2_1_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_public_keys_hash_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); + } +}; + +/////////////////// lookup_address_derivation_public_keys_hash_poseidon2_2 /////////////////// + +class lookup_address_derivation_public_keys_hash_poseidon2_2_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PUBLIC_KEYS_HASH_POSEIDON2_2"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_sel; + static constexpr Column COUNTS = Column::lookup_address_derivation_public_keys_hash_poseidon2_2_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_public_keys_hash_poseidon2_2_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_outgoing_viewing_key_x, + ColumnAndShifts::address_derivation_outgoing_viewing_key_y, + ColumnAndShifts::address_derivation_public_keys_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_derivation_sel() == 1 || in._poseidon2_hash_sel() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._address_derivation_sel()); + const auto is_table_entry = View(in._poseidon2_hash_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_address_derivation_public_keys_hash_poseidon2_2_inv(), + in._lookup_address_derivation_public_keys_hash_poseidon2_2_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_sel(), + in._precomputed_zero(), + in._address_derivation_outgoing_viewing_key_x(), + in._address_derivation_outgoing_viewing_key_y(), + in._address_derivation_public_keys_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_public_keys_hash_poseidon2_2_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_public_keys_hash_poseidon2_2_settings; + static constexpr std::string_view NAME = lookup_address_derivation_public_keys_hash_poseidon2_2_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_public_keys_hash_poseidon2_2_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_public_keys_hash_poseidon2_2_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_address_derivation_public_keys_hash_poseidon2_3 /////////////////// + +class lookup_address_derivation_public_keys_hash_poseidon2_3_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PUBLIC_KEYS_HASH_POSEIDON2_3"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_sel; + static constexpr Column COUNTS = Column::lookup_address_derivation_public_keys_hash_poseidon2_3_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_public_keys_hash_poseidon2_3_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_tagging_key_x, + ColumnAndShifts::address_derivation_tagging_key_y, + ColumnAndShifts::address_derivation_public_keys_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_derivation_sel() == 1 || in._poseidon2_hash_sel() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._address_derivation_sel()); + const auto is_table_entry = View(in._poseidon2_hash_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_address_derivation_public_keys_hash_poseidon2_3_inv(), + in._lookup_address_derivation_public_keys_hash_poseidon2_3_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_sel(), + in._precomputed_zero(), + in._address_derivation_tagging_key_x(), + in._address_derivation_tagging_key_y(), + in._address_derivation_public_keys_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_public_keys_hash_poseidon2_3_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_public_keys_hash_poseidon2_3_settings; + static constexpr std::string_view NAME = lookup_address_derivation_public_keys_hash_poseidon2_3_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_public_keys_hash_poseidon2_3_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_public_keys_hash_poseidon2_3_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_address_derivation_public_keys_hash_poseidon2_4 /////////////////// + +class lookup_address_derivation_public_keys_hash_poseidon2_4_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PUBLIC_KEYS_HASH_POSEIDON2_4"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end; + static constexpr Column COUNTS = Column::lookup_address_derivation_public_keys_hash_poseidon2_4_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_public_keys_hash_poseidon2_4_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_public_keys_hash + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_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._address_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_address_derivation_public_keys_hash_poseidon2_4_inv(), + in._lookup_address_derivation_public_keys_hash_poseidon2_4_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_end(), + in._precomputed_zero(), + in._precomputed_zero(), + in._precomputed_zero(), + in._address_derivation_public_keys_hash(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_public_keys_hash_poseidon2_4_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_public_keys_hash_poseidon2_4_settings; + static constexpr std::string_view NAME = lookup_address_derivation_public_keys_hash_poseidon2_4_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_public_keys_hash_poseidon2_4_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_public_keys_hash_poseidon2_4_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_address_derivation_preaddress_poseidon2 /////////////////// + +class lookup_address_derivation_preaddress_poseidon2_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PREADDRESS_POSEIDON2"; + static constexpr std::string_view RELATION_NAME = "address_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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end; + static constexpr Column COUNTS = Column::lookup_address_derivation_preaddress_poseidon2_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_preaddress_poseidon2_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_preaddress_domain_separator, + ColumnAndShifts::address_derivation_public_keys_hash, + ColumnAndShifts::address_derivation_partial_address, + ColumnAndShifts::address_derivation_preaddress + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::poseidon2_hash_input_0, + ColumnAndShifts::poseidon2_hash_input_1, + ColumnAndShifts::poseidon2_hash_input_2, + ColumnAndShifts::poseidon2_hash_output + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_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._address_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_address_derivation_preaddress_poseidon2_inv(), + in._lookup_address_derivation_preaddress_poseidon2_counts(), + in._address_derivation_sel(), + in._poseidon2_hash_end(), + in._address_derivation_preaddress_domain_separator(), + in._address_derivation_public_keys_hash(), + in._address_derivation_partial_address(), + in._address_derivation_preaddress(), + in._poseidon2_hash_input_0(), + in._poseidon2_hash_input_1(), + in._poseidon2_hash_input_2(), + in._poseidon2_hash_output()); + } +}; + +template +class lookup_address_derivation_preaddress_poseidon2_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_preaddress_poseidon2_settings; + static constexpr std::string_view NAME = lookup_address_derivation_preaddress_poseidon2_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_preaddress_poseidon2_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_preaddress_poseidon2_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_address_derivation_preaddress_scalar_mul /////////////////// + +class lookup_address_derivation_preaddress_scalar_mul_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_PREADDRESS_SCALAR_MUL"; + static constexpr std::string_view RELATION_NAME = "address_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 = 7; + 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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::scalar_mul_start; + static constexpr Column COUNTS = Column::lookup_address_derivation_preaddress_scalar_mul_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_preaddress_scalar_mul_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_preaddress, + ColumnAndShifts::address_derivation_g1_x, + ColumnAndShifts::address_derivation_g1_y, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_preaddress_public_key_x, + ColumnAndShifts::address_derivation_preaddress_public_key_y, + ColumnAndShifts::precomputed_zero + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::scalar_mul_scalar, ColumnAndShifts::scalar_mul_point_x, ColumnAndShifts::scalar_mul_point_y, + ColumnAndShifts::scalar_mul_point_inf, ColumnAndShifts::scalar_mul_res_x, ColumnAndShifts::scalar_mul_res_y, + ColumnAndShifts::scalar_mul_res_inf + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_derivation_sel() == 1 || in._scalar_mul_start() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._address_derivation_sel()); + const auto is_table_entry = View(in._scalar_mul_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_address_derivation_preaddress_scalar_mul_inv(), + in._lookup_address_derivation_preaddress_scalar_mul_counts(), + in._address_derivation_sel(), + in._scalar_mul_start(), + in._address_derivation_preaddress(), + in._address_derivation_g1_x(), + in._address_derivation_g1_y(), + in._precomputed_zero(), + in._address_derivation_preaddress_public_key_x(), + in._address_derivation_preaddress_public_key_y(), + in._precomputed_zero(), + in._scalar_mul_scalar(), + in._scalar_mul_point_x(), + in._scalar_mul_point_y(), + in._scalar_mul_point_inf(), + in._scalar_mul_res_x(), + in._scalar_mul_res_y(), + in._scalar_mul_res_inf()); + } +}; + +template +class lookup_address_derivation_preaddress_scalar_mul_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_preaddress_scalar_mul_settings; + static constexpr std::string_view NAME = lookup_address_derivation_preaddress_scalar_mul_settings::NAME; + static constexpr std::string_view RELATION_NAME = + lookup_address_derivation_preaddress_scalar_mul_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_preaddress_scalar_mul_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_address_derivation_address_ecadd /////////////////// + +class lookup_address_derivation_address_ecadd_settings { + public: + static constexpr std::string_view NAME = "LOOKUP_ADDRESS_DERIVATION_ADDRESS_ECADD"; + static constexpr std::string_view RELATION_NAME = "address_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 = 9; + 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::address_derivation_sel; + static constexpr Column DST_SELECTOR = Column::ecc_sel; + static constexpr Column COUNTS = Column::lookup_address_derivation_address_ecadd_counts; + static constexpr Column INVERSES = Column::lookup_address_derivation_address_ecadd_inv; + static constexpr std::array SRC_COLUMNS = { + ColumnAndShifts::address_derivation_preaddress_public_key_x, + ColumnAndShifts::address_derivation_preaddress_public_key_y, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_incoming_viewing_key_x, + ColumnAndShifts::address_derivation_incoming_viewing_key_y, + ColumnAndShifts::precomputed_zero, + ColumnAndShifts::address_derivation_address, + ColumnAndShifts::address_derivation_address_y, + ColumnAndShifts::precomputed_zero + }; + static constexpr std::array DST_COLUMNS = { + ColumnAndShifts::ecc_p_x, ColumnAndShifts::ecc_p_y, ColumnAndShifts::ecc_p_is_inf, + ColumnAndShifts::ecc_q_x, ColumnAndShifts::ecc_q_y, ColumnAndShifts::ecc_q_is_inf, + ColumnAndShifts::ecc_r_x, ColumnAndShifts::ecc_r_y, ColumnAndShifts::ecc_r_is_inf + }; + + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) + { + return (in._address_derivation_sel() == 1 || in._ecc_sel() == 1); + } + + template + static inline auto compute_inverse_exists(const AllEntities& in) + { + using View = typename Accumulator::View; + const auto is_operation = View(in._address_derivation_sel()); + const auto is_table_entry = View(in._ecc_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_address_derivation_address_ecadd_inv(), + in._lookup_address_derivation_address_ecadd_counts(), + in._address_derivation_sel(), + in._ecc_sel(), + in._address_derivation_preaddress_public_key_x(), + in._address_derivation_preaddress_public_key_y(), + in._precomputed_zero(), + in._address_derivation_incoming_viewing_key_x(), + in._address_derivation_incoming_viewing_key_y(), + in._precomputed_zero(), + in._address_derivation_address(), + in._address_derivation_address_y(), + in._precomputed_zero(), + in._ecc_p_x(), + in._ecc_p_y(), + in._ecc_p_is_inf(), + in._ecc_q_x(), + in._ecc_q_y(), + in._ecc_q_is_inf(), + in._ecc_r_x(), + in._ecc_r_y(), + in._ecc_r_is_inf()); + } +}; + +template +class lookup_address_derivation_address_ecadd_relation + : public GenericLookupRelation { + public: + using Settings = lookup_address_derivation_address_ecadd_settings; + static constexpr std::string_view NAME = lookup_address_derivation_address_ecadd_settings::NAME; + static constexpr std::string_view RELATION_NAME = lookup_address_derivation_address_ecadd_settings::RELATION_NAME; + + template inline static bool skip(const AllEntities& in) + { + return in.lookup_address_derivation_address_ecadd_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/simulation/address_derivation.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.cpp index ec689ef1d6a2..f5e2addccd9f 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.cpp @@ -3,16 +3,46 @@ #include #include "barretenberg/vm/aztec_constants.hpp" -#include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" +#include "barretenberg/vm2/common/field.hpp" namespace bb::avm2::simulation { void AddressDerivation::assert_derivation(const AztecAddress& address, const ContractInstance& instance) { // TODO: Cache and deduplicate. - // TODO: Use gadget. - assert(compute_contract_address(instance) == address); - events.emit({ .address = address, .instance = instance }); + FF salted_initialization_hash = poseidon2.hash( + { GENERATOR_INDEX__PARTIAL_ADDRESS, instance.salt, instance.initialisation_hash, instance.deployer_addr }); + + FF partial_address = + poseidon2.hash({ GENERATOR_INDEX__PARTIAL_ADDRESS, instance.contract_class_id, salted_initialization_hash }); + + std::vector public_keys_hash_fields = instance.public_keys.to_fields(); + std::vector public_key_hash_vec{ GENERATOR_INDEX__PUBLIC_KEYS_HASH }; + for (size_t i = 0; i < public_keys_hash_fields.size(); i += 2) { + public_key_hash_vec.push_back(public_keys_hash_fields[i]); + public_key_hash_vec.push_back(public_keys_hash_fields[i + 1]); + // is_infinity will be removed from address preimage, asumming false. + public_key_hash_vec.push_back(FF::zero()); + } + FF public_keys_hash = poseidon2.hash(public_key_hash_vec); + + FF preaddress = poseidon2.hash({ GENERATOR_INDEX__CONTRACT_ADDRESS_V1, public_keys_hash, partial_address }); + + EmbeddedCurvePoint preaddress_public_key = ecc.scalar_mul(EmbeddedCurvePoint::one(), preaddress); + EmbeddedCurvePoint address_point = ecc.add(preaddress_public_key, instance.public_keys.incoming_viewing_key); + + assert(address == address_point.x()); + + events.emit({ + .address = address, + .instance = instance, + .salted_initialization_hash = salted_initialization_hash, + .partial_address = partial_address, + .public_keys_hash = public_keys_hash, + .preaddress = preaddress, + .preaddress_public_key = preaddress_public_key, + .address_point = address_point, + }); } -} // namespace bb::avm2::simulation \ No newline at end of file +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.hpp index e751723157e5..b8c77fdc650b 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.hpp @@ -1,8 +1,10 @@ #pragma once #include "barretenberg/vm2/common/aztec_types.hpp" +#include "barretenberg/vm2/simulation/ecc.hpp" #include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" #include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/poseidon2.hpp" namespace bb::avm2::simulation { @@ -14,14 +16,20 @@ class AddressDerivationInterface { class AddressDerivation : public AddressDerivationInterface { public: - AddressDerivation(EventEmitterInterface& events) + AddressDerivation(Poseidon2Interface& poseidon2, + EccInterface& ecc, + EventEmitterInterface& events) : events(events) + , poseidon2(poseidon2) + , ecc(ecc) {} void assert_derivation(const AztecAddress& address, const ContractInstance& instance) override; private: EventEmitterInterface& events; + Poseidon2Interface& poseidon2; + EccInterface& ecc; }; -} // namespace bb::avm2::simulation \ No newline at end of file +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.test.cpp new file mode 100644 index 000000000000..06a914fe9c12 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.test.cpp @@ -0,0 +1,84 @@ +#include "barretenberg/vm2/simulation/address_derivation.hpp" + +#include +#include +#include + +#include "barretenberg/crypto/poseidon2/poseidon2.hpp" +#include "barretenberg/crypto/poseidon2/poseidon2_params.hpp" +#include "barretenberg/vm/aztec_constants.hpp" +#include "barretenberg/vm2/common/aztec_types.hpp" +#include "barretenberg/vm2/common/field.hpp" +#include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" +#include "barretenberg/vm2/simulation/testing/mock_ecc.hpp" +#include "barretenberg/vm2/simulation/testing/mock_poseidon2.hpp" +#include "barretenberg/vm2/testing/fixtures.hpp" + +using ::testing::Return; +using ::testing::SizeIs; +using ::testing::StrictMock; + +using poseidon2 = bb::crypto::Poseidon2; + +namespace bb::avm2::simulation { + +namespace { + +TEST(AvmSimulationAddressDerivationTest, Positive) +{ + EventEmitter address_derivation_event_emitter; + StrictMock poseidon2; + StrictMock ecc; + + AddressDerivation address_derivation(poseidon2, ecc, address_derivation_event_emitter); + + ContractInstance instance = testing::random_contract_instance(); + AztecAddress derived_address = compute_contract_address(instance); + std::vector salted_init_hash_inputs = { + GENERATOR_INDEX__PARTIAL_ADDRESS, instance.salt, instance.initialisation_hash, instance.deployer_addr + }; + FF salted_init_hash = poseidon2::hash(salted_init_hash_inputs); + EXPECT_CALL(poseidon2, hash(salted_init_hash_inputs)).WillOnce(Return(salted_init_hash)); + + std::vector partial_address_inputs = { GENERATOR_INDEX__PARTIAL_ADDRESS, + instance.contract_class_id, + salted_init_hash }; + FF partial_address = poseidon2::hash(partial_address_inputs); + EXPECT_CALL(poseidon2, hash(partial_address_inputs)).WillOnce(Return(partial_address)); + + std::vector public_keys_hash_fields = instance.public_keys.to_fields(); + std::vector public_key_hash_vec{ GENERATOR_INDEX__PUBLIC_KEYS_HASH }; + for (size_t i = 0; i < public_keys_hash_fields.size(); i += 2) { + public_key_hash_vec.push_back(public_keys_hash_fields[i]); + public_key_hash_vec.push_back(public_keys_hash_fields[i + 1]); + // is_infinity will be removed from address preimage, asumming false. + public_key_hash_vec.push_back(FF::zero()); + } + FF public_keys_hash = poseidon2::hash(public_key_hash_vec); + EXPECT_CALL(poseidon2, hash(public_key_hash_vec)).WillOnce(Return(public_keys_hash)); + + std::vector preaddress_inputs = { GENERATOR_INDEX__CONTRACT_ADDRESS_V1, public_keys_hash, partial_address }; + FF preaddress = poseidon2::hash(preaddress_inputs); + EXPECT_CALL(poseidon2, hash(preaddress_inputs)).WillOnce(Return(preaddress)); + + EmbeddedCurvePoint g1 = EmbeddedCurvePoint::one(); + EmbeddedCurvePoint preaddress_public_key = g1 * Fq(preaddress); + EXPECT_CALL(ecc, scalar_mul(g1, preaddress)).WillOnce(Return(preaddress_public_key)); + + EmbeddedCurvePoint address_point = preaddress_public_key + instance.public_keys.incoming_viewing_key; + EXPECT_CALL(ecc, add(preaddress_public_key, EmbeddedCurvePoint(instance.public_keys.incoming_viewing_key))) + .WillOnce(Return(address_point)); + + address_derivation.assert_derivation(derived_address, instance); + + auto events = address_derivation_event_emitter.dump_events(); + ASSERT_THAT(events, SizeIs(1)); + EXPECT_THAT(events[0].instance, instance); + EXPECT_THAT(events[0].address, derived_address); + EXPECT_THAT(events[0].address_point.x(), derived_address); +} + +} // namespace +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/ecc.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/ecc.test.cpp index d27d172021e2..38dbdb24e831 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/ecc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/ecc.test.cpp @@ -1,6 +1,6 @@ #include "barretenberg/vm2/simulation/ecc.hpp" -#include "gmock/gmock.h" +#include #include #include "barretenberg/vm2/common/field.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/address_derivation_event.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/address_derivation_event.hpp index 06c191510541..1de0547eb744 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/events/address_derivation_event.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/events/address_derivation_event.hpp @@ -1,12 +1,19 @@ #pragma once #include "barretenberg/vm2/common/aztec_types.hpp" +#include "barretenberg/vm2/common/field.hpp" namespace bb::avm2::simulation { struct AddressDerivationEvent { AztecAddress address; ContractInstance instance; + FF salted_initialization_hash; + FF partial_address; + FF public_keys_hash; + FF preaddress; + EmbeddedCurvePoint preaddress_public_key; + EmbeddedCurvePoint address_point; }; -} // namespace bb::avm2::simulation \ No newline at end of file +} // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.cpp index cf4de3f5757e..ef4a5300673e 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.cpp @@ -54,25 +54,30 @@ FF compute_contract_class_id(const FF& artifact_hash, const FF& private_fn_root, { GENERATOR_INDEX__CONTRACT_LEAF, artifact_hash, private_fn_root, public_bytecode_commitment }); } -FF compute_contract_address(const ContractInstance& contract_instance) +FF hash_public_keys(const PublicKeys& public_keys) { - FF salted_initialization_hash = poseidon2::hash({ GENERATOR_INDEX__PARTIAL_ADDRESS, - contract_instance.salt, - contract_instance.initialisation_hash, - contract_instance.deployer_addr }); - FF partial_address = poseidon2::hash( - { GENERATOR_INDEX__PARTIAL_ADDRESS, contract_instance.contract_class_id, salted_initialization_hash }); + std::vector public_keys_hash_fields = public_keys.to_fields(); - std::vector public_keys_hash_fields = contract_instance.public_keys.to_fields(); std::vector public_key_hash_vec{ GENERATOR_INDEX__PUBLIC_KEYS_HASH }; for (size_t i = 0; i < public_keys_hash_fields.size(); i += 2) { public_key_hash_vec.push_back(public_keys_hash_fields[i]); public_key_hash_vec.push_back(public_keys_hash_fields[i + 1]); - // Is it guaranteed we wont get a point at infinity here? + // is_infinity will be removed from address preimage, asumming false. public_key_hash_vec.push_back(FF::zero()); } - FF public_keys_hash = poseidon2::hash({ public_key_hash_vec }); + return poseidon2::hash({ public_key_hash_vec }); +} + +FF compute_contract_address(const ContractInstance& contract_instance) +{ + FF salted_initialization_hash = poseidon2::hash({ GENERATOR_INDEX__PARTIAL_ADDRESS, + contract_instance.salt, + contract_instance.initialisation_hash, + contract_instance.deployer_addr }); + FF partial_address = poseidon2::hash( + { GENERATOR_INDEX__PARTIAL_ADDRESS, contract_instance.contract_class_id, salted_initialization_hash }); + FF public_keys_hash = hash_public_keys(contract_instance.public_keys); FF h = poseidon2::hash({ GENERATOR_INDEX__CONTRACT_ADDRESS_V1, public_keys_hash, partial_address }); // This is safe since BN254_Fr < GRUMPKIN_Fr so we know there is no modulo reduction grumpkin::fr h_fq = grumpkin::fr(h); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.hpp index 9048d09d3038..4fd5e54d4e98 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/contract_crypto.hpp @@ -11,6 +11,7 @@ namespace bb::avm2::simulation { std::vector encode_bytecode(std::span bytecode); FF compute_public_bytecode_commitment(std::span bytecode); FF compute_contract_class_id(const FF& artifact_hash, const FF& private_fn_root, const FF& public_bytecode_commitment); +FF hash_public_keys(const PublicKeys& public_keys); FF compute_contract_address(const ContractInstance& contract_instance); } // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/raw_data_dbs.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/raw_data_dbs.cpp index e90c2118e5cd..d8f9510fb709 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/raw_data_dbs.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/raw_data_dbs.cpp @@ -42,7 +42,6 @@ ContractInstance HintedRawContractDB::get_contract_instance(const AztecAddress& auto contract_instance_hint = contract_instances.at(address); return { - .address = contract_instance_hint.address, .salt = contract_instance_hint.salt, .deployer_addr = contract_instance_hint.deployer, .contract_class_id = contract_instance_hint.originalContractClassId, diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_ecc.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_ecc.hpp index 0e282d0848c5..a281201b5db2 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_ecc.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/testing/mock_ecc.hpp @@ -13,6 +13,7 @@ class MockEcc : public EccInterface { ~MockEcc() override; MOCK_METHOD(EmbeddedCurvePoint, add, (const EmbeddedCurvePoint& p, const EmbeddedCurvePoint& q), (override)); + MOCK_METHOD(EmbeddedCurvePoint, scalar_mul, (const EmbeddedCurvePoint& p, const FF& scalar), (override)); }; } // namespace bb::avm2::simulation diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/to_radix.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/to_radix.test.cpp index 8df93219fc7f..6fe45cb43a19 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/to_radix.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/to_radix.test.cpp @@ -1,7 +1,7 @@ #include "barretenberg/vm2/simulation/to_radix.hpp" -#include "gmock/gmock.h" #include +#include #include #include "barretenberg/vm2/common/aztec_types.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp index a0c9b45ab0c1..62a205ce37f7 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation_helper.cpp @@ -75,8 +75,10 @@ template EventsContainer AvmSimulationHelper::simulate_with_setting typename S::template DefaultEventEmitter to_radix_emitter; Poseidon2 poseidon2(poseidon2_hash_emitter, poseidon2_perm_emitter); + ToRadix to_radix(to_radix_emitter); + Ecc ecc(to_radix, ecc_add_emitter, scalar_mul_emitter); - AddressDerivation address_derivation(address_derivation_emitter); + AddressDerivation address_derivation(poseidon2, ecc, address_derivation_emitter); ClassIdDerivation class_id_derivation(poseidon2, class_id_derivation_emitter); HintedRawContractDB raw_contract_db(inputs.hints); HintedRawMerkleDB raw_merkle_db(inputs.hints, inputs.publicInputs.startTreeSnapshots); @@ -101,8 +103,6 @@ template EventsContainer AvmSimulationHelper::simulate_with_setting Execution execution(alu, addressing, context_provider, context_stack, instruction_info_db, execution_emitter); TxExecution tx_execution(execution); Sha256 sha256(sha256_compression_emitter); - ToRadix to_radix(to_radix_emitter); - Ecc ecc_add(to_radix, ecc_add_emitter, scalar_mul_emitter); tx_execution.simulate({ .enqueued_calls = inputs.hints.enqueuedCalls }); diff --git a/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.cpp b/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.cpp index 48c703f0fdf3..c9f484c883ed 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.cpp @@ -2,7 +2,9 @@ #include +#include "barretenberg/vm2/common/aztec_types.hpp" #include "barretenberg/vm2/common/instruction_spec.hpp" +#include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" using bb::avm2::tracegen::TestTraceContainer; @@ -113,4 +115,19 @@ TestTraceContainer empty_trace() return TestTraceContainer::from_rows({ { .precomputed_first_row = 1 }, { .precomputed_clk = 1 } }); } +ContractInstance random_contract_instance() +{ + ContractInstance instance = { .salt = FF::random_element(), + .deployer_addr = FF::random_element(), + .contract_class_id = FF::random_element(), + .initialisation_hash = FF::random_element(), + .public_keys = PublicKeys{ + .nullifier_key = AffinePoint::random_element(), + .incoming_viewing_key = AffinePoint::random_element(), + .outgoing_viewing_key = AffinePoint::random_element(), + .tagging_key = AffinePoint::random_element(), + } }; + return instance; +} + } // namespace bb::avm2::testing diff --git a/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.hpp b/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.hpp index e43cd1bb5535..803e33c0dc15 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/testing/fixtures.hpp @@ -2,6 +2,7 @@ #include +#include "barretenberg/vm2/common/aztec_types.hpp" #include "barretenberg/vm2/common/field.hpp" #include "barretenberg/vm2/simulation/lib/serialization.hpp" #include "barretenberg/vm2/tracegen/test_trace_container.hpp" @@ -32,5 +33,6 @@ simulation::Operand random_operand(simulation::OperandType operand_type); // address resolution. simulation::Instruction random_instruction(WireOpCode w_opcode); tracegen::TestTraceContainer empty_trace(); +ContractInstance random_contract_instance(); } // namespace bb::avm2::testing diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/address_derivation_trace.cpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/address_derivation_trace.cpp new file mode 100644 index 000000000000..62bc2597788c --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/address_derivation_trace.cpp @@ -0,0 +1,54 @@ +#include "barretenberg/vm2/tracegen/address_derivation_trace.hpp" + +#include "barretenberg/vm/aztec_constants.hpp" +#include "barretenberg/vm2/common/aztec_types.hpp" +#include "barretenberg/vm2/common/field.hpp" +#include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/tracegen/trace_container.hpp" + +namespace bb::avm2::tracegen { + +void AddressDerivationTraceBuilder::process( + const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace) +{ + using C = Column; + + EmbeddedCurvePoint g1 = EmbeddedCurvePoint::one(); + + uint32_t row = 0; + for (const auto& event : events) { + trace.set( + row, + { { { C::address_derivation_sel, 1 }, + { C::address_derivation_salt, event.instance.salt }, + { C::address_derivation_deployer_addr, event.instance.deployer_addr }, + { C::address_derivation_class_id, event.instance.contract_class_id }, + { C::address_derivation_init_hash, event.instance.initialisation_hash }, + { C::address_derivation_nullifier_key_x, event.instance.public_keys.nullifier_key.x }, + { C::address_derivation_nullifier_key_y, event.instance.public_keys.nullifier_key.y }, + { C::address_derivation_incoming_viewing_key_x, event.instance.public_keys.incoming_viewing_key.x }, + { C::address_derivation_incoming_viewing_key_y, event.instance.public_keys.incoming_viewing_key.y }, + { C::address_derivation_outgoing_viewing_key_x, event.instance.public_keys.outgoing_viewing_key.x }, + { C::address_derivation_outgoing_viewing_key_y, event.instance.public_keys.outgoing_viewing_key.y }, + { C::address_derivation_tagging_key_x, event.instance.public_keys.tagging_key.x }, + { C::address_derivation_tagging_key_y, event.instance.public_keys.tagging_key.y }, + { C::address_derivation_address, event.address }, + { C::address_derivation_salted_init_hash, event.salted_initialization_hash }, + { C::address_derivation_partial_address_domain_separator, GENERATOR_INDEX__PARTIAL_ADDRESS }, + { C::address_derivation_partial_address, event.partial_address }, + { C::address_derivation_public_keys_hash, event.public_keys_hash }, + { C::address_derivation_public_keys_hash_domain_separator, GENERATOR_INDEX__PUBLIC_KEYS_HASH }, + { C::address_derivation_preaddress, event.preaddress }, + { C::address_derivation_preaddress_domain_separator, GENERATOR_INDEX__CONTRACT_ADDRESS_V1 }, + { C::address_derivation_preaddress_public_key_x, event.preaddress_public_key.x() }, + { C::address_derivation_preaddress_public_key_y, event.preaddress_public_key.y() }, + { C::address_derivation_g1_x, g1.x() }, + { C::address_derivation_g1_y, g1.y() }, + { C::address_derivation_address_y, event.address_point.y() } } }); + row++; + } +} + +} // namespace bb::avm2::tracegen diff --git a/barretenberg/cpp/src/barretenberg/vm2/tracegen/address_derivation_trace.hpp b/barretenberg/cpp/src/barretenberg/vm2/tracegen/address_derivation_trace.hpp new file mode 100644 index 000000000000..e86ddc8a4206 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen/address_derivation_trace.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "barretenberg/vm2/generated/columns.hpp" +#include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" +#include "barretenberg/vm2/simulation/events/event_emitter.hpp" +#include "barretenberg/vm2/tracegen/trace_container.hpp" + +namespace bb::avm2::tracegen { + +class AddressDerivationTraceBuilder final { + public: + void process(const simulation::EventEmitterInterface::Container& events, + TraceContainer& trace); +}; + +} // 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 09597901d808..7a920c2acf77 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/tracegen_helper.cpp @@ -14,6 +14,7 @@ #include "barretenberg/vm2/common/map.hpp" #include "barretenberg/vm2/generated/columns.hpp" #include "barretenberg/vm2/generated/flavor.hpp" +#include "barretenberg/vm2/generated/relations/lookups_address_derivation.hpp" #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" @@ -24,6 +25,7 @@ #include "barretenberg/vm2/generated/relations/lookups_scalar_mul.hpp" #include "barretenberg/vm2/generated/relations/lookups_sha256.hpp" #include "barretenberg/vm2/generated/relations/lookups_to_radix.hpp" +#include "barretenberg/vm2/tracegen/address_derivation_trace.hpp" #include "barretenberg/vm2/tracegen/alu_trace.hpp" #include "barretenberg/vm2/tracegen/bytecode_trace.hpp" #include "barretenberg/vm2/tracegen/class_id_derivation_trace.hpp" @@ -174,6 +176,12 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) clear_events(events.execution); clear_events(events.addressing); }, + [&]() { + AddressDerivationTraceBuilder address_derivation_builder; + AVM_TRACK_TIME("tracegen/address_derivation", + address_derivation_builder.process(events.address_derivation, trace)); + clear_events(events.address_derivation); + }, [&]() { AluTraceBuilder alu_builder; AVM_TRACK_TIME("tracegen/alu", alu_builder.process(events.alu, trace)); @@ -288,7 +296,29 @@ TraceContainer AvmTraceGenHelper::generate_trace(EventsContainer&& events) std::make_unique>(), std::make_unique>(), std::make_unique>(), - std::make_unique>()); + std::make_unique>(), + // Address derivation + std::make_unique>(), + std::make_unique>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique< + LookupIntoDynamicTableSequential>(), + std::make_unique>()); AVM_TRACK_TIME("tracegen/interactions", parallel_for(jobs_interactions.size(), [&](size_t i) { jobs_interactions[i]->process(trace); })); diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 1cd742220615..316a37b3f365 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -317,4 +317,7 @@ library Constants { uint256 internal constant MINIMUM_UPDATE_DELAY = 25; uint256 internal constant UPDATES_VALUE_SIZE = 1; uint256 internal constant UPDATES_SHARED_MUTABLE_VALUES_LEN = 3; + uint256 internal constant GRUMPKIN_ONE_X = 1; + uint256 internal constant GRUMPKIN_ONE_Y = + 17631683881184975370165255887551781615748388533673675138860; } diff --git a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr index 5768b056fb54..8660aad06eae 100644 --- a/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/avm_test_contract/src/main.nr @@ -26,7 +26,7 @@ pub contract AvmTest { scalar::Scalar, }; use dep::aztec::protocol_types::{ - constants::MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS, + constants::{GRUMPKIN_ONE_X, GRUMPKIN_ONE_Y, MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS}, contract_class_id::ContractClassId, storage::map::derive_storage_slot_in_map, traits::{Empty, FromField, ToField}, @@ -156,11 +156,7 @@ pub contract AvmTest { #[public] fn elliptic_curve_add_and_double() -> Point { - let g = Point { - x: 1, - y: 17631683881184975370165255887551781615748388533673675138860, - is_infinite: false, - }; + let g = Point { x: GRUMPKIN_ONE_X, y: GRUMPKIN_ONE_Y, is_infinite: false }; let doubled = g + g; let added = g + doubled; @@ -174,11 +170,7 @@ pub contract AvmTest { scalar2_lo: Field, scalar2_hi: Field, ) -> Point { - let g = Point { - x: 1, - y: 17631683881184975370165255887551781615748388533673675138860, - is_infinite: false, - }; + let g = Point { x: GRUMPKIN_ONE_X, y: GRUMPKIN_ONE_Y, is_infinite: false }; let triple_g = multi_scalar_mul( [g, g], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index 67d8735b76ba..75b8eeb70d3c 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -787,6 +787,9 @@ pub global MINIMUM_UPDATE_DELAY: u32 = 25; pub global UPDATES_VALUE_SIZE: u32 = 1; pub global UPDATES_SHARED_MUTABLE_VALUES_LEN: u32 = 2 * UPDATES_VALUE_SIZE + 1; +pub global GRUMPKIN_ONE_X: Field = 1; +pub global GRUMPKIN_ONE_Y: Field = 17631683881184975370165255887551781615748388533673675138860; + mod test { use crate::constants::{ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, diff --git a/yarn-project/constants/src/constants.gen.ts b/yarn-project/constants/src/constants.gen.ts index 50ad9bab80d1..037a0aa4e2cd 100644 --- a/yarn-project/constants/src/constants.gen.ts +++ b/yarn-project/constants/src/constants.gen.ts @@ -357,6 +357,8 @@ export const DEFAULT_UPDATE_DELAY = 3600; export const MINIMUM_UPDATE_DELAY = 25; export const UPDATES_VALUE_SIZE = 1; export const UPDATES_SHARED_MUTABLE_VALUES_LEN = 3; +export const GRUMPKIN_ONE_X = 1; +export const GRUMPKIN_ONE_Y = 17631683881184975370165255887551781615748388533673675138860n; export enum GeneratorIndex { NOTE_HASH = 1, NOTE_HASH_NONCE = 2, diff --git a/yarn-project/constants/src/scripts/constants.in.ts b/yarn-project/constants/src/scripts/constants.in.ts index 8eb2e8cf7b44..45cad98c17ae 100644 --- a/yarn-project/constants/src/scripts/constants.in.ts +++ b/yarn-project/constants/src/scripts/constants.in.ts @@ -154,6 +154,8 @@ const PIL_CONSTANTS = [ 'MEM_TAG_U128', 'MEM_TAG_FF', 'MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS', + 'GRUMPKIN_ONE_X', + 'GRUMPKIN_ONE_Y', ]; const PIL_GENERATORS: string[] = [ diff --git a/yarn-project/simulator/src/public/avm/fixtures/index.ts b/yarn-project/simulator/src/public/avm/fixtures/index.ts index f04c14ed979f..c94d5022f0fc 100644 --- a/yarn-project/simulator/src/public/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/public/avm/fixtures/index.ts @@ -23,6 +23,7 @@ import { import { isNoirCallStackUnresolved } from '@aztec/stdlib/errors'; import { GasFees } from '@aztec/stdlib/gas'; import { siloNullifier } from '@aztec/stdlib/hash'; +import { deriveKeys } from '@aztec/stdlib/keys'; import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/stdlib/testing'; import { GlobalVariables } from '@aztec/stdlib/tx'; @@ -284,17 +285,20 @@ export async function createContractClassAndInstance( ); const constructorAbi = getContractFunctionArtifact('constructor', contractArtifact); + const { publicKeys } = await deriveKeys(Fr.random()); const initializationHash = await computeInitializationHash(constructorAbi, constructorArgs); const contractInstance = originalContractClassId === undefined ? await makeContractInstanceFromClassId(contractClass.id, seed, { deployer, initializationHash, + publicKeys, }) : await makeContractInstanceFromClassId(originalContractClassId, seed, { deployer, initializationHash, currentClassId: contractClass.id, + publicKeys, }); const contractAddressNullifier = await siloNullifier(