Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-constraint Relations #444

Merged
merged 20 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "standard_honk_composer.hpp"
#include "barretenberg/honk/sumcheck/relations/relation.hpp"
#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
#include <cstddef>
#include <cstdint>
#include <vector>
#include "barretenberg/honk/proof_system/prover.hpp"
#include "barretenberg/honk/sumcheck/sumcheck_round.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/permutation_relation.hpp"
#include "barretenberg/polynomials/polynomial.hpp"

#pragma GCC diagnostic ignored "-Wunused-variable"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "ultra_honk_composer.hpp"
#include "barretenberg/common/log.hpp"
#include "barretenberg/honk/proof_system/ultra_prover.hpp"
#include "barretenberg/honk/sumcheck/relations/relation.hpp"
#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp"
#include "barretenberg/numeric/uint256/uint256.hpp"
#include <cstddef>
#include <cstdint>
#include "barretenberg/honk/proof_system/prover.hpp"
#include "barretenberg/honk/sumcheck/sumcheck_round.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/permutation_relation.hpp"
#include "barretenberg/honk/utils/grand_product_delta.hpp"
#include "barretenberg/proof_system/plookup_tables/types.hpp"

Expand Down Expand Up @@ -649,7 +648,6 @@ TEST(UltraHonkComposer, non_native_field_multiplication)

fq a = fq::random_element();
fq b = fq::random_element();

uint256_t modulus = fq::modulus;

uint1024_t a_big = uint512_t(uint256_t(a));
Expand Down
18 changes: 10 additions & 8 deletions cpp/src/barretenberg/honk/flavor/standard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#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/sumcheck/relations/permutation_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 @@ -53,17 +52,20 @@ class Standard {
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>>;
using Relations = std::tuple<sumcheck::ArithmeticRelation<FF>, sumcheck::PermutationRelation<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>());
// Instantiate the BarycentricData needed to extend each Relation Univariate
static_assert(instantiate_barycentric_utils<FF, MAX_RELATION_LENGTH>());

// define the containers for storing the contributions from each relation in Sumcheck
using RelationUnivariates = decltype(create_relation_univariates_container<FF, Relations>());
using RelationValues = decltype(create_relation_values_container<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>());
// using BarycentricUtils = decltype(create_barycentric_utils<FF, Relations, MAX_RELATION_LENGTH>());

private:
/**
Expand Down
21 changes: 9 additions & 12 deletions cpp/src/barretenberg/honk/flavor/ultra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
#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/permutation_relation.hpp"
#include "barretenberg/honk/sumcheck/relations/lookup_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"
Expand Down Expand Up @@ -52,22 +50,21 @@ class Ultra {

// 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::UltraPermutationRelation<FF>,
sumcheck::LookupRelation<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;

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

// 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>());
using RelationUnivariates = decltype(create_relation_univariates_container<FF, Relations>());
using RelationValues = decltype(create_relation_values_container<FF, Relations>());

private:
template <typename DataType, typename HandleType>
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "barretenberg/honk/pcs/kzg/kzg.hpp"
#include "barretenberg/honk/transcript/transcript.hpp"
#include "barretenberg/honk/flavor/ultra.hpp"
#include "barretenberg/honk/sumcheck/relations/relation.hpp"
#include "barretenberg/honk/sumcheck/relations/relation_parameters.hpp"
#include "barretenberg/honk/sumcheck/sumcheck_output.hpp"

namespace proof_system::honk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <tuple>

#include "../polynomials/univariate.hpp"
#include "relation.hpp"
#include "relation_parameters.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a really good change, I was confused about the naming of this file beforehand :)


namespace proof_system::honk::sumcheck {

Expand All @@ -12,6 +12,12 @@ template <typename FF> class ArithmeticRelation {
// 1 + polynomial degree of this relation
static constexpr size_t RELATION_LENGTH = 4;

static constexpr size_t NUM_CONSTRAINTS = 1;
static constexpr std::array<size_t, NUM_CONSTRAINTS> CONSTRAINT_LENGTH = { 4 };

using RelationUnivariates = std::tuple<Univariate<FF, CONSTRAINT_LENGTH[0]>>;
using RelationValues = std::array<FF, NUM_CONSTRAINTS>;

/**
* @brief Expression for the StandardArithmetic gate.
* @details The relation is defined as C(extended_edges(X)...) =
Expand All @@ -22,7 +28,7 @@ template <typename FF> class ArithmeticRelation {
* @param parameters contains beta, gamma, and public_input_delta, ....
* @param scaling_factor optional term to scale the evaluation before adding to evals.
*/
void add_edge_contribution(Univariate<FF, RELATION_LENGTH>& evals,
void add_edge_contribution(RelationUnivariates& evals,
const auto& extended_edges,
const RelationParameters<FF>&,
const FF& scaling_factor) const
Expand All @@ -44,10 +50,17 @@ template <typename FF> class ArithmeticRelation {
tmp += q_o * w_o;
tmp += q_c;
tmp *= scaling_factor;
evals += tmp;
std::get<0>(evals) += tmp;
};

void add_full_relation_value_contribution(FF& full_honk_relation_value,
/**
* @brief Add the result of each identity in this relation evaluated at the multivariate evaluations produced by the
* Sumcheck Prover.
*
* @param full_honk_relation_value
* @param purported_evaluations
*/
void add_full_relation_value_contribution(RelationValues& full_honk_relation_value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's clear what this function is doing but also it would benefit from a bit of documentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call - Added a Doxygen brief to this guy

const auto& purported_evaluations,
const RelationParameters<FF>&) const
{
Expand All @@ -60,10 +73,10 @@ template <typename FF> class ArithmeticRelation {
auto q_o = purported_evaluations.q_o;
auto q_c = purported_evaluations.q_c;

full_honk_relation_value += w_l * (q_m * w_r + q_l);
full_honk_relation_value += q_r * w_r;
full_honk_relation_value += q_o * w_o;
full_honk_relation_value += q_c;
std::get<0>(full_honk_relation_value) += w_l * (q_m * w_r + q_l);
std::get<0>(full_honk_relation_value) += q_r * w_r;
std::get<0>(full_honk_relation_value) += q_o * w_o;
std::get<0>(full_honk_relation_value) += q_c;
};
};
} // namespace proof_system::honk::sumcheck
Loading