-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update to protogalaxy interfaces (#2498)
This PR resolves [#725](AztecProtocol/barretenberg#725) and introduces `ProverInstances` and `VerifierInstances` classes responsible of managing the Instances objects and determining the number of instances to be folded.
- Loading branch information
1 parent
868cceb
commit 9a3d265
Showing
10 changed files
with
127 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ { | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 17 additions & 19 deletions
36
barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters