|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
A purely static class (never add state to this!) consisting of functions used by the Protogalaxy prover. More...
#include <protogalaxy_prover_internal.hpp>
Public Member Functions | |
| ProtogalaxyProverInternal (ExecutionTraceUsageTracker trace_usage_tracker=ExecutionTraceUsageTracker{}) | |
| Polynomial< FF > | compute_row_evaluations (const ProverPolynomials &polynomials, const SubrelationSeparators &alphas, const RelationParameters< FF > &relation_parameters) |
| Compute the values of the aggregated relation evaluations at each row in the execution trace, representing f_i(ω) in the Protogalaxy paper, given the evaluations of all the prover polynomials and \vec{α} (the batching challenges that help establishing each subrelation is independently valid in Mega Honk relation - this α is same as in the Plonk paper, DO NOT confuse with α in Protogalaxy). | |
| Polynomial< FF > | compute_perturbator (const std::shared_ptr< const ProverInstance > &accumulator, const std::vector< FF > &deltas) |
| Construct the perturbator polynomial F(X) in coefficient form from the accumulator resulted from a previous round of Protogalaxy. | |
| ExtendedUnivariateWithRandomization | compute_combiner (const ProverInstances &instances, const GateSeparatorPolynomial< FF > &gate_separators, const UnivariateRelationParameters &relation_parameters, const UnivariateSubrelationSeparators &alphas, TupleOfTuplesOfUnivariates &univariate_accumulators) |
| Compute the combiner polynomial \(G\) in the Protogalaxy paper. | |
Static Public Member Functions | |
| template<size_t skip_count = 0> | |
| static auto | row_to_univariates (const ProverInstances &instances, size_t row_idx) |
| Constructs univariates that interpolate the values of each instance across a given row. | |
| static FF | process_subrelation_evaluations (const RelationEvaluations &evals, const SubrelationSeparators &challenges, FF &linearly_dependent_contribution) |
| Scale all linearly independent subrelations evaluations by challenges ('alphas'). | |
| static std::vector< FF > | construct_coefficients_tree (std::span< const FF > betas, std::span< const FF > deltas, std::vector< FF > ¤t_level_buffer, size_t current_width, size_t current_degree) |
| Non-recursively compute the parent nodes of each level in the tree, starting from the leaves. | |
| static std::vector< FF > | construct_perturbator_coefficients (std::span< const FF > betas, std::span< const FF > deltas, const Polynomial< FF > &full_honk_evaluations) |
| Construct the perturbator polynomial F(X) coefficients in O(n) time using binary tree reduction. | |
| template<size_t skip_count = 0> | |
| static BB_INLINE void | extend_univariates (ExtendedUnivariatesType &extended_univariates, const ProverInstances &instances, const size_t row_idx) |
| Prepare a univariate polynomial for relation execution in one step of the combiner construction. | |
| template<size_t relation_idx = 0> | |
| static BB_INLINE void | accumulate_relation_univariates (TupleOfTuplesOfUnivariates &univariate_accumulators, const ExtendedUnivariatesType &extended_univariates, const UnivariateRelationParameters &relation_parameters, const FF &scaling_factor) |
| Add the value of each relation over univariates to an appropriate accumulator. | |
| template<typename TupleOfTuplesOfUnivariatePossiblyOptimistic > | |
| static TupleOfTuplesOfUnivariatesNoOptimisticSkipping | deoptimize_univariates (const TupleOfTuplesOfUnivariatePossiblyOptimistic &tup) |
| Convert univariates from optimized form to regular. | |
| static ExtendedUnivariateWithRandomization | batch_over_relations (TupleOfTuplesOfUnivariatesNoOptimisticSkipping &univariate_accumulators, const UnivariateSubrelationSeparators &alphas) |
| Given the univariate accumulators and the batching challenges, compute the combiner by batching the subrelations. | |
| static std::pair< typename ProverInstance::FF, std::array< typename ProverInstance::FF, NUM_INSTANCES > > | compute_vanishing_polynomial_and_lagranges (const FF &challenge) |
| Compute the vanishing polynomial \(Z(X) = X * (X - 1)\) and Lagranges \(L_0(X) = 1 - X, L_1(X) = X\) at the challenge. | |
| static Univariate< FF, BATCHED_EXTENDED_LENGTH, NUM_INSTANCES > | compute_combiner_quotient (FF perturbator_evaluation, ExtendedUnivariateWithRandomization combiner) |
| Compute the combiner quotient defined as $K$ polynomial in the paper specialised for only folding two instances at once. | |
| template<typename ExtendedRelationParameters > | |
| static ExtendedRelationParameters | compute_extended_relation_parameters (const ProverInstances &instances) |
| For each parameter, collect the value in each ProverInstance in a univariate and extend for use in the combiner computation. | |
| static UnivariateSubrelationSeparators | compute_and_extend_alphas (const ProverInstances &instances) |
| Combine the relation batching parameters (alphas) from each prover instance into a univariate for the combiner computation. | |
| static size_t | compute_num_threads (const size_t domain_size) |
| Determine number of threads for multithreading of perterbator/combiner operations. | |
Public Attributes | |
| ExecutionTraceUsageTracker | trace_usage_tracker |
Static Public Attributes | |
| static constexpr size_t | EXTENDED_LENGTH = computed_extended_length<Flavor>() |
| static constexpr size_t | BATCHED_EXTENDED_LENGTH = computed_batched_extended_length<Flavor>() |
| static constexpr size_t | NUM_SUBRELATIONS = Flavor::NUM_SUBRELATIONS |
A purely static class (never add state to this!) consisting of functions used by the Protogalaxy prover.
| ProverInstance |
Definition at line 26 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::AllValues = typename Flavor::AllValues |
Definition at line 33 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ExtendedUnivariate = Univariate<FF, EXTENDED_LENGTH> |
Definition at line 47 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ExtendedUnivariates = typename Flavor::template ProverUnivariatesWithOptimisticSkipping<ExtendedUnivariate::LENGTH, SKIP_COUNT> |
Definition at line 72 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ExtendedUnivariatesType = std::conditional_t<Flavor::USE_SHORT_MONOMIALS, ShortUnivariates, ExtendedUnivariates> |
Definition at line 76 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ExtendedUnivariateWithRandomization = Univariate<FF, BATCHED_EXTENDED_LENGTH> |
Definition at line 49 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::FF = typename Flavor::FF |
Definition at line 29 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::Flavor = typename ProverInstance::Flavor |
Definition at line 28 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ProverInstances = std::array<std::shared_ptr<ProverInstance>, NUM_INSTANCES> |
Definition at line 35 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ProverPolynomials = typename Flavor::ProverPolynomials |
Definition at line 31 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::RelationEvaluations = decltype(create_tuple_of_arrays_of_values<typename Flavor::Relations>()) |
Definition at line 83 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::Relations = typename Flavor::Relations |
Definition at line 32 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::RelationUtils = bb::RelationUtils<Flavor> |
Definition at line 30 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::ShortUnivariates = typename Flavor::template ProverUnivariates<NUM_INSTANCES> |
ShortUnivariates is an optimisation to improve the evaluation of Flavor relations when the output is a low-degree monomial.
Each Flavor relation is computed as a degree-Flavor::MAX_TOTAL_RELATION_LENGTH Univariate monomial in the Lagrange basis, however it is more efficient if the input monomials into the relation are not in this form, but are instead left as a degree-1 monomial using the coefficient basis (i.e. P(X) = a0 + a1.X)
When computing relation algebra, it is typically more efficient to use the coefficient basis up to degree-2. If the degree must be extended beyond 2, then the monomials are converted into their higher-degree representation in the Lagrange basis.
Not only is the relation algebra more efficient, but we do not have to perform a basis extension on all the Flavor polynomials each time the Flavor relation algebra is evaluated. Given the sparse representation of our circuits, many relations are skipped each row which means many polynomials can go unused. By skipping the basis extension entirely we avoid this unneccessary work.
Tests indicates that utilizing ShortUnivariates speeds up the benchmark_client_ivc.sh benchmark by 10%
Definition at line 70 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::SubrelationSeparators = typename Flavor::SubrelationSeparators |
Definition at line 34 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::TupleOfTuplesOfUnivariates = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates<NUM_INSTANCES> |
Definition at line 79 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::TupleOfTuplesOfUnivariatesNoOptimisticSkipping = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping<NUM_INSTANCES> |
Definition at line 80 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::UnivariateRelationParameters = bb::RelationParameters<Univariate<FF, EXTENDED_LENGTH, 0, SKIP_COUNT> > |
Definition at line 42 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::UnivariateRelationParametersNoOptimisticSkipping = bb::RelationParameters<Univariate<FF, EXTENDED_LENGTH> > |
Definition at line 41 of file protogalaxy_prover_internal.hpp.
| using bb::ProtogalaxyProverInternal< ProverInstance >::UnivariateSubrelationSeparators = std::array<Univariate<FF, BATCHED_EXTENDED_LENGTH>, NUM_SUBRELATIONS - 1> |
Definition at line 44 of file protogalaxy_prover_internal.hpp.
|
inline |
Definition at line 87 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Add the value of each relation over univariates to an appropriate accumulator.
| TupleOfTuplesOfUnivariates_ | A tuple of univariate accumulators, where the univariates may be optimized to avoid computation on some indices. |
| ExtendedUnivariates_ | T |
| Parameters | relation parameters type |
| relation_idx | The index of the relation |
| univariate_accumulators | |
| extended_univariates | |
| relation_parameters | |
| scaling_factor |
Definition at line 487 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Given the univariate accumulators and the batching challenges, compute the combiner by batching the subrelations.
univariate_accumulators contain the contributions from the entire trace for each folded subrelation. To complete the calculation of the combiner, we have to batch these contributions using the folded batching challenges.
| univariate_accumulators | |
| alphas |
Definition at line 640 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Combine the relation batching parameters (alphas) from each prover instance into a univariate for the combiner computation.
The ProverInstance is made of prover polynomials, relation parameters, and subrelations batching challenges: the alphas. As the alphas are part of the instance, they must be folded. This function arranges the alphas from the instances in a matrix where column i represents the alphas from the i-th instance to be folded and then defines a univariate for each row of the matrix by using the alphas in that row as coefficients. The univariates are extended up to length BATCHED_EXTENDED_LENGTH, which is the max degree of the \(f_i\)'s in the relation calculation.
Definition at line 748 of file protogalaxy_prover_internal.hpp.
|
inline |
Compute the combiner polynomial \(G\) in the Protogalaxy paper.
We have implemented an optimization that (eg in the case where we fold one instance-witness pair at a time) assumes the value G(1) is 0, which is true in the case where the witness to be folded is valid.
| instances | |
| gate_separators | |
| relation_parameters | |
| alphas | |
| univariate_accumulators |
Definition at line 532 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Compute the combiner quotient defined as $K$ polynomial in the paper specialised for only folding two instances at once.
The combiner quotient is defined by the formula \(G(X) = F(\alpha) L_0(X) + Z(X) K(X)\). The polynomial \(Z(X)\) is the vanishing polynomial of the set 0, NUM_INSTANCES-1 = 1. Therefore, we cannot compute the value of \(K(X)\) on these values. We evaluate \(K(X)\) on NUM_INSTANCES = 2, ..., BATCHED_EXTENDED_LENGTH (the length of the combiner) and we return the univariate over this domain.
Definition at line 690 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
For each parameter, collect the value in each ProverInstance in a univariate and extend for use in the combiner computation.
The ProverInstance is made of prover polynomials, relation parameters, and subrelations batching challenges. As the relation parameters are part of the instance, they must be folded. This function arranges the relation parameters from the instances in a matrix where column i represents the relation parameters from the i-th instance to be folded and then defines a univariate for each row of the matrix by using the relation parameters in that row as coefficients. The univariates are extended up to length EXTENDED_LENGTH, which is the max length of a subrelation when the relation parameters are considered as variables.
Definition at line 720 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Determine number of threads for multithreading of perterbator/combiner operations.
Potentially uses fewer threads than are available to avoid distributing very small amounts of work
| domain_size |
Definition at line 769 of file protogalaxy_prover_internal.hpp.
|
inline |
Construct the perturbator polynomial F(X) in coefficient form from the accumulator resulted from a previous round of Protogalaxy.
Definition at line 421 of file protogalaxy_prover_internal.hpp.
|
inline |
Compute the values of the aggregated relation evaluations at each row in the execution trace, representing f_i(ω) in the Protogalaxy paper, given the evaluations of all the prover polynomials and \vec{α} (the batching challenges that help establishing each subrelation is independently valid in Mega Honk relation - this α is same as in the Plonk paper, DO NOT confuse with α in Protogalaxy).
When folding Mega prover instances, one of the relations is linearly dependent. We define such relations as acting on the entire execution trace and hence requiring to be accumulated separately as we iterate over each row. At the end of the function, the linearly dependent contribution is accumulated at index 0 representing the sum f_0(ω) + α_j*g(ω) where f_0 represents the full honk evaluation at row 0, g(ω) is the linearly dependent subrelation and α_j is its corresponding batching challenge.
Definition at line 183 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Compute the vanishing polynomial \(Z(X) = X * (X - 1)\) and Lagranges \(L_0(X) = 1 - X, L_1(X) = X\) at the challenge.
Definition at line 670 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Non-recursively compute the parent nodes of each level in the tree, starting from the leaves.
Inputs:
Output: F(X) = Σᵢ fᵢXⁱ - perturbator polynomial coefficient vector
Level ℓ (General Case): For parent node p ∈ [0, n/2ℓ) with children at 2p and 2p+1:
Pℓ[p](X) = Pℓ₋₁[2p](X) + Pℓ₋₁[2p+1](X) · (βℓ + δℓX)
In Lagrange basis: Pℓ[p][d] = Pℓ₋₁[2p][d] + Pℓ₋₁[2p+1][d] · βℓ for d ∈ [0, ℓ+1] Pℓ[p][d+1] += Pℓ₋₁[2p+1][d] · δℓ for d ∈ [0, ℓ+1]
Note: Pℓ[p] has degree ℓ+1 (requires ℓ+2 coefficients)
At level ℓ with w nodes and stride s = ℓ+2:
Complexity:
Parallelism: n/2ℓ independent tasks per level
This iterative implementation uses flat contiguous buffers that alternate roles as source and destination, enabling efficient parallel initialization and better cache locality.
Definition at line 265 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Construct the perturbator polynomial F(X) coefficients in O(n) time using binary tree reduction.
Inputs:
Output: F(X) = Σᵢ fᵢXⁱ - perturbator polynomial of degree k
Level 0 (Leaves): L₀[i] = eᵢ for i ∈ [0, n)
Level 1 (First Combination): For parent p ∈ [0, n/2) with children at 2p and 2p+1: P₁[p](X) = e₂ₚ + e₂ₚ₊₁ · (β₀ + δ₀X)
Expanding to coefficients: P₁[p][0] = e₂ₚ + e₂ₚ₊₁ · β₀ P₁[p][1] = e₂ₚ₊₁ · δ₀
General Level ℓ ∈ [1, k): For parent p with children from previous level: Pℓ[p](X) = Pℓ₋₁[2p](X) + Pℓ₋₁[2p+1](X) · (βℓ + δℓX)
Final Result: F(X) = Pₖ[0](X) (root node after k levels)
Tree Structure Example (n=8): Level 0: e₀ e₁ e₂ e₃ e₄ e₅ e₆ e₇ (degree 0, 8 nodes) └─┬┘ └─┬┘ └─┬┘ └─┬┘ ↓β₀ ↓β₀ ↓β₀ ↓β₀ Level 1: P₁[0] P₁[1] P₁[2] P₁[3] (degree 1, 4 nodes) └────┬────┘ └────┬────┘ ↓β₁ ↓β₁ Level 2: P₂[0] P₂[1] (degree 2, 2 nodes) └──────┬──────┘ ↓β₂ Level 3: P₃[0] (degree 3, 1 node) ↓ F(X)
Properties:
Zeroth coefficient: F(0) = f₀ equals the target sum
This implementation is non-recursive and uses flat contiguous buffers with alternating roles, enabling efficient parallel initialization and minimizing memory allocations.
Definition at line 390 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Convert univariates from optimized form to regular.
We need to convert before we batch relations, since optimized versions don't have enough information to extend the univariates to maximum length
Definition at line 608 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Prepare a univariate polynomial for relation execution in one step of the combiner construction.
For a fixed prover polynomial index, extract that polynomial from each key in ProverInstances. From each polynomial, extract the value at row_idx. Use these values to create a univariate polynomial, and then extend (i.e., compute additional evaluations at adjacent domain values) as needed.
Definition at line 457 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Scale all linearly independent subrelations evaluations by challenges ('alphas').
Note that this is not done for linearly dependent subrelation, because their evaluation is not computed on a specific row but rather on the entire execution trace.
| evals | The evaluations of all subrelations on some row |
| challenges | The 'alpha' challenges used to batch the subrelations (we use separate challenges rather than a single alpha raised to powers to avoid an unsustainable degree increase in the combiner polynomial) |
| linearly_dependent_contribution | An accumulator for values of the linearly-dependent (i.e., 'whole-trace') subrelations |
Definition at line 146 of file protogalaxy_prover_internal.hpp.
|
inlinestatic |
Constructs univariates that interpolate the values of each instance across a given row.
The returned univariates are over the domain 0, .., EXTENDED_LENGTH - 1.
| skip_count | The number of evaluations to skip in the returned univariates. Used only if not using short monomials. |
| row_idx | A fixed row position in several execution traces |
Definition at line 101 of file protogalaxy_prover_internal.hpp.
|
staticconstexpr |
Definition at line 38 of file protogalaxy_prover_internal.hpp.
|
staticconstexpr |
Definition at line 37 of file protogalaxy_prover_internal.hpp.
|
staticconstexpr |
Definition at line 39 of file protogalaxy_prover_internal.hpp.
| ExecutionTraceUsageTracker bb::ProtogalaxyProverInternal< ProverInstance >::trace_usage_tracker |
Definition at line 85 of file protogalaxy_prover_internal.hpp.