diff --git a/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp index 5f96f232cdd..144fb1a3933 100644 --- a/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp @@ -39,6 +39,21 @@ template 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 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 TOTAL_LENGTH_ADJUSTMENTS{ 1, // auxiliary sub-relation @@ -96,9 +111,13 @@ template 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; using ParameterView = GetParameterView; const auto& eta = ParameterView(params.eta); @@ -260,9 +279,10 @@ template 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 @@ -308,10 +328,12 @@ template 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 @@ -339,7 +361,7 @@ template 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); }; }; diff --git a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp index 4d24c0baf4b..55e9e03c64c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp @@ -57,6 +57,19 @@ template 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 SUBRELATION_WITNESS_DEGREES{ + 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 SUBRELATION_LINEARLY_INDEPENDENT = { @@ -290,4 +303,4 @@ template class DatabusLookupRelationImpl { template using DatabusLookupRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp index b6f3d3e36c4..47883138208 100644 --- a/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp @@ -13,6 +13,17 @@ template 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 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 @@ -95,4 +106,4 @@ template class DeltaRangeConstraintRelationImpl { template using DeltaRangeConstraintRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp index 254057744be..1b716d6c147 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_op_queue_relation.hpp @@ -17,6 +17,21 @@ template 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 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 inline static bool skip([[maybe_unused]] const AllEntities& in) { @@ -108,4 +123,4 @@ template class EccOpQueueRelationImpl { template using EccOpQueueRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_bools_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_bools_relation.hpp index 88d6eef5dc8..95afbf3aca9 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_bools_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_bools_relation.hpp @@ -20,6 +20,15 @@ template class ECCVMBoolsRelationImpl { static constexpr std::array 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 SUBRELATION_WITNESS_DEGREES{ + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + }; template static void accumulate(ContainerOverSubrelations& accumulator, @@ -30,4 +39,4 @@ template class ECCVMBoolsRelationImpl { template using ECCVMBoolsRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp index fd89cbe5819..687d81d2f73 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp @@ -21,6 +21,16 @@ template 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 SUBRELATION_WITNESS_DEGREES{ + LENGTH - 1, // grand product construction sub-relation + LENGTH - 1 // left-shiftable polynomial sub-relation + }; static constexpr std::array SUBRELATION_LINEARLY_INDEPENDENT = { true, false }; @@ -247,4 +257,4 @@ template class ECCVMLookupRelationImpl { template using ECCVMLookupRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp index 51e15f608ed..e7572f4e585 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp @@ -41,6 +41,15 @@ template class ECCVMMSMRelationImpl { static constexpr std::array 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 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 static void accumulate(ContainerOverSubrelations& accumulator, @@ -51,4 +60,4 @@ template class ECCVMMSMRelationImpl { template using ECCVMMSMRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp index 771e54018fd..30b4eb77c84 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp @@ -1,3 +1,4 @@ + #pragma once #include "barretenberg/relations/relation_types.hpp" @@ -20,6 +21,13 @@ template class ECCVMPointTableRelationImpl { using FF = FF_; static constexpr std::array 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 SUBRELATION_WITNESS_DEGREES{ 5, 5, 5, 5, 5, 5 }; template static void accumulate(ContainerOverSubrelations& accumulator, diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp index 2e8393cd661..d958f7a5481 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp @@ -17,6 +17,16 @@ template 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 SUBRELATION_WITNESS_DEGREES{ + 20, // grand product construction sub-relation + 20 // left-shiftable polynomial sub-relation + }; template static Accumulator convert_to_wnaf(const auto& s0, const auto& s1) { @@ -46,4 +56,4 @@ template class ECCVMSetRelationImpl { template using ECCVMSetRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp index 21546026046..f5500649a4f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp @@ -33,6 +33,15 @@ template class ECCVMTranscriptRelationImpl { static constexpr std::array 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 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 static void accumulate(ContainerOverSubrelations& accumulator, @@ -55,4 +64,4 @@ template class ECCVMTranscriptRelationImpl { template using ECCVMTranscriptRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp index 4373d1e7f44..b8a1e3255d5 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp @@ -38,6 +38,15 @@ template class ECCVMWnafRelationImpl { static constexpr std::array 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 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 static void accumulate(ContainerOverSubrelations& accumulator, @@ -48,4 +57,4 @@ template class ECCVMWnafRelationImpl { template using ECCVMWnafRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp index 09ed7dd1d90..9033179a59e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/elliptic_relation.hpp @@ -13,6 +13,15 @@ template 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 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 @@ -108,4 +117,4 @@ template class EllipticRelationImpl { }; template using EllipticRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp index d2cb576b575..7e39ebc7df8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/logderiv_lookup_relation.hpp @@ -22,6 +22,15 @@ template class LogDerivLookupRelationImpl { LENGTH, // inverse construction sub-relation LENGTH // log derivative lookup argument 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 SUBRELATION_WITNESS_DEGREES{ + 2, // inverse construction sub-relation + 3, // log derivative lookup argument sub-relation + }; // TODO(https://github.com/AztecProtocol/barretenberg/issues/1036): Scrutinize these adjustment factors. Counting // degrees suggests the first subrelation should require an adjustment of 2. @@ -128,7 +137,7 @@ template class LogDerivLookupRelationImpl { auto derived_table_entry_2 = w_2 + negative_column_2_step_size * w_2_shift; auto derived_table_entry_3 = w_3 + negative_column_3_step_size * w_3_shift; - // (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η₂(w_3 + q_c*w_3_shift) + η₃q_index. + // (w_1 + \gamma q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η₂(w_3 + q_c*w_3_shift) + η₃q_index. // deg 2 or 3 return derived_table_entry_1 + derived_table_entry_2 * eta + derived_table_entry_3 * eta_two + table_index * eta_three; @@ -206,8 +215,14 @@ template class LogDerivLookupRelationImpl { const FF& scaling_factor) { BB_OP_COUNT_TIME_NAME("Lookup::accumulate"); - 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 log derivative lookup argument sub-relation is the + // longest + using Accumulator = typename std::tuple_element_t<1, ContainerOverSubrelations>; using View = typename Accumulator::View; + // allows to re-use the values accumulated by the accumulator of the size smaller than + // the size of Accumulator declared above + using ShortView = typename std::tuple_element_t<0, ContainerOverSubrelations>::View; const auto inverses = View(in.lookup_inverses); // Degree 1 const auto read_counts = View(in.lookup_read_counts); // Degree 1 @@ -221,7 +236,8 @@ template class LogDerivLookupRelationImpl { // Establish the correctness of the polynomial of inverses I. Note: inverses is computed so that the value is 0 // if !inverse_exists. // Degrees: 2 (3) 1 (2) 1 1 - std::get<0>(accumulator) += (read_term * write_term * inverses - inverse_exists) * scaling_factor; // Deg 4 (6) + std::get<0>(accumulator) += + ShortView((read_term * write_term * inverses - inverse_exists) * scaling_factor); // Deg 4 (6) // Establish validity of the read. Note: no scaling factor here since this constraint is 'linearly dependent, // i.e. enforced across the entire trace, not on a per-row basis. @@ -232,4 +248,4 @@ template class LogDerivLookupRelationImpl { template using LogDerivLookupRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp index b904fabeb95..7f5afc0b384 100644 --- a/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/permutation_relation.hpp @@ -2,7 +2,26 @@ #include "barretenberg/relations/relation_types.hpp" namespace bb { - +/** + * @brief Ultra Permutation Relation + * + * @details The Ultra Permutation Relation is given by the equation + \f{align}{ + \left( Z_{\text{perm}}(\vec X) + L_{0}(\vec X) \right) \cdot + \left[ (w_1(\vec X) + id_1(\vec X) \cdot \beta + \gamma) \cdot (w_2(\vec X) + id_2(\vec X) \cdot \beta + \gamma) + \cdot (w_3(\vec X) + id_3(\vec X) \cdot \beta + \gamma) \cdot (w_4(\vec X) + id_4(\vec X) \cdot \beta + \gamma)\right] + &\ + - \\ + \left(Z_{\text{perm, shifted}}(\vec X) + L_{2^d-1}(\vec X) \cdot \delta_{\text{pub}} \right) \cdot + \left[ (w_1(\vec X) + \sigma_1(\vec X) \cdot \beta + \gamma) \cdot (w_2(\vec X) + \sigma_2(\vec X) \cdot \beta + + \gamma) \cdot (w_3(\vec X) + \sigma_3 (\vec X) \cdot \beta + \gamma) \cdot (w_4 (\vec X) + \sigma_4(\vec X) \cdot \beta + + \gamma)\right] &\ = 0 \f} and \f{align}{ L_{2^d-1}(\vec X)\cdot Z_{\text{perm, shifted}}(\vec X) = 0 \f} + + Here, \f$ \vec X = (X_0,\ldots, X_{d-1})\f$, where \f$ d \f$ is the log of the circuit size. + + + * @tparam FF_ + */ template class UltraPermutationRelationImpl { public: using FF = FF_; @@ -17,6 +36,16 @@ template class UltraPermutationRelationImpl { 0 // left-shiftable polynomial 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 SUBRELATION_WITNESS_DEGREES{ + 5, // grand product construction sub-relation + 1 // left-shiftable polynomial sub-relation + }; + /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * @@ -49,7 +78,7 @@ template class UltraPermutationRelationImpl { const auto& beta = ParameterView(params.beta); const auto& gamma = ParameterView(params.gamma); - // witness degree 4; fully degree 8 + // witness degree 4; full degree 8 return (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * (w_3 + id_3 * beta + gamma) * (w_4 + id_4 * beta + gamma); } @@ -73,7 +102,7 @@ template class UltraPermutationRelationImpl { const auto& beta = ParameterView(params.beta); const auto& gamma = ParameterView(params.gamma); - // witness degree 4; fully degree 8 + // witness degree 4; full degree 8 return (w_1 + sigma_1 * beta + gamma) * (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma) * (w_4 + sigma_4 * beta + gamma); } @@ -81,8 +110,13 @@ template class UltraPermutationRelationImpl { /** * @brief Compute contribution of the permutation relation for a given edge (internal function) * - * @details This the relation confirms faithful calculation of the grand - * product polynomial Z_perm. + * @details This relation confirms faithful calculation of the grand + * product polynomial \f$ Z_{\text{perm}}\f$. + * In Sumcheck Prover Round, this method adds to accumulators evaluations of subrelations at the point + \f$(u_0,\ldots, u_{i-1}, k, \vec\ell)\f$ for \f$ k=0,\ldots, D\f$, where \f$ \vec \ell\f$ is a point on the + Boolean hypercube \f$\{0,1\}^{d-1-i}\f$ and \f$ D \f$ is specified by the calling class. It does so by taking as + input an array of Prover Polynomials partially evaluated at the points \f$(u_0,\ldots, u_{i-1}, k, \vec\ell)\f$ and + computing point-wise evaluations of the sub-relations. \todo Protogalaxy Accumulation * * @param evals transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Univariate edges. @@ -130,4 +164,4 @@ template class UltraPermutationRelationImpl { template using UltraPermutationRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp index a14d633272f..bb75064effa 100644 --- a/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/poseidon2_external_relation.hpp @@ -12,6 +12,17 @@ template class Poseidon2ExternalRelationImpl { 7, // external poseidon2 round sub-relation for third value 7, // external poseidon2 round sub-relation for fourth value }; + /** + * @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 SUBRELATION_WITNESS_DEGREES{ + 5, // external poseidon2 round sub-relation for first value + 5, // external poseidon2 round sub-relation for second value + 5, // external poseidon2 round sub-relation for third value + 5, // external poseidon2 round sub-relation for fourth value + }; /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero @@ -121,4 +132,4 @@ template class Poseidon2ExternalRelationImpl { }; template using Poseidon2ExternalRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp index 77a1f498b92..02dcfaf6192 100644 --- a/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/poseidon2_internal_relation.hpp @@ -14,6 +14,17 @@ template class Poseidon2InternalRelationImpl { 7, // internal poseidon2 round sub-relation for third value 7, // internal poseidon2 round sub-relation for fourth value }; + /** + * @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 SUBRELATION_WITNESS_DEGREES{ + 5, // external poseidon2 round sub-relation for first value + 5, // external poseidon2 round sub-relation for second value + 5, // external poseidon2 round sub-relation for third value + 5, // external poseidon2 round sub-relation for fourth value + }; /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero @@ -102,4 +113,4 @@ template class Poseidon2InternalRelationImpl { }; // namespace bb template using Poseidon2InternalRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp index a5f4956edbc..e97869a8185 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp @@ -61,6 +61,62 @@ template class TranslatorDecompositionRelationImpl { 3, // decomposition of z1 into 2 limbs subrelation 3 // decomposition of z2 into 2 limbs 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 given by SUBRELATION_PARTIAL_LENGTH - 1. + */ + static constexpr std::array SUBRELATION_WITNESS_DEGREES{ + 2, // decomposition of P.x limb 0 into microlimbs subrelation + 2, // decomposition of P.x limb 1 into microlimbs subrelation + 2, // decomposition of P.x limb 2 into microlimbs subrelation + 2, // decomposition of P.x limb 3 into microlimbs subrelation + 2, // decomposition of P.y limb 0 into microlimbs subrelation + 2, // decomposition of P.y limb 1 into microlimbs subrelation + 2, // decomposition of P.y limb 2 into microlimbs subrelation + 2, // decomposition of P.y limb 3 into microlimbs subrelation + 2, // decomposition of z1 limb 0 into microlimbs subrelation + 2, // decomposition of z2 limb 0 into microlimbs subrelation + 2, // decomposition of z1 limb 1 into microlimbs subrelation + 2, // decomposition of z2 limb 1 into microlimbs subrelation + 2, // decomposition of accumulator limb 0 into microlimbs subrelation + 2, // decomposition of accumulator limb 1 into microlimbs subrelation + 2, // decomposition of accumulator limb 2 into microlimbs subrelation + 2, // decomposition of accumulator limb 3 into microlimbs subrelation + 2, // decomposition of quotient limb 0 into microlimbs subrelation + 2, // decomposition of quotient limb 1 into microlimbs subrelation + 2, // decomposition of quotient limb 2 into microlimbs subrelation + 2, // decomposition of quotient limb 3 into microlimbs subrelation + 2, // decomposition of low relation wide limb into microlimbs subrelation + 2, // decomposition of high relation wide limb into microlimbs subrelation + 2, // stricter constraint on highest microlimb of P.x limb 0 subrelation + 2, // stricter constraint on highest microlimb of P.x limb 1 subrelation + 2, // stricter constraint on highest microlimb of P.x limb 2 subrelation + 2, // stricter constraint on highest microlimb of P.x limb 3 subrelation + 2, // stricter constraint on highest microlimb of P.y limb 0 subrelation + 2, // stricter constraint on highest microlimb of P.y limb 1 subrelation + 2, // stricter constraint on highest microlimb of P.y limb 2 subrelation + 2, // stricter constraint on highest microlimb of P.y limb 3 subrelation + 2, // stricter constraint on highest microlimb of z1 limb 0 subrelation + 2, // stricter constraint on highest microlimb of z2 limb 0 subrelation + 2, // stricter constraint on highest microlimb of z1 limb 1 subrelation + 2, // stricter constraint on highest microlimb of z2 limb 1 subrelation + 2, // stricter constraint on highest microlimb of accumulator limb 0 subrelation + 2, // stricter constraint on highest microlimb of accumulator limb 1 subrelation + 2, // stricter constraint on highest microlimb of accumulator limb 2 subrelation + 2, // stricter constraint on highest microlimb of accumulator limb 3 subrelation + 2, // stricter constraint on highest microlimb of quotient limb 0 subrelation + 2, // stricter constraint on highest microlimb of quotient limb 1 subrelation + 2, // stricter constraint on highest microlimb of quotient limb 2 subrelation + 2, // stricter constraint on highest microlimb of quotient limb 3 subrelation + 2, // decomposition of x_lo into 2 limbs subrelation + 2, // decomposition of x_hi into 2 limbs subrelation + 2, // decomposition of y_lo into 2 limbs subrelation + 2, // decomposition of y_hi into 2 limbs subrelation + 2, // decomposition of z1 into 2 limbs subrelation + 2 // decomposition of z2 into 2 limbs subrelation + }; /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_delta_range_constraint_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_delta_range_constraint_relation.hpp index 1515598dc88..498bd835e80 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_delta_range_constraint_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_delta_range_constraint_relation.hpp @@ -23,7 +23,25 @@ template class TranslatorDeltaRangeConstraintRelationImpl { 3 // ordered_range_constraints_4 ends with defined maximum value 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 given by SUBRELATION_PARTIAL_LENGTH - 1. + */ + static constexpr std::array SUBRELATION_WITNESS_DEGREES{ + 5, // ordered_range_constraints_0 step in {0,1,2,3} subrelation + 5, // ordered_range_constraints_1 step in {0,1,2,3} subrelation + 5, // ordered_range_constraints_2 step in {0,1,2,3} subrelation + 5, // ordered_range_constraints_3 step in {0,1,2,3} subrelation + 5, // ordered_range_constraints_4 step in {0,1,2,3} subrelation + 2, // ordered_range_constraints_0 ends with defined maximum value subrelation + 2, // ordered_range_constraints_1 ends with defined maximum value subrelation + 2, // ordered_range_constraints_2 ends with defined maximum value subrelation + 2, // ordered_range_constraints_3 ends with defined maximum value subrelation + 2 // ordered_range_constraints_4 ends with defined maximum value subrelation + }; /** * @brief Expression for the generalized permutation sort relation * diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp index 5e25c0eaf00..dbc80857edd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp @@ -12,7 +12,15 @@ template class TranslatorOpcodeConstraintRelationImpl { static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 7 // opcode constraint 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 SUBRELATION_WITNESS_DEGREES{ + 6 // opcode constraint relation + }; /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * @@ -57,7 +65,27 @@ template class TranslatorAccumulatorTransferRelationImpl { 3 // accumulator limb 3 is equal to given result at the end of accumulation 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 given by SUBRELATION_PARTIAL_LENGTH - 1. + */ + static constexpr std::array SUBRELATION_WITNESS_DEGREES{ + 2, // transfer accumulator limb 0 at even index subrelation + 2, // transfer accumulator limb 1 at even index subrelation + 2, // transfer accumulator limb 2 at even index subrelation + 2, // transfer accumulator limb 3 at even index subrelation + 2, // accumulator limb 0 is zero at the start of accumulation subrelation + 2, // accumulator limb 1 is zero at the start of accumulation subrelation + 2, // accumulator limb 2 is zero at the start of accumulation subrelation + 2, // accumulator limb 3 is zero at the start of accumulation subrelation + 2, // accumulator limb 0 is equal to given result at the end of accumulation subrelation + 2, // accumulator limb 1 is equal to given result at the end of accumulation subrelation + 2, // accumulator limb 2 is equal to given result at the end of accumulation subrelation + 2 // accumulator limb 3 is equal to given result at the end of accumulation subrelation + }; /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp index b94fa346e97..4218c4d4c5e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp @@ -14,7 +14,17 @@ template class TranslatorNonNativeFieldRelationImpl { 3, // Higher wide limb subrelation (checks result is 0 in higher mod 2¹³⁶), 3 // Prime subrelation (checks result in native field) }; - + /** + * @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 SUBRELATION_WITNESS_DEGREES{ + 2, // Lower wide limb subrelation (checks result is 0 mod 2¹³⁶) + 2, // Higher wide limb subrelation (checks result is 0 in higher mod 2¹³⁶), + 2 // Prime subrelation (checks result in native field) + }; /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp index b5b6f276ab5..439c17d247d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp @@ -13,7 +13,15 @@ template class TranslatorPermutationRelationImpl { 7, // grand product construction sub-relation 3 // left-shiftable polynomial 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 SUBRELATION_WITNESS_DEGREES{ + 6, // grand product construction sub-relation + 1 // left-shiftable polynomial sub-relation + }; inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } diff --git a/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp index 55f4a38b211..69dfd2b9d11 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ultra_arithmetic_relation.hpp @@ -12,6 +12,13 @@ template class UltraArithmeticRelationImpl { 5 // secondary arithmetic 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 SUBRELATION_WITNESS_DEGREES{ 2, 2 }; + /** * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero * @@ -121,4 +128,4 @@ template class UltraArithmeticRelationImpl { }; template using UltraArithmeticRelation = Relation>; -} // namespace bb +} // namespace bb \ No newline at end of file