From 255e00bc265f1322a03939588d6369af3085e059 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 2 Oct 2024 19:41:47 +0000 Subject: [PATCH 1/3] connect the public inputs only --- .../dsl/acir_format/acir_format.cpp | 11 +++++----- .../ivc_recursion_constraint.test.cpp | 3 ++- .../dsl/acir_format/proof_surgeon.hpp | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) 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 486e7f599ad8..7a2a9c7999d0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -493,13 +493,12 @@ MegaCircuitBuilder create_kernel_circuit(AcirFormat& constraint_system, 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()); + 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..77284ae0b650 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 @@ -66,9 +66,10 @@ class IvcRecursionConstraintTest : public ::testing::Test { // The proof type can be either Oink or PG PROOF_TYPE proof_type = input.type == QUEUE_TYPE::OINK ? OINK : PG; + // WORKTODO: start by simply clearing the proof witness indices in the output here return RecursionConstraint{ .key = key_indices, - .proof = proof_indices, + .proof = {}, .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..02b94e81ca9e 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp @@ -103,6 +103,27 @@ class ProofSurgeon { return public_input_witnesses; } + /** + * @brief Extract then remove a given number of public inputs from a proof + * + * @param proof_witnesses Witness values of a bberg style proof containing public inputs + * @param num_public_inputs The number of public inputs to extract from the proof + * @return std::vector The extracted public input witness values + */ + static std::vector get_public_inputs_witness_indices_from_proof(const auto& proof_witnesses, + const size_t num_public_inputs_to_extract) + { + std::vector public_input_witness_indices; + public_input_witness_indices.reserve(num_public_inputs_to_extract); + size_t start = HONK_RECURSION_PUBLIC_INPUT_OFFSET; + size_t end = start + num_public_inputs_to_extract; + for (size_t i = start; i < end; ++i) { + public_input_witness_indices.push_back(proof_witnesses[i].get_witness_index()); + } + + return public_input_witness_indices; + } + struct RecursionWitnessData { std::vector key_indices; std::vector proof_indices; From c887e3eb4fe57fa838c2a1686f73d188133d33da Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Wed, 2 Oct 2024 21:02:45 +0000 Subject: [PATCH 2/3] cleanup --- .../barretenberg/dsl/acir_format/acir_format.cpp | 8 ++++---- .../ivc_recursion_constraint.test.cpp | 5 ++--- .../dsl/acir_format/proof_surgeon.hpp | 16 +++++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) 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 7a2a9c7999d0..39df7bbe925a 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/acir_format.cpp @@ -486,13 +486,13 @@ 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) + // 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()); 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 77284ae0b650..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] = @@ -66,10 +66,9 @@ class IvcRecursionConstraintTest : public ::testing::Test { // The proof type can be either Oink or PG PROOF_TYPE proof_type = input.type == QUEUE_TYPE::OINK ? OINK : PG; - // WORKTODO: start by simply clearing the proof witness indices in the output here return RecursionConstraint{ .key = key_indices, - .proof = {}, + .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 02b94e81ca9e..f8e48b15384d 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 @@ -104,21 +105,22 @@ class ProofSurgeon { } /** - * @brief Extract then remove a given number of public inputs from a proof + * @brief Get the witness indices for a given number of public inputs contained within a stdlib proof * - * @param proof_witnesses Witness values of a bberg style proof containing public inputs - * @param num_public_inputs The number of public inputs to extract from the proof - * @return std::vector The extracted public input witness values + * @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 auto& proof_witnesses, - const size_t num_public_inputs_to_extract) + 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); + size_t start = HONK_RECURSION_PUBLIC_INPUT_OFFSET; size_t end = start + num_public_inputs_to_extract; for (size_t i = start; i < end; ++i) { - public_input_witness_indices.push_back(proof_witnesses[i].get_witness_index()); + public_input_witness_indices.push_back(proof[i].get_witness_index()); } return public_input_witness_indices; From 9f09b1c24c0d3ad9620b4036ed3f5f3dc64f5b58 Mon Sep 17 00:00:00 2001 From: ledwards2225 <98505400+ledwards2225@users.noreply.github.com> Date: Thu, 3 Oct 2024 08:44:17 -0700 Subject: [PATCH 3/3] make start and end const --- .../cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f8e48b15384d..d6877def5de2 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/proof_surgeon.hpp @@ -117,8 +117,8 @@ class ProofSurgeon { std::vector public_input_witness_indices; public_input_witness_indices.reserve(num_public_inputs_to_extract); - size_t start = HONK_RECURSION_PUBLIC_INPUT_OFFSET; - size_t end = start + 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()); }