Skip to content

Commit

Permalink
specify relations in Flavor
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed May 23, 2023
1 parent d4761c1 commit cf67b5c
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 120 deletions.
14 changes: 14 additions & 0 deletions 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,16 @@ class Standard {
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 4;

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;

using UnivariateTuple = decltype(create_univariate_tuple<FF, Relations, 0>());
using BarycentricUtils = decltype(create_barycentric_utils<FF, Relations, MAX_RELATION_LENGTH, 0>());

private:
/**
* @brief A base class labelling precomputed entities and (ordered) subsets of interest.
Expand Down
25 changes: 25 additions & 0 deletions 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,22 @@ class Ultra {
// The total number of witness entities not including shifts.
static constexpr size_t NUM_WITNESS_ENTITIES = 11;

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;

using UnivariateTuple = decltype(create_univariate_tuple<FF, Relations, 0>());
using BarycentricUtils = decltype(create_barycentric_utils<FF, Relations, MAX_RELATION_LENGTH, 0>());

private:
template <typename DataType, typename HandleType>
/**
Expand Down
9 changes: 1 addition & 8 deletions cpp/src/barretenberg/honk/proof_system/prover.cpp
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
21 changes: 1 addition & 20 deletions cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp
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
20 changes: 1 addition & 19 deletions cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp
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
9 changes: 1 addition & 8 deletions cpp/src/barretenberg/honk/proof_system/verifier.cpp
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsSpecial)

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = Transcript::init_empty();
auto sumcheck = Sumcheck<Flavor, Transcript, ArithmeticRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, Transcript>(multivariate_n, transcript);

FF round_challenge_0 = { 0x6c7301b49d85a46c, 0x44311531e39c64f6, 0xb13d66d8d6c1a24c, 0x04410c360230a295 };
round_challenge_0.self_to_montgomery_form();
Expand Down Expand Up @@ -98,7 +98,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsGeneric)

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = Transcript::init_empty();
auto sumcheck = Sumcheck<Flavor, Transcript, ArithmeticRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, Transcript>(multivariate_n, transcript);

FF round_challenge_0 = FF::random_element();
FF expected_lo = v00 * (FF(1) - round_challenge_0) + v10 * round_challenge_0;
Expand Down Expand Up @@ -159,7 +159,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsSpecial)

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = Transcript::init_empty();
auto sumcheck = Sumcheck<Flavor, Transcript, ArithmeticRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, Transcript>(multivariate_n, transcript);

FF round_challenge_0 = 1;
FF expected_q1 = v000 * (FF(1) - round_challenge_0) + v100 * round_challenge_0; // 2
Expand Down Expand Up @@ -210,7 +210,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGeneric)

auto full_polynomials = std::array<std::span<FF>, 1>({ f0 });
auto transcript = Transcript::init_empty();
auto sumcheck = Sumcheck<Flavor, Transcript, ArithmeticRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, Transcript>(multivariate_n, transcript);

FF round_challenge_0 = FF::random_element();
FF expected_q1 = v000 * (FF(1) - round_challenge_0) + v100 * round_challenge_0;
Expand Down Expand Up @@ -272,7 +272,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGenericMultiplePolys)

auto full_polynomials = std::array<std::span<FF>, 3>{ f0, f1, f2 };
auto transcript = Transcript::init_empty();
auto sumcheck = Sumcheck<Flavor, Transcript, ArithmeticRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, Transcript>(multivariate_n, transcript);

std::array<FF, 3> expected_q1;
std::array<FF, 3> expected_q2;
Expand Down
10 changes: 5 additions & 5 deletions cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

namespace proof_system::honk::sumcheck {

template <typename Flavor, class Transcript, template <class> class... Relations> class Sumcheck {
template <typename Flavor, class Transcript> class Sumcheck {

public:
using FF = typename Flavor::FF;
using FoldedPolynomials = typename Flavor::FoldedPolynomials;
using PurportedEvaluations = typename Flavor::PurportedEvaluations;

static constexpr size_t MAX_RELATION_LENGTH = std::max({ Relations<FF>::RELATION_LENGTH... });
static constexpr size_t MAX_RELATION_LENGTH = Flavor::MAX_RELATION_LENGTH;
static constexpr size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES;

Transcript& transcript;
const size_t multivariate_n;
const size_t multivariate_d;
SumcheckRound<Flavor, Relations...> round;
SumcheckRound<Flavor> round;

/**
*
Expand Down Expand Up @@ -69,7 +69,7 @@ template <typename Flavor, class Transcript, template <class> class... Relations
: transcript(transcript)
, multivariate_n(multivariate_n)
, multivariate_d(numeric::get_msb(multivariate_n))
, round(multivariate_n, std::tuple(Relations<FF>()...))
, round(multivariate_n)
{
for (auto& polynomial : folded_polynomials) {
polynomial.resize(multivariate_n >> 1);
Expand All @@ -81,7 +81,7 @@ template <typename Flavor, class Transcript, template <class> class... Relations
: transcript(transcript)
, multivariate_n(multivariate_n)
, multivariate_d(numeric::get_msb(multivariate_n))
, round(std::tuple(Relations<FF>()...)){};
, round(){};

/**
* @brief Compute univariate restriction place in transcript, generate challenge, fold,... repeat until final round,
Expand Down
36 changes: 6 additions & 30 deletions cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ TEST(Sumcheck, PolynomialNormalization)

auto transcript = ProverTranscript<FF>::init_empty();

auto sumcheck = Sumcheck<Flavor,
ProverTranscript<FF>,
ArithmeticRelation,
GrandProductComputationRelation,
GrandProductInitializationRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, ProverTranscript<FF>>(multivariate_n, transcript);

auto [multivariate_challenge, evaluations] = sumcheck.execute_prover(full_polynomials, {});

Expand Down Expand Up @@ -238,11 +234,7 @@ TEST(Sumcheck, Prover)

auto transcript = ProverTranscript<FF>::init_empty();

auto sumcheck = Sumcheck<Flavor,
ProverTranscript<FF>,
ArithmeticRelation,
GrandProductComputationRelation,
GrandProductInitializationRelation>(multivariate_n, transcript);
auto sumcheck = Sumcheck<Flavor, ProverTranscript<FF>>(multivariate_n, transcript);

auto [multivariate_challenge, evaluations] = sumcheck.execute_prover(full_polynomials, {});
FF u_0 = multivariate_challenge[0];
Expand Down Expand Up @@ -319,21 +311,13 @@ TEST(Sumcheck, ProverAndVerifier)

auto prover_transcript = ProverTranscript<FF>::init_empty();

auto sumcheck_prover = Sumcheck<Flavor,
ProverTranscript<FF>,
ArithmeticRelation,
GrandProductComputationRelation,
GrandProductInitializationRelation>(multivariate_n, prover_transcript);
auto sumcheck_prover = Sumcheck<Flavor, ProverTranscript<FF>>(multivariate_n, prover_transcript);

auto prover_output = sumcheck_prover.execute_prover(full_polynomials, relation_parameters);

auto verifier_transcript = VerifierTranscript<FF>::init_empty(prover_transcript);

auto sumcheck_verifier = Sumcheck<Flavor,
VerifierTranscript<FF>,
ArithmeticRelation,
GrandProductComputationRelation,
GrandProductInitializationRelation>(multivariate_n, verifier_transcript);
auto sumcheck_verifier = Sumcheck<Flavor, VerifierTranscript<FF>>(multivariate_n, verifier_transcript);

std::optional verifier_output = sumcheck_verifier.execute_verifier(relation_parameters);

Expand Down Expand Up @@ -401,21 +385,13 @@ TEST(Sumcheck, ProverAndVerifierLonger)

auto prover_transcript = ProverTranscript<FF>::init_empty();

auto sumcheck_prover = Sumcheck<Flavor,
ProverTranscript<FF>,
ArithmeticRelation,
GrandProductComputationRelation,
GrandProductInitializationRelation>(multivariate_n, prover_transcript);
auto sumcheck_prover = Sumcheck<Flavor, ProverTranscript<FF>>(multivariate_n, prover_transcript);

auto prover_output = sumcheck_prover.execute_prover(full_polynomials, relation_parameters);

auto verifier_transcript = VerifierTranscript<FF>::init_empty(prover_transcript);

auto sumcheck_verifier = Sumcheck<Flavor,
VerifierTranscript<FF>,
ArithmeticRelation,
GrandProductComputationRelation,
GrandProductInitializationRelation>(multivariate_n, verifier_transcript);
auto sumcheck_verifier = Sumcheck<Flavor, VerifierTranscript<FF>>(multivariate_n, verifier_transcript);

std::optional verifier_output = sumcheck_verifier.execute_verifier(relation_parameters);

Expand Down
Loading

0 comments on commit cf67b5c

Please sign in to comment.