Skip to content

Commit

Permalink
make gemini method return fold polys per Adrians suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Mar 29, 2023
1 parent d571a53 commit f172261
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
27 changes: 19 additions & 8 deletions cpp/src/barretenberg/honk/pcs/gemini/gemini.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,27 @@ template <typename Params> class MultilinearReductionScheme {
/**
* @brief Computes d-1 fold polynomials Fold_i, i = 1, ..., d-1
*
* @param mle_opening_point u = (u₀,...,uₘ₋₁) is the MLE opening point
* @param fold_polynomials (m + 1) - many polynomials. The first two are assumed initialized to F(X) = ∑ⱼ ρʲfⱼ(X)
* and G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X), i.e. the batched unshifted polynomials and the batched to-be-shifted polynomials. This
* function populates the next d-1 elements with Fold_i, i = 1, ..., d-1.
*
* @param mle_opening_point multilinear opening point 'u'
* @param batched_unshifted F(X) = ∑ⱼ ρʲ fⱼ(X)
* @param batched_to_be_shifted G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X)
* @return std::vector<Polynomial>
*/
static void compute_fold_polynomials(std::span<const Fr> mle_opening_point, auto& fold_polynomials)
static std::vector<Polynomial> compute_fold_polynomials(std::span<const Fr> mle_opening_point,
const Polynomial&& batched_unshifted,
const Polynomial&& batched_to_be_shifted)
{
const size_t num_variables = mle_opening_point.size(); // m

Polynomial& batched_F = fold_polynomials[0]; // F(X) = ∑ⱼ ρʲ fⱼ(X)
Polynomial& batched_G = fold_polynomials[1]; // G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X)
// Allocate space for m+1 Fold polynomials
//
// The first two are populated here with the batched unshifted and to-be-shifted polynomial respectively.
// They will eventually contain the full batched polynomial A₀ partially evaluated at the challenges r,-r.
// This function populates the other m-1 polynomials with the foldings of A₀.
std::vector<Polynomial> fold_polynomials;
fold_polynomials.reserve(num_variables + 1);

Polynomial& batched_F = fold_polynomials.emplace_back(batched_unshifted); // F(X) = ∑ⱼ ρʲ fⱼ(X)
Polynomial& batched_G = fold_polynomials.emplace_back(batched_to_be_shifted); // G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X)

// A₀(X) = F(X) + G↺(X) = F(X) + G(X)/X.
Polynomial A_0(batched_F);
Expand Down Expand Up @@ -123,6 +132,8 @@ template <typename Params> class MultilinearReductionScheme {
// set Aₗ₊₁ = Aₗ for the next iteration
A_l = A_l_fold;
}

return fold_polynomials;
};

/**
Expand Down
7 changes: 2 additions & 5 deletions cpp/src/barretenberg/honk/pcs/gemini/gemini.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ template <class Params> class GeminiTest : public CommitmentTest<Params> {
batched_commitment_to_be_shifted += multilinear_commitments_to_be_shifted[i] * rhos[rho_idx];
}

std::vector<Polynomial> fold_polynomials;
fold_polynomials.emplace_back(batched_unshifted);
fold_polynomials.emplace_back(batched_to_be_shifted);

// Compute:
// - (d+1) opening pairs: {r, \hat{a}_0}, {-r^{2^i}, a_i}, i = 0, ..., d-1
// - (d+1) Fold polynomials Fold_{r}^(0), Fold_{-r}^(0), and Fold^(i), i = 0, ..., d-1
Gemini::compute_fold_polynomials(multilinear_evaluation_point, fold_polynomials);
auto fold_polynomials = Gemini::compute_fold_polynomials(
multilinear_evaluation_point, std::move(batched_unshifted), std::move(batched_to_be_shifted));

for (size_t l = 0; l < log_n - 1; ++l) {
std::string label = "FOLD_" + std::to_string(l + 1);
Expand Down
7 changes: 2 additions & 5 deletions cpp/src/barretenberg/honk/pcs/kzg/kzg.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ TYPED_TEST(BilinearAccumulationTest, GeminiShplonkKzgWithShift)
batched_unshifted.add_scaled(poly2, rhos[1]);
batched_to_be_shifted.add_scaled(poly2, rhos[2]);

std::vector<Polynomial> fold_polynomials;
fold_polynomials.emplace_back(batched_unshifted);
fold_polynomials.emplace_back(batched_to_be_shifted);

// Compute batched commitments
Commitment batched_commitment_unshifted = Commitment::zero();
Commitment batched_commitment_to_be_shifted = Commitment::zero();
Expand All @@ -119,7 +115,8 @@ TYPED_TEST(BilinearAccumulationTest, GeminiShplonkKzgWithShift)
// Compute:
// - (d+1) opening pairs: {r, \hat{a}_0}, {-r^{2^i}, a_i}, i = 0, ..., d-1
// - (d+1) Fold polynomials Fold_{r}^(0), Fold_{-r}^(0), and Fold^(i), i = 0, ..., d-1
Gemini::compute_fold_polynomials(mle_opening_point, fold_polynomials);
auto fold_polynomials = Gemini::compute_fold_polynomials(
mle_opening_point, std::move(batched_unshifted), std::move(batched_to_be_shifted));

for (size_t l = 0; l < log_n - 1; ++l) {
std::string label = "FOLD_" + std::to_string(l + 1);
Expand Down
15 changes: 8 additions & 7 deletions cpp/src/barretenberg/honk/proof_system/prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,15 +303,16 @@ template <typename settings> void Prover<settings>::execute_univariatization_rou
Polynomial batched_poly_to_be_shifted(key->circuit_size); // batched to-be-shifted polynomials
batched_poly_to_be_shifted.add_scaled(prover_polynomials[POLYNOMIAL::Z_PERM], rhos[NUM_UNSHIFTED_POLYS]);

// Reserve space for d+1 Fold polynomials. At the end of this round, the last d-1 polynomials will
// correspond to Fold^(i). At the end of the full Gemini prover protocol, the first two will
// be the partially evaluated Fold polynomials Fold_{r}^(0) and Fold_{-r}^(0).
fold_polynomials.reserve(key->log_circuit_size + 1);
fold_polynomials.emplace_back(batched_poly_unshifted);
fold_polynomials.emplace_back(batched_poly_to_be_shifted);
// // Reserve space for d+1 Fold polynomials. At the end of this round, the last d-1 polynomials will
// // correspond to Fold^(i). At the end of the full Gemini prover protocol, the first two will
// // be the partially evaluated Fold polynomials Fold_{r}^(0) and Fold_{-r}^(0).
// fold_polynomials.reserve(key->log_circuit_size + 1);
// fold_polynomials.emplace_back(batched_poly_unshifted);
// fold_polynomials.emplace_back(batched_poly_to_be_shifted);

// Compute d-1 polynomials Fold^(i), i = 1, ..., d-1.
Gemini::compute_fold_polynomials(sumcheck_output.challenge_point, fold_polynomials);
fold_polynomials = Gemini::compute_fold_polynomials(
sumcheck_output.challenge_point, std::move(batched_poly_unshifted), std::move(batched_poly_to_be_shifted));

// Compute and add to trasnscript the commitments [Fold^(i)], i = 1, ..., d-1
for (size_t l = 0; l < key->log_circuit_size - 1; ++l) {
Expand Down

0 comments on commit f172261

Please sign in to comment.