Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
maramihali committed Sep 13, 2023
1 parent 4e11ee8 commit 67ace3b
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 588 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "instance.hpp"
#include "barretenberg/honk/proof_system/grand_product_library.hpp"
#include "barretenberg/honk/proof_system/prover_library.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/proof_system/composer/composer_lib.hpp"
#include "barretenberg/proof_system/composer/permutation_lib.hpp"
Expand Down Expand Up @@ -312,17 +311,87 @@ template <UltraFlavor Flavor> void Instance_<Flavor>::compute_sorted_accumulator
{
relation_parameters.eta = eta;
// Compute sorted witness-table accumulator
proving_key->sorted_accum = prover_library::compute_sorted_list_accumulator<Flavor>(proving_key, eta);
compute_sorted_list_accumulator(eta);
prover_polynomials.sorted_accum = proving_key->sorted_accum;
prover_polynomials.sorted_accum_shift = proving_key->sorted_accum.shifted();

// Finalize fourth wire polynomial by adding lookup memory records
prover_library::add_plookup_memory_records_to_wire_4<Flavor>(proving_key, eta);

prover_polynomials.sorted_accum_shift = proving_key->sorted_accum.shifted();
prover_polynomials.sorted_accum = proving_key->sorted_accum;
add_plookup_memory_records_to_wire_4(eta);
prover_polynomials.w_4 = proving_key->w_4;
prover_polynomials.w_4_shift = proving_key->w_4.shifted();
}

/**
* @brief Construct sorted list accumulator polynomial 's'.
*
* @details Compute s = s_1 + η*s_2 + η²*s_3 + η³*s_4 (via Horner) where s_i are the
* sorted concatenated witness/table polynomials
*
* @param key proving key
* @param sorted_list_polynomials sorted concatenated witness/table polynomials
* @param eta random challenge
* @return Polynomial
*/
template <UltraFlavor Flavor> void Instance_<Flavor>::compute_sorted_list_accumulator(FF eta)
{
const size_t circuit_size = proving_key->circuit_size;

auto sorted_list_accumulator = Polynomial{ circuit_size };

auto sorted_polynomials = proving_key->get_sorted_polynomials();

// Construct s via Horner, i.e. s = s_1 + η(s_2 + η(s_3 + η*s_4))
for (size_t i = 0; i < circuit_size; ++i) {
FF T0 = sorted_polynomials[3][i];
T0 *= eta;
T0 += sorted_polynomials[2][i];
T0 *= eta;
T0 += sorted_polynomials[1][i];
T0 *= eta;
T0 += sorted_polynomials[0][i];
sorted_list_accumulator[i] = T0;
}
proving_key->sorted_accum = sorted_list_accumulator;
}

/**
* @brief Add plookup memory records to the fourth wire polynomial
*
* @details This operation must be performed after the first three wires have been committed to, hence the dependence on
* the `eta` challenge.
*
* @tparam Flavor
* @param eta challenge produced after commitment to first three wire polynomials
*/
template <UltraFlavor Flavor> void Instance_<Flavor>::add_plookup_memory_records_to_wire_4(FF eta)
{
// The plookup memory record values are computed at the indicated indices as
// w4 = w3 * eta^3 + w2 * eta^2 + w1 * eta + read_write_flag;
// (See plookup_auxiliary_widget.hpp for details)
auto wires = proving_key->get_wires();

// Compute read record values
for (const auto& gate_idx : proving_key->memory_read_records) {
wires[3][gate_idx] += wires[2][gate_idx];
wires[3][gate_idx] *= eta;
wires[3][gate_idx] += wires[1][gate_idx];
wires[3][gate_idx] *= eta;
wires[3][gate_idx] += wires[0][gate_idx];
wires[3][gate_idx] *= eta;
}

// Compute write record values
for (const auto& gate_idx : proving_key->memory_write_records) {
wires[3][gate_idx] += wires[2][gate_idx];
wires[3][gate_idx] *= eta;
wires[3][gate_idx] += wires[1][gate_idx];
wires[3][gate_idx] *= eta;
wires[3][gate_idx] += wires[0][gate_idx];
wires[3][gate_idx] *= eta;
wires[3][gate_idx] += 1;
}
}

template <UltraFlavor Flavor> void Instance_<Flavor>::compute_grand_product_polynomials(FF beta, FF gamma)
{
auto public_input_delta =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ template <UltraFlavor Flavor> class Instance_ {
using FF = typename Flavor::FF;
using FoldingParameters = typename Flavor::FoldingParameters;
using ProverPolynomials = typename Flavor::ProverPolynomials;
using Polynomial = typename Flavor::Polynomial;

// offset due to placing zero wires at the start of execution trace
static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0;
Expand Down Expand Up @@ -63,6 +64,8 @@ template <UltraFlavor Flavor> class Instance_ {
// Used by the prover for domain separation in the transcript
uint32_t index;

Instance_();

Instance_(Circuit& circuit)
{
compute_circuit_size_parameters(circuit);
Expand Down Expand Up @@ -97,6 +100,10 @@ template <UltraFlavor Flavor> class Instance_ {

void compute_sorted_accumulator_polynomials(FF);

void compute_sorted_list_accumulator(FF);

void add_plookup_memory_records_to_wire_4(FF);

void compute_grand_product_polynomials(FF, FF);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "prover.hpp"
#include "barretenberg/honk/proof_system/grand_product_library.hpp"
#include "barretenberg/honk/proof_system/prover_library.hpp"
#include "barretenberg/honk/sumcheck/sumcheck.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/honk/utils/power_polynomial.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "barretenberg/honk/flavor/standard_grumpkin.hpp"
#include "barretenberg/honk/pcs/gemini/gemini.hpp"
#include "barretenberg/honk/pcs/shplonk/shplonk.hpp"
#include "barretenberg/honk/proof_system/prover_library.hpp"
#include "barretenberg/honk/proof_system/work_queue.hpp"
#include "barretenberg/honk/sumcheck/sumcheck.hpp"
#include "barretenberg/honk/sumcheck/sumcheck_output.hpp"
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 67ace3b

Please sign in to comment.