Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ecc_lookup_short_relation.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
8
12
13namespace bb {
14
24template <typename FF_> class ECCVMLookupShortRelationImpl : public ECCVMLookupRelationImpl<FF_> {
25 public:
26 using FF = FF_;
28
29 template <typename Accumulator, typename AllEntities>
30 static Accumulator compute_inverse_exists(const AllEntities& in)
31 {
32 return Accumulator(compute_inverse_exists_short<Accumulator>(in));
33 }
34
35 template <typename Accumulator, typename AllEntities>
36 static auto compute_inverse_exists_short(const AllEntities& in)
37 {
39 const auto row_has_write = ShortView(in.precompute_select); // length 2
40 const auto row_has_read = ShortView(in.msm_add) + ShortView(in.msm_skew); // length 2
41 const auto write_times_read = row_has_write * row_has_read; // length 3
42 // length-3 term on LHS preserves the a2 coefficient under +.
43 return (-write_times_read) + (row_has_write + row_has_read);
44 }
45
46 template <typename Accumulator, size_t index, typename AllEntities>
47 static Accumulator lookup_read_counts(const AllEntities& in)
48 {
49 return Accumulator(lookup_read_counts_short<Accumulator, index>(in));
50 }
51
52 template <typename Accumulator, size_t index, typename AllEntities>
53 static auto lookup_read_counts_short(const AllEntities& in)
54 {
56 if constexpr (index == 0) {
57 return ShortView(in.lookup_read_counts_0);
58 } else if constexpr (index == 1) {
59 return ShortView(in.lookup_read_counts_1);
60 } else {
61 return ShortView(Accumulator(FF(1)));
62 }
63 }
64
65 template <typename Accumulator, size_t lookup_index, typename AllEntities>
66 static Accumulator get_lookup_term_predicate(const AllEntities& in)
67 {
68 return Accumulator(get_lookup_term_predicate_short<Accumulator, lookup_index>(in));
69 }
70
71 template <typename Accumulator, size_t lookup_index, typename AllEntities>
72 static auto get_lookup_term_predicate_short(const AllEntities& in)
73 {
75 if constexpr (lookup_index == 0) {
76 return ShortView(in.msm_add1);
77 } else if constexpr (lookup_index == 1) {
78 return ShortView(in.msm_add2);
79 } else if constexpr (lookup_index == 2) {
80 return ShortView(in.msm_add3);
81 } else if constexpr (lookup_index == 3) {
82 return ShortView(in.msm_add4);
83 } else {
84 return ShortView(Accumulator(FF(1)));
85 }
86 }
87
88 template <typename Accumulator, size_t table_index, typename AllEntities>
89 static Accumulator get_table_term_predicate(const AllEntities& in)
90 {
91 return Accumulator(get_table_term_predicate_short<Accumulator, table_index>(in));
92 }
93
94 template <typename Accumulator, size_t table_index, typename AllEntities>
95 static auto get_table_term_predicate_short(const AllEntities& in)
96 {
98 if constexpr (table_index == 0 || table_index == 1) {
99 return ShortView(in.precompute_select);
100 } else {
101 return ShortView(Accumulator(FF(1)));
102 }
103 }
104
105 template <typename Accumulator, size_t table_index, typename AllEntities, typename Parameters>
106 static Accumulator compute_table_term(const AllEntities& in, const Parameters& params)
107 {
108 return Accumulator(compute_table_term_short<Accumulator, table_index>(in, params));
109 }
110
111 template <typename Accumulator, size_t table_index, typename AllEntities, typename Parameters>
112 static auto compute_table_term_short(const AllEntities& in, const Parameters& params)
113 {
114 using ShortView = ECCVMShortMonomialView<Accumulator>;
115 static_assert(table_index < Base::NUM_TABLE_TERMS);
116
117 const auto precompute_pc = ShortView(in.precompute_pc);
118 const auto tx = ShortView(in.precompute_tx);
119 const auto ty = ShortView(in.precompute_ty);
120 const auto precompute_round = ShortView(in.precompute_round);
121 const auto& gamma = params.gamma;
122 const auto& beta = params.beta;
123 const auto& beta_sqr = params.beta_sqr;
124 const auto& beta_cube = params.beta_cube;
125
126 if constexpr (table_index == 0) {
127 const auto positive_slice_value = -precompute_round + FF(15);
128 const auto positive_term =
129 ((tx * beta_sqr + ty * beta_cube) + positive_slice_value * beta) + (precompute_pc * FF(1) + gamma);
130 return positive_term;
131 } else if constexpr (table_index == 1) {
132 const auto negative_term =
133 ((tx * beta_sqr - ty * beta_cube) + precompute_round * beta) + (precompute_pc * FF(1) + gamma);
134 return negative_term;
135 } else {
136 return ShortView(Accumulator(FF(1)));
137 }
138 }
139
140 template <typename Accumulator, size_t lookup_index, typename AllEntities, typename Parameters>
141 static Accumulator compute_lookup_term(const AllEntities& in, const Parameters& params)
142 {
143 return Accumulator(compute_lookup_term_short<Accumulator, lookup_index>(in, params));
144 }
145
146 template <typename Accumulator, size_t lookup_index, typename AllEntities, typename Parameters>
147 static auto compute_lookup_term_short(const AllEntities& in, const Parameters& params)
148 {
149 using ShortView = ECCVMShortMonomialView<Accumulator>;
150 static_assert(lookup_index < Base::NUM_LOOKUP_TERMS);
151
152 const auto& gamma = params.gamma;
153 const auto& beta = params.beta;
154 const auto& beta_sqr = params.beta_sqr;
155 const auto& beta_cube = params.beta_cube;
156 const auto msm_pc = ShortView(in.msm_pc);
157 const auto msm_count = ShortView(in.msm_count);
158 const auto current_pc = msm_pc - msm_count;
159
160 if constexpr (lookup_index == 0) {
161 const auto slice = ShortView(in.msm_slice1);
162 const auto x = ShortView(in.msm_x1);
163 const auto y = ShortView(in.msm_y1);
164 const auto term = ((slice * beta + x * beta_sqr) + y * beta_cube) + (current_pc + gamma);
165 return term;
166 } else if constexpr (lookup_index == 1) {
167 const auto slice = ShortView(in.msm_slice2);
168 const auto x = ShortView(in.msm_x2);
169 const auto y = ShortView(in.msm_y2);
170 const auto term = ((slice * beta + x * beta_sqr) + y * beta_cube) + ((current_pc - FF(1)) + gamma);
171 return term;
172 } else if constexpr (lookup_index == 2) {
173 const auto slice = ShortView(in.msm_slice3);
174 const auto x = ShortView(in.msm_x3);
175 const auto y = ShortView(in.msm_y3);
176 const auto term = ((slice * beta + x * beta_sqr) + y * beta_cube) + ((current_pc - FF(2)) + gamma);
177 return term;
178 } else if constexpr (lookup_index == 3) {
179 const auto slice = ShortView(in.msm_slice4);
180 const auto x = ShortView(in.msm_x4);
181 const auto y = ShortView(in.msm_y4);
182 const auto term = ((slice * beta + x * beta_sqr) + y * beta_cube) + ((current_pc - FF(3)) + gamma);
183 return term;
184 } else {
185 return ShortView(Accumulator(FF(1)));
186 }
187 }
188
189 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
190 static void accumulate(ContainerOverSubrelations& accumulator,
191 const AllEntities& in,
192 const Parameters& params,
193 const FF& scaling_factor);
194};
195
197
198} // namespace bb
static constexpr size_t NUM_LOOKUP_TERMS
static constexpr size_t NUM_TABLE_TERMS
Short-monomial variant of ECCVMLookupRelationImpl.
static auto lookup_read_counts_short(const AllEntities &in)
static Accumulator compute_table_term(const AllEntities &in, const Parameters &params)
static auto compute_inverse_exists_short(const AllEntities &in)
static Accumulator compute_inverse_exists(const AllEntities &in)
static auto get_lookup_term_predicate_short(const AllEntities &in)
static Accumulator compute_lookup_term(const AllEntities &in, const Parameters &params)
static Accumulator lookup_read_counts(const AllEntities &in)
static Accumulator get_table_term_predicate(const AllEntities &in)
static auto compute_table_term_short(const AllEntities &in, const Parameters &params)
static Accumulator get_lookup_term_predicate(const AllEntities &in)
static void accumulate(ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters &params, const FF &scaling_factor)
static auto get_table_term_predicate_short(const AllEntities &in)
static auto compute_lookup_term_short(const AllEntities &in, const Parameters &params)
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
C slice(C const &container, size_t start)
Definition container.hpp:9
typename Accumulator::CoefficientAccumulator ECCVMShortMonomialView