-
Notifications
You must be signed in to change notification settings - Fork 310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update to protogalaxy interfaces #2498
Changes from 3 commits
cf18c69
2d0bd07
99504a5
77e2e7f
93cdec5
02a11a7
a70d67c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
#include "barretenberg/honk/instance/prover_instance.hpp" | ||
#include "barretenberg/honk/instance/verifier_instance.hpp" | ||
namespace proof_system::honk { | ||
|
||
template <typename Flavor_, size_t NUM_> struct ProverInstances { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a duplication of your code in the combiner reworked to fit the rest of the interfaces |
||
using Flavor = Flavor_; | ||
using Instance = ProverInstance_<Flavor>; | ||
using ArrayType = std::array<std::shared_ptr<Instance>, NUM_>; | ||
|
||
public: | ||
static constexpr size_t NUM = NUM_; | ||
ArrayType _data; | ||
Instance const& operator[](size_t idx) const { return _data[idx]; } | ||
typename ArrayType::iterator begin() { return _data.begin(); }; | ||
typename ArrayType::iterator end() { return _data.end(); }; | ||
ProverInstances(std::vector<std::shared_ptr<Instance>> data) | ||
{ | ||
ASSERT(data.size() == NUM); | ||
for (size_t idx = 0; idx < data.size(); idx++) { | ||
_data[idx] = std::move(data[idx]); | ||
} | ||
}; | ||
}; | ||
|
||
template <typename Flavor_, size_t NUM_> struct VerifierInstances { | ||
using Flavor = Flavor_; | ||
using VerificationKey = typename Flavor::VerificationKey; | ||
using Instance = VerifierInstance_<Flavor>; | ||
using ArrayType = std::array<Instance, NUM_>; | ||
|
||
public: | ||
static constexpr size_t NUM = NUM_; | ||
ArrayType _data; | ||
Instance const& operator[](size_t idx) const { return _data[idx]; } | ||
typename ArrayType::iterator begin() { return _data.begin(); }; | ||
typename ArrayType::iterator end() { return _data.end(); }; | ||
VerifierInstances(std::vector<std::shared_ptr<VerificationKey>> vks) | ||
{ | ||
ASSERT(vks.size() == NUM); | ||
for (size_t idx = 0; idx < vks.size(); idx++) { | ||
Instance inst; | ||
inst.verification_key = std::move(vks[idx]); | ||
_data[idx] = inst; | ||
} | ||
}; | ||
}; | ||
} // namespace proof_system::honk |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
#include "protogalaxy_prover.hpp" | ||
#include "barretenberg/proof_system/flavor/flavor.hpp" | ||
namespace proof_system::honk { | ||
template <class Flavor> | ||
ProtoGalaxyProver_<Flavor>::ProtoGalaxyProver_(std::vector<std::shared_ptr<Instance>> insts) | ||
: instances(insts) | ||
{} | ||
|
||
/** | ||
* @brief Prior to folding we need to add all the public inputs to the transcript, labelled by their corresponding | ||
* instance index, compute all the instance's polynomials and record the relation parameters involved in computing these | ||
* polynomials in the transcript. | ||
* | ||
*/ | ||
template <class Flavor> void ProtoGalaxyProver_<Flavor>::prepare_for_folding() | ||
template <class ProverInstances> void ProtoGalaxyProver_<ProverInstances>::prepare_for_folding() | ||
{ | ||
for (const auto& instance : instances) { | ||
// this doesnt work in the current format | ||
auto idx = 0; | ||
for (auto it = instances.begin(); it != instances.end(); it++, idx++) { | ||
auto instance = *it; | ||
instance->initialise_prover_polynomials(); | ||
|
||
const auto instance_index = std::to_string(instance->index); | ||
auto domain_separator = std::to_string(idx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we still need to domain separate information coming from different instances but now the index is not part of |
||
const auto circuit_size = static_cast<uint32_t>(instance->proving_key->circuit_size); | ||
const auto num_public_inputs = static_cast<uint32_t>(instance->proving_key->num_public_inputs); | ||
|
||
transcript.send_to_verifier(instance_index + "_circuit_size", circuit_size); | ||
transcript.send_to_verifier(instance_index + "_public_input_size", num_public_inputs); | ||
transcript.send_to_verifier(instance_index + "_pub_inputs_offset", | ||
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<uint32_t>(instance->pub_inputs_offset)); | ||
|
||
for (size_t i = 0; i < instance->proving_key->num_public_inputs; ++i) { | ||
auto public_input_i = instance->public_inputs[i]; | ||
transcript.send_to_verifier(instance_index + "_public_input_" + std::to_string(i), public_input_i); | ||
transcript.send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i); | ||
} | ||
|
||
auto [eta, beta, gamma] = | ||
transcript.get_challenges(instance_index + "_eta", instance_index + "_beta", instance_index + "_gamma"); | ||
auto [eta, beta, gamma] = transcript.get_challenges( | ||
domain_separator + "_eta", domain_separator + "_beta", domain_separator + "_gamma"); | ||
instance->compute_sorted_accumulator_polynomials(eta); | ||
instance->compute_grand_product_polynomials(beta, gamma); | ||
} | ||
} | ||
|
||
// TODO(#689): implement this function | ||
template <class Flavor> ProverFoldingResult<Flavor> ProtoGalaxyProver_<Flavor>::fold_instances() | ||
template <class ProverInstances> | ||
ProverFoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstances>::fold_instances() | ||
{ | ||
prepare_for_folding(); | ||
ProverFoldingResult<Flavor> res; | ||
res.folding_data = transcript.proof_data; | ||
return res; | ||
} | ||
|
||
template class ProtoGalaxyProver_<honk::flavor::Ultra>; | ||
template class ProtoGalaxyProver_<honk::flavor::UltraGrumpkin>; | ||
template class ProtoGalaxyProver_<honk::flavor::GoblinUltra>; | ||
|
||
template class ProtoGalaxyProver_<ProverInstances<honk::flavor::Ultra, 2>>; | ||
template class ProtoGalaxyProver_<ProverInstances<honk::flavor::UltraGrumpkin, 2>>; | ||
template class ProtoGalaxyProver_<ProverInstances<honk::flavor::GoblinUltra, 2>>; | ||
} // namespace proof_system::honk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After fighting linker and compile errors having the create folding prover and verifier functions in the header and specify the numbers of instances to be folded in the composer (see above) seemed like the most reasonable thing to do. Very open to ways to improve this if there are any.