Skip to content

Commit

Permalink
feat: Protogalaxy folding of challenges (#2935)
Browse files Browse the repository at this point in the history
We need to fold challenges as well. This means a refactor around how
relation parameters are specified and relation degrees are calculated.

The `RelationParameters` class is now templated on a generic type `T`
that could be a field or could be a `Univariate` class.

We need separate terminology for the length (==degree + 1) of a
polynomial depending on whether we regard the challenges as constants or
variables. I settled on "partial" and "total" since I think "partial
degree" and "total degree" is what you'd expect in math. The way we
calculate the total degree is to add some adjust ment factors. We only
had to add these in three relations (the only three that make use of
relation parameters). NB I focused only on relations for flavors where
we intend to do folding.

If $f$ has length $l_f$ and $g$ has length $l_g$, then $f(g(X))$ has
degree $(l_f-1)\cdot (l_g-1)$, hence its length is $(l_f - 1) \cdot (l_g
- 1) + 1$. We need to calculate these of this form in cases now where
the challenge parameters in $f$ are regarded as variable.

Since I had to refactor the relations, I do some light touching up of
the relations for uniformity. I also move the Goblin Translator
relations into a folder (like we already had for ECCVM) and move some of
the Goblin relations that were contained in other relation files out
into their own files.

I made some comments en route to calculating the total degree of the
auxiliary relation. I leave those in since I think they'll be helpful
later.
  • Loading branch information
codygunton authored Oct 27, 2023
1 parent 524cecf commit 7ed30e8
Show file tree
Hide file tree
Showing 49 changed files with 978 additions and 741 deletions.
5 changes: 3 additions & 2 deletions barretenberg/barretenberg.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
// Clangd. Note that this setting may be overridden by user settings
// to the default value "clangd".
//
"clangd.path": "clangd-15",
"clangd.path": "clangd-16",
// We should disable automatic inclusion of headers unless we decide to follow "WhyIWYU".
"clangd.arguments": [
"-header-insertion=never"
Expand Down Expand Up @@ -156,6 +156,7 @@
"-g"
],
"cmake.useCMakePresets": "auto",
"editor.inlayHints.enabled": "offUnlessPressed"
"editor.inlayHints.enabled": "offUnlessPressed",
"git.detectSubmodules": false
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/proof_system/relations/lookup_relation.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/relation_parameters.hpp"
#include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp"
#include <benchmark/benchmark.h>

Expand Down
15 changes: 8 additions & 7 deletions barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp"
#include "barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp"
#include "barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp"
#include "barretenberg/proof_system/relations/relation_parameters.hpp"
#include "barretenberg/proof_system/relations/relation_types.hpp"
#include <array>
#include <concepts>
Expand Down Expand Up @@ -65,19 +66,19 @@ template <typename CycleGroup_T, typename Curve_T, typename PCS_T> class ECCVMBa
sumcheck::ECCVMLookupRelation<FF>>;

using LookupRelation = sumcheck::ECCVMLookupRelation<FF>;
static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();

// MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random
// polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3
static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1;
// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;

// Instantiate the BarycentricData needed to extend each Relation Univariate
// static_assert(instantiate_barycentric_utils<FF, MAX_RANDOM_RELATION_LENGTH>());

// define the containers for storing the contributions from each relation in Sumcheck
using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values<Relations>());
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());

private:
/**
Expand Down Expand Up @@ -721,7 +722,7 @@ template <typename CycleGroup_T, typename Curve_T, typename PCS_T> class ECCVMBa
/**
* @brief A container for univariates produced during the hot loop in sumcheck.
*/
using ExtendedEdges = ProverUnivariates<MAX_RELATION_LENGTH>;
using ExtendedEdges = ProverUnivariates<MAX_PARTIAL_RELATION_LENGTH>;

/**
* @brief A container for the prover polynomials handles; only stores spans.
Expand Down
27 changes: 15 additions & 12 deletions barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "barretenberg/proof_system/arithmetization/arithmetization.hpp"
#include "barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/proof_system/relations/decomposition_relation.hpp"
#include "barretenberg/proof_system/relations/extra_relations.hpp"
#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/proof_system/relations/non_native_field_relation.hpp"
#include "barretenberg/proof_system/relations/permutation_relation.hpp"
#include "barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp"
#include "barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp"
#include "barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp"
#include "barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp"
#include "barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp"
#include <array>
#include <concepts>
#include <span>
Expand Down Expand Up @@ -316,16 +316,19 @@ template <size_t mini_circuit_size> class GoblinTranslator_ {
GoblinTranslatorDecompositionRelation<FF>,
GoblinTranslatorNonNativeFieldRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length<Relations>();

// MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random
// polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3
static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;
// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t BATCHED_RELATION_TOTAL_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size_v<Relations>;

// define the containers for storing the contributions from each relation in Sumcheck
using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values<Relations>());
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());

private:
template <typename DataType, typename HandleType>
Expand Down Expand Up @@ -1503,7 +1506,7 @@ template <size_t mini_circuit_size> class GoblinTranslator_ {
/**
* @brief A container for univariates produced during the hot loop in sumcheck.
*/
using ExtendedEdges = ProverUnivariates<MAX_RELATION_LENGTH>;
using ExtendedEdges = ProverUnivariates<MAX_PARTIAL_RELATION_LENGTH>;

/**
* @brief A container for commitment labels.
Expand Down
17 changes: 10 additions & 7 deletions barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ class GoblinUltra {
proof_system::AuxiliaryRelation<FF>,
proof_system::EccOpQueueRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length<Relations>();

// MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random
// polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3
static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;
// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t BATCHED_RELATION_TOTAL_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size_v<Relations>;

template <size_t NUM_INSTANCES>
using ProtogalaxyTupleOfTuplesOfUnivariates =
decltype(create_protogalaxy_tuple_of_tuples_of_univariates<Relations, NUM_INSTANCES>());
using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values<Relations>());
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());

// Whether or not the first row of the execution trace is reserved for 0s to enable shifts
static constexpr bool has_zero_row = true;
Expand Down Expand Up @@ -330,7 +333,7 @@ class GoblinUltra {
/**
* @brief A container for univariates produced during the hot loop in sumcheck.
*/
using ExtendedEdges = ProverUnivariates<MAX_RELATION_LENGTH>;
using ExtendedEdges = ProverUnivariates<MAX_PARTIAL_RELATION_LENGTH>;

/**
* @brief A field element for each entity of the flavor. These entities represent the prover polynomials evaluated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ template <typename BuilderType> class GoblinUltraRecursive_ {
proof_system::AuxiliaryRelation<FF>,
proof_system::EccOpQueueRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();

// MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random
// polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3
static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1;
// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;

// define the container for storing the univariate contribution from each relation in Sumcheck
using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values<Relations>());
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());

private:
template <typename DataType, typename HandleType>
Expand Down
24 changes: 14 additions & 10 deletions barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#pragma once
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/pcs/kzg/kzg.hpp"
#include "barretenberg/polynomials/barycentric.hpp"
#include "barretenberg/polynomials/univariate.hpp"

#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/polynomials/barycentric.hpp"
#include "barretenberg/polynomials/evaluation_domain.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/polynomials/univariate.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/proof_system/relations/auxiliary_relation.hpp"
Expand Down Expand Up @@ -53,18 +52,23 @@ class Ultra {
proof_system::EllipticRelation<FF>,
proof_system::AuxiliaryRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();
static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length<Relations>();
static_assert(MAX_PARTIAL_RELATION_LENGTH == 6);
static_assert(MAX_TOTAL_RELATION_LENGTH == 12);

// MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random
// polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3
static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;
// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t BATCHED_RELATION_TOTAL_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size_v<Relations>;

template <size_t NUM_INSTANCES>
using ProtogalaxyTupleOfTuplesOfUnivariates =
decltype(create_protogalaxy_tuple_of_tuples_of_univariates<Relations, NUM_INSTANCES>());
using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values<Relations>());
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());

// Whether or not the first row of the execution trace is reserved for 0s to enable shifts
static constexpr bool has_zero_row = true;
Expand Down Expand Up @@ -327,7 +331,7 @@ class Ultra {
/**
* @brief A container for univariates produced during the hot loop in sumcheck.
*/
using ExtendedEdges = ProverUnivariates<MAX_RELATION_LENGTH>;
using ExtendedEdges = ProverUnivariates<MAX_PARTIAL_RELATION_LENGTH>;

/**
* @brief A container for commitment labels.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ template <typename BuilderType> class UltraRecursive_ {
proof_system::EllipticRelation<FF>,
proof_system::AuxiliaryRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length<Relations>();

// MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random
// polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3
static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1;
// BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta`
// random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation
// length = 3
static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1;
static constexpr size_t NUM_RELATIONS = std::tuple_size<Relations>::value;

// define the container for storing the univariate contribution from each relation in Sumcheck
using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates<Relations>());
using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values<Relations>());
using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values<Relations>());

private:
template <typename DataType, typename HandleType>
Expand Down
10 changes: 8 additions & 2 deletions barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
namespace proof_system::honk {

template <typename Flavor_, size_t NUM_> struct ProverInstances_ {
public:
using Flavor = Flavor_;
using FF = typename Flavor::FF;
static constexpr size_t NUM = NUM_;
using Instance = ProverInstance_<Flavor>;

using ArrayType = std::array<std::shared_ptr<Instance>, NUM_>;
// The extended length here is the length of a composition of polynomials.
static constexpr size_t EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1) * (NUM - 1) + 1;
using RelationParameters = proof_system::RelationParameters<Univariate<FF, EXTENDED_LENGTH>>;

public:
static constexpr size_t NUM = NUM_;
ArrayType _data;
RelationParameters relation_parameters;

std::shared_ptr<Instance> const& operator[](size_t idx) const { return _data[idx]; }
typename ArrayType::iterator begin() { return _data.begin(); };
typename ArrayType::iterator end() { return _data.end(); };
Expand Down
Loading

0 comments on commit 7ed30e8

Please sign in to comment.