@@ -49,7 +49,13 @@ namespace nil {
49
49
return strstr .str ();
50
50
}
51
51
52
- static inline std::string rot_string (int j, std::string mode){
52
+ static inline std::string rot_string (int j, std::size_t rows_amount, std::string mode){
53
+ int abs_j = j>0 ? j: -j;
54
+ int other_j = rows_amount - abs_j;
55
+ if (other_j < abs_j) {
56
+ j = j > 0 ? -other_j: other_j;
57
+ }
58
+
53
59
if ( mode == " recursive" ){
54
60
if (j == 0 ) return " xi" ; else
55
61
if (j == 1 ) return " xi*omega" ; else
@@ -60,8 +66,8 @@ namespace nil {
60
66
if (j == 0 ) return " xi" ; else
61
67
if (j == 1 ) return " mulmod(xi, omega, modulus)" ; else
62
68
if (j == -1 ) return " mulmod(xi, inversed_omega, modulus)" ; else
63
- if (j > 0 ) return " mulmod(xi,pow_small(omega, " + to_string (j) + " , modulus), modulus)" ; else
64
- if (j < 0 ) return " mulmod(xi,pow_small(omega , " + to_string (-j) + " , modulus), modulus)" ;
69
+ if (j > 0 ) return " mulmod(xi, field. pow_small(omega, " + to_string (j) + " , modulus), modulus)" ; else
70
+ if (j < 0 ) return " mulmod(xi, field. pow_small(inversed_omega , " + to_string (-j) + " , modulus), modulus)" ;
65
71
}
66
72
return " " ;
67
73
}
@@ -104,9 +110,10 @@ namespace nil {
104
110
std::vector<std::string> singles;
105
111
std::map<std::string, std::size_t > singles_map;
106
112
std::vector<std::vector<std::size_t >> poly_ids;
113
+ std::size_t rows_amount = common_data.rows_amount ;
107
114
108
- singles.push_back (rot_string (0 , mode));
109
- singles_map[rot_string (0 , mode)] = singles_map.size ();
115
+ singles.push_back (rot_string (0 , rows_amount, mode));
116
+ singles_map[rot_string (0 , rows_amount, mode)] = singles_map.size ();
110
117
111
118
singles.push_back (" eta" );
112
119
singles_map[" eta" ] = singles_map.size ();
@@ -115,132 +122,144 @@ namespace nil {
115
122
// Sigma and permutation polys
116
123
std::size_t count = 0 ;
117
124
for ( std::size_t i = 0 ; i < permutation_size; i++){
118
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
125
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
119
126
poly_ids[singles_map[" eta" ]].push_back (count);
120
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
127
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
121
128
z_points_indices.push_back (singles_map[" eta" ]);
122
129
poly_ids[singles_map[" eta" ]].push_back (count+1 );
123
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count+1 );
124
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
130
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count+1 );
131
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
125
132
z_points_indices.push_back (singles_map[" eta" ]);
126
133
count += 2 ;
127
134
}
135
+ std::cout << " Permutations are done!" << std::endl;
128
136
129
137
// Special selectors
130
- singles.push_back (rot_string (1 , mode));
131
- singles_map[rot_string (1 , mode)] = singles_map.size ();
138
+ singles.push_back (rot_string (1 , rows_amount, mode));
139
+ singles_map[rot_string (1 , rows_amount, mode)] = singles_map.size ();
132
140
poly_ids.resize (singles.size ());
133
141
134
142
poly_ids[singles_map[" eta" ]].push_back (count);
135
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
136
- poly_ids[singles_map[rot_string (1 , mode)]].push_back (count);
137
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
138
- z_points_indices.push_back (singles_map[rot_string (1 , mode)]);
143
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
144
+ poly_ids[singles_map[rot_string (1 , rows_amount, mode)]].push_back (count);
145
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
146
+ z_points_indices.push_back (singles_map[rot_string (1 , rows_amount, mode)]);
139
147
z_points_indices.push_back (singles_map[" eta" ]);
140
148
count++;
141
149
poly_ids[singles_map[" eta" ]].push_back (count);
142
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
143
- poly_ids[singles_map[rot_string (1 , mode)]].push_back (count);
144
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
145
- z_points_indices.push_back (singles_map[rot_string (1 , mode)]);
150
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
151
+ poly_ids[singles_map[rot_string (1 , rows_amount, mode)]].push_back (count);
152
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
153
+ z_points_indices.push_back (singles_map[rot_string (1 , rows_amount, mode)]);
146
154
z_points_indices.push_back (singles_map[" eta" ]);
147
155
count++;
148
-
156
+ std::cout << " Special selectors are done! " << std::endl;
149
157
150
158
for (std::size_t i = 0 ; i < PlaceholderParams::constant_columns; i++){
151
159
std::stringstream str;
152
160
for (auto j:common_data.columns_rotations [i + PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns]){
153
- if (singles_map.find (rot_string (j, mode)) == singles_map.end ()){
154
- singles_map[rot_string (j, mode)] = singles_map.size ();
155
- singles.push_back (rot_string (j, mode));
161
+ if (singles_map.find (rot_string (j, rows_amount, mode)) == singles_map.end ()){
162
+ singles_map[rot_string (j, rows_amount, mode)] = singles_map.size ();
163
+ singles.push_back (rot_string (j, rows_amount, mode));
156
164
poly_ids.resize (singles.size ());
157
165
}
158
- poly_ids[singles_map[rot_string (j, mode)]].push_back (count);
159
- z_points_indices.push_back (singles_map[rot_string (j, mode)]);
166
+ poly_ids[singles_map[rot_string (j, rows_amount, mode)]].push_back (count);
167
+ z_points_indices.push_back (singles_map[rot_string (j, rows_amount, mode)]);
160
168
}
161
169
poly_ids[singles_map[" eta" ]].push_back (count);
162
170
z_points_indices.push_back (singles_map[" eta" ]);
163
171
count++;
164
172
}
173
+ std::cout << " Constants are done!" << std::endl;
165
174
166
175
for (std::size_t i = 0 ; i < PlaceholderParams::selector_columns; i++){
167
176
std::stringstream str;
168
177
for (auto j:common_data.columns_rotations [i + PlaceholderParams::witness_columns + PlaceholderParams::public_input_columns + PlaceholderParams::constant_columns]){
169
- if (singles_map.find (rot_string (j, mode)) == singles_map.end ()){
170
- singles_map[rot_string (j, mode)] = singles_map.size ();
171
- singles.push_back (rot_string (j, mode));
178
+ if (singles_map.find (rot_string (j, rows_amount, mode)) == singles_map.end ()){
179
+ singles_map[rot_string (j, rows_amount, mode)] = singles_map.size ();
180
+ singles.push_back (rot_string (j, rows_amount, mode));
172
181
poly_ids.resize (singles.size ());
173
182
}
174
- poly_ids[singles_map[rot_string (j, mode)]].push_back (count);
175
- z_points_indices.push_back (singles_map[rot_string (j, mode)]);
183
+ poly_ids[singles_map[rot_string (j, rows_amount, mode)]].push_back (count);
184
+ z_points_indices.push_back (singles_map[rot_string (j, rows_amount, mode)]);
176
185
}
177
186
poly_ids[singles_map[" eta" ]].push_back (count);
178
187
z_points_indices.push_back (singles_map[" eta" ]);
179
188
count++;
180
189
}
190
+ std::cout << " Selectors are done!" << std::endl;
181
191
182
192
for (std::size_t i = 0 ; i < PlaceholderParams::witness_columns; i++){
183
193
std::stringstream str;
184
194
for (auto j:common_data.columns_rotations [i]){
185
- if (singles_map.find (rot_string (j, mode)) == singles_map.end ()){
186
- singles_map[rot_string (j, mode)] = singles_map.size ();
187
- singles.push_back (rot_string (j, mode));
195
+ if (singles_map.find (rot_string (j, rows_amount, mode)) == singles_map.end ()){
196
+ singles_map[rot_string (j, rows_amount, mode)] = singles_map.size ();
197
+ singles.push_back (rot_string (j, rows_amount, mode));
188
198
poly_ids.resize (singles.size ());
189
199
}
190
- poly_ids[singles_map[rot_string (j, mode)]].push_back (count);
191
- z_points_indices.push_back (singles_map[rot_string (j, mode)]);
200
+ poly_ids[singles_map[rot_string (j, rows_amount, mode)]].push_back (count);
201
+ z_points_indices.push_back (singles_map[rot_string (j, rows_amount, mode)]);
192
202
}
193
203
count++;
194
204
}
205
+ std::cout << " Witnesses are done!" << std::endl;
195
206
196
207
for (std::size_t i = 0 ; i < PlaceholderParams::public_input_columns; i++){
197
208
std::stringstream str;
198
209
for (auto j:common_data.columns_rotations [i + PlaceholderParams::witness_columns]){
199
- if (singles_map.find (rot_string (j, mode)) == singles_map.end ()){
200
- singles_map[rot_string (j, mode)] = singles_map.size ();
201
- singles.push_back (rot_string (j, mode));
210
+ if (singles_map.find (rot_string (j, rows_amount, mode)) == singles_map.end ()){
211
+ singles_map[rot_string (j, rows_amount, mode)] = singles_map.size ();
212
+ singles.push_back (rot_string (j, rows_amount, mode));
202
213
poly_ids.resize (singles.size ());
203
214
}
204
- poly_ids[singles_map[rot_string (j, mode)]].push_back (count);
205
- z_points_indices.push_back (singles_map[rot_string (j, mode)]);
215
+ poly_ids[singles_map[rot_string (j, rows_amount, mode)]].push_back (count);
216
+ z_points_indices.push_back (singles_map[rot_string (j, rows_amount, mode)]);
206
217
}
207
218
count++;
208
219
}
220
+ std::cout << " Public inputs are done!" << std::endl;
209
221
210
222
// Permutation argument
211
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
212
- poly_ids[singles_map[rot_string (1 , mode)]].push_back (count);
213
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
214
- z_points_indices.push_back (singles_map[rot_string (1 , mode)]);
223
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
224
+ poly_ids[singles_map[rot_string (1 , rows_amount, mode)]].push_back (count);
225
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
226
+ z_points_indices.push_back (singles_map[rot_string (1 , rows_amount, mode)]);
215
227
count++;
228
+ std::cout << " Permutation polynomials are done!" << std::endl;
216
229
217
230
// Lookup permutation
218
231
if (use_lookups){
219
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
220
- poly_ids[singles_map[rot_string (1 , mode)]].push_back (count);
221
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
222
- z_points_indices.push_back (singles_map[rot_string (1 , mode)]);
232
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
233
+ poly_ids[singles_map[rot_string (1 , rows_amount, mode)]].push_back (count);
234
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
235
+ z_points_indices.push_back (singles_map[rot_string (1 , rows_amount, mode)]);
223
236
count++;
237
+ std::cout << " Lookup permutation polynomials are done!" << std::endl;
224
238
}
225
239
// Quotient
226
240
for (std::size_t i = 0 ; i < quotient_size; i++){
227
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
228
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
241
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
242
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
229
243
count++;
230
244
}
245
+ std::cout << " Quotient polynomials are done!" << std::endl;
231
246
// Lookup batch
232
247
if (use_lookups){
233
- singles_map[rot_string (common_data.usable_rows_amount , mode)] = singles.size ();
234
- singles.push_back (rot_string (common_data.usable_rows_amount , mode));
248
+ if (singles_map.find (rot_string (common_data.usable_rows_amount , rows_amount, mode)) == singles_map.end ()){
249
+ singles_map[rot_string (common_data.usable_rows_amount , rows_amount, mode)] = singles.size ();
250
+ singles.push_back (rot_string (common_data.usable_rows_amount , rows_amount, mode));
251
+ poly_ids.resize (singles.size ());
252
+ }
235
253
for ( std::size_t i = 0 ; i < sorted_size; i++ ){
236
- poly_ids[singles_map[rot_string (0 , mode)]].push_back (count);
237
- z_points_indices.push_back (singles_map[rot_string (0 , mode)]);
238
- poly_ids[singles_map[rot_string (1 , mode)]].push_back (count);
239
- z_points_indices.push_back (singles_map[rot_string (1 , mode)]);
240
- poly_ids[singles_map[rot_string (common_data.usable_rows_amount , mode)]].push_back (count);
241
- z_points_indices.push_back (singles_map[rot_string (common_data.usable_rows_amount , mode)]);
254
+ poly_ids[singles_map[rot_string (0 , rows_amount, mode)]].push_back (count);
255
+ z_points_indices.push_back (singles_map[rot_string (0 , rows_amount, mode)]);
256
+ poly_ids[singles_map[rot_string (1 , rows_amount, mode)]].push_back (count);
257
+ z_points_indices.push_back (singles_map[rot_string (1 , rows_amount, mode)]);
258
+ poly_ids[singles_map[rot_string (common_data.usable_rows_amount , rows_amount, mode)]].push_back (count);
259
+ z_points_indices.push_back (singles_map[rot_string (common_data.usable_rows_amount , rows_amount, mode)]);
242
260
count++;
243
261
}
262
+ std::cout << " Lookup polynomials are done!" << std::endl;
244
263
}
245
264
246
265
return std::make_tuple (z_points_indices, singles, singles_map, poly_ids);
0 commit comments