Skip to content
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: protogalaxy interfaces #2125

Merged
merged 31 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
94418e5
wip
maramihali Sep 6, 2023
f98e95f
more wip
maramihali Sep 7, 2023
0749289
even more wip
maramihali Sep 7, 2023
06c02ac
more wip
maramihali Sep 8, 2023
884318a
more wip
maramihali Sep 8, 2023
6403b3b
more wip
maramihali Sep 8, 2023
18e4019
finding bug
maramihali Sep 10, 2023
9172e6f
more interface
maramihali Sep 11, 2023
2018ffe
more wip
maramihali Sep 11, 2023
9ff0c23
wip
maramihali Sep 11, 2023
c76f0cd
remove unwanted lines
maramihali Sep 11, 2023
8c38123
potentially fix test-ci
maramihali Sep 11, 2023
34a1da5
debug
maramihali Sep 11, 2023
88ea704
check crs_factor is null before initialising it
maramihali Sep 12, 2023
1560d24
fix bug
maramihali Sep 12, 2023
fc4880f
remove info statements
maramihali Sep 12, 2023
4e11ee8
cleanup of namings
maramihali Sep 13, 2023
67ace3b
cleanup
maramihali Sep 13, 2023
cf4435f
remove prover_library
maramihali Sep 13, 2023
c7a6282
add instance.test.cpp that i forgot to add
maramihali Sep 13, 2023
0157a1c
add grand_product_library.test.cpp that i forgot to add
maramihali Sep 13, 2023
62e0c62
chore: move bb for merge
ludamad0 Sep 13, 2023
b5de3a9
chore: remove build-system for merge
ludamad0 Sep 13, 2023
8f07bd4
Merge
ludamad0 Sep 13, 2023
7e3bf57
resolve merge conflicts
maramihali Sep 13, 2023
78a643b
actually delete prover_library and resolve comments
maramihali Sep 14, 2023
1eb15fb
address some review comments
maramihali Sep 14, 2023
4fba3a2
start work to make standard honk support instances
maramihali Sep 14, 2023
ce7d33c
continue work for standard honk with instances
maramihali Sep 15, 2023
7406e65
Merge branch 'master' into mm/pg-interfaces
maramihali Sep 15, 2023
599d20a
Merge branch 'master' into mm/pg-interfaces
maramihali Sep 15, 2023
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
@@ -1,5 +1,8 @@
#include <benchmark/benchmark.h>

#include "barretenberg/honk/composer/standard_composer.hpp"
#include "barretenberg/honk/composer/ultra_composer.hpp"
#include "barretenberg/proof_system/types/circuit_type.hpp"
#include "barretenberg/stdlib/encryption/ecdsa/ecdsa.hpp"
#include "barretenberg/stdlib/hash/keccak/keccak.hpp"
#include "barretenberg/stdlib/hash/sha256/sha256.hpp"
Expand Down Expand Up @@ -192,11 +195,20 @@ void construct_proof_with_specified_num_gates(State& state,
test_circuit_function(builder, num_gates);

auto composer = Composer();
auto ext_prover = composer.create_prover(builder);
state.ResumeTiming();

// Construct proof
auto proof = ext_prover.construct_proof();
if constexpr (proof_system::IsAnyOf<Composer, proof_system::honk::StandardComposer>) {
auto instance = composer.create_instance(builder);
auto ext_prover = composer.create_prover(instance);
state.ResumeTiming();

// Construct proof
auto proof = ext_prover.construct_proof();
} else {
auto ext_prover = composer.create_prover(builder);
state.ResumeTiming();

// Construct proof
auto proof = ext_prover.construct_proof();
}
}
}

Expand Down Expand Up @@ -224,11 +236,21 @@ void construct_proof_with_specified_num_iterations(State& state,
test_circuit_function(builder, num_iterations);

auto composer = Composer();
auto ext_prover = composer.create_prover(builder);
state.ResumeTiming();
if constexpr (proof_system::IsAnyOf<Composer, proof_system::honk::UltraComposer>) {
auto instance = composer.create_instance(builder);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ideally, I think the benchmarks should be templated by Flavor

auto ext_prover = composer.create_prover(instance);
state.ResumeTiming();

// Construct proof
auto proof = ext_prover.construct_proof();

} else {
auto ext_prover = composer.create_prover(builder);
Copy link
Contributor

Choose a reason for hiding this comment

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

How much more work would it be to implement for StandardHonk? I know we talked about this and I suggested doing Ultra only, but now that I see it leads a major divergence in structure and also in interace, I'm in favor of bringing Standard along for the ride. Should be routine now that you've done the same for Ultra, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

erm, couple of hours max, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but the divergence around here is between honk and plonk now

Copy link
Contributor

Choose a reason for hiding this comment

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

Not ideal, but we have accepted divergence with Plonk if it means improving Honk.

state.ResumeTiming();

// Construct proof
auto proof = ext_prover.construct_proof();
// Construct proof
auto proof = ext_prover.construct_proof();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class GoblinUltraHonkComposerTests : public ::testing::Test {
*/
TEST_F(GoblinUltraHonkComposerTests, SimpleCircuit)
{
auto builder = UltraCircuitBuilder();
using fr = barretenberg::fr;
using g1 = barretenberg::g1;
auto builder = proof_system::UltraCircuitBuilder();

// Define an arbitrary number of operations/gates
size_t num_ecc_ops = 3;
Expand Down Expand Up @@ -55,8 +57,9 @@ TEST_F(GoblinUltraHonkComposerTests, SimpleCircuit)
}

auto composer = GoblinUltraComposer();
auto prover = composer.create_prover(builder);
auto verifier = composer.create_verifier(builder);
auto instance = composer.create_instance(builder);
auto prover = composer.create_prover(instance);
auto verifier = composer.create_verifier(instance);
auto proof = prover.construct_proof();
bool verified = verifier.verify_proof(proof);
EXPECT_EQ(verified, true);
Expand Down
108 changes: 8 additions & 100 deletions barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,122 +9,30 @@

namespace proof_system::honk {

/**
* Compute witness polynomials (w_1, w_2, w_3, w_4).
*
* @details Fills 3 or 4 witness polynomials w_1, w_2, w_3, w_4 with the values of in-circuit variables. The beginning
* of w_1, w_2 polynomials is filled with public_input values.
* @return Witness with computed witness polynomials.
*
* @tparam Program settings needed to establish if w_4 is being used.
* */
template <StandardFlavor Flavor>
void StandardComposer_<Flavor>::compute_witness(const CircuitBuilder& circuit_constructor, const size_t /*unused*/)
std::shared_ptr<ProverInstance_<Flavor>> StandardComposer_<Flavor>::create_instance(CircuitBuilder& circuit)
{
if (computed_witness) {
return;
}
auto wire_polynomials = construct_wire_polynomials_base<Flavor>(circuit_constructor, dyadic_circuit_size);

proving_key->w_l = wire_polynomials[0];
proving_key->w_r = wire_polynomials[1];
proving_key->w_o = wire_polynomials[2];

computed_witness = true;
}

/**
* Compute proving key.
* Compute the polynomials q_l, q_r, etc. and sigma polynomial.
*
* @return Proving key with saved computed polynomials.
* */

template <StandardFlavor Flavor>
std::shared_ptr<typename Flavor::ProvingKey> StandardComposer_<Flavor>::compute_proving_key(
const CircuitBuilder& circuit_constructor)
{
if (proving_key) {
return proving_key;
}

// Construct a proving key
proving_key = std::make_shared<ProvingKey>(dyadic_circuit_size, num_public_inputs);

// Compute lagrange selectors
construct_selector_polynomials<Flavor>(circuit_constructor, proving_key.get());

// Compute sigma polynomials (we should update that late)
compute_standard_honk_sigma_permutations<Flavor>(circuit_constructor, proving_key.get());
compute_standard_honk_id_polynomials<Flavor>(proving_key.get());

compute_first_and_last_lagrange_polynomials<Flavor>(proving_key.get());

return proving_key;
auto instance = std::make_shared<Instance>(circuit);
instance->commitment_key = compute_commitment_key(instance->proving_key->circuit_size);
return instance;
}

/**
* Compute verification key consisting of selector precommitments.
*
* @return Pointer to created circuit verification key.
* */
template <StandardFlavor Flavor>
std::shared_ptr<typename Flavor::VerificationKey> StandardComposer_<Flavor>::compute_verification_key(
const CircuitBuilder& /*unused*/)
StandardVerifier_<Flavor> StandardComposer_<Flavor>::create_verifier(std::shared_ptr<Instance> instance)
{
if (verification_key) {
return verification_key;
}

verification_key =
std::make_shared<typename Flavor::VerificationKey>(proving_key->circuit_size, proving_key->num_public_inputs);

// Compute and store commitments to all precomputed polynomials
verification_key->q_m = commitment_key->commit(proving_key->q_m);
verification_key->q_l = commitment_key->commit(proving_key->q_l);
verification_key->q_r = commitment_key->commit(proving_key->q_r);
verification_key->q_o = commitment_key->commit(proving_key->q_o);
verification_key->q_c = commitment_key->commit(proving_key->q_c);
verification_key->sigma_1 = commitment_key->commit(proving_key->sigma_1);
verification_key->sigma_2 = commitment_key->commit(proving_key->sigma_2);
verification_key->sigma_3 = commitment_key->commit(proving_key->sigma_3);
verification_key->id_1 = commitment_key->commit(proving_key->id_1);
verification_key->id_2 = commitment_key->commit(proving_key->id_2);
verification_key->id_3 = commitment_key->commit(proving_key->id_3);
verification_key->lagrange_first = commitment_key->commit(proving_key->lagrange_first);
verification_key->lagrange_last = commitment_key->commit(proving_key->lagrange_last);

return verification_key;
}

template <StandardFlavor Flavor>
StandardVerifier_<Flavor> StandardComposer_<Flavor>::create_verifier(const CircuitBuilder& circuit_constructor)
{
compute_verification_key(circuit_constructor);
auto verification_key = instance->compute_verification_key();
StandardVerifier_<Flavor> output_state(verification_key);

auto pcs_verification_key =
std::make_unique<typename Flavor::VerifierCommitmentKey>(verification_key->circuit_size, crs_factory_);

output_state.pcs_verification_key = std::move(pcs_verification_key);

return output_state;
}

template <StandardFlavor Flavor>
StandardProver_<Flavor> StandardComposer_<Flavor>::create_prover(const CircuitBuilder& circuit_constructor)
StandardProver_<Flavor> StandardComposer_<Flavor>::create_prover(std::shared_ptr<Instance> instance)
{
// Compute some key cicuit size paramaters
num_public_inputs = circuit_constructor.public_inputs.size();
total_num_gates = circuit_constructor.num_gates + num_public_inputs;
dyadic_circuit_size = circuit_constructor.get_circuit_subgroup_size(total_num_gates);

compute_proving_key(circuit_constructor);
compute_witness(circuit_constructor);

compute_commitment_key(proving_key->circuit_size);

StandardProver_<Flavor> output_state(proving_key, commitment_key);
StandardProver_<Flavor> output_state(instance);

return output_state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "barretenberg/honk/instance/prover_instance.hpp"
#include "barretenberg/honk/proof_system/prover.hpp"
#include "barretenberg/honk/proof_system/verifier.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"
Expand All @@ -18,6 +19,7 @@ template <StandardFlavor Flavor> class StandardComposer_ {
using ProvingKey = typename Flavor::ProvingKey;
using VerificationKey = typename Flavor::VerificationKey;
using CommitmentKey = typename Flavor::CommitmentKey;
using Instance = ProverInstance_<Flavor>;

static constexpr std::string_view NAME_STRING = "StandardHonk";
static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES;
Expand All @@ -29,14 +31,11 @@ template <StandardFlavor Flavor> class StandardComposer_ {

// The commitment key is passed to the prover but also used herein to compute the verfication key commitments
std::shared_ptr<CommitmentKey> commitment_key;

size_t total_num_gates; // total num gates prior to computing dyadic size
size_t dyadic_circuit_size; // final dyadic circuit size
size_t num_public_inputs;
;

bool computed_witness = false;
// TODO(Luke): use make_shared
// TODO(#637): design the crs factory better
// TODO(https://github.com/AztecProtocol/barretenberg/issues/637): design the crs factory better
StandardComposer_()
{
if constexpr (IsGrumpkinFlavor<Flavor>) {
Expand Down Expand Up @@ -64,18 +63,15 @@ template <StandardFlavor Flavor> class StandardComposer_ {
StandardComposer_& operator=(const StandardComposer_& other) = delete;
~StandardComposer_() = default;

std::shared_ptr<ProvingKey> compute_proving_key(const CircuitBuilder& circuit_constructor);
std::shared_ptr<VerificationKey> compute_verification_key(const CircuitBuilder& circuit_constructor);

StandardVerifier_<Flavor> create_verifier(const CircuitBuilder& circuit_constructor);

StandardProver_<Flavor> create_prover(const CircuitBuilder& circuit_constructor);
std::shared_ptr<Instance> create_instance(CircuitBuilder& circuit);

void compute_witness(const CircuitBuilder& circuit_constructor, const size_t minimum_circuit_size = 0);
StandardProver_<Flavor> create_prover(std::shared_ptr<Instance>);
StandardVerifier_<Flavor> create_verifier(std::shared_ptr<Instance>);

void compute_commitment_key(size_t circuit_size)
std::shared_ptr<CommitmentKey> compute_commitment_key(size_t circuit_size)
{
commitment_key = std::make_shared<CommitmentKey>(circuit_size, crs_factory_);
return commitment_key;
};
};

Expand Down
Loading