Skip to content

Commit

Permalink
"Everything builds" in clang!
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Apr 11, 2023
1 parent 953b23a commit 3ff32af
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace proof_system::honk {
* Compute proving key base.
*
* 1. Load crs.
* 2. Initialize this.circuit_proving_key.
* 2. Initialize this.proving_key.
* 3. Create constraint selector polynomials from each of this composer's `selectors` vectors and add them to the
* proving key.
*
Expand All @@ -28,14 +28,14 @@ namespace proof_system::honk {
std::shared_ptr<StandardHonkComposerHelper::ProvingKey> StandardHonkComposerHelper::compute_proving_key_base(
const CircuitConstructor& constructor, const size_t minimum_circuit_size, const size_t num_randomized_gates)
{
// Initialize circuit_proving_key
// Initialize proving_key
// TODO(#229)(Kesha): replace composer types.
circuit_proving_key = initialize_proving_key<Flavor>(
proving_key = initialize_proving_key<Flavor>(
constructor, crs_factory_.get(), minimum_circuit_size, num_randomized_gates, ComposerType::STANDARD_HONK);
// Compute lagrange selectors
construct_selector_polynomials<Flavor>(constructor, circuit_proving_key.get());
construct_selector_polynomials<Flavor>(constructor, proving_key.get());

return circuit_proving_key;
return proving_key;
}

/**
Expand Down Expand Up @@ -103,20 +103,20 @@ void StandardHonkComposerHelper::compute_witness(const CircuitConstructor& circu
std::shared_ptr<StandardHonkComposerHelper::ProvingKey> StandardHonkComposerHelper::compute_proving_key(
const CircuitConstructor& circuit_constructor)
{
if (circuit_proving_key) {
return circuit_proving_key;
if (proving_key) {
return proving_key;
}
// Compute q_l, q_r, q_o, etc polynomials
// WORKTODO(Cody): meaningless constructor here
StandardHonkComposerHelper::compute_proving_key_base(circuit_constructor, ComposerType::STANDARD_HONK);

// Compute sigma polynomials (we should update that late)
compute_standard_honk_sigma_permutations<Flavor>(circuit_constructor, circuit_proving_key.get());
compute_standard_honk_id_polynomials<Flavor>(circuit_proving_key.get());
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(circuit_proving_key.get());
compute_first_and_last_lagrange_polynomials(proving_key.get());

return circuit_proving_key;
return proving_key;
}

/**
Expand All @@ -130,13 +130,13 @@ std::shared_ptr<plonk::verification_key> StandardHonkComposerHelper::compute_ver
if (circuit_verification_key) {
return circuit_verification_key;
}
if (!circuit_proving_key) {
if (!proving_key) {
compute_proving_key(circuit_constructor);
}

circuit_verification_key = StandardHonkComposerHelper::compute_verification_key_base(
circuit_proving_key, crs_factory_->get_verifier_crs());
circuit_verification_key->composer_type = circuit_proving_key->composer_type;
circuit_verification_key =
StandardHonkComposerHelper::compute_verification_key_base(proving_key, crs_factory_->get_verifier_crs());
circuit_verification_key->composer_type = proving_key->composer_type;

return circuit_verification_key;
}
Expand All @@ -159,14 +159,7 @@ StandardProver StandardHonkComposerHelper::create_prover(const CircuitConstructo
compute_proving_key(circuit_constructor);
compute_witness(circuit_constructor);

// size_t num_sumcheck_rounds(circuit_proving_key->log_circuit_size);
// StandardProver output_state(std::move(wire_polynomials), circuit_proving_key);
// WORKTODO
auto crs_factory = ReferenceStringFactory();
auto crs = crs_factory.get_prover_crs(999);
auto pk_ptr = std::make_shared<plonk::proving_key>(12, 2, crs, ComposerType::STANDARD);

StandardProver output_state(std::move(wire_polynomials), pk_ptr);
StandardProver output_state(std::move(wire_polynomials), proving_key);

return output_state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StandardHonkComposerHelper {

static constexpr size_t NUM_RANDOMIZED_GATES = 2; // equal to the number of multilinear evaluations leaked
static constexpr size_t num_wires = CircuitConstructor::num_wires;
std::shared_ptr<ProvingKey> circuit_proving_key;
std::shared_ptr<ProvingKey> proving_key;
std::vector<barretenberg::polynomial> wire_polynomials;
std::shared_ptr<plonk::verification_key> circuit_verification_key;
// TODO(#218)(kesha): we need to put this into the commitment key, so that the composer doesn't have to handle srs
Expand All @@ -44,7 +44,7 @@ class StandardHonkComposerHelper {
: crs_factory_(std::move(crs_factory))
{}
StandardHonkComposerHelper(std::shared_ptr<ProvingKey> p_key, std::shared_ptr<plonk::verification_key> v_key)
: circuit_proving_key(std::move(p_key))
: proving_key(std::move(p_key))
, circuit_verification_key(std::move(v_key))
{}
StandardHonkComposerHelper(StandardHonkComposerHelper&& other) noexcept = default;
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/barretenberg/honk/composer/standard_honk_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ namespace proof_system::honk {
*/
class StandardHonkComposer {
public:
// TODO(Cody): This should go in flavor or something.
static constexpr merkle::HashType merkle_hash_type = merkle::HashType::LOOKUP_PEDERSEN;
static constexpr pedersen::CommitmentType commitment_type = pedersen::CommitmentType::FIXED_BASE_PEDERSEN;

using Flavor = flavor::Standard;
using CircuitConstructor = StandardCircuitConstructor;
using ProvingKey = typename Flavor::ProvingKey;
Expand Down
44 changes: 22 additions & 22 deletions cpp/src/barretenberg/honk/composer/standard_honk_composer.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/utils/public_inputs.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"

#include <gtest/gtest.h>

Expand Down Expand Up @@ -376,7 +377,6 @@ TEST(StandardHonkComposer, SumcheckRelationCorrectness)
{
// Create a composer and a dummy circuit with a few gates
StandardHonkComposer composer = StandardHonkComposer();
static const size_t num_wires = StandardHonkComposer::num_wires;
fr a = fr::one();
// Using the public variable to check that public_input_delta is computed and added to the relation correctly
uint32_t a_idx = composer.add_public_variable(a);
Expand Down Expand Up @@ -410,34 +410,34 @@ TEST(StandardHonkComposer, SumcheckRelationCorrectness)

constexpr size_t num_polynomials = proof_system::honk::StandardArithmetization::NUM_POLYNOMIALS;
// Compute grand product polynomial
polynomial z_perm_poly =
prover_library::compute_permutation_grand_product<num_wires>(prover.key, prover.wire_polynomials, beta, gamma);
polynomial z_perm_poly = prover_library::compute_permutation_grand_product<honk::flavor::Standard>(
prover.key, prover.wire_polynomials, beta, gamma);

// Create an array of spans to the underlying polynomials to more easily
// get the transposition.
// Ex: polynomial_spans[3][i] returns the i-th coefficient of the third polynomial
// in the list below
std::array<std::span<const fr>, num_polynomials> evaluations_array;

using POLYNOMIAL = proof_system::honk::StandardArithmetization::POLYNOMIAL;
evaluations_array[POLYNOMIAL::W_L] = prover.wire_polynomials[0];
evaluations_array[POLYNOMIAL::W_R] = prover.wire_polynomials[1];
evaluations_array[POLYNOMIAL::W_O] = prover.wire_polynomials[2];
evaluations_array[POLYNOMIAL::Z_PERM] = z_perm_poly;
evaluations_array[POLYNOMIAL::Z_PERM_SHIFT] = z_perm_poly.shifted();
evaluations_array[POLYNOMIAL::Q_M] = prover.key->polynomial_store.get("q_m_lagrange");
evaluations_array[POLYNOMIAL::Q_L] = prover.key->polynomial_store.get("q_1_lagrange");
evaluations_array[POLYNOMIAL::Q_R] = prover.key->polynomial_store.get("q_2_lagrange");
evaluations_array[POLYNOMIAL::Q_O] = prover.key->polynomial_store.get("q_3_lagrange");
evaluations_array[POLYNOMIAL::Q_C] = prover.key->polynomial_store.get("q_c_lagrange");
evaluations_array[POLYNOMIAL::SIGMA_1] = prover.key->polynomial_store.get("sigma_1_lagrange");
evaluations_array[POLYNOMIAL::SIGMA_2] = prover.key->polynomial_store.get("sigma_2_lagrange");
evaluations_array[POLYNOMIAL::SIGMA_3] = prover.key->polynomial_store.get("sigma_3_lagrange");
evaluations_array[POLYNOMIAL::ID_1] = prover.key->polynomial_store.get("id_1_lagrange");
evaluations_array[POLYNOMIAL::ID_2] = prover.key->polynomial_store.get("id_2_lagrange");
evaluations_array[POLYNOMIAL::ID_3] = prover.key->polynomial_store.get("id_3_lagrange");
evaluations_array[POLYNOMIAL::LAGRANGE_FIRST] = prover.key->polynomial_store.get("L_first_lagrange");
evaluations_array[POLYNOMIAL::LAGRANGE_LAST] = prover.key->polynomial_store.get("L_last_lagrange");
// WORKTODO
// evaluations_array[POLYNOMIAL::W_L] = prover.wire_polynomials[0];
// evaluations_array[POLYNOMIAL::W_R] = prover.wire_polynomials[1];
// evaluations_array[POLYNOMIAL::W_O] = prover.wire_polynomials[2];
// evaluations_array[POLYNOMIAL::Z_PERM] = z_perm_poly;
// evaluations_array[POLYNOMIAL::Z_PERM_SHIFT] = z_perm_poly.shifted();
// evaluations_array[POLYNOMIAL::Q_M] = prover.key->polynomial_store.get("q_m_lagrange");
// evaluations_array[POLYNOMIAL::Q_L] = prover.key->polynomial_store.get("q_1_lagrange");
// evaluations_array[POLYNOMIAL::Q_R] = prover.key->polynomial_store.get("q_2_lagrange");
// evaluations_array[POLYNOMIAL::Q_O] = prover.key->polynomial_store.get("q_3_lagrange");
// evaluations_array[POLYNOMIAL::Q_C] = prover.key->polynomial_store.get("q_c_lagrange");
// evaluations_array[POLYNOMIAL::SIGMA_1] = prover.key->polynomial_store.get("sigma_1_lagrange");
// evaluations_array[POLYNOMIAL::SIGMA_2] = prover.key->polynomial_store.get("sigma_2_lagrange");
// evaluations_array[POLYNOMIAL::SIGMA_3] = prover.key->polynomial_store.get("sigma_3_lagrange");
// evaluations_array[POLYNOMIAL::ID_1] = prover.key->polynomial_store.get("id_1_lagrange");
// evaluations_array[POLYNOMIAL::ID_2] = prover.key->polynomial_store.get("id_2_lagrange");
// evaluations_array[POLYNOMIAL::ID_3] = prover.key->polynomial_store.get("id_3_lagrange");
// evaluations_array[POLYNOMIAL::LAGRANGE_FIRST] = prover.key->polynomial_store.get("L_first_lagrange");
// evaluations_array[POLYNOMIAL::LAGRANGE_LAST] = prover.key->polynomial_store.get("L_last_lagrange");

// Construct the round for applying sumcheck relations and results for storing computed results
auto relations = std::tuple(honk::sumcheck::ArithmeticRelation<fr>(),
Expand Down
Loading

0 comments on commit 3ff32af

Please sign in to comment.