Skip to content

Commit

Permalink
resolved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
iakovenkos committed Jul 16, 2024
1 parent 41ccb19 commit dd62c83
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ template <typename FF_> class AuxiliaryRelationImpl {
6 // RAM consistency sub-relation 3
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
* @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{
Expand Down Expand Up @@ -110,9 +111,12 @@ 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
// 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<Parameters, View>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ template <typename FF_> class DatabusLookupRelationImpl {
};

/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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{
LENGTH - 1, // inverse polynomial correctness subrelation
Expand Down Expand Up @@ -90,6 +92,7 @@ template <typename FF_> class DatabusLookupRelationImpl {
static auto& inverses(AllEntities& in) { return in.calldata_inverses; }
static auto& inverses(const AllEntities& in) { return in.calldata_inverses; } // const version
static auto& read_counts(const AllEntities& in) { return in.calldata_read_counts; }
static auto& read_tags(const AllEntities& in) { return in.calldata_read_tags; }
};

// Specialization for return data (bus_idx = 1)
Expand All @@ -99,6 +102,7 @@ template <typename FF_> class DatabusLookupRelationImpl {
static auto& inverses(AllEntities& in) { return in.return_data_inverses; }
static auto& inverses(const AllEntities& in) { return in.return_data_inverses; } // const version
static auto& read_counts(const AllEntities& in) { return in.return_data_read_counts; }
static auto& read_tags(const AllEntities& in) { return in.return_data_read_tags; }
};

/**
Expand All @@ -112,8 +116,8 @@ template <typename FF_> class DatabusLookupRelationImpl {
template <size_t bus_idx, typename AllValues> static bool operation_exists_at_row(const AllValues& row)
{
auto read_selector = get_read_selector<FF, bus_idx>(row);
auto read_counts = BusData<bus_idx, AllValues>::read_counts(row);
return (read_selector == 1 || read_counts > 0);
auto read_tag = BusData<bus_idx, AllValues>::read_tags(row);
return (read_selector == 1 || read_tag == 1);
}

/**
Expand All @@ -128,10 +132,10 @@ template <typename FF_> class DatabusLookupRelationImpl {
{
using View = typename Accumulator::View;

const auto is_read_gate = get_read_selector<Accumulator, bus_idx>(in);
const auto read_counts = View(BusData<bus_idx, AllEntities>::read_counts(in));
const auto is_read_gate = get_read_selector<Accumulator, bus_idx>(in); // is this a read gate
const auto read_tag = View(BusData<bus_idx, AllEntities>::read_tags(in)); // does row contain data being read

return is_read_gate + read_counts - (is_read_gate * read_counts);
return is_read_gate + read_tag - (is_read_gate * read_tag);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ template <typename FF_> class DeltaRangeConstraintRelationImpl {
6 // range constrain sub-relation 4
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
* @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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ template <typename FF_> class EccOpQueueRelationImpl {
3 // op-queue-wire vanishes sub-relation 4
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
* @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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ 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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ template <typename FF_> class ECCVMLookupRelationImpl {
LENGTH // left-shiftable polynomial sub-relation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ template <typename FF_> class ECCVMMSMRelationImpl {
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 Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ template <typename FF_> class ECCVMPointTableRelationImpl {

static constexpr std::array<size_t, 6> SUBRELATION_PARTIAL_LENGTHS{ 6, 6, 6, 6, 6, 6 };
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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 };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ template <typename FF_> class ECCVMSetRelationImpl {
21 // left-shiftable polynomial sub-relation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ template <typename FF_> class ECCVMTranscriptRelationImpl {
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 Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ template <typename FF_> class ECCVMWnafRelationImpl {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ template <typename FF_> class EllipticRelationImpl {
6, // y-coordinate sub-relation
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
* @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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ template <typename FF_> 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<size_t, 2> SUBRELATION_WITNESS_DEGREES{
2, // read_term has witness degree 1, write_term does not carry witness info, inverses has witness degree 1
3, // write_inverse has witness degree 2, read_counts has witness degree 1
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
Expand Down Expand Up @@ -211,8 +215,13 @@ template <typename FF_> class LogDerivLookupRelationImpl {
const FF& scaling_factor)
{
BB_OP_COUNT_TIME_NAME("Lookup::accumulate");
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ template <typename FF_> class UltraPermutationRelationImpl {
};

/**
* @brief Total Degrees of Ultra Permutation Sub-Relations considered as polynomials in witnesses.
* @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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ template <typename FF_> class Poseidon2ExternalRelationImpl {
7, // external poseidon2 round sub-relation for fourth value
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
* @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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ template <typename FF_> class Poseidon2InternalRelationImpl {
7, // internal poseidon2 round sub-relation for fourth value
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
* @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{
6, // external poseidon2 round sub-relation for first value
6, // external poseidon2 round sub-relation for second value
6, // external poseidon2 round sub-relation for third value
6, // external poseidon2 round sub-relation for fourth value
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
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ template <typename FF_> class TranslatorDecompositionRelationImpl {
3 // decomposition of z2 into 2 limbs subrelation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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, 48> SUBRELATION_WITNESS_DEGREES{
2, // decomposition of P.x limb 0 into microlimbs subrelation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ template <typename FF_> class TranslatorDeltaRangeConstraintRelationImpl {

};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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, 10> SUBRELATION_WITNESS_DEGREES{
5, // ordered_range_constraints_0 step in {0,1,2,3} subrelation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ template <typename FF_> class TranslatorOpcodeConstraintRelationImpl {
7 // opcode constraint relation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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, 1> SUBRELATION_WITNESS_DEGREES{
6 // opcode constraint relation
Expand Down Expand Up @@ -64,8 +66,10 @@ template <typename FF_> class TranslatorAccumulatorTransferRelationImpl {

};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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, 12> SUBRELATION_WITNESS_DEGREES{
2, // transfer accumulator limb 0 at even index subrelation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ template <typename FF_> class TranslatorNonNativeFieldRelationImpl {
3 // Prime subrelation (checks result in native field)
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
* @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, 3> SUBRELATION_WITNESS_DEGREES{
2, // Lower wide limb subrelation (checks result is 0 mod 2¹³⁶)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ template <typename FF_> class TranslatorPermutationRelationImpl {
3 // left-shiftable polynomial sub-relation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
* @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{
6, // grand product construction sub-relation
2 // left-shiftable polynomial 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; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ template <typename FF_> class UltraArithmeticRelationImpl {
};

/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
* @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{ 2, 2 };
Expand Down

0 comments on commit dd62c83

Please sign in to comment.