Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit e98e9f9

Browse files
committed
Add marshalling status checks everywhere #316
1 parent e9dff5d commit e98e9f9

File tree

22 files changed

+106
-64
lines changed

22 files changed

+106
-64
lines changed

libs/blueprint/include/nil/blueprint/components/algebra/curves/pasta/plonk/endo_scalar.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace nil {
220220
std::array<bool, BlueprintFieldType::modulus_bits> bits_msb_all =
221221
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_scalar, status);
222222

223-
assert(status == nil::marshalling::status_type::success);
223+
THROW_IF_ERROR_STATUS(status, "plonk_endo_scalar::generate_assignments");
224224

225225
std::copy(bits_msb_all.end() - component.scalar_size, bits_msb_all.end(), bits_msb.begin());
226226

libs/blueprint/include/nil/blueprint/components/algebra/curves/pasta/plonk/variable_base_endo_scalar_mul_15_wires.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ namespace nil {
177177
nil::marshalling::status_type status;
178178
std::array<bool, 255> bits_all =
179179
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
180+
THROW_IF_ERROR_STATUS(status, "curve_element_variable_base_endo_scalar_mul::generate_assignments");
180181
std::copy(bits_all.end() - 128, bits_all.end(), bits.begin());
181182
}
182183

libs/blueprint/include/nil/blueprint/components/algebra/curves/pasta/plonk/variable_base_scalar_mul.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ namespace nil {
248248
nil::marshalling::status_type status;
249249
std::array<bool, scalar_size> bits =
250250
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
251+
THROW_IF_ERROR_STATUS(status, "curve_element_variable_base_scalar_mul::generate_assignments");
251252

252253
typename BlueprintFieldType::value_type z_n2;
253254
typename BlueprintFieldType::value_type aux;
@@ -267,6 +268,7 @@ namespace nil {
267268
const std::size_t base_size = 255;
268269
std::array<bool, base_size> aux_bits =
269270
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_aux, status);
271+
THROW_IF_ERROR_STATUS(status, "curve_element_variable_base_scalar_mul::generate_assignments");
270272

271273
typename BlueprintFieldType::value_type n = 0;
272274
typename BlueprintFieldType::value_type n_next = 0;

libs/blueprint/include/nil/blueprint/components/algebra/fields/plonk/non_native/bit_decomposition.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ namespace nil {
193193
nil::marshalling::status_type status;
194194
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
195195
nil::marshalling::pack<nil::marshalling::option::big_endian>(input, status);
196+
THROW_IF_ERROR_STATUS(status, "bit_decomposition::calculate");
196197
std::copy(bytes_all.end() - bits_amount, bytes_all.end(), bits.begin());
197-
assert(status == nil::marshalling::status_type::success);
198198
}
199199
std::vector<bool> true_bits(bits_amount);
200200
for (std::size_t i = 0; i < bits_amount; i++) {
@@ -225,8 +225,8 @@ namespace nil {
225225
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
226226
nil::marshalling::pack<nil::marshalling::option::big_endian>(
227227
var_value(assignment, instance_input.input), status);
228+
THROW_IF_ERROR_STATUS(status, "bit_decomposition::generate_assignments");
228229
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(), input_bits.begin());
229-
assert(status == nil::marshalling::status_type::success);
230230
}
231231
// calling bit_builder_component's generate_assignments
232232
generate_assignments<BlueprintFieldType>(
@@ -324,4 +324,4 @@ namespace nil {
324324
} // namespace blueprint
325325
} // namespace nil
326326

327-
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_VARIABLE_BASE_MULTIPLICATION_EDWARD25519_HPP
327+
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_VARIABLE_BASE_MULTIPLICATION_EDWARD25519_HPP

libs/blueprint/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_checked.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ namespace nil {
497497
nil::marshalling::status_type status;
498498
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
499499
nil::marshalling::pack<nil::marshalling::option::big_endian>(integrals[i], status);
500+
THROW_IF_ERROR_STATUS(status, "comparison_checked::generate_assignments");
500501
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(),
501502
bits[i].begin() + component.padding_bits);
502-
assert(status == nil::marshalling::status_type::success);
503503
}
504504

505505
std::array<std::vector<chunk_type>, 2> chunks;

libs/blueprint/include/nil/blueprint/components/algebra/fields/plonk/non_native/comparison_flag.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,10 @@ namespace nil {
314314
nil::marshalling::status_type status;
315315
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
316316
nil::marshalling::pack<nil::marshalling::option::big_endian>(integrals[i], status);
317+
THROW_IF_ERROR_STATUS(status, "comparison_flag::calculate");
318+
317319
std::copy(bytes_all.end() - arg_bits_amount, bytes_all.end(),
318320
bits[i].begin() + padding_bits);
319-
assert(status == nil::marshalling::status_type::success);
320321
}
321322

322323
BOOST_ASSERT(padded_chunks * chunk_size ==
@@ -470,9 +471,9 @@ namespace nil {
470471
nil::marshalling::status_type status;
471472
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
472473
nil::marshalling::pack<nil::marshalling::option::big_endian>(integrals[i], status);
474+
THROW_IF_ERROR_STATUS(status, "comparison_flag::generate_assignments");
473475
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(),
474476
bits[i].begin() + component.padding_bits);
475-
assert(status == nil::marshalling::status_type::success);
476477
}
477478

478479
BOOST_ASSERT(component.padded_chunks * component.chunk_size ==

libs/blueprint/include/nil/blueprint/components/algebra/fields/plonk/range_check.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ namespace nil {
267267
nil::marshalling::status_type status;
268268
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
269269
nil::marshalling::pack<nil::marshalling::option::big_endian>(x_integral, status);
270+
THROW_IF_ERROR_STATUS(status, "range_check::generate_assignments");
270271
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(),
271272
bits.begin() + component.padding_bits);
272-
assert(status == nil::marshalling::status_type::success);
273273
}
274274

275275
BOOST_ASSERT(component.chunk_size <= 8);
@@ -404,4 +404,4 @@ namespace nil {
404404
} // namespace blueprint
405405
} // namespace nil
406406

407-
#endif // CRYPTO3_ZK_BLUEPRINT_PLONK_FIELD_RANGE_CHECK_HPP
407+
#endif // CRYPTO3_ZK_BLUEPRINT_PLONK_FIELD_RANGE_CHECK_HPP

libs/blueprint/include/nil/blueprint/components/hashes/sha2/plonk/sha256_process.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,17 @@ namespace nil {
205205
typename BlueprintFieldType::value_type g = input_state[6];
206206
typename BlueprintFieldType::value_type h = input_state[7];
207207

208+
nil::marshalling::status_type status;
208209
std::array<typename BlueprintFieldType::integral_type, 8> sparse_values {};
209210
for (std::size_t i = 0; i < 4; i++) {
210211
typename BlueprintFieldType::integral_type integral_input_state_sparse =
211212
typename BlueprintFieldType::integral_type(input_state[i].data);
212213
std::vector<bool> input_state_sparse(32);
213214
{
214-
nil::marshalling::status_type status;
215215
std::vector<bool> input_state_sparse_all =
216216
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
217217
status);
218+
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
218219
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
219220
input_state_sparse.begin());
220221
}
@@ -230,10 +231,10 @@ namespace nil {
230231
typename BlueprintFieldType::integral_type(input_state[i].data);
231232
std::vector<bool> input_state_sparse(32);
232233
{
233-
nil::marshalling::status_type status;
234234
std::vector<bool> input_state_sparse_all =
235235
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
236236
status);
237+
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
237238
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
238239
input_state_sparse.begin());
239240
}
@@ -254,9 +255,9 @@ namespace nil {
254255
typename BlueprintFieldType::integral_type(message_scheduling_words[(i - row) / 5 + 1].data);
255256
std::vector<bool> a(32);
256257
{
257-
nil::marshalling::status_type status;
258258
std::vector<bool> a_all =
259259
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
260+
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
260261
std::copy(a_all.end() - 32, a_all.end(), a.begin());
261262
}
262263

@@ -276,9 +277,9 @@ namespace nil {
276277
typename BlueprintFieldType::integral_type(message_scheduling_words[(i - row) / 5 + 14].data);
277278
std::vector<bool> b(32);
278279
{
279-
nil::marshalling::status_type status;
280280
std::vector<bool> b_all =
281281
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
282+
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
282283
std::copy(b_all.end() - 32, b_all.end(), b.begin());
283284
}
284285

@@ -313,9 +314,9 @@ namespace nil {
313314
typename BlueprintFieldType::integral_type(e.data);
314315
std::vector<bool> e_bits(32);
315316
{
316-
nil::marshalling::status_type status;
317317
std::vector<bool> e_bits_all =
318318
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_e, status);
319+
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
319320
std::copy(e_bits_all.end() - 32, e_bits_all.end(), e_bits.begin());
320321
}
321322

@@ -370,9 +371,9 @@ namespace nil {
370371
typename BlueprintFieldType::integral_type(a.data);
371372
std::vector<bool> a_bits(32);
372373
{
373-
nil::marshalling::status_type status;
374374
std::vector<bool> a_bits_all =
375375
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
376+
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
376377
std::copy(a_bits_all.end() - 32, a_bits_all.end(), a_bits.begin());
377378
}
378379

@@ -1386,17 +1387,18 @@ namespace nil {
13861387
typename BlueprintFieldType::value_type g = input_state[6];
13871388
typename BlueprintFieldType::value_type h = input_state[7];
13881389

1390+
nil::marshalling::status_type status;
13891391
std::array<typename BlueprintFieldType::integral_type, 8> sparse_values {};
13901392
for (std::size_t i = 0; i < 4; i++) {
13911393
assignment.witness(component.W(i), row) = input_state[i];
13921394
typename BlueprintFieldType::integral_type integral_input_state_sparse =
13931395
typename BlueprintFieldType::integral_type(input_state[i].data);
13941396
std::vector<bool> input_state_sparse(32);
13951397
{
1396-
nil::marshalling::status_type status;
13971398
std::vector<bool> input_state_sparse_all =
13981399
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
13991400
status);
1401+
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
14001402
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
14011403
input_state_sparse.begin());
14021404
}
@@ -1415,10 +1417,10 @@ namespace nil {
14151417
typename BlueprintFieldType::integral_type(input_state[i].data);
14161418
std::vector<bool> input_state_sparse(32);
14171419
{
1418-
nil::marshalling::status_type status;
14191420
std::vector<bool> input_state_sparse_all =
14201421
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
14211422
status);
1423+
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
14221424
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
14231425
input_state_sparse.begin());
14241426
}
@@ -1444,9 +1446,9 @@ namespace nil {
14441446
assignment.witness(component.W(0), i) = message_scheduling_words[(i - row) / 5 + 1];
14451447
std::vector<bool> a(32);
14461448
{
1447-
nil::marshalling::status_type status;
14481449
std::vector<bool> a_all =
14491450
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
1451+
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
14501452
std::copy(a_all.end() - 32, a_all.end(), a.begin());
14511453
}
14521454

@@ -1486,9 +1488,9 @@ namespace nil {
14861488
typename BlueprintFieldType::integral_type(message_scheduling_words[(i - row) / 5 + 14].data);
14871489
std::vector<bool> b(32);
14881490
{
1489-
nil::marshalling::status_type status;
14901491
std::vector<bool> b_all =
14911492
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
1493+
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
14921494
std::copy(b_all.end() - 32, b_all.end(), b.begin());
14931495
}
14941496

@@ -1555,9 +1557,9 @@ namespace nil {
15551557
typename BlueprintFieldType::integral_type(e.data);
15561558
std::vector<bool> e_bits(32);
15571559
{
1558-
nil::marshalling::status_type status;
15591560
std::vector<bool> e_bits_all =
15601561
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_e, status);
1562+
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
15611563
std::copy(e_bits_all.end() - 32, e_bits_all.end(), e_bits.begin());
15621564
}
15631565

@@ -1655,9 +1657,9 @@ namespace nil {
16551657
typename BlueprintFieldType::integral_type(a.data);
16561658
std::vector<bool> a_bits(32);
16571659
{
1658-
nil::marshalling::status_type status;
16591660
std::vector<bool> a_bits_all =
16601661
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
1662+
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
16611663
std::copy(a_bits_all.end() - 32, a_bits_all.end(), a_bits.begin());
16621664
}
16631665

0 commit comments

Comments
 (0)