@@ -103,7 +103,12 @@ namespace nil {
103
103
bits_amount, true );
104
104
}
105
105
106
+ constexpr static std::size_t get_empty_rows_amount (std::size_t bits_amount) {
107
+ return bits_amount / 9 + (bits_amount % 9 != 0 );
108
+ }
109
+
106
110
const bit_composition_mode mode;
111
+ const std::size_t empty_rows_amount = get_empty_rows_amount(this ->bits_amount);
107
112
108
113
struct input_type {
109
114
var input;
@@ -129,6 +134,13 @@ namespace nil {
129
134
output[i] = var (component.W (pos.second ), pos.first , false );
130
135
}
131
136
}
137
+ result_type (const bit_decomposition &component, std::uint32_t start_row_index, bool skip) {
138
+ output.resize (component.bits_amount );
139
+
140
+ for (std::size_t i = 0 ; i < component.bits_amount ; i++) {
141
+ output[i] = var (component.W (i % 9 ), start_row_index + i / 9 , false );
142
+ }
143
+ }
132
144
133
145
std::vector<var> all_vars () const {
134
146
return output;
@@ -167,6 +179,26 @@ namespace nil {
167
179
168
180
check_params (bits_amount, mode);
169
181
};
182
+
183
+ static std::vector<bool > calculate (typename BlueprintFieldType::value_type input,
184
+ std::uint32_t bits_amount, bit_composition_mode mode) {
185
+ auto bit_index = [&mode, &bits_amount](std::size_t i) {
186
+ return mode == bit_composition_mode::MSB ? i : bits_amount - i - 1 ;
187
+ };
188
+ std::vector<bool > bits (bits_amount);
189
+ {
190
+ nil::marshalling::status_type status;
191
+ std::array<bool , BlueprintFieldType::modulus_bits> bytes_all =
192
+ nil::marshalling::pack<nil::marshalling::option::big_endian>(input, status);
193
+ std::copy (bytes_all.end () - bits_amount, bytes_all.end (), bits.begin ());
194
+ assert (status == nil::marshalling::status_type::success);
195
+ }
196
+ std::vector<bool > true_bits (bits_amount);
197
+ for (std::size_t i = 0 ; i < bits_amount; i++) {
198
+ true_bits[i] = bits[bit_index (i)];
199
+ }
200
+ return true_bits;
201
+ }
170
202
};
171
203
172
204
template <typename BlueprintFieldType, typename ArithmetizationParams>
@@ -183,6 +215,7 @@ namespace nil {
183
215
const typename plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>::input_type
184
216
&instance_input,
185
217
const std::uint32_t start_row_index) {
218
+ using component_type = plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>;
186
219
187
220
typename BlueprintFieldType::integral_type input_data =
188
221
typename BlueprintFieldType::integral_type (var_value (assignment, instance_input.input ).data );
@@ -204,6 +237,31 @@ namespace nil {
204
237
component, start_row_index);
205
238
}
206
239
240
+ template <typename BlueprintFieldType, typename ArithmetizationParams>
241
+ typename plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>::result_type
242
+ generate_empty_assignments (
243
+ const plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>
244
+ &component,
245
+ assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
246
+ &assignment,
247
+ const typename plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>::input_type
248
+ &instance_input,
249
+ const std::uint32_t start_row_index) {
250
+ using component_type = plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>;
251
+ using value_type = typename BlueprintFieldType::value_type;
252
+
253
+ value_type input_data = var_value (assignment, instance_input.input );
254
+
255
+ std::vector<bool > bits = component_type::calculate (input_data, component.bits_amount , component.mode );
256
+
257
+ for (std::size_t i = 0 ; i < component.bits_amount ; i++) {
258
+ assignment.witness (component.W (i % 9 ), start_row_index + i / 9 ) = value_type (bits[i] ? 1 : 0 );
259
+ }
260
+
261
+ return typename plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>::result_type (
262
+ component, start_row_index, true );
263
+ }
264
+
207
265
template <typename BlueprintFieldType, typename ArithmetizationParams>
208
266
void generate_copy_constraints (
209
267
const plonk_bit_decomposition<BlueprintFieldType, ArithmetizationParams>
0 commit comments