Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
relation_types.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
10#include <algorithm>
11
12template <typename T>
13concept IsField = std::same_as<T, bb::fr> /* || std::same_as<T, grumpkin::fr> */;
14
15namespace bb {
16
27template <typename Params, typename View>
29
30template <typename T>
32 { std::get<0>(T::SUBRELATION_LINEARLY_INDEPENDENT) } -> std::convertible_to<bool>;
33};
34
35template <typename T>
36concept HasParameterLengthAdjustmentsMember = requires { T::TOTAL_LENGTH_ADJUSTMENTS; };
37
46template <typename Relation, size_t subrelation_index> constexpr bool subrelation_is_linearly_independent()
47{
49 return std::get<subrelation_index>(Relation::SUBRELATION_LINEARLY_INDEPENDENT);
50 } else {
51 return true;
52 }
53}
54
59template <typename RelationImpl>
60consteval std::array<size_t, RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size()> compute_total_subrelation_lengths()
61{
63 constexpr size_t NUM_SUBRELATIONS = RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size();
65 for (size_t idx = 0; idx < NUM_SUBRELATIONS; idx++) {
66 result[idx] = RelationImpl::SUBRELATION_PARTIAL_LENGTHS[idx] + RelationImpl::TOTAL_LENGTH_ADJUSTMENTS[idx];
67 }
68 return result;
69 } else {
70 return RelationImpl::SUBRELATION_PARTIAL_LENGTHS;
71 }
72};
73
85template <size_t NUM_KEYS, size_t NUM_SUBRELATIONS>
87 std::array<size_t, NUM_SUBRELATIONS> SUBRELATION_PARTIAL_LENGTHS)
88{
89 std::transform(SUBRELATION_PARTIAL_LENGTHS.begin(),
90 SUBRELATION_PARTIAL_LENGTHS.end(),
91 SUBRELATION_PARTIAL_LENGTHS.begin(),
92 [](const size_t x) { return (x - 1) * (NUM_KEYS - 1) + 1; });
93 return SUBRELATION_PARTIAL_LENGTHS;
94};
95
126template <typename Relation, typename AllEntities>
127concept isSkippable = requires(const AllEntities& input) {
128 { Relation::skip(input) } -> std::same_as<bool>;
129};
130
140template <typename Flavor, typename ProverPolynomialsOrPartiallyEvaluatedMultivariates, typename EdgeType>
142 requires(const ProverPolynomialsOrPartiallyEvaluatedMultivariates& input, const EdgeType edge_idx) {
143 { Flavor::skip_entire_row(input, edge_idx) } -> std::same_as<bool>;
144 };
145
153template <typename RelationImpl> class Relation : public RelationImpl {
154 public:
155 using FF = typename RelationImpl::FF;
156
157 static constexpr std::array<size_t, RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size()> SUBRELATION_TOTAL_LENGTHS =
158 compute_total_subrelation_lengths<RelationImpl>();
159
160 static constexpr size_t RELATION_LENGTH = *std::max_element(RelationImpl::SUBRELATION_PARTIAL_LENGTHS.begin(),
161 RelationImpl::SUBRELATION_PARTIAL_LENGTHS.end());
162
163 static constexpr size_t TOTAL_RELATION_LENGTH =
165
166 template <size_t NUM_KEYS>
169 template <size_t NUM_KEYS>
172 compute_composed_subrelation_partial_lengths<NUM_KEYS>(
174 NUM_KEYS - 1>;
177
179
180 // These are commonly needed, most importantly, for explicitly instantiating
181 // compute_foo_numerator/denomintor.
184};
185} // namespace bb
static bool skip_entire_row(const ProverPolynomialsOrPartiallyEvaluatedMultivariates &polynomials, const EdgeType edge_idx)
When evaluating the sumcheck protocol - can we skip evaluation of all relations for a given row?
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
TupleOfUnivariatesWithOptimisticSkipping< FF, compute_composed_subrelation_partial_lengths< NUM_KEYS >(SUBRELATION_TOTAL_LENGTHS), NUM_KEYS - 1 > ProtogalaxyTupleOfUnivariatesOverSubrelations
static constexpr size_t TOTAL_RELATION_LENGTH
ArrayOfValues< FF, RelationImpl::SUBRELATION_PARTIAL_LENGTHS > SumcheckArrayOfValuesOverSubrelations
TupleOfUnivariates< FF, compute_composed_subrelation_partial_lengths< NUM_KEYS >(SUBRELATION_TOTAL_LENGTHS)> ProtogalaxyTupleOfUnivariatesOverSubrelationsNoOptimisticSkipping
typename RelationImpl::FF FF
static constexpr size_t RELATION_LENGTH
static constexpr std::array< size_t, RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size()> SUBRELATION_TOTAL_LENGTHS
TupleOfUnivariates< FF, RelationImpl::SUBRELATION_PARTIAL_LENGTHS > SumcheckTupleOfUnivariatesOverSubrelations
std::tuple_element_t< 0, SumcheckArrayOfValuesOverSubrelations > ValueAccumulator0
std::tuple_element_t< 0, SumcheckTupleOfUnivariatesOverSubrelations > UnivariateAccumulator0
constexpr size_t NUM_KEYS
Check if the flavor has a static skip method to determine if accumulation of all relations can be ski...
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
Entry point for Barretenberg command-line interface.
std::conditional_t< IsField< typename Params::DataType >, typename Params::DataType, View > GetParameterView
A type to optionally extract a view of a relation parameter in a relation.
typename TupleOfContainersOverArray< bb::Univariate, FF, LENGTHS, 0, SKIP_COUNT >::type TupleOfUnivariatesWithOptimisticSkipping
typename TupleOfContainersOverArray< bb::Univariate, FF, LENGTHS, 0, 0 >::type TupleOfUnivariates
HomogeneousTupleToArray< TupleOfValues< FF, LENGTHS > > ArrayOfValues
consteval std::array< size_t, NUM_SUBRELATIONS > compute_composed_subrelation_partial_lengths(std::array< size_t, NUM_SUBRELATIONS > SUBRELATION_PARTIAL_LENGTHS)
Get the subrelation accumulators for the Protogalaxy combiner calculation.
constexpr bool subrelation_is_linearly_independent()
Check whether a given subrelation is linearly independent from the other subrelations.
consteval std::array< size_t, RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size()> compute_total_subrelation_lengths()
Compute the total subrelation lengths, i.e., the lengths when regarding the challenges as variables.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13