Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "barretenberg/benchmark/ultra_bench/mock_circuits.hpp"
#include "barretenberg/common/op_count_google_bench.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp"
#include "barretenberg/ultra_honk/decider_prover.hpp"
#include "barretenberg/ultra_honk/ultra_prover.hpp"

using namespace benchmark;
Expand Down Expand Up @@ -49,11 +50,16 @@ BB_PROFILE static void test_round_inner(State& state, GoblinUltraProver& prover,
time_if_index(SORTED_LIST_ACCUMULATOR, [&] { prover.oink_prover.execute_sorted_list_accumulator_round(); });
time_if_index(LOG_DERIVATIVE_INVERSE, [&] { prover.oink_prover.execute_log_derivative_inverse_round(); });
time_if_index(GRAND_PRODUCT_COMPUTATION, [&] { prover.oink_prover.execute_grand_product_computation_round(); });
prover.instance->alphas = prover.oink_prover.generate_alphas();
// we need to get the relation_parameters and prover_polynomials from the oink_prover
prover.instance->relation_parameters = prover.oink_prover.relation_parameters;
prover.instance->prover_polynomials = GoblinUltraFlavor::ProverPolynomials(prover.instance->proving_key);
time_if_index(RELATION_CHECK, [&] { prover.execute_relation_check_rounds(); });
time_if_index(ZEROMORPH, [&] { prover.execute_zeromorph_rounds(); });

prover.generate_gate_challenges();

DeciderProver_<GoblinUltraFlavor> decider_prover(prover.instance, prover.transcript);
time_if_index(RELATION_CHECK, [&] { decider_prover.execute_relation_check_rounds(); });
time_if_index(ZEROMORPH, [&] { decider_prover.execute_zeromorph_rounds(); });
}
BB_PROFILE static void test_round(State& state, size_t index) noexcept
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include "barretenberg/goblin/goblin.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/protogalaxy/decider_prover.hpp"
#include "barretenberg/protogalaxy/decider_verifier.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp"
#include "barretenberg/sumcheck/instance/instances.hpp"
#include "barretenberg/ultra_honk/decider_prover.hpp"

namespace bb {

Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ template <IsECCVMFlavor Flavor> void ECCVMProver_<Flavor>::execute_transcript_co
translation_batching_challenge_v = transcript->template get_challenge<FF>("Translation:batching_challenge");
}

template <IsECCVMFlavor Flavor> HonkProof& ECCVMProver_<Flavor>::export_proof()
template <IsECCVMFlavor Flavor> HonkProof ECCVMProver_<Flavor>::export_proof()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it more efficient to pass by reference?

{
proof = transcript->export_proof();
return proof;
}

template <IsECCVMFlavor Flavor> HonkProof& ECCVMProver_<Flavor>::construct_proof()
template <IsECCVMFlavor Flavor> HonkProof ECCVMProver_<Flavor>::construct_proof()
{
BB_OP_COUNT_TIME_NAME("ECCVMProver::construct_proof");

Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ template <IsECCVMFlavor Flavor> class ECCVMProver_ {
BB_PROFILE void execute_zeromorph_rounds();
BB_PROFILE void execute_transcript_consistency_univariate_opening_round();

HonkProof& export_proof();
HonkProof& construct_proof();
HonkProof export_proof();
HonkProof construct_proof();

std::shared_ptr<Transcript> transcript;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/polynomials/pow.hpp"
#include "barretenberg/protogalaxy/decider_prover.hpp"
#include "barretenberg/protogalaxy/decider_verifier.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp"
#include "barretenberg/ultra_honk/decider_prover.hpp"

#include <gtest/gtest.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ void ProtoGalaxyProver_<ProverInstances>::finalise_and_send_instance(std::shared
{
OinkProver<Flavor> oink_prover(instance->proving_key, commitment_key, transcript, domain_separator + '_');

auto [relation_params] = oink_prover.prove();
auto [relation_params, alphas] = oink_prover.prove();
instance->relation_parameters = std::move(relation_params);
instance->prover_polynomials = ProverPolynomials(instance->proving_key);

// Generate relation separators alphas for sumcheck
for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) {
instance->alphas[idx] =
transcript->template get_challenge<FF>(domain_separator + "_alpha_" + std::to_string(idx));
}
instance->alphas = std::move(alphas);
}

template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::prepare_for_folding()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "barretenberg/stdlib/honk_recursion/verifier/protogalaxy_recursive_verifier.hpp"
#include "barretenberg/circuit_checker/circuit_checker.hpp"
#include "barretenberg/common/test.hpp"
#include "barretenberg/protogalaxy/decider_prover.hpp"
#include "barretenberg/protogalaxy/decider_verifier.hpp"
#include "barretenberg/protogalaxy/protogalaxy_prover.hpp"
#include "barretenberg/protogalaxy/protogalaxy_verifier.hpp"
Expand All @@ -11,6 +10,7 @@
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
#include "barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp"
#include "barretenberg/sumcheck/instance/instances.hpp"
#include "barretenberg/ultra_honk/decider_prover.hpp"
#include "barretenberg/ultra_honk/ultra_prover.hpp"
#include "barretenberg/ultra_honk/ultra_verifier.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ void GoblinTranslatorProver::execute_zeromorph_rounds()
prover_polynomials.get_concatenation_groups());
}

HonkProof& GoblinTranslatorProver::export_proof()
HonkProof GoblinTranslatorProver::export_proof()
{
proof = transcript->export_proof();
return proof;
}

HonkProof& GoblinTranslatorProver::construct_proof()
HonkProof GoblinTranslatorProver::construct_proof()
{
BB_OP_COUNT_TIME_NAME("GoblinTranslatorProver::construct_proof");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class GoblinTranslatorProver {
BB_PROFILE void execute_grand_product_computation_round();
BB_PROFILE void execute_relation_check_rounds();
BB_PROFILE void execute_zeromorph_rounds();
HonkProof& export_proof();
HonkProof& construct_proof();
HonkProof export_proof();
HonkProof construct_proof();

std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ DeciderProver_<Flavor>::DeciderProver_(const std::shared_ptr<Instance>& inst,
const std::shared_ptr<Transcript>& transcript)
: accumulator(std::move(inst))
, transcript(transcript)
, commitment_key(inst->proving_key->commitment_key)
, commitment_key(accumulator->proving_key->commitment_key)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not meaningful, but I wasn't sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, shouldn't inst be nullified by the std::move on line 18?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::move doesn't nullify the object being moved it just facilities moving rather than copying resources, your change makes sense but the previous code wasn't incorrect

{}

/**
Expand Down Expand Up @@ -49,13 +49,13 @@ template <IsUltraFlavor Flavor> void DeciderProver_<Flavor>::execute_zeromorph_r
transcript);
}

template <IsUltraFlavor Flavor> HonkProof& DeciderProver_<Flavor>::export_proof()
template <IsUltraFlavor Flavor> HonkProof DeciderProver_<Flavor>::export_proof()
{
proof = transcript->proof_data;
return proof;
}

template <IsUltraFlavor Flavor> HonkProof& DeciderProver_<Flavor>::construct_proof()
template <IsUltraFlavor Flavor> HonkProof DeciderProver_<Flavor>::construct_proof()
{
BB_OP_COUNT_TIME_NAME("Decider::construct_proof");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ template <IsUltraFlavor Flavor> class DeciderProver_ {
BB_PROFILE void execute_relation_check_rounds();
BB_PROFILE void execute_zeromorph_rounds();

HonkProof& export_proof();
HonkProof& construct_proof();
HonkProof export_proof();
HonkProof construct_proof();

std::shared_ptr<Instance> accumulator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ MergeVerifier_<Flavor>::MergeVerifier_()
* Schwartz-Zippel check. Evaluations are checked via batched KZG.
*
* @tparam Flavor
* @return HonkProof&
* @return bool
*/
template <typename Flavor> bool MergeVerifier_<Flavor>::verify_proof(const HonkProof& proof)
{
Expand Down
12 changes: 12 additions & 0 deletions barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ template <IsUltraFlavor Flavor> OinkProverOutput<Flavor> OinkProver<Flavor>::pro
// Compute grand product(s) and commitments.
execute_grand_product_computation_round();

// Generate relation separators alphas for sumcheck

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably make a separate function for this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they are not only for sumcheck, they are for batching all subrelations into the big U(G)H relation either in sumcheck or combiner computation, cna you make the comment more specific?

RelationSeparator alphas = generate_alphas();

return OinkProverOutput<Flavor>{
.relation_parameters = std::move(relation_parameters),
.alphas = std::move(alphas),
};
}

Expand Down Expand Up @@ -149,6 +153,14 @@ template <IsUltraFlavor Flavor> void OinkProver<Flavor>::execute_grand_product_c
transcript->send_to_verifier(domain_separator + commitment_labels.z_lookup, witness_commitments.z_lookup);
}

template <IsUltraFlavor Flavor> typename Flavor::RelationSeparator OinkProver<Flavor>::generate_alphas()
{
RelationSeparator alphas;
for (size_t idx = 0; idx < alphas.size(); idx++) {
alphas[idx] = transcript->template get_challenge<FF>("Sumcheck:alpha_" + std::to_string(idx));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not necessarily for sumcheck (and neither are the gate challenges) so maybe it should be made explicit?

}
return alphas;
}
template class OinkProver<UltraFlavor>;
template class OinkProver<GoblinUltraFlavor>;

Expand Down
3 changes: 3 additions & 0 deletions barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace bb {
template <IsUltraFlavor Flavor> struct OinkProverOutput {
bb::RelationParameters<typename Flavor::FF> relation_parameters;
typename Flavor::RelationSeparator alphas;
};

/**
Expand All @@ -49,6 +50,7 @@ template <IsUltraFlavor Flavor> class OinkProver {
std::string domain_separator;
typename Flavor::WitnessCommitments witness_commitments;
typename Flavor::CommitmentLabels commitment_labels;
using RelationSeparator = typename Flavor::RelationSeparator;

bb::RelationParameters<typename Flavor::FF> relation_parameters;

Expand All @@ -68,5 +70,6 @@ template <IsUltraFlavor Flavor> class OinkProver {
void execute_sorted_list_accumulator_round();
void execute_log_derivative_inverse_round();
void execute_grand_product_computation_round();
RelationSeparator generate_alphas();
};
} // namespace bb
63 changes: 15 additions & 48 deletions barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ultra_prover.hpp"
#include "barretenberg/sumcheck/sumcheck.hpp"
#include "barretenberg/ultra_honk/decider_prover.hpp"

namespace bb {

Expand All @@ -15,7 +16,7 @@ UltraProver_<Flavor>::UltraProver_(const std::shared_ptr<Instance>& inst, const
: instance(std::move(inst))
, transcript(transcript)
, commitment_key(instance->proving_key->commitment_key)
, oink_prover(inst->proving_key, commitment_key, transcript, "")
, oink_prover(instance->proving_key, commitment_key, transcript, "")
{}

/**
Expand All @@ -33,65 +34,31 @@ UltraProver_<Flavor>::UltraProver_(Builder& circuit)
, oink_prover(instance->proving_key, commitment_key, transcript, "")
{}

/**
* @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated.
*
*/
template <IsUltraFlavor Flavor> void UltraProver_<Flavor>::execute_relation_check_rounds()
template <IsUltraFlavor Flavor> HonkProof UltraProver_<Flavor>::export_proof()
{
using Sumcheck = SumcheckProver<Flavor>;
auto circuit_size = instance->proving_key->circuit_size;
auto sumcheck = Sumcheck(circuit_size, transcript);
RelationSeparator alphas;
for (size_t idx = 0; idx < alphas.size(); idx++) {
alphas[idx] = transcript->template get_challenge<FF>("Sumcheck:alpha_" + std::to_string(idx));
}
instance->alphas = alphas;
std::vector<FF> gate_challenges(numeric::get_msb(circuit_size));
proof = transcript->proof_data;
return proof;
}
template <IsUltraFlavor Flavor> void UltraProver_<Flavor>::generate_gate_challenges()
{
std::vector<FF> gate_challenges(numeric::get_msb(instance->proving_key->circuit_size));
for (size_t idx = 0; idx < gate_challenges.size(); idx++) {
gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
}
instance->gate_challenges = gate_challenges;
sumcheck_output = sumcheck.prove(instance);
}

/**
* @brief Execute the ZeroMorph protocol to prove the multilinear evaluations produced by Sumcheck
* @details See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the unrolled protocol.
*
* */
template <IsUltraFlavor Flavor> void UltraProver_<Flavor>::execute_zeromorph_rounds()
{
ZeroMorph::prove(instance->prover_polynomials.get_unshifted(),
instance->prover_polynomials.get_to_be_shifted(),
sumcheck_output.claimed_evaluations.get_unshifted(),
sumcheck_output.claimed_evaluations.get_shifted(),
sumcheck_output.challenge,
commitment_key,
transcript);
}

template <IsUltraFlavor Flavor> HonkProof& UltraProver_<Flavor>::export_proof()
template <IsUltraFlavor Flavor> HonkProof UltraProver_<Flavor>::construct_proof()
{
proof = transcript->proof_data;
return proof;
}

template <IsUltraFlavor Flavor> HonkProof& UltraProver_<Flavor>::construct_proof()
{
auto [relation_params] = oink_prover.prove();
auto [relation_params, alphas] = oink_prover.prove();
instance->relation_parameters = std::move(relation_params);
instance->alphas = alphas;
instance->prover_polynomials = ProverPolynomials(instance->proving_key);

// Fiat-Shamir: alpha
// Run sumcheck subprotocol.
execute_relation_check_rounds();

// Fiat-Shamir: rho, y, x, z
// Execute Zeromorph multilinear PCS
execute_zeromorph_rounds();
generate_gate_challenges();

return export_proof();
DeciderProver_<Flavor> decider_prover(instance, transcript);
return decider_prover.construct_proof();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's quite odd that the decider_prover is being called here since the ultra prover should not care about folding, this is one of those place where round abstraction would be awesome :-?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but until then I would kinda leave the sumcheck and zeromorph rounds unshared between the decider and ultra prover just to not create this dependence

}

template class UltraProver_<UltraFlavor>;
Expand Down
13 changes: 3 additions & 10 deletions barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ template <IsUltraFlavor Flavor_> class UltraProver_ {
using ProverInstance = ProverInstance_<Flavor>;
using Instance = ProverInstance;
using Transcript = typename Flavor::Transcript;
using RelationSeparator = typename Flavor::RelationSeparator;
using ZeroMorph = ZeroMorphProver_<PCS>;

std::shared_ptr<Instance> instance;
Expand All @@ -47,16 +46,10 @@ template <IsUltraFlavor Flavor_> class UltraProver_ {

explicit UltraProver_(Builder&);

BB_PROFILE void execute_preamble_round();
BB_PROFILE void execute_wire_commitments_round();
BB_PROFILE void execute_sorted_list_accumulator_round();
BB_PROFILE void execute_log_derivative_inverse_round();
BB_PROFILE void execute_grand_product_computation_round();
BB_PROFILE void execute_relation_check_rounds();
BB_PROFILE void execute_zeromorph_rounds();
BB_PROFILE void generate_gate_challenges();

HonkProof& export_proof();
HonkProof& construct_proof();
HonkProof export_proof();
HonkProof construct_proof();

private:
HonkProof proof;
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ void AvmProver::execute_zeromorph_rounds()
transcript);
}

HonkProof& AvmProver::export_proof()
HonkProof AvmProver::export_proof()
{
proof = transcript->proof_data;
return proof;
}

HonkProof& AvmProver::construct_proof()
HonkProof AvmProver::construct_proof()
{
// Add circuit size public input size and public inputs to transcript.
execute_preamble_round();
Expand Down
4 changes: 2 additions & 2 deletions barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class AvmProver {
void execute_relation_check_rounds();
void execute_zeromorph_rounds();

HonkProof& export_proof();
HonkProof& construct_proof();
HonkProof export_proof();
HonkProof construct_proof();

std::shared_ptr<Transcript> transcript = std::make_shared<Transcript>();

Expand Down