Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Sep 11, 2023
1 parent 0e24e2a commit d23a275
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,32 @@ template <UltraFlavor Flavor> UltraVerifier_<Flavor> UltraComposer_<Flavor>::cre
}

template <UltraFlavor Flavor>
ProtoGalaxyProver_<Flavor> UltraComposer_<Flavor>::create_folding_prover(std::vector<Instance> instances)
ProtoGalaxyProver_<Flavor> UltraComposer_<Flavor>::create_folding_prover(
std::vector<std::shared_ptr<Instance>> instances)
{
for (size_t i = 0; i < instances.size(); i++) {
instances[i].index = i;
uint32_t idx = 0;
for (const auto& inst : instances) {
inst->index = idx;
idx++;
}
ProtoGalaxyProver_<Flavor> output_state(instances);

return output_state;
}

template <UltraFlavor Flavor>
ProtoGalaxyVerifier_<Flavor> UltraComposer_<Flavor>::create_folding_verifier(
std::vector<std::shared_ptr<Instance>> instances)
{
std::vector<std::shared_ptr<VerificationKey>> vks;
for (const auto& inst : instances) {
vks.emplace_back(inst->compute_verification_key());
}
ProtoGalaxyVerifier_<Flavor> output_state(vks);

return output_state;
}

template class UltraComposer_<honk::flavor::Ultra>;
template class UltraComposer_<honk::flavor::UltraGrumpkin>;
template class UltraComposer_<honk::flavor::GoblinUltra>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include "barretenberg/honk/instance/instance.hpp"
#include "barretenberg/honk/proof_system/protogalaxy_prover.hpp"
#include "barretenberg/honk/proof_system/protogalaxy_verifier.hpp"
Expand Down Expand Up @@ -75,8 +74,8 @@ template <UltraFlavor Flavor> class UltraComposer_ {
UltraProver_<Flavor> create_prover(Instance&);
UltraVerifier_<Flavor> create_verifier(Instance&);

ProtoGalaxyProver_<Flavor> create_folding_prover(std::vector<Instance&>);
ProtoGalaxyVerifier_<Flavor> create_folding_verifier(std::vector<Instance&>);
ProtoGalaxyProver_<Flavor> create_folding_prover(std::vector<std::shared_ptr<Instance>>);
ProtoGalaxyVerifier_<Flavor> create_folding_verifier(std::vector<std::shared_ptr<Instance>>);
};
extern template class UltraComposer_<honk::flavor::Ultra>;
// TODO: the UltraGrumpkin flavor still works on BN254 because plookup needs to be templated to be able to construct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
#include <vector>
namespace proof_system::honk {
// Need verifier instance as well
// An Instance is created from a Circuit and we initialise all the data structure that rely on information from a
// An Instance is created from a Circuit and we ini tialise all the data structure that rely on information from a
// circuit Then a Prover and a Verifier is created from an Instance or several instances and each manages their own
// polynomials
// The responsability of a Prover is to commit, add to transcript while the Instance manages its polynomials
// TODO: we might wanna have a specialisaition of the Instance class for the Accumulator
template <UltraFlavor Flavor> class Instance_ {
public:
using Circuit = typename Flavor::CircuitBuilder;
Expand All @@ -37,6 +38,10 @@ template <UltraFlavor Flavor> class Instance_ {
std::shared_ptr<CommitmentKey> commitment_key;

ProverPolynomials prover_polynomials;

// After instances have been folded, the pub_inputs_offset will become irrelevant as it's used for computing the 4th
// wire polynomial and a folded instance does not care about wires anymore.
// Furthermore, folding limits us to having the same number of public inputs.
std::vector<FF> public_inputs;
size_t pub_inputs_offset;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
#pragma once
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/proof_system/relations/relation_parameters.hpp"
namespace proof_system::honk {
template <UltraFlavor Flavor> class VerifierInstance_ {
public:
using FF = typename Flavor::FF;
using VerificationKey = typename Flavor::VerificationKey;
using FoldingParameters = typename Flavor::FoldingParameters;

std::shared_ptr<VerificationKey> verification_key;
std::vector<FF> public_inputs;
size_t pub_inputs_offset;
size_t public_input_size;
size_t circuit_size;
RelationParameters<FF> relation_parameters;
FoldingParameters folding_params;
size_t index;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include "barretenberg/proof_system/flavor/flavor.hpp"
namespace proof_system::honk {
template <UltraFlavor Flavor> struct ProverFoldingResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "barretenberg/proof_system/flavor/flavor.hpp"
namespace proof_system::honk {
template <UltraFlavor Flavor>
ProtoGalaxyProver_<Flavor>::ProtoGalaxyProver_(std::vector<Instance&> insts)
ProtoGalaxyProver_<Flavor>::ProtoGalaxyProver_(std::vector<std::shared_ptr<Instance>> insts)
: instances(insts)
{}

Expand All @@ -12,28 +12,32 @@ ProtoGalaxyProver_<Flavor>::ProtoGalaxyProver_(std::vector<Instance&> insts)
// - add the relation parameters involved in computing the instances polynomials to the transcript
template <UltraFlavor Flavor> void ProtoGalaxyProver_<Flavor>::prepare_for_folding()
{
for (const Instance& instance : instances) {
instance.initialise_prover_polynomials();
for (const auto& instance : instances) {
instance->initialise_prover_polynomials();

const auto instance_index = std::string(instance.index);
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);
const auto instance_index = std::to_string(instance->index);
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",
static_cast<uint32_t>(instance.pub_inputs_offset));
// transcript.send_to_verifier(instance_index + "_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];
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);
}

auto eta = transcript.get_challenge(instance_index + "_eta");
instance.compute_sorted_accumulator_polynomials(eta);
instance->compute_sorted_accumulator_polynomials(eta);
auto [beta, gamma] = transcript.get_challenges(instance_index + "_beta", instance_index + "_gamma");
instance.compute_grand_product_polynomials(beta, gamma);
instance->compute_grand_product_polynomials(beta, gamma);
}
}

template class ProtoGalaxyProver_<honk::flavor::Ultra>;
template class ProtoGalaxyProver_<honk::flavor::UltraGrumpkin>;
template class ProtoGalaxyProver_<honk::flavor::GoblinUltra>;

} // namespace proof_system::honk
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#pragma once
#include "barretenberg/honk/flavor/goblin_ultra.hpp"
#include "barretenberg/honk/flavor/ultra.hpp"
#include "barretenberg/honk/flavor/ultra_grumpkin.hpp"
#include "barretenberg/honk/instance/instance.hpp"
#include "barretenberg/honk/proof_system/folding_result.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/proof_system/folding_result.hpp"
namespace proof_system::honk {
template <UltraFlavor Flavor> class ProtoGalaxyProver_ {
public:
using FF = typename Flavor::FF;
using Instance = Instance_<Flavor>;
using ProverPolynomials = typename Flavor::ProverPolynomials;

std::vector<Instance&> instances;
std::vector<std::shared_ptr<Instance>> instances;

ProverTranscript<FF> transcript;

explicit ProtoGalaxyProver_(std::vector<Instance&>);
explicit ProtoGalaxyProver_(std::vector<std::shared_ptr<Instance>>);

void prepare_for_folding();

// TODO: implement this function
ProverFoldingResult<Flavor> fold_instances();
};

extern template class ProtoGalaxyProver_<honk::flavor::Ultra>;
extern template class ProtoGalaxyProver_<honk::flavor::UltraGrumpkin>;
extern template class ProtoGalaxyProver_<honk::flavor::GoblinUltra>;
// the folding prover returns the new prover polynomials and the new public inputs(does the verifier do anything)
} // namespace proof_system::honk
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
#include "protogalaxy_verifier.hpp"
#include "barretenberg/honk/utils/grand_product_delta.hpp"
namespace proof_system::honk {
template <UltraFlavor Flavor>
ProtoGalaxyVerifier_<Flavor>::ProtoGalaxyVerifier_(std::vector<VerificationKey> vks, std::vector<uint8_t> proof_data)
ProtoGalaxyVerifier_<Flavor>::ProtoGalaxyVerifier_(std::vector<std::shared_ptr<VerificationKey>> vks)
{
uint32_t idx = 0;
for (const auto& vk : vks) {
VerifierInstance inst;
inst.verification_key = std::move(vk);
inst.index = idx;
verifier_instances.emplace_back(inst);
idx++;
}
}

template <UltraFlavor Flavor>
VerifierFoldingResult<Flavor> ProtoGalaxyVerifier_<Flavor>::fold_public_parameters(std::vector<uint8_t> fold_data)
{
transcript = VerifierTranscript<FF>{ proof_data };
transcript = VerifierTranscript<FF>{ fold_data };
for (auto& inst : verifier_instances) {
auto idx = std::to_string(inst.index);
inst.circuit_size = transcript.template receive_from_prover<uint32_t>(idx + "_circuit_size");
inst.public_input_size = transcript.template receive_from_prover<uint32_t>(idx + "_public_input_size");
inst.pub_inputs_offset = transcript.template receive_from_prover<uint32_t>(idx + "_pub_inputs_offset");

for (size_t i = 0; i < inst.public_input_size; ++i) {
auto public_input_i =
transcript.template receive_from_prover<FF>(idx + "public_input_" + std::to_string(i));
inst.public_inputs.emplace_back(public_input_i);
}
auto eta = transcript.get_challenge(idx + "_eta");
auto [beta, gamma] = transcript.get_challenges(idx + "_beta", idx + "_gamma");
const FF public_input_delta = compute_public_input_delta<Flavor>(
inst.public_inputs, beta, gamma, inst.circuit_size, inst.pub_inputs_offset);
const FF lookup_grand_product_delta = compute_lookup_grand_product_delta<FF>(beta, gamma, inst.circuit_size);
inst.relation_parameters =
RelationParameters<FF>{ eta, beta, gamma, public_input_delta, lookup_grand_product_delta };
verifier_instances.emplace_back(inst);
}
VerifierFoldingResult<Flavor> res;
return res;
}

template class ProtoGalaxyVerifier_<honk::flavor::Ultra>;
template class ProtoGalaxyVerifier_<honk::flavor::UltraGrumpkin>;
template class ProtoGalaxyVerifier_<honk::flavor::GoblinUltra>;
} // namespace proof_system::honk
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
#pragma once
#include "barretenberg/honk/flavor/goblin_ultra.hpp"
#include "barretenberg/honk/flavor/ultra.hpp"
#include "barretenberg/honk/flavor/ultra_grumpkin.hpp"
#include "barretenberg/honk/instance/verifier_instance.hpp"
#include "barretenberg/honk/proof_system/folding_result.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/proof_system/folding_result.hpp"

namespace proof_system::honk {
template <UltraFlavor Flavor> class ProtoGalaxyVerifier_ {
public:
using FF = typename Flavor::FF;
using VerificationKey = typename Flavor::VerificationKey;
using VerifierInstance = VerifierInstance_<Flavor>;
std::vector<VerifierInstance> verifier_instances;
VerifierTranscript<FF> transcript;

explicit ProtoGalaxyVerifier_(std::vector<VerificationKey> vks);
VerifierFoldingResult<Flavor> fold_public_parameters();
explicit ProtoGalaxyVerifier_(std::vector<std::shared_ptr<VerificationKey>> vks);
VerifierFoldingResult<Flavor> fold_public_parameters(std::vector<uint8_t> fold_data);
};

extern template class ProtoGalaxyVerifier_<honk::flavor::Ultra>;
extern template class ProtoGalaxyVerifier_<honk::flavor::UltraGrumpkin>;
extern template class ProtoGalaxyVerifier_<honk::flavor::GoblinUltra>;
} // namespace proof_system::honk

0 comments on commit d23a275

Please sign in to comment.