Skip to content

Commit

Permalink
Sumcheck improvements (AztecProtocol/barretenberg#455)
Browse files Browse the repository at this point in the history
* convert partially evaluated polynomials from vectors to Polynomials and rename

* rename fold method to partially_evaluate

* static constexpr barycentric arrays

* change purported evaluations to claimed evaluations

* specify relations in Flavor
  • Loading branch information
ledwards2225 authored May 23, 2023
1 parent 3873f3a commit 1fca69c
Show file tree
Hide file tree
Showing 18 changed files with 301 additions and 254 deletions.
12 changes: 6 additions & 6 deletions barretenberg/cpp/src/barretenberg/honk/flavor/flavor.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TEST(Flavor, StandardGetters)
Flavor::VerificationKey verification_key;
Flavor::ProverPolynomials prover_polynomials;
Flavor::ExtendedEdges<Flavor::NUM_ALL_ENTITIES> edges;
Flavor::PurportedEvaluations evals;
Flavor::ClaimedEvaluations evals;
Flavor::CommitmentLabels commitment_labels;

// Globals are also available through STL container sizes
Expand Down Expand Up @@ -120,11 +120,11 @@ TEST(Flavor, AllEntitiesSpecialMemberFunctions)
{
using Flavor = proof_system::honk::flavor::Standard;
using FF = Flavor::FF;
using FoldedPolynomials = Flavor::FoldedPolynomials;
using PartiallyEvaluatedMultivariates = Flavor::PartiallyEvaluatedMultivariates;
using Polynomial = Polynomial<FF>;

FoldedPolynomials polynomials_A;
std::vector<FF> random_poly{ 10 };
PartiallyEvaluatedMultivariates polynomials_A;
auto random_poly = Polynomial(10);
for (auto& coeff : random_poly) {
coeff = FF::random_element();
}
Expand All @@ -135,10 +135,10 @@ TEST(Flavor, AllEntitiesSpecialMemberFunctions)

ASSERT_EQ(random_poly, polynomials_A.w_l);

FoldedPolynomials polynomials_B(polynomials_A);
PartiallyEvaluatedMultivariates polynomials_B(polynomials_A);
ASSERT_EQ(random_poly, polynomials_B.w_l);

FoldedPolynomials polynomials_C(std::move(polynomials_B));
PartiallyEvaluatedMultivariates polynomials_C(std::move(polynomials_B));
ASSERT_EQ(random_poly, polynomials_C.w_l);
}

Expand Down
37 changes: 32 additions & 5 deletions barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
#include <type_traits>
#include <vector>
#include "barretenberg/honk/pcs/commitment_key.hpp"
#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp"
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp"
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_computation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/plonk/proof_system/proving_key/proving_key.hpp"
#include "barretenberg/polynomials/evaluation_domain.hpp"
Expand Down Expand Up @@ -48,6 +52,19 @@ class Standard {
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 4;

// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<sumcheck::ArithmeticRelation<FF>,
sumcheck::GrandProductComputationRelation<FF>,
sumcheck::GrandProductInitializationRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
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 UnivariateTuple = decltype(create_univariate_tuple<FF, Relations>());
// define utilities to extend univarates from RELATION_LENGTH to MAX_RELATION_LENGTH for each Relation
using BarycentricUtils = decltype(create_barycentric_utils<FF, Relations, MAX_RELATION_LENGTH>());

private:
/**
* @brief A base class labelling precomputed entities and (ordered) subsets of interest.
Expand Down Expand Up @@ -190,10 +207,20 @@ class Standard {
using ProverPolynomials = AllEntities<PolynomialHandle, PolynomialHandle>;

/**
* @brief A container for polynomials produced after the first round of sumcheck.
* @todo TODO(#394) Use polynomial classes for guaranteed memory alignment.
* @brief A container for storing the partially evaluated multivariates produced by sumcheck.
*/
using FoldedPolynomials = AllEntities<std::vector<FF>, PolynomialHandle>;
class PartiallyEvaluatedMultivariates : public AllEntities<Polynomial, PolynomialHandle> {

public:
PartiallyEvaluatedMultivariates() = default;
PartiallyEvaluatedMultivariates(const size_t circuit_size)
{
// Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2)
for (auto& poly : this->_data) {
poly = Polynomial(circuit_size / 2);
}
}
};

/**
* @brief A container for univariates produced during the hot loop in sumcheck.
Expand All @@ -207,11 +234,11 @@ class Standard {
* @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the
* evaluations of polynomials committed in earlier rounds.
*/
class PurportedEvaluations : public AllEntities<FF, FF> {
class ClaimedEvaluations : public AllEntities<FF, FF> {
public:
using Base = AllEntities<FF, FF>;
using Base::Base;
PurportedEvaluations(std::array<FF, NUM_ALL_ENTITIES> _data_in) { this->_data = _data_in; }
ClaimedEvaluations(std::array<FF, NUM_ALL_ENTITIES> _data_in) { this->_data = _data_in; }
};

/**
Expand Down
48 changes: 43 additions & 5 deletions barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <type_traits>
#include <vector>
#include "barretenberg/honk/pcs/commitment_key.hpp"
#include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp"
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp"
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
Expand All @@ -15,6 +16,14 @@
#include "barretenberg/proof_system/circuit_constructors/ultra_circuit_constructor.hpp"
#include "barretenberg/srs/reference_string/reference_string.hpp"
#include "barretenberg/proof_system/flavor/flavor.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation_secondary.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_computation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/lookup_grand_product_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp"

namespace proof_system::honk::flavor {

Expand All @@ -41,6 +50,25 @@ class Ultra {
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 11;

// define the tuple of Relations that comprise the Sumcheck relation
using Relations = std::tuple<sumcheck::UltraArithmeticRelation<FF>,
sumcheck::UltraArithmeticRelationSecondary<FF>,
sumcheck::UltraGrandProductComputationRelation<FF>,
sumcheck::UltraGrandProductInitializationRelation<FF>,
sumcheck::LookupGrandProductComputationRelation<FF>,
sumcheck::LookupGrandProductInitializationRelation<FF>,
sumcheck::GenPermSortRelation<FF>,
sumcheck::EllipticRelation<FF>,
sumcheck::AuxiliaryRelation<FF>>;

static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length<Relations>();
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 UnivariateTuple = decltype(create_univariate_tuple<FF, Relations>());
// define utilities to extend univarates from RELATION_LENGTH to MAX_RELATION_LENGTH for each Relation
using BarycentricUtils = decltype(create_barycentric_utils<FF, Relations, MAX_RELATION_LENGTH>());

private:
template <typename DataType, typename HandleType>
/**
Expand Down Expand Up @@ -249,10 +277,20 @@ class Ultra {
using ProverPolynomials = AllEntities<PolynomialHandle, PolynomialHandle>;

/**
* @brief A container for polynomials produced after the first round of sumcheck.
* @todo TODO(#394) Use polynomial classes for guaranteed memory alignment.
* @brief A container for storing the partially evaluated multivariates produced by sumcheck.
*/
using FoldedPolynomials = AllEntities<std::vector<FF>, PolynomialHandle>;
class PartiallyEvaluatedMultivariates : public AllEntities<Polynomial, PolynomialHandle> {

public:
PartiallyEvaluatedMultivariates() = default;
PartiallyEvaluatedMultivariates(const size_t circuit_size)
{
// Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2)
for (auto& poly : this->_data) {
poly = Polynomial(circuit_size / 2);
}
}
};

/**
* @brief A container for univariates produced during the hot loop in sumcheck.
Expand All @@ -266,11 +304,11 @@ class Ultra {
* @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the
* evaluations of polynomials committed in earlier rounds.
*/
class PurportedEvaluations : public AllEntities<FF, FF> {
class ClaimedEvaluations : public AllEntities<FF, FF> {
public:
using Base = AllEntities<FF, FF>;
using Base::Base;
PurportedEvaluations(std::array<FF, NUM_ALL_ENTITIES> _data_in) { this->_data = _data_in; }
ClaimedEvaluations(std::array<FF, NUM_ALL_ENTITIES> _data_in) { this->_data = _data_in; }
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
#include "barretenberg/honk/sumcheck/sumcheck.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/honk/utils/power_polynomial.hpp"
#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_computation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/flavor/standard.hpp"

namespace proof_system::honk {
Expand Down Expand Up @@ -130,11 +127,7 @@ template <StandardFlavor Flavor> void StandardProver_<Flavor>::execute_grand_pro
* */
template <StandardFlavor Flavor> void StandardProver_<Flavor>::execute_relation_check_rounds()
{
using Sumcheck = sumcheck::Sumcheck<Flavor,
ProverTranscript<FF>,
sumcheck::ArithmeticRelation,
sumcheck::GrandProductComputationRelation,
sumcheck::GrandProductInitializationRelation>;
using Sumcheck = sumcheck::Sumcheck<Flavor, ProverTranscript<FF>>;

auto sumcheck = Sumcheck(key->circuit_size, transcript);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include <algorithm>
#include <cstddef>
#include "barretenberg/honk/proof_system/prover_library.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation_secondary.hpp"
#include "barretenberg/honk/sumcheck/sumcheck.hpp"
#include <array>
#include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" // will go away
Expand All @@ -15,13 +13,6 @@
#include <vector>
#include "barretenberg/ecc/curves/bn254/fr.hpp"
#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_computation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/lookup_grand_product_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/transcript/transcript_wrappers.hpp"
#include <string>
Expand Down Expand Up @@ -191,17 +182,7 @@ template <UltraFlavor Flavor> void UltraProver_<Flavor>::execute_grand_product_c
*/
template <UltraFlavor Flavor> void UltraProver_<Flavor>::execute_relation_check_rounds()
{
using Sumcheck = sumcheck::Sumcheck<Flavor,
ProverTranscript<FF>,
sumcheck::UltraArithmeticRelation,
sumcheck::UltraArithmeticRelationSecondary,
sumcheck::UltraGrandProductComputationRelation,
sumcheck::UltraGrandProductInitializationRelation,
sumcheck::LookupGrandProductComputationRelation,
sumcheck::LookupGrandProductInitializationRelation,
sumcheck::GenPermSortRelation,
sumcheck::EllipticRelation,
sumcheck::AuxiliaryRelation>;
using Sumcheck = sumcheck::Sumcheck<Flavor, ProverTranscript<FF>>;

auto sumcheck = Sumcheck(key->circuit_size, transcript);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
#include "barretenberg/honk/flavor/standard.hpp"
#include "barretenberg/ecc/curves/bn254/scalar_multiplication/scalar_multiplication.hpp"
#include "barretenberg/honk/utils/power_polynomial.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/ultra_arithmetic_relation_secondary.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_computation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/lookup_grand_product_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/gen_perm_sort_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/elliptic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/auxiliary_relation.hpp"

#pragma GCC diagnostic ignored "-Wunused-variable"

Expand Down Expand Up @@ -107,17 +99,7 @@ template <typename Flavor> bool UltraVerifier_<Flavor>::verify_proof(const plonk
commitments.z_lookup = transcript.template receive_from_prover<Commitment>(commitment_labels.z_lookup);

// Execute Sumcheck Verifier
auto sumcheck = Sumcheck<Flavor,
VerifierTranscript<FF>,
honk::sumcheck::UltraArithmeticRelation,
honk::sumcheck::UltraArithmeticRelationSecondary,
honk::sumcheck::UltraGrandProductComputationRelation,
honk::sumcheck::UltraGrandProductInitializationRelation,
honk::sumcheck::LookupGrandProductComputationRelation,
honk::sumcheck::LookupGrandProductInitializationRelation,
honk::sumcheck::GenPermSortRelation,
honk::sumcheck::EllipticRelation,
honk::sumcheck::AuxiliaryRelation>(circuit_size, transcript);
auto sumcheck = Sumcheck<Flavor, VerifierTranscript<FF>>(circuit_size, transcript);

std::optional sumcheck_output = sumcheck.execute_verifier(relation_parameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include "barretenberg/honk/flavor/standard.hpp"
#include "barretenberg/ecc/curves/bn254/scalar_multiplication/scalar_multiplication.hpp"
#include "barretenberg/honk/utils/power_polynomial.hpp"
#include "barretenberg/honk/sumcheck/relations/arithmetic_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_initialization_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/grand_product_computation_relation.hpp"

using namespace barretenberg;
using namespace proof_system::honk::sumcheck;
Expand Down Expand Up @@ -111,11 +108,7 @@ template <typename Flavor> bool StandardVerifier_<Flavor>::verify_proof(const pl
commitments.z_perm = transcript.template receive_from_prover<Commitment>(commitment_labels.z_perm);

// Execute Sumcheck Verifier
auto sumcheck = Sumcheck<Flavor,
VerifierTranscript<FF>,
honk::sumcheck::ArithmeticRelation,
honk::sumcheck::GrandProductComputationRelation,
honk::sumcheck::GrandProductInitializationRelation>(circuit_size, transcript);
auto sumcheck = Sumcheck<Flavor, VerifierTranscript<FF>>(circuit_size, transcript);
std::optional sumcheck_output = sumcheck.execute_verifier(relation_parameters);

// If Sumcheck does not return an output, sumcheck verification has failed
Expand Down
Loading

0 comments on commit 1fca69c

Please sign in to comment.