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

chore: included subrelation witness degrees in the relations relevant to zk-sumcheck #7479

Merged
merged 3 commits into from
Jul 16, 2024
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
42 changes: 32 additions & 10 deletions barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ template <typename FF_> class AuxiliaryRelationImpl {
6, // RAM consistency sub-relation 2
6 // RAM consistency sub-relation 3
};
/**
* @brief For ZK-Flavors: The degrees of subrelations considered as polynomials only in witness polynomials,
* i.e. all selectors and public polynomials are treated as constants.
*
*/
static constexpr std::array<size_t, 6> SUBRELATION_WITNESS_DEGREES{
2, // auxiliary sub-relation;
2, // ROM consistency sub-relation 1: adjacent values match if adjacent indices match and next access is a read
// operation
2, // ROM consistency sub-relation 2: index is monotonously increasing
3, // RAM consistency sub-relation 1: adjacent values match if adjacent indices match and next access is a read
// operation
2, // RAM consistency sub-relation 2: index is monotonously increasing
2 // RAM consistency sub-relation 3: next gate access type is boolean
};

static constexpr std::array<size_t, 6> TOTAL_LENGTH_ADJUSTMENTS{
1, // auxiliary sub-relation
Expand Down Expand Up @@ -96,9 +111,13 @@ template <typename FF_> class AuxiliaryRelationImpl {
const FF& scaling_factor)
{
BB_OP_COUNT_TIME_NAME("Auxiliary::accumulate");
// All subrelations have the same length so we use the same length view for all calculations
using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>;
// declare the accumulator of the maximum length, in non-ZK Flavors, they are of the same length,
// whereas in ZK Flavors, the accumulator corresponding to RAM consistency sub-relation 1 is the longest
using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>;
using View = typename Accumulator::View;
// allows to re-use the values accumulated by accumulators of the sizes smaller or equal to
// the size of Accumulator declared above
using ShortView = typename std::tuple_element_t<0, ContainerOverSubrelations>::View;
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 would be nice to add the related comment from the PR description here

using ParameterView = GetParameterView<Parameters, View>;

const auto& eta = ParameterView(params.eta);
Expand Down Expand Up @@ -260,9 +279,10 @@ template <typename FF_> class AuxiliaryRelationImpl {
auto q_one_by_two_by_aux_by_scaling = q_one_by_two * q_aux_by_scaling;

std::get<1>(accumulators) +=
adjacent_values_match_if_adjacent_indices_match * q_one_by_two_by_aux_by_scaling; // deg 5
std::get<2>(accumulators) += index_is_monotonically_increasing * q_one_by_two_by_aux_by_scaling; // deg 5
auto ROM_consistency_check_identity = memory_record_check * q_one_by_two; // deg 3 or 4
ShortView(adjacent_values_match_if_adjacent_indices_match * q_one_by_two_by_aux_by_scaling); // deg 5
std::get<2>(accumulators) +=
ShortView(index_is_monotonically_increasing * q_one_by_two_by_aux_by_scaling); // deg 5
auto ROM_consistency_check_identity = memory_record_check * q_one_by_two; // deg 3 or 4

/**
* RAM Consistency Check
Expand Down Expand Up @@ -308,10 +328,12 @@ template <typename FF_> class AuxiliaryRelationImpl {
// Putting it all together...
std::get<3>(accumulators) +=
adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation *
q_arith_by_aux_and_scaling; // deg 5 or 6
std::get<4>(accumulators) += index_is_monotonically_increasing * q_arith_by_aux_and_scaling; // deg 4
std::get<5>(accumulators) += next_gate_access_type_is_boolean * q_arith_by_aux_and_scaling; // deg 4 or 6
auto RAM_consistency_check_identity = access_check * (q_arith); // deg 3 or 5
q_arith_by_aux_and_scaling; // deg 5 or 6
std::get<4>(accumulators) += ShortView(index_is_monotonically_increasing * q_arith_by_aux_and_scaling); // deg 4
std::get<5>(accumulators) +=
ShortView(next_gate_access_type_is_boolean * q_arith_by_aux_and_scaling); // deg 4 or 6

auto RAM_consistency_check_identity = access_check * (q_arith); // deg 3 or 5

/**
* RAM Timestamp Consistency Check
Expand Down Expand Up @@ -339,7 +361,7 @@ template <typename FF_> class AuxiliaryRelationImpl {
// (deg 3 or 5) + (deg 4) + (deg 3)
auto auxiliary_identity = memory_identity + non_native_field_identity + limb_accumulator_identity;
auxiliary_identity *= q_aux_by_scaling; // deg 5 or 6
std::get<0>(accumulators) += auxiliary_identity;
std::get<0>(accumulators) += ShortView(auxiliary_identity);
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ template <typename FF_> class DatabusLookupRelationImpl {
LENGTH // log-derivative lookup argument subrelation
};

/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree, which is given by LENGTH - 1 in this case.
*/
static constexpr std::array<size_t, NUM_BUS_COLUMNS * 2> SUBRELATION_WITNESS_DEGREES{
Copy link
Contributor

Choose a reason for hiding this comment

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

please explain here the -1 and in the other places, it really helps the reader in a few months

LENGTH - 1, // inverse polynomial correctness subrelation
LENGTH - 1, // log-derivative lookup argument subrelation
LENGTH - 1, // inverse polynomial correctness subrelation
LENGTH - 1 // log-derivative lookup argument subrelation
};

// The lookup subrelations are "linearly dependent" in the sense that they establish the value of a sum across the
// entire execution trace rather than a per-row identity.
static constexpr std::array<bool, NUM_BUS_COLUMNS* 2> SUBRELATION_LINEARLY_INDEPENDENT = {
Expand Down Expand Up @@ -290,4 +303,4 @@ template <typename FF_> class DatabusLookupRelationImpl {

template <typename FF> using DatabusLookupRelation = Relation<DatabusLookupRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ template <typename FF_> class DeltaRangeConstraintRelationImpl {
6, // range constrain sub-relation 3
6 // range constrain sub-relation 4
};
/**
* @brief For ZK-Flavors: The degrees of subrelations considered as polynomials only in witness polynomials,
* i.e. all selectors and public polynomials are treated as constants.
*
*/
static constexpr std::array<size_t, 4> SUBRELATION_WITNESS_DEGREES{
3, // range constrain sub-relation 1
3, // range constrain sub-relation 2
3, // range constrain sub-relation 3
3 // range constrain sub-relation 4
};

/**
* @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero
Expand Down Expand Up @@ -95,4 +106,4 @@ template <typename FF_> class DeltaRangeConstraintRelationImpl {

template <typename FF> using DeltaRangeConstraintRelation = Relation<DeltaRangeConstraintRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ template <typename FF_> class EccOpQueueRelationImpl {
3, // op-queue-wire vanishes sub-relation 3
3 // op-queue-wire vanishes sub-relation 4
};
/**
* @brief For ZK-Flavors: The degrees of subrelations considered as polynomials only in witness polynomials,
* i.e. all selectors and public polynomials are treated as constants.
*
*/
static constexpr std::array<size_t, 8> SUBRELATION_WITNESS_DEGREES{
1, // wire - op-queue-wire consistency sub-relation 1
1, // wire - op-queue-wire consistency sub-relation 2
1, // wire - op-queue-wire consistency sub-relation 3
1, // wire - op-queue-wire consistency sub-relation 4
1, // op-queue-wire vanishes sub-relation 1
1, // op-queue-wire vanishes sub-relation 2
1, // op-queue-wire vanishes sub-relation 3
1 // op-queue-wire vanishes sub-relation 4
};

template <typename AllEntities> inline static bool skip([[maybe_unused]] const AllEntities& in)
{
Expand Down Expand Up @@ -108,4 +123,4 @@ template <typename FF_> class EccOpQueueRelationImpl {

template <typename FF> using EccOpQueueRelation = Relation<EccOpQueueRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ template <typename FF_> class ECCVMBoolsRelationImpl {
static constexpr std::array<size_t, 19> SUBRELATION_PARTIAL_LENGTHS{
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
};
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1.
*/
static constexpr std::array<size_t, 19> SUBRELATION_WITNESS_DEGREES{
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
};

template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
static void accumulate(ContainerOverSubrelations& accumulator,
Expand All @@ -30,4 +39,4 @@ template <typename FF_> class ECCVMBoolsRelationImpl {

template <typename FF> using ECCVMBoolsRelation = Relation<ECCVMBoolsRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ template <typename FF_> class ECCVMLookupRelationImpl {
LENGTH, // grand product construction sub-relation
LENGTH // left-shiftable polynomial sub-relation
};
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by LENGTH - 1.
*/
static constexpr std::array<size_t, 2> SUBRELATION_WITNESS_DEGREES{
LENGTH - 1, // grand product construction sub-relation
LENGTH - 1 // left-shiftable polynomial sub-relation
};

static constexpr std::array<bool, 2> SUBRELATION_LINEARLY_INDEPENDENT = { true, false };

Expand Down Expand Up @@ -247,4 +257,4 @@ template <typename FF_> class ECCVMLookupRelationImpl {

template <typename FF> using ECCVMLookupRelation = Relation<ECCVMLookupRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ template <typename FF_> class ECCVMMSMRelationImpl {
static constexpr std::array<size_t, 36> SUBRELATION_PARTIAL_LENGTHS{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 };
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1.
*/
static constexpr std::array<size_t, 36> SUBRELATION_WITNESS_DEGREES{ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 };

template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
static void accumulate(ContainerOverSubrelations& accumulator,
Expand All @@ -51,4 +60,4 @@ template <typename FF_> class ECCVMMSMRelationImpl {

template <typename FF> using ECCVMMSMRelation = Relation<ECCVMMSMRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#pragma once
#include "barretenberg/relations/relation_types.hpp"

Expand All @@ -20,6 +21,13 @@ template <typename FF_> class ECCVMPointTableRelationImpl {
using FF = FF_;

static constexpr std::array<size_t, 6> SUBRELATION_PARTIAL_LENGTHS{ 6, 6, 6, 6, 6, 6 };
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1.
*/
static constexpr std::array<size_t, 6> SUBRELATION_WITNESS_DEGREES{ 5, 5, 5, 5, 5, 5 };

template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
static void accumulate(ContainerOverSubrelations& accumulator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ template <typename FF_> class ECCVMSetRelationImpl {
21, // grand product construction sub-relation
21 // left-shiftable polynomial sub-relation
};
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1.
*/
static constexpr std::array<size_t, 2> SUBRELATION_WITNESS_DEGREES{
20, // grand product construction sub-relation
20 // left-shiftable polynomial sub-relation
};

template <typename Accumulator> static Accumulator convert_to_wnaf(const auto& s0, const auto& s1)
{
Expand Down Expand Up @@ -46,4 +56,4 @@ template <typename FF_> class ECCVMSetRelationImpl {

template <typename FF> using ECCVMSetRelation = Relation<ECCVMSetRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ template <typename FF_> class ECCVMTranscriptRelationImpl {
static constexpr std::array<size_t, 25> SUBRELATION_PARTIAL_LENGTHS{
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
};
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1.
*/
static constexpr std::array<size_t, 25> SUBRELATION_WITNESS_DEGREES{
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
};

template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
static void accumulate(ContainerOverSubrelations& accumulator,
Expand All @@ -55,4 +64,4 @@ template <typename FF_> class ECCVMTranscriptRelationImpl {

template <typename FF> using ECCVMTranscriptRelation = Relation<ECCVMTranscriptRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ template <typename FF_> class ECCVMWnafRelationImpl {
static constexpr std::array<size_t, 21> SUBRELATION_PARTIAL_LENGTHS{
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
};
/**
* @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness
polynomials,
* i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not
* exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1.
*/
static constexpr std::array<size_t, 21> SUBRELATION_WITNESS_DEGREES{
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
};

template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
static void accumulate(ContainerOverSubrelations& accumulator,
Expand All @@ -48,4 +57,4 @@ template <typename FF_> class ECCVMWnafRelationImpl {

template <typename FF> using ECCVMWnafRelation = Relation<ECCVMWnafRelationImpl<FF>>;

} // namespace bb
} // namespace bb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ template <typename FF_> class EllipticRelationImpl {
6, // x-coordinate sub-relation
6, // y-coordinate sub-relation
};
/**
* @brief For ZK-Flavors: The degrees of subrelations considered as polynomials only in witness polynomials,
* i.e. all selectors and public polynomials are treated as constants.
*
*/
static constexpr std::array<size_t, 2> SUBRELATION_WITNESS_DEGREES{
3, // x-coordinate sub-relation
3, // y-coordinate sub-relation (because of point doubling)
};

/**
* @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero
Expand Down Expand Up @@ -108,4 +117,4 @@ template <typename FF_> class EllipticRelationImpl {
};

template <typename FF> using EllipticRelation = Relation<EllipticRelationImpl<FF>>;
} // namespace bb
} // namespace bb
Loading
Loading