Skip to content

Commit

Permalink
feat: protogalaxy combiner quotient (#3245)
Browse files Browse the repository at this point in the history
This PR implements the computation of combiner quotient ($K$ polynomial
in the paper) together with the necessary updates in various parts of
the codebase:
* In the Barycentric and Univariate classes , we can now provide
evaluations with custom `domain_start` and `domain_end` rather than
assuming the list of evaluations is for points starting from 0 onwards
* In the common functionality shared between Sumcheck and Protogalaxy, I
ensure the version of pow polynomial from PG paper can be used.

Co-authored-by: codygunton <codygunton@gmail.com>
  • Loading branch information
maramihali and codygunton authored Nov 12, 2023
1 parent ede7a47 commit db0f3ab
Show file tree
Hide file tree
Showing 20 changed files with 388 additions and 223 deletions.
2 changes: 1 addition & 1 deletion barretenberg/cpp/src/barretenberg/flavor/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* relationships between these. We aim for a more uniform treatment, to enfore identical and informative naming, and to
* prevent the developer having to think very much about the ordering of protocol entities in disparate places.
*
* Another motivation is iterate on the polynomial manifest of plonk, which is nice in its compatness, but which feels
* Another motivation is iterate on the polynomial manifest of plonk, which is nice in its compactness, but which feels
* needlessly manual and low-level. In the past, this contained even more boolean parameters, making it quite hard to
* parse. A typical construction is to loop over the polynomial manifest by extracting a globally-defined
* "FOO_MANIFEST_SIZE" (the use of "manifest" here is distinct from the manifests in the transcript) to loop
Expand Down
44 changes: 44 additions & 0 deletions barretenberg/cpp/src/barretenberg/honk/proof_system/barycentric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import numpy as np


def get_A_at_z(z, xs):
result = 1
for x in xs:
result *= (z - x)
return result

def get_A_deriv(i, xs):
result = 1
xi = xs[i]
for j in range(len(xs)):
if j != i:
result *= (xi - xs[j])
return result



points = [2,3]
evals = [2, 3]

z = 5

result = get_A_at_z(z, points)
s = 0
for i in range(len(evals)):
s += evals[i] / ((z - points[i])* get_A_deriv(i, points))
result *= s
print(result)

points = [32, 33, 34, 35, 36]
evals = [1,11,111,1111,11111]

z = 2

result = get_A_at_z(z, points)
s = 0
for i in range(len(evals)):
s += evals[i] / ((z - points[i])* get_A_deriv(i, points))
result *= s
print(result)


26 changes: 15 additions & 11 deletions barretenberg/cpp/src/barretenberg/polynomials/barycentric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,25 @@ namespace barretenberg {

/**
* @todo: TODO(https://github.com/AztecProtocol/barretenberg/issues/713) Optimize with lookup tables?
* @tparam domain_end, domain_start specify the given evaluation domain {domain_start,..., domain_end - 1}
* @tparam num_evals the number of evaluations that are computable with specific barycentric extension formula
*/

template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataCompileTime {
template <class Fr, size_t domain_end, size_t num_evals, size_t domain_start = 0> class BarycentricDataCompileTime {
public:
static constexpr size_t domain_size = domain_end - domain_start;
static constexpr size_t big_domain_size = std::max(domain_size, num_evals);

/**
* Static constexpr methods for computing arrays of precomputable data used for barycentric extension and evaluation
*/

// build big_domain, currently the set of x_i in {0, 1, ..., t-1}
// build big_domain, currently the set of x_i in {domain_start, ..., big_domain_end - 1 }
static constexpr std::array<Fr, big_domain_size> construct_big_domain()
{
std::array<Fr, big_domain_size> result;
for (size_t i = 0; i < big_domain_size; ++i) {
result[i] = static_cast<Fr>(i);
result[i] = static_cast<Fr>(i + domain_start);
}
return result;
}
Expand Down Expand Up @@ -109,7 +112,7 @@ template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataC
std::array<Fr, num_evals> result;
for (size_t i = 0; i != num_evals; ++i) {
result[i] = 1;
Fr v_i = i;
Fr v_i = i + domain_start;
for (size_t j = 0; j != domain_size; ++j) {
result[i] *= v_i - big_domain[j];
}
Expand All @@ -124,20 +127,21 @@ template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataC
static constexpr auto full_numerator_values = construct_full_numerator_values(big_domain);
};

template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataRunTime {
template <class Fr, size_t domain_end, size_t num_evals, size_t domain_start = 0> class BarycentricDataRunTime {
public:
static constexpr size_t domain_size = domain_end - domain_start;
static constexpr size_t big_domain_size = std::max(domain_size, num_evals);

/**
* Static constexpr methods for computing arrays of precomputable data used for barycentric extension and evaluation
*/

// build big_domain, currently the set of x_i in {0, 1, ..., t-1}
// build big_domain, currently the set of x_i in {domain_start, ..., big_domain_end - 1 }
static std::array<Fr, big_domain_size> construct_big_domain()
{
std::array<Fr, big_domain_size> result;
for (size_t i = 0; i < big_domain_size; ++i) {
result[i] = static_cast<Fr>(i);
result[i] = static_cast<Fr>(i + domain_start);
}
return result;
}
Expand Down Expand Up @@ -210,7 +214,7 @@ template <class Fr, size_t domain_size, size_t num_evals> class BarycentricDataR
std::array<Fr, num_evals> result;
for (size_t i = 0; i != num_evals; ++i) {
result[i] = 1;
Fr v_i = i;
Fr v_i = i + domain_start;
for (size_t j = 0; j != domain_size; ++j) {
result[i] *= v_i - big_domain[j];
}
Expand Down Expand Up @@ -247,9 +251,9 @@ template <typename T> inline constexpr bool is_field_type_v = is_field_type<T>::
* @tparam domain_size
* @tparam num_evals
*/
template <class Fr, size_t domain_size, size_t num_evals>
template <class Fr, size_t domain_end, size_t num_evals, size_t domain_start = 0>
using BarycentricData = std::conditional_t<is_field_type_v<Fr>,
BarycentricDataCompileTime<Fr, domain_size, num_evals>,
BarycentricDataRunTime<Fr, domain_size, num_evals>>;
BarycentricDataCompileTime<Fr, domain_end, num_evals, domain_start>,
BarycentricDataRunTime<Fr, domain_end, num_evals, domain_start>>;

} // namespace barretenberg
Loading

0 comments on commit db0f3ab

Please sign in to comment.