Skip to content

Commit

Permalink
changed the location of the allocation of the polynomials to where th…
Browse files Browse the repository at this point in the history
…ey get populated instead of all at once in the proving key
  • Loading branch information
lucasxia01 committed Sep 17, 2024
1 parent 6165ae0 commit 7b449f9
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ typename ExecutionTrace_<Flavor>::TraceData ExecutionTrace_<Flavor>::construct_t
Builder& builder, typename Flavor::ProvingKey& proving_key, bool is_structured)
{
ZoneScopedN("construct_trace_data");
// Allocate the wires and selectors polynomials
if constexpr (IsHonkFlavor<Flavor>) {
for (auto wire : proving_key.polynomials.get_wires()) {
wire = Polynomial(proving_key.circuit_size);
}
for (auto selector : proving_key.polynomials.get_selectors()) {
selector = Polynomial(proving_key.circuit_size);
}
}

TraceData trace_data{ builder, proving_key };

// Complete the public inputs execution trace block from builder.public_inputs
Expand Down Expand Up @@ -134,6 +144,13 @@ void ExecutionTrace_<Flavor>::add_ecc_op_wires_to_proving_key(Builder& builder,
typename Flavor::ProvingKey& proving_key)
requires IsGoblinFlavor<Flavor>
{
// Allocate the ecc op wires and selector
if constexpr (IsHonkFlavor<Flavor>) {
for (auto wire : proving_key.polynomials.get_ecc_op_wires()) {
wire = Polynomial(proving_key.circuit_size);
}
proving_key.polynomials.lagrange_ecc_op = Polynomial(proving_key.circuit_size);
}
// Copy the ecc op data from the conventional wires into the op wires over the range of ecc op gates
auto& ecc_op_selector = proving_key.polynomials.lagrange_ecc_op;
const size_t op_wire_offset = Flavor::has_zero_row ? 1 : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ void construct_lookup_table_polynomials(const RefArray<typename Flavor::Polynomi
size_t dyadic_circuit_size,
size_t additional_offset = 0)
{
// Allocate the table polynomials
if constexpr (IsHonkFlavor<Flavor>) {
for (auto& poly : table_polynomials) {
poly = typename Flavor::Polynomial(dyadic_circuit_size);
}
}
// Create lookup selector polynomials which interpolate each table column.
// Our selector polys always need to interpolate the full subgroup size, so here we offset so as to
// put the table column's values at the end. (The first gates are for non-lookup constraints).
Expand Down Expand Up @@ -51,6 +57,11 @@ void construct_lookup_read_counts(typename Flavor::Polynomial& read_counts,
typename Flavor::CircuitBuilder& circuit,
size_t dyadic_circuit_size)
{
// Allocate the read counts and tags polynomials
if constexpr (IsHonkFlavor<Flavor>) {
read_counts = typename Flavor::Polynomial(dyadic_circuit_size);
read_tags = typename Flavor::Polynomial(dyadic_circuit_size);
}
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1033): construct tables and counts at top of trace
size_t offset = dyadic_circuit_size - circuit.get_tables_size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ void compute_permutation_argument_polynomials(const typename Flavor::CircuitBuil
compute_monomial_and_coset_fft_polynomials_from_lagrange<Flavor::NUM_WIRES>("id", key);
}
} else if constexpr (IsUltraFlavor<Flavor>) { // any UltraHonk flavor
// Allocate sigma and id polynomials
for (auto& sigma : key->polynomials.get_sigmas()) {
sigma = Polynomial(key->circuit_size);
}
for (auto& id : key->polynomials.get_ids()) {
id = Polynomial(key->circuit_size);
}
// Compute Honk-style sigma and ID polynomials from the corresponding mappings
{
ZoneScopedN("compute_honk_style_permutation_lagrange_polynomials_from_mapping");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ class MegaFlavor {
ProvingKey(const size_t circuit_size,
const size_t num_public_inputs,
std::shared_ptr<CommitmentKey> commitment_key = nullptr)
: Base(circuit_size, num_public_inputs, commitment_key)
, polynomials(circuit_size){};
: Base(circuit_size, num_public_inputs, commitment_key){};

std::vector<uint32_t> memory_read_records;
std::vector<uint32_t> memory_write_records;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ class UltraFlavor {
ProvingKey(const size_t circuit_size,
const size_t num_public_inputs,
std::shared_ptr<CommitmentKey> commitment_key = nullptr)
: Base(circuit_size, num_public_inputs, std::move(commitment_key))
, polynomials(circuit_size){};
: Base(circuit_size, num_public_inputs, std::move(commitment_key)){};

std::vector<uint32_t> memory_read_records;
std::vector<uint32_t> memory_write_records;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ class UltraKeccakFlavor {
ProvingKey(const size_t circuit_size,
const size_t num_public_inputs,
std::shared_ptr<CommitmentKey> commitment_key = nullptr)
: Base(circuit_size, num_public_inputs, commitment_key)
, polynomials(circuit_size){};
: Base(circuit_size, num_public_inputs, commitment_key){};

std::vector<uint32_t> memory_read_records;
std::vector<uint32_t> memory_write_records;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ template <class Flavor>
void DeciderProvingKey_<Flavor>::construct_databus_polynomials(Circuit& circuit)
requires IsGoblinFlavor<Flavor>
{
// Allocate the databus polynomials and databus_id
for (auto& databus_poly : proving_key.polynomials.get_databus_entities()) {
databus_poly = Polynomial(proving_key.circuit_size);
}
proving_key.polynomials.databus_id = Polynomial(proving_key.circuit_size);

auto& public_calldata = proving_key.polynomials.calldata;
auto& calldata_read_counts = proving_key.polynomials.calldata_read_counts;
auto& calldata_read_tags = proving_key.polynomials.calldata_read_tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ template <class Flavor> class DeciderProvingKey_ {
}

// First and last lagrange polynomials (in the full circuit size)
proving_key.polynomials.lagrange_first = Polynomial(dyadic_circuit_size);
proving_key.polynomials.lagrange_last = Polynomial(dyadic_circuit_size);
proving_key.polynomials.lagrange_first.at(0) = 1;
proving_key.polynomials.lagrange_last.at(dyadic_circuit_size - 1) = 1;

Expand Down
9 changes: 9 additions & 0 deletions barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ template <IsUltraFlavor Flavor> void OinkProver<Flavor>::execute_log_derivative_
proving_key->relation_parameters.beta = beta;
proving_key->relation_parameters.gamma = gamma;

// Allocate the lookup_inverses polynomial
proving_key->proving_key.polynomials.lookup_inverses =
typename Flavor::Polynomial(proving_key->proving_key.circuit_size);
// Compute the inverses used in log-derivative lookup relations
proving_key->proving_key.compute_logderivative_inverses(proving_key->relation_parameters);

Expand All @@ -177,11 +180,14 @@ template <IsUltraFlavor Flavor> void OinkProver<Flavor>::execute_log_derivative_

// If Mega, commit to the databus inverse polynomials and send
if constexpr (IsGoblinFlavor<Flavor>) {
// Allocate the databus inverse polynomials
for (auto [commitment, polynomial, label] :
zip_view(witness_commitments.get_databus_inverses(),
proving_key->proving_key.polynomials.get_databus_inverses(),
commitment_labels.get_databus_inverses())) {
{
// Allocate the databus inverse polynomial
polynomial = typename Flavor::Polynomial(proving_key->proving_key.circuit_size);
BB_OP_COUNT_TIME_NAME("COMMIT::databus_inverses");
commitment = commitment_key->commit_sparse(polynomial);
}
Expand All @@ -197,6 +203,9 @@ template <IsUltraFlavor Flavor> void OinkProver<Flavor>::execute_log_derivative_
template <IsUltraFlavor Flavor> void OinkProver<Flavor>::execute_grand_product_computation_round()
{
BB_OP_COUNT_TIME_NAME("OinkProver::execute_grand_product_computation_round");
// Allocate the z_perm polynomial
proving_key->proving_key.polynomials.z_perm = typename Flavor::Polynomial(proving_key->proving_key.circuit_size);
// Compute the permutation and lookup grand product polynomials
proving_key->proving_key.compute_grand_product_polynomials(proving_key->relation_parameters);

{
Expand Down

0 comments on commit 7b449f9

Please sign in to comment.