diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index 5625d4fddac..81583e16c92 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -46,15 +46,13 @@ BB_PROFILE static void test_round_inner(State& state, MegaProver& prover, size_t BB_REPORT_OP_COUNT_BENCH_CANCEL(); } }; - OinkProver oink_prover(prover.instance->proving_key, prover.transcript); + OinkProver oink_prover(prover.instance, prover.transcript); time_if_index(PREAMBLE, [&] { oink_prover.execute_preamble_round(); }); time_if_index(WIRE_COMMITMENTS, [&] { oink_prover.execute_wire_commitments_round(); }); time_if_index(SORTED_LIST_ACCUMULATOR, [&] { oink_prover.execute_sorted_list_accumulator_round(); }); time_if_index(LOG_DERIVATIVE_INVERSE, [&] { oink_prover.execute_log_derivative_inverse_round(); }); time_if_index(GRAND_PRODUCT_COMPUTATION, [&] { oink_prover.execute_grand_product_computation_round(); }); time_if_index(GENERATE_ALPHAS, [&] { prover.instance->alphas = oink_prover.generate_alphas_round(); }); - // we need to get the relation_parameters and prover_polynomials from the oink_prover - prover.instance->relation_parameters = oink_prover.relation_parameters; prover.generate_gate_challenges(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index e4254c1bf8c..d8c55c76aab 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -218,12 +218,9 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared const std::string& domain_separator) { ZoneScopedN("ProtoGalaxyProver::finalise_and_send_instance"); - OinkProver oink_prover(instance->proving_key, transcript, domain_separator + '_'); + OinkProver oink_prover(instance, transcript, domain_separator + '_'); - auto [proving_key, relation_params, alphas] = oink_prover.prove(); - instance->proving_key = std::move(proving_key); - instance->relation_parameters = std::move(relation_params); - instance->alphas = std::move(alphas); + oink_prover.prove(); } template void ProtoGalaxyProver_::prepare_for_folding() diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index 69f72bde193..c61576cdfc0 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -9,13 +9,8 @@ template void ProtoGalaxyVerifier_::receive_and_finalise_instance(const std::shared_ptr& inst, const std::string& domain_separator) { - auto& key = inst->verification_key; - OinkVerifier oink_verifier{ key, transcript, domain_separator + '_' }; - auto [relation_parameters, witness_commitments, public_inputs, alphas] = oink_verifier.verify(); - inst->relation_parameters = std::move(relation_parameters); - inst->witness_commitments = std::move(witness_commitments); - inst->public_inputs = std::move(public_inputs); - inst->alphas = std::move(alphas); + OinkVerifier oink_verifier{ inst, transcript, domain_separator + '_' }; + oink_verifier.verify(); } template diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp index 25f225796a7..ab1b5dc32e1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp @@ -9,10 +9,10 @@ namespace bb::stdlib::recursion::honk { template OinkRecursiveVerifier_::OinkRecursiveVerifier_(Builder* builder, - const std::shared_ptr& vkey, + const std::shared_ptr& instance, std::shared_ptr transcript, std::string domain_separator) - : key(vkey) + : instance(instance) , builder(builder) , transcript(transcript) , domain_separator(std::move(domain_separator)) @@ -22,12 +22,10 @@ OinkRecursiveVerifier_::OinkRecursiveVerifier_(Builder* builder, * @brief This function constructs a recursive verifier circuit for a native Ultra Honk proof of a given flavor. * @return Output aggregation object */ -template OinkRecursiveVerifier_::Output OinkRecursiveVerifier_::verify() +template void OinkRecursiveVerifier_::verify() { using CommitmentLabels = typename Flavor::CommitmentLabels; - using RelationParams = ::bb::RelationParameters; - RelationParams relation_parameters; WitnessCommitments commitments; CommitmentLabels labels; @@ -42,7 +40,7 @@ template OinkRecursiveVerifier_::Output OinkRecursiveV // ASSERT(static_cast(pub_inputs_offset.get_value()) == key->pub_inputs_offset); std::vector public_inputs; - for (size_t i = 0; i < key->num_public_inputs; ++i) { + for (size_t i = 0; i < instance->verification_key->num_public_inputs; ++i) { public_inputs.emplace_back( transcript->template receive_from_prover(domain_separator + "public_input_" + std::to_string(i))); } @@ -90,9 +88,7 @@ template OinkRecursiveVerifier_::Output OinkRecursiveV } const FF public_input_delta = compute_public_input_delta( - public_inputs, beta, gamma, circuit_size, static_cast(key->pub_inputs_offset)); - - relation_parameters = RelationParameters{ eta, eta_two, eta_three, beta, gamma, public_input_delta }; + public_inputs, beta, gamma, circuit_size, static_cast(instance->verification_key->pub_inputs_offset)); // Get commitment to permutation and lookup grand products commitments.z_perm = transcript->template receive_from_prover(domain_separator + labels.z_perm); @@ -102,10 +98,10 @@ template OinkRecursiveVerifier_::Output OinkRecursiveV alphas[idx] = transcript->template get_challenge(domain_separator + "alpha_" + std::to_string(idx)); } - return { .relation_parameters = relation_parameters, - .commitments = std::move(commitments), - .public_inputs = public_inputs, - .alphas = alphas }; + instance->relation_parameters = RelationParameters{ eta, eta_two, eta_three, beta, gamma, public_input_delta }; + instance->witness_commitments = std::move(commitments); + instance->public_inputs = std::move(public_inputs); + instance->alphas = std::move(alphas); } template class OinkRecursiveVerifier_>; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.hpp index 33a392398f6..ef6989e9814 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.hpp @@ -1,4 +1,5 @@ #pragma once +#include "barretenberg/stdlib/protogalaxy_verifier/recursive_verifier_instance.hpp" #include "barretenberg/stdlib/transcript/transcript.hpp" #include "barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp" @@ -10,27 +11,21 @@ template class OinkRecursiveVerifier_ { using FF = typename Flavor::FF; using Commitment = typename Flavor::Commitment; using GroupElement = typename Flavor::GroupElement; + using Instance = RecursiveVerifierInstance_; using VerificationKey = typename Flavor::VerificationKey; using Builder = typename Flavor::CircuitBuilder; using RelationSeparator = typename Flavor::RelationSeparator; using Transcript = bb::BaseTranscript>; using WitnessCommitments = typename Flavor::WitnessCommitments; - struct Output { - bb::RelationParameters relation_parameters; - WitnessCommitments commitments; - std::vector public_inputs; - typename Flavor::RelationSeparator alphas; - }; - explicit OinkRecursiveVerifier_(Builder* builder, - const std::shared_ptr& vkey, + const std::shared_ptr& instance, std::shared_ptr transcript, std::string domain_separator = ""); - Output verify(); + void verify(); - std::shared_ptr key; + std::shared_ptr instance; Builder* builder; std::shared_ptr transcript; std::string domain_separator; // used in PG to distinguish between instances in transcript diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp index 39d30985849..00de17ee64d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp @@ -47,10 +47,11 @@ UltraRecursiveVerifier_::AggregationObject UltraRecursiveVerifier_(proof); - OinkVerifier oink_verifier{ builder, key, transcript }; - auto [relation_parameters, witness_commitments, public_inputs, alphas] = oink_verifier.verify(); + auto instance = std::make_shared(builder, key); + OinkVerifier oink_verifier{ builder, instance, transcript }; + oink_verifier.verify(); - VerifierCommitments commitments{ key, witness_commitments }; + VerifierCommitments commitments{ key, instance->witness_commitments }; auto gate_challenges = std::vector(CONST_PROOF_SIZE_LOG_N); for (size_t idx = 0; idx < CONST_PROOF_SIZE_LOG_N; idx++) { @@ -66,7 +67,7 @@ UltraRecursiveVerifier_::AggregationObject UltraRecursiveVerifier_ bigfield_limbs; for (size_t k = 0; k < 4; k++) { - bigfield_limbs[k] = public_inputs[key->recursive_proof_public_input_indices[idx]]; + bigfield_limbs[k] = instance->public_inputs[key->recursive_proof_public_input_indices[idx]]; idx++; } base_field_vals[j] = @@ -88,7 +89,7 @@ UltraRecursiveVerifier_::AggregationObject UltraRecursiveVerifier_relation_parameters, instance->alphas, gate_challenges); // Execute ZeroMorph to produce an opening claim subsequently verified by a univariate PCS auto opening_claim = ZeroMorph::verify(key->circuit_size, diff --git a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp index 302c77b4e69..b1ddf11d4ba 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.hpp @@ -13,6 +13,7 @@ template class UltraRecursiveVerifier_ { using FF = typename Flavor::FF; using Commitment = typename Flavor::Commitment; using GroupElement = typename Flavor::GroupElement; + using Instance = RecursiveVerifierInstance_; using VerificationKey = typename Flavor::VerificationKey; using NativeVerificationKey = typename Flavor::NativeVerificationKey; using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index eca266a1565..ce1428f06d7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -9,12 +9,8 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst const std::shared_ptr& inst, std::string& domain_separator) { domain_separator = domain_separator + "_"; - OinkVerifier oink_verifier{ builder, inst->verification_key, transcript, domain_separator }; - auto [relation_parameters, witness_commitments, public_inputs, alphas] = oink_verifier.verify(); - inst->relation_parameters = std::move(relation_parameters); - inst->witness_commitments = std::move(witness_commitments); - inst->public_inputs = std::move(public_inputs); - inst->alphas = std::move(alphas); + OinkVerifier oink_verifier{ builder, inst, transcript, domain_separator }; + oink_verifier.verify(); } // TODO(https://github.com/AztecProtocol/barretenberg/issues/795): The rounds prior to actual verifying are common diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index d2062a32355..67057040aef 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -10,7 +10,7 @@ namespace bb { * @tparam Flavor * @return OinkProverOutput */ -template OinkProverOutput OinkProver::prove() +template void OinkProver::prove() { { ZoneScopedN("execute_preamble_round"); @@ -41,13 +41,7 @@ template OinkProverOutput OinkProver::pro } // Generate relation separators alphas for sumcheck/combiner computation - RelationSeparator alphas = generate_alphas_round(); - - return OinkProverOutput{ - .proving_key = std::move(proving_key), - .relation_parameters = std::move(relation_parameters), - .alphas = std::move(alphas), - }; + instance->alphas = generate_alphas_round(); } /** @@ -56,17 +50,17 @@ template OinkProverOutput OinkProver::pro */ template void OinkProver::execute_preamble_round() { - const auto circuit_size = static_cast(proving_key.circuit_size); - const auto num_public_inputs = static_cast(proving_key.num_public_inputs); + const auto circuit_size = static_cast(instance->proving_key.circuit_size); + const auto num_public_inputs = static_cast(instance->proving_key.num_public_inputs); transcript->send_to_verifier(domain_separator + "circuit_size", circuit_size); transcript->send_to_verifier(domain_separator + "public_input_size", num_public_inputs); transcript->send_to_verifier(domain_separator + "pub_inputs_offset", - static_cast(proving_key.pub_inputs_offset)); + static_cast(instance->proving_key.pub_inputs_offset)); - ASSERT(proving_key.num_public_inputs == proving_key.public_inputs.size()); + ASSERT(instance->proving_key.num_public_inputs == instance->proving_key.public_inputs.size()); - for (size_t i = 0; i < proving_key.num_public_inputs; ++i) { - auto public_input_i = proving_key.public_inputs[i]; + for (size_t i = 0; i < instance->proving_key.num_public_inputs; ++i) { + auto public_input_i = instance->proving_key.public_inputs[i]; transcript->send_to_verifier(domain_separator + "public_input_" + std::to_string(i), public_input_i); } } @@ -82,9 +76,9 @@ template void OinkProver::execute_wire_commitment // We only commit to the fourth wire polynomial after adding memory recordss { BB_OP_COUNT_TIME_NAME("COMMIT::wires"); - witness_commitments.w_l = commitment_key->commit(proving_key.polynomials.w_l); - witness_commitments.w_r = commitment_key->commit(proving_key.polynomials.w_r); - witness_commitments.w_o = commitment_key->commit(proving_key.polynomials.w_o); + witness_commitments.w_l = commitment_key->commit(instance->proving_key.polynomials.w_l); + witness_commitments.w_r = commitment_key->commit(instance->proving_key.polynomials.w_r); + witness_commitments.w_o = commitment_key->commit(instance->proving_key.polynomials.w_o); } auto wire_comms = witness_commitments.get_wires(); @@ -97,7 +91,7 @@ template void OinkProver::execute_wire_commitment // Commit to Goblin ECC op wires for (auto [commitment, polynomial, label] : zip_view(witness_commitments.get_ecc_op_wires(), - proving_key.polynomials.get_ecc_op_wires(), + instance->proving_key.polynomials.get_ecc_op_wires(), commitment_labels.get_ecc_op_wires())) { { BB_OP_COUNT_TIME_NAME("COMMIT::ecc_op_wires"); @@ -108,7 +102,7 @@ template void OinkProver::execute_wire_commitment // Commit to DataBus related polynomials for (auto [commitment, polynomial, label] : zip_view(witness_commitments.get_databus_entities(), - proving_key.polynomials.get_databus_entities(), + instance->proving_key.polynomials.get_databus_entities(), commitment_labels.get_databus_entities())) { { BB_OP_COUNT_TIME_NAME("COMMIT::databus"); @@ -128,22 +122,23 @@ template void OinkProver::execute_sorted_list_acc // Get eta challenges auto [eta, eta_two, eta_three] = transcript->template get_challenges( domain_separator + "eta", domain_separator + "eta_two", domain_separator + "eta_three"); - relation_parameters.eta = eta; - relation_parameters.eta_two = eta_two; - relation_parameters.eta_three = eta_three; + instance->relation_parameters.eta = eta; + instance->relation_parameters.eta_two = eta_two; + instance->relation_parameters.eta_three = eta_three; - proving_key.add_ram_rom_memory_records_to_wire_4( - relation_parameters.eta, relation_parameters.eta_two, relation_parameters.eta_three); + instance->proving_key.add_ram_rom_memory_records_to_wire_4(eta, eta_two, eta_three); // Commit to lookup argument polynomials and the finalized (i.e. with memory records) fourth wire polynomial { BB_OP_COUNT_TIME_NAME("COMMIT::lookup_counts_tags"); - witness_commitments.lookup_read_counts = commitment_key->commit(proving_key.polynomials.lookup_read_counts); - witness_commitments.lookup_read_tags = commitment_key->commit(proving_key.polynomials.lookup_read_tags); + witness_commitments.lookup_read_counts = + commitment_key->commit(instance->proving_key.polynomials.lookup_read_counts); + witness_commitments.lookup_read_tags = + commitment_key->commit(instance->proving_key.polynomials.lookup_read_tags); } { BB_OP_COUNT_TIME_NAME("COMMIT::wires"); - witness_commitments.w_4 = commitment_key->commit(proving_key.polynomials.w_4); + witness_commitments.w_4 = commitment_key->commit(instance->proving_key.polynomials.w_4); } transcript->send_to_verifier(domain_separator + commitment_labels.lookup_read_counts, @@ -160,15 +155,15 @@ template void OinkProver::execute_sorted_list_acc template void OinkProver::execute_log_derivative_inverse_round() { auto [beta, gamma] = transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); - relation_parameters.beta = beta; - relation_parameters.gamma = gamma; + instance->relation_parameters.beta = beta; + instance->relation_parameters.gamma = gamma; // Compute the inverses used in log-derivative lookup relations - proving_key.compute_logderivative_inverses(relation_parameters); + instance->proving_key.compute_logderivative_inverses(instance->relation_parameters); { BB_OP_COUNT_TIME_NAME("COMMIT::lookup_inverses"); - witness_commitments.lookup_inverses = commitment_key->commit(proving_key.polynomials.lookup_inverses); + witness_commitments.lookup_inverses = commitment_key->commit(instance->proving_key.polynomials.lookup_inverses); } transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, witness_commitments.lookup_inverses); @@ -176,7 +171,7 @@ template void OinkProver::execute_log_derivative_ // If Mega, commit to the databus inverse polynomials and send if constexpr (IsGoblinFlavor) { for (auto [commitment, polynomial, label] : zip_view(witness_commitments.get_databus_inverses(), - proving_key.polynomials.get_databus_inverses(), + instance->proving_key.polynomials.get_databus_inverses(), commitment_labels.get_databus_inverses())) { { BB_OP_COUNT_TIME_NAME("COMMIT::databus_inverses"); @@ -193,11 +188,11 @@ template void OinkProver::execute_log_derivative_ */ template void OinkProver::execute_grand_product_computation_round() { - proving_key.compute_grand_product_polynomials(relation_parameters); + instance->proving_key.compute_grand_product_polynomials(instance->relation_parameters); { BB_OP_COUNT_TIME_NAME("COMMIT::z_perm"); - witness_commitments.z_perm = commitment_key->commit(proving_key.polynomials.z_perm); + witness_commitments.z_perm = commitment_key->commit(instance->proving_key.polynomials.z_perm); } transcript->send_to_verifier(domain_separator + commitment_labels.z_perm, witness_commitments.z_perm); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp index 245d8256cd6..16c02cfd1cd 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp @@ -2,12 +2,12 @@ // clang-format off /* )\ /| * .-/'-|_/ | -* __ __,-' ( / \/ -* .-'" "'-..__,-'"" -o.`-._ +* __ __,-' ( / \/ +* .-'" "'-..__,-'"" -o.`-._ * / '/ -* *--._ ./ _.-- -* | _.-' -* : .-/ +* *--._ ./ _.-- +* | _.-' +* : .-/ * \ )_ / * \ _) / \( * `. /-.___.---'( / \\ @@ -22,15 +22,10 @@ #include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_keccak.hpp" +#include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/transcript/transcript.hpp" namespace bb { -template struct OinkProverOutput { - typename Flavor::ProvingKey proving_key; - bb::RelationParameters relation_parameters; - typename Flavor::RelationSeparator alphas; -}; - /** * @brief Class for all the oink rounds, which are shared between the folding prover and ultra prover. * @details This class contains execute_preamble_round(), execute_wire_commitments_round(), @@ -41,12 +36,12 @@ template struct OinkProverOutput { */ template class OinkProver { using CommitmentKey = typename Flavor::CommitmentKey; - using ProvingKey = typename Flavor::ProvingKey; + using Instance = ProverInstance_; using Transcript = typename Flavor::Transcript; using FF = typename Flavor::FF; public: - ProvingKey proving_key; + std::shared_ptr instance; std::shared_ptr transcript; std::shared_ptr commitment_key; std::string domain_separator; @@ -54,18 +49,16 @@ template class OinkProver { typename Flavor::CommitmentLabels commitment_labels; using RelationSeparator = typename Flavor::RelationSeparator; - bb::RelationParameters relation_parameters; - - OinkProver(ProvingKey& proving_key, + OinkProver(std::shared_ptr instance, const std::shared_ptr& transcript, std::string domain_separator = "") - : proving_key(std::move(proving_key)) + : instance(instance) , transcript(transcript) - , commitment_key(this->proving_key.commitment_key) + , commitment_key(this->instance->proving_key.commitment_key) , domain_separator(std::move(domain_separator)) {} - OinkProverOutput prove(); + void prove(); void execute_preamble_round(); void execute_wire_commitments_round(); void execute_sorted_list_accumulator_round(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp index 0ccb68893c6..bd29170b8be 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.cpp @@ -9,7 +9,7 @@ namespace bb { * @tparam Flavor * @return OinkOutput */ -template OinkOutput OinkVerifier::verify() +template void OinkVerifier::verify() { // Execute the Verifier rounds execute_preamble_round(); @@ -17,12 +17,11 @@ template OinkOutput OinkVerifier::verify( execute_sorted_list_accumulator_round(); execute_log_derivative_inverse_round(); execute_grand_product_computation_round(); - RelationSeparator alphas = generate_alphas_round(); - return OinkOutput{ .relation_parameters = relation_parameters, - .commitments = std::move(witness_comms), - .public_inputs = public_inputs, - .alphas = alphas }; + instance->witness_commitments = witness_comms; + instance->relation_parameters = relation_parameters; + instance->public_inputs = public_inputs; + instance->alphas = generate_alphas_round(); } /** @@ -38,13 +37,13 @@ template void OinkVerifier::execute_preamble_roun const auto pub_inputs_offset = transcript->template receive_from_prover(domain_separator + "pub_inputs_offset"); - if (circuit_size != key->circuit_size) { + if (circuit_size != instance->verification_key->circuit_size) { throw_or_abort("OinkVerifier::execute_preamble_round: proof circuit size does not match verification key!"); } - if (public_input_size != key->num_public_inputs) { + if (public_input_size != instance->verification_key->num_public_inputs) { throw_or_abort("OinkVerifier::execute_preamble_round: public inputs size does not match verification key!"); } - if (pub_inputs_offset != key->pub_inputs_offset) { + if (pub_inputs_offset != instance->verification_key->pub_inputs_offset) { throw_or_abort("OinkVerifier::execute_preamble_round: public inputs offset does not match verification key!"); } @@ -132,11 +131,12 @@ template void OinkVerifier::execute_log_derivativ */ template void OinkVerifier::execute_grand_product_computation_round() { - const FF public_input_delta = compute_public_input_delta(public_inputs, - relation_parameters.beta, - relation_parameters.gamma, - key->circuit_size, - static_cast(key->pub_inputs_offset)); + const FF public_input_delta = + compute_public_input_delta(public_inputs, + relation_parameters.beta, + relation_parameters.gamma, + instance->verification_key->circuit_size, + static_cast(instance->verification_key->pub_inputs_offset)); relation_parameters.public_input_delta = public_input_delta; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.hpp index d66dd2a2b9d..d33fd405791 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_verifier.hpp @@ -6,16 +6,10 @@ #include "barretenberg/stdlib_circuit_builders/mega_flavor.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_keccak.hpp" +#include "barretenberg/sumcheck/instance/verifier_instance.hpp" namespace bb { -template struct OinkOutput { - bb::RelationParameters relation_parameters; - typename Flavor::WitnessCommitments commitments; - std::vector public_inputs; - typename Flavor::RelationSeparator alphas; -}; - /** * @brief Verifier class for all the presumcheck rounds, which are shared between the folding verifier and ultra * verifier. @@ -26,7 +20,7 @@ template struct OinkOutput { * @tparam Flavor */ template class OinkVerifier { - using VerificationKey = typename Flavor::VerificationKey; + using Instance = VerifierInstance_; using WitnessCommitments = typename Flavor::WitnessCommitments; using Transcript = typename Flavor::Transcript; using FF = typename Flavor::FF; @@ -35,22 +29,22 @@ template class OinkVerifier { public: std::shared_ptr transcript; - std::shared_ptr key; + std::shared_ptr instance; std::string domain_separator; typename Flavor::CommitmentLabels comm_labels; bb::RelationParameters relation_parameters; WitnessCommitments witness_comms; std::vector public_inputs; - OinkVerifier(const std::shared_ptr& verifier_key, + OinkVerifier(const std::shared_ptr& instance, const std::shared_ptr& transcript, std::string domain_separator = "") : transcript(transcript) - , key(verifier_key) + , instance(instance) , domain_separator(std::move(domain_separator)) {} - OinkOutput verify(); + void verify(); void execute_preamble_round(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index 9a7fd8fa07f..61baefda815 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -48,11 +48,8 @@ template void UltraProver_::generate_gate_challen template HonkProof UltraProver_::construct_proof() { - OinkProver oink_prover(instance->proving_key, transcript); - auto [proving_key, relation_params, alphas] = oink_prover.prove(); - instance->proving_key = std::move(proving_key); - instance->relation_parameters = std::move(relation_params); - instance->alphas = alphas; + OinkProver oink_prover(instance, transcript); + oink_prover.prove(); generate_gate_challenges(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp index 54ca67d58d2..445808a82a2 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp @@ -15,11 +15,8 @@ template bool UltraVerifier_::verify_proof(const HonkP using FF = typename Flavor::FF; transcript = std::make_shared(proof); - OinkVerifier oink_verifier{ instance->verification_key, transcript }; - auto [relation_parameters, witness_commitments, public_inputs, alphas] = oink_verifier.verify(); - instance->relation_parameters = std::move(relation_parameters); - instance->witness_commitments = std::move(witness_commitments); - instance->alphas = std::move(alphas); + OinkVerifier oink_verifier{ instance, transcript }; + oink_verifier.verify(); for (size_t idx = 0; idx < CONST_PROOF_SIZE_LOG_N; idx++) { instance->gate_challenges.emplace_back(