Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
relation_parameters.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Planned, auditors: [], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
10#include <array>
11
12namespace bb {
13
19template <typename T> struct RelationParameters {
20 using DataType = T;
21 static constexpr int NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR = 4;
22 static constexpr int NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR = 1;
24 static constexpr size_t NUM_MULTILINEAR_BATCHING_CHALLENGES = CHONK_MAX_CLAIMS_PER_KERNEL;
25
26 T eta{ 0 }; // Aux Memory (eta)
27 T eta_two{ 0 }; // Aux Memory (eta²)
28 T eta_three{ 0 }; // Aux Memory (eta³)
29 T rom_logup_gamma{ 0 }; // ROM-LogUp additive offset
30 T beta{ 0 }; // Permutation + Lookup (column batching)
31 T gamma{ 0 }; // Permutation + Lookup
32
33 T public_input_delta{ 0 }; // Permutation
34 T beta_sqr{ 0 };
35 T beta_cube{ 0 };
37
38 // Compute eta powers from a single eta challenge
39 void compute_eta_powers(const T& eta_challenge)
40 {
41 eta = eta_challenge;
42 eta_two = eta * eta;
44 }
45
46 void compute_beta_powers(const T& beta_challenge)
47 {
48 beta = beta_challenge;
49 beta_sqr = beta * beta;
52 }
53
54 // Multilinear batching (γ^0, ..., γ^{num_claims - 1}); entries past the claim count are left untouched so that
55 // a recursive verifier does not spend gates on powers that are never consumed.
56 std::array<T, NUM_MULTILINEAR_BATCHING_CHALLENGES> multilinear_batching_challenges = {};
58
59 void compute_multilinear_batching_challenges(const T& batching_challenge, const size_t num_claims)
60 {
61 BB_ASSERT_LTE(num_claims,
63 "num_claims is larger than the maximum number of claims that can be processed.");
66 for (size_t idx = 1; idx < num_claims; ++idx) {
67 multilinear_batching_challenges[idx] = multilinear_batching_challenges[idx - 1] * batching_challenge;
68 }
69 }
70
71 // `eccvm_set_permutation_delta` is used in the set membership gadget in eccvm/ecc_set_relation.hpp, specifically to
72 // constrain (pc, round, wnaf_slice) to match between the MSM table and the Precomputed table. The number of rows we
73 // add per short scalar `mul` is slightly less in the Precomputed table as in the MSM table, so to get the
74 // permutation argument to work out, when `precompute_select == 0`, we must implicitly _remove_ (0, 0, 0) as a tuple
75 // on the wNAF side. This corresponds to dividing by (γ+t·β⁴)·(γ+β²+t·β⁴)·(γ+2β²+t·β⁴)·(γ+3β²+t·β⁴), where
76 // t = FIRST_TERM_TAG (the domain separation tag for WNAF slice tuples).
77 //
78 // We can remove this by modifying the relation, but this would increase the complexity.
80 std::array<T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR> accumulated_result = { T(0), T(0), T(0), T(0) }; // Translator
81 std::array<T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR + NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR> evaluation_input_x = {
82 T(0), T(0), T(0), T(0), T(0)
83 }; // Translator
86 batching_challenge_v = { { { T(0), T(0), T(0), T(0), T(0) },
87 { T(0), T(0), T(0), T(0), T(0) },
88 { T(0), T(0), T(0), T(0), T(0) },
89 { T(0), T(0), T(0), T(0), T(0) } } };
90
91 // Re-instantiate this struct under a different element type `U` (e.g. `RelationParameters<FF>` ->
92 // `RelationParameters<VectorField>`) by per-field conversion through `U`'s implicit `Field` ctor.
93 // Lives next to the field declarations so adding a new parameter forces updating the conversion in the
94 // same diff, instead of getting silently dropped by a distant consumer.
95 template <typename U> RelationParameters<U> convert_to() const
96 {
98 result.eta = U(eta);
99 result.eta_two = U(eta_two);
100 result.eta_three = U(eta_three);
101 result.rom_logup_gamma = U(rom_logup_gamma);
102 result.beta = U(beta);
103 result.gamma = U(gamma);
104 result.public_input_delta = U(public_input_delta);
105 result.beta_sqr = U(beta_sqr);
106 result.beta_cube = U(beta_cube);
107 result.beta_quartic = U(beta_quartic);
108 result.eccvm_set_permutation_delta = U(eccvm_set_permutation_delta);
109 result.num_multilinear_batching_challenges = num_multilinear_batching_challenges;
110 for (size_t i = 0; i < multilinear_batching_challenges.size(); ++i) {
111 result.multilinear_batching_challenges[i] = U(multilinear_batching_challenges[i]);
112 }
113 for (size_t i = 0; i < accumulated_result.size(); ++i) {
114 result.accumulated_result[i] = U(accumulated_result[i]);
115 }
116 for (size_t i = 0; i < evaluation_input_x.size(); ++i) {
117 result.evaluation_input_x[i] = U(evaluation_input_x[i]);
118 }
119 for (size_t i = 0; i < batching_challenge_v.size(); ++i) {
120 for (size_t j = 0; j < batching_challenge_v[i].size(); ++j) {
121 result.batching_challenge_v[i][j] = U(batching_challenge_v[i][j]);
122 }
123 }
124 return result;
125 }
126
127 // only used for testing
129 {
131 result.compute_eta_powers(T::random_element()); // eta, eta_two = eta², eta_three = eta³
132 result.rom_logup_gamma = T::random_element();
133 result.compute_beta_powers(
134 T::random_element()); // beta, beta_sqr = beta², beta_cube = beta³, beta_quartic = beta⁴
135 result.gamma = T::random_element();
136 result.public_input_delta = T::random_element();
137 auto first_term_tag = result.beta_quartic; // FIRST_TERM_TAG (= 1) * beta_quartic
138 result.eccvm_set_permutation_delta =
139 (result.gamma + first_term_tag) * (result.gamma + result.beta_sqr + first_term_tag) *
140 (result.gamma + result.beta_sqr + result.beta_sqr + first_term_tag) *
141 (result.gamma + result.beta_sqr + result.beta_sqr + result.beta_sqr + first_term_tag);
142 result.accumulated_result = {
143 T::random_element(), T::random_element(), T::random_element(), T::random_element()
144 };
145
146 result.evaluation_input_x = {
147 T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element()
148 };
149 result.batching_challenge_v = {
150 std::array{ T::random_element(),
151 T::random_element(),
152 T::random_element(),
153 T::random_element(),
154 T::random_element() },
155 { T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() },
156 { T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() },
157 { T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() },
158 };
159
160 return result;
161 }
162};
163} // namespace bb
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Container for parameters used by the grand product (permutation, lookup) Honk relations.
std::array< std::array< T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR+NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR >, NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR > batching_challenge_v
static constexpr int NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR
void compute_eta_powers(const T &eta_challenge)
static constexpr int NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR
std::array< T, NUM_MULTILINEAR_BATCHING_CHALLENGES > multilinear_batching_challenges
static constexpr int NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR
static constexpr size_t NUM_MULTILINEAR_BATCHING_CHALLENGES
RelationParameters< U > convert_to() const
void compute_multilinear_batching_challenges(const T &batching_challenge, const size_t num_claims)
static RelationParameters get_random()
std::array< T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR > accumulated_result
std::array< T, NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR+NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR > evaluation_input_x
void compute_beta_powers(const T &beta_challenge)
VectorField result