Skip to content

Commit

Permalink
chore: added subrelation witness degrees to relations relevant to zk-…
Browse files Browse the repository at this point in the history
…sumcheck
  • Loading branch information
iakovenkos committed Jul 15, 2024
1 parent 66d257b commit 41ccb19
Show file tree
Hide file tree
Showing 22 changed files with 323 additions and 42 deletions.
36 changes: 27 additions & 9 deletions barretenberg/cpp/src/barretenberg/relations/auxiliary_relation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ template <typename FF_> class AuxiliaryRelationImpl {
6, // RAM consistency sub-relation 2
6 // RAM consistency sub-relation 3
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 @@ -97,8 +111,9 @@ template <typename FF_> class AuxiliaryRelationImpl {
{
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>;
using Accumulator = typename std::tuple_element_t<3, ContainerOverSubrelations>;
using View = typename Accumulator::View;
using ShortView = typename std::tuple_element_t<0, ContainerOverSubrelations>::View;
using ParameterView = GetParameterView<Parameters, View>;

const auto& eta = ParameterView(params.eta);
Expand Down Expand Up @@ -260,9 +275,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 +324,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 +357,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,17 @@ template <typename FF_> class DatabusLookupRelationImpl {
LENGTH // log-derivative lookup argument subrelation
};

/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
static constexpr std::array<size_t, NUM_BUS_COLUMNS * 2> 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<bool, NUM_BUS_COLUMNS* 2> SUBRELATION_LINEARLY_INDEPENDENT = {
Expand All @@ -79,7 +90,6 @@ 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 @@ -89,7 +99,6 @@ 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 @@ -103,8 +112,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_tag = BusData<bus_idx, AllValues>::read_tags(row);
return (read_selector == 1 || read_tag == 1);
auto read_counts = BusData<bus_idx, AllValues>::read_counts(row);
return (read_selector == 1 || read_counts > 0);
}

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

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
const auto is_read_gate = get_read_selector<Accumulator, bus_idx>(in);
const auto read_counts = View(BusData<bus_idx, AllEntities>::read_counts(in));

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

/**
Expand Down Expand Up @@ -290,4 +299,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,16 @@ template <typename FF_> class DeltaRangeConstraintRelationImpl {
6, // range constrain sub-relation 3
6 // range constrain sub-relation 4
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +105,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,20 @@ template <typename FF_> class EccOpQueueRelationImpl {
3, // op-queue-wire vanishes sub-relation 3
3 // op-queue-wire vanishes sub-relation 4
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +122,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 @@ -21,6 +21,10 @@ template <typename FF_> class ECCVMBoolsRelationImpl {
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
};

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,
const AllEntities& in,
Expand All @@ -30,4 +34,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,14 @@ template <typename FF_> class ECCVMLookupRelationImpl {
LENGTH, // grand product construction sub-relation
LENGTH // left-shiftable polynomial sub-relation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +255,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,13 @@ 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 Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +58,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,11 @@ 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 Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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,14 @@ template <typename FF_> class ECCVMSetRelationImpl {
21, // grand product construction sub-relation
21 // left-shiftable polynomial sub-relation
};
/**
* @brief Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +54,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,13 @@ 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 Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +62,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,13 @@ 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 Upper bound on total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +55,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,14 @@ template <typename FF_> class EllipticRelationImpl {
6, // x-coordinate sub-relation
6, // y-coordinate sub-relation
};
/**
* @brief Total degrees of sub-relations considered as polynomials in witnesses.
*
*/
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 +116,4 @@ template <typename FF_> class EllipticRelationImpl {
};

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

0 comments on commit 41ccb19

Please sign in to comment.