diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp index d92d010a7502..99d27ce387ce 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -513,22 +513,19 @@ MegaCircuitBuilder create_kernel_circuit(AcirFormat& constraint_system, // Create stdlib representations of each {proof, vkey} pair to be recursively verified ivc.instantiate_stdlib_verification_queue(circuit, stdlib_verification_keys); - // Connect the proof/public_input witness indices from each constraint to the corresponding proof witnesses in the - // internal verification queue. This ensures that the witnesses utlized in constraints generated based on acir are - // properly connected to the constraints generated herein via the ivc scheme (e.g. recursive verifications). + // Connect the public_input witnesses in each constraint to the corresponding public input witnesses in the internal + // verification queue. This ensures that the witnesses utlized in constraints generated based on acir are properly + // connected to the constraints generated herein via the ivc scheme (e.g. recursive verifications). for (auto [constraint, queue_entry] : zip_view(constraint_system.ivc_recursion_constraints, ivc.stdlib_verification_queue)) { - // Reconstruct complete proof indices from acir constraint data (in which proof is - // stripped of public inputs) - std::vector complete_proof_indices = - ProofSurgeon::create_indices_for_reconstructed_proof(constraint.proof, constraint.public_inputs); - ASSERT(complete_proof_indices.size() == queue_entry.proof.size()); + // Get the witness indices for the public inputs contained within the proof in the verification queue + std::vector public_input_indices = ProofSurgeon::get_public_inputs_witness_indices_from_proof( + queue_entry.proof, constraint.public_inputs.size()); - // Assert equality between the proof indices from the constraint data and those of the - // internal proof - for (auto [proof_value, proof_idx] : zip_view(queue_entry.proof, complete_proof_indices)) { - circuit.assert_equal(proof_value.get_witness_index(), proof_idx); + // Assert equality between the internal public input witness indices and those in the acir constraint + for (auto [witness_idx, constraint_witness_idx] : zip_view(public_input_indices, constraint.public_inputs)) { + circuit.assert_equal(witness_idx, constraint_witness_idx); } } diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp index f4a2d6b0c95b..a77b017fdfa4 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.test.cpp @@ -57,7 +57,7 @@ class IvcRecursionConstraintTest : public ::testing::Test { { // Assemble simple vectors of witnesses for vkey and proof std::vector key_witnesses = input.honk_verification_key->to_field_elements(); - std::vector proof_witnesses = input.proof; + std::vector proof_witnesses = input.proof; // proof contains the public inputs at this stage // Construct witness indices for each component in the constraint; populate the witness array auto [key_indices, proof_indices, public_inputs_indices] = @@ -68,7 +68,7 @@ class IvcRecursionConstraintTest : public ::testing::Test { return RecursionConstraint{ .key = key_indices, - .proof = proof_indices, + .proof = {}, // the proof witness indices are not needed in an ivc recursion constraint .public_inputs = public_inputs_indices, .key_hash = 0, // not used .proof_type = proof_type, diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp index 6906b048ff47..d6877def5de2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp @@ -2,6 +2,7 @@ #include "barretenberg/common/map.hpp" #include "barretenberg/common/serialize.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/honk/proof_system/types/proof.hpp" #include "barretenberg/plonk_honk_shared/types/aggregation_object_type.hpp" #include "barretenberg/serialize/msgpack.hpp" #include @@ -103,6 +104,28 @@ class ProofSurgeon { return public_input_witnesses; } + /** + * @brief Get the witness indices for a given number of public inputs contained within a stdlib proof + * + * @param proof A bberg style stdlib proof (contains public inputs) + * @param num_public_inputs The number of public input witness indices to get from the proof + * @return std::vector The corresponding public input witness indices + */ + static std::vector get_public_inputs_witness_indices_from_proof( + const bb::StdlibProof& proof, const size_t num_public_inputs_to_extract) + { + std::vector public_input_witness_indices; + public_input_witness_indices.reserve(num_public_inputs_to_extract); + + const size_t start = HONK_RECURSION_PUBLIC_INPUT_OFFSET; + const size_t end = start + num_public_inputs_to_extract; + for (size_t i = start; i < end; ++i) { + public_input_witness_indices.push_back(proof[i].get_witness_index()); + } + + return public_input_witness_indices; + } + struct RecursionWitnessData { std::vector key_indices; std::vector proof_indices;