From 9a6f57a8b309f0316be358a3e6aa381387d8b230 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Tue, 10 Sep 2024 20:46:31 +0000 Subject: [PATCH] from witness indices method for UH rec VK --- .../acir_format/honk_recursion_constraint.cpp | 31 ++++++++----------- .../ultra_recursive_flavor.hpp | 18 +++++++++++ 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp index 28611d07622..ffd15f941c6 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp @@ -32,7 +32,7 @@ namespace { void create_dummy_vkey_and_proof(Builder& builder, size_t proof_size, size_t public_inputs_size, - const std::vector& key_fields, + const std::vector& key_indices, const std::vector& proof_fields) { using Flavor = UltraFlavor; @@ -50,29 +50,29 @@ void create_dummy_vkey_and_proof(Builder& builder, Flavor::NUM_ALL_ENTITIES * num_frs_fr - 2 * num_frs_comm) / (num_frs_comm + num_frs_fr * Flavor::BATCHED_RELATION_PARTIAL_LENGTH); // First key field is circuit size - builder.assert_equal(builder.add_variable(1 << log_circuit_size), key_fields[0].witness_index); + builder.assert_equal(builder.add_variable(1 << log_circuit_size), key_indices[0]); // Second key field is number of public inputs - builder.assert_equal(builder.add_variable(public_inputs_size), key_fields[1].witness_index); + builder.assert_equal(builder.add_variable(public_inputs_size), key_indices[1]); // Third key field is the pub inputs offset - builder.assert_equal(builder.add_variable(Flavor::has_zero_row ? 1 : 0), key_fields[2].witness_index); + builder.assert_equal(builder.add_variable(Flavor::has_zero_row ? 1 : 0), key_indices[2]); // Fourth key field is the whether the proof contains an aggregation object. - builder.assert_equal(builder.add_variable(1), key_fields[3].witness_index); + builder.assert_equal(builder.add_variable(1), key_indices[3]); uint32_t offset = 4; size_t num_inner_public_inputs = public_inputs_size - bb::AGGREGATION_OBJECT_SIZE; // We are making the assumption that the aggregation object are behind all the inner public inputs for (size_t i = 0; i < bb::AGGREGATION_OBJECT_SIZE; i++) { - builder.assert_equal(builder.add_variable(num_inner_public_inputs + i), key_fields[offset].witness_index); + builder.assert_equal(builder.add_variable(num_inner_public_inputs + i), key_indices[offset]); offset++; } for (size_t i = 0; i < Flavor::NUM_PRECOMPUTED_ENTITIES; ++i) { auto comm = curve::BN254::AffineElement::one() * fr::random_element(); auto frs = field_conversion::convert_to_bn254_frs(comm); - builder.assert_equal(builder.add_variable(frs[0]), key_fields[offset].witness_index); - builder.assert_equal(builder.add_variable(frs[1]), key_fields[offset + 1].witness_index); - builder.assert_equal(builder.add_variable(frs[2]), key_fields[offset + 2].witness_index); - builder.assert_equal(builder.add_variable(frs[3]), key_fields[offset + 3].witness_index); + builder.assert_equal(builder.add_variable(frs[0]), key_indices[offset]); + builder.assert_equal(builder.add_variable(frs[1]), key_indices[offset + 1]); + builder.assert_equal(builder.add_variable(frs[2]), key_indices[offset + 2]); + builder.assert_equal(builder.add_variable(frs[3]), key_indices[offset + 3]); offset += 4; } @@ -168,12 +168,8 @@ AggregationObjectIndices create_honk_recursion_constraints(Builder& builder, // Construct an in-circuit representation of the verification key. // For now, the v-key is a circuit constant and is fixed for the circuit. // (We may need a separate recursion opcode for this to vary, or add more config witnesses to this opcode) - std::vector key_fields; - key_fields.reserve(input.key.size()); - for (const auto& idx : input.key) { - auto field = field_ct::from_witness_index(&builder, idx); - key_fields.emplace_back(field); - } + auto vkey = + std::make_shared(RecursiveVerificationKey::from_witness_indices(builder, input.key)); std::vector proof_fields; @@ -193,11 +189,10 @@ AggregationObjectIndices create_honk_recursion_constraints(Builder& builder, size_t size_of_proof_with_no_pub_inputs = input.proof.size() - bb::AGGREGATION_OBJECT_SIZE; size_t total_num_public_inputs = input.public_inputs.size() + bb::AGGREGATION_OBJECT_SIZE; create_dummy_vkey_and_proof( - builder, size_of_proof_with_no_pub_inputs, total_num_public_inputs, key_fields, proof_fields); + builder, size_of_proof_with_no_pub_inputs, total_num_public_inputs, input.key, proof_fields); } // Recursively verify the proof - auto vkey = std::make_shared(builder, key_fields); RecursiveVerifier verifier(&builder, vkey); aggregation_state_ct input_agg_obj = bb::stdlib::recursion::convert_witness_indices_to_agg_obj( builder, input_aggregation_object_indices); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp index a908d41226f..5cb743e26e6 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp @@ -158,6 +158,24 @@ template class UltraRecursiveFlavor_ { commitment = deserialize_from_frs(builder, elements, num_frs_read); } } + + /** + * @brief Construct a VerificationKey from a set of corresponding witness indices + * + * @param builder + * @param witness_indices + * @return VerificationKey + */ + static VerificationKey from_witness_indices(CircuitBuilder& builder, + const std::span& witness_indices) + { + std::vector vkey_fields; + vkey_fields.reserve(witness_indices.size()); + for (const auto& idx : witness_indices) { + vkey_fields.emplace_back(FF::from_witness_index(&builder, idx)); + } + return VerificationKey(builder, vkey_fields); + } }; /**