Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t> 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<uint32_t> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class IvcRecursionConstraintTest : public ::testing::Test {
{
// Assemble simple vectors of witnesses for vkey and proof
std::vector<FF> key_witnesses = input.honk_verification_key->to_field_elements();
std::vector<FF> proof_witnesses = input.proof;
std::vector<FF> 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] =
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <barretenberg/common/container.hpp>
Expand Down Expand Up @@ -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<bb::fr> The corresponding public input witness indices
*/
static std::vector<uint32_t> get_public_inputs_witness_indices_from_proof(
const bb::StdlibProof<bb::MegaCircuitBuilder>& proof, const size_t num_public_inputs_to_extract)
{
std::vector<uint32_t> 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<uint32_t> key_indices;
std::vector<uint32_t> proof_indices;
Expand Down