Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added macro for throw/assert to check marshalling status #317

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace nil {
std::array<bool, BlueprintFieldType::modulus_bits> bits_msb_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_scalar, status);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ namespace nil {
nil::marshalling::status_type status;
std::array<bool, 255> bits_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
THROW_IF_ERROR_STATUS(status, "curve_element_variable_base_endo_scalar_mul::generate_assignments");
std::copy(bits_all.end() - 128, bits_all.end(), bits.begin());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ namespace nil {
nil::marshalling::status_type status;
std::array<bool, scalar_size> bits =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
THROW_IF_ERROR_STATUS(status, "curve_element_variable_base_scalar_mul::generate_assignments");

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

typename BlueprintFieldType::value_type n = 0;
typename BlueprintFieldType::value_type n_next = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ namespace nil {
nil::marshalling::status_type status;
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(input, status);
THROW_IF_ERROR_STATUS(status, "bit_decomposition::calculate");
std::copy(bytes_all.end() - bits_amount, bytes_all.end(), bits.begin());
assert(status == nil::marshalling::status_type::success);
}
std::vector<bool> true_bits(bits_amount);
for (std::size_t i = 0; i < bits_amount; i++) {
Expand Down Expand Up @@ -225,8 +225,8 @@ namespace nil {
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(
var_value(assignment, instance_input.input), status);
THROW_IF_ERROR_STATUS(status, "bit_decomposition::generate_assignments");
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(), input_bits.begin());
assert(status == nil::marshalling::status_type::success);
}
// calling bit_builder_component's generate_assignments
generate_assignments<BlueprintFieldType>(
Expand Down Expand Up @@ -324,4 +324,4 @@ namespace nil {
} // namespace blueprint
} // namespace nil

#endif // CRYPTO3_BLUEPRINT_COMPONENTS_VARIABLE_BASE_MULTIPLICATION_EDWARD25519_HPP
#endif // CRYPTO3_BLUEPRINT_COMPONENTS_VARIABLE_BASE_MULTIPLICATION_EDWARD25519_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ namespace nil {
nil::marshalling::status_type status;
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integrals[i], status);
THROW_IF_ERROR_STATUS(status, "comparison_checked::generate_assignments");
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(),
bits[i].begin() + component.padding_bits);
assert(status == nil::marshalling::status_type::success);
}

std::array<std::vector<chunk_type>, 2> chunks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,10 @@ namespace nil {
nil::marshalling::status_type status;
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integrals[i], status);
THROW_IF_ERROR_STATUS(status, "comparison_flag::calculate");

std::copy(bytes_all.end() - arg_bits_amount, bytes_all.end(),
bits[i].begin() + padding_bits);
assert(status == nil::marshalling::status_type::success);
}

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

BOOST_ASSERT(component.padded_chunks * component.chunk_size ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ namespace nil {
nil::marshalling::status_type status;
std::array<bool, BlueprintFieldType::modulus_bits> bytes_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(x_integral, status);
THROW_IF_ERROR_STATUS(status, "range_check::generate_assignments");
std::copy(bytes_all.end() - component.bits_amount, bytes_all.end(),
bits.begin() + component.padding_bits);
assert(status == nil::marshalling::status_type::success);
}

BOOST_ASSERT(component.chunk_size <= 8);
Expand Down Expand Up @@ -404,4 +404,4 @@ namespace nil {
} // namespace blueprint
} // namespace nil

#endif // CRYPTO3_ZK_BLUEPRINT_PLONK_FIELD_RANGE_CHECK_HPP
#endif // CRYPTO3_ZK_BLUEPRINT_PLONK_FIELD_RANGE_CHECK_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,17 @@ namespace nil {
typename BlueprintFieldType::value_type g = input_state[6];
typename BlueprintFieldType::value_type h = input_state[7];

nil::marshalling::status_type status;
std::array<typename BlueprintFieldType::integral_type, 8> sparse_values {};
for (std::size_t i = 0; i < 4; i++) {
typename BlueprintFieldType::integral_type integral_input_state_sparse =
typename BlueprintFieldType::integral_type(input_state[i].data);
std::vector<bool> input_state_sparse(32);
{
nil::marshalling::status_type status;
std::vector<bool> input_state_sparse_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
status);
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
input_state_sparse.begin());
}
Expand All @@ -230,10 +231,10 @@ namespace nil {
typename BlueprintFieldType::integral_type(input_state[i].data);
std::vector<bool> input_state_sparse(32);
{
nil::marshalling::status_type status;
std::vector<bool> input_state_sparse_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
status);
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
input_state_sparse.begin());
}
Expand All @@ -254,9 +255,9 @@ namespace nil {
typename BlueprintFieldType::integral_type(message_scheduling_words[(i - row) / 5 + 1].data);
std::vector<bool> a(32);
{
nil::marshalling::status_type status;
std::vector<bool> a_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
std::copy(a_all.end() - 32, a_all.end(), a.begin());
}

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

Expand Down Expand Up @@ -313,9 +314,9 @@ namespace nil {
typename BlueprintFieldType::integral_type(e.data);
std::vector<bool> e_bits(32);
{
nil::marshalling::status_type status;
std::vector<bool> e_bits_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_e, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
std::copy(e_bits_all.end() - 32, e_bits_all.end(), e_bits.begin());
}

Expand Down Expand Up @@ -370,9 +371,9 @@ namespace nil {
typename BlueprintFieldType::integral_type(a.data);
std::vector<bool> a_bits(32);
{
nil::marshalling::status_type status;
std::vector<bool> a_bits_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::calculate");
std::copy(a_bits_all.end() - 32, a_bits_all.end(), a_bits.begin());
}

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

nil::marshalling::status_type status;
std::array<typename BlueprintFieldType::integral_type, 8> sparse_values {};
for (std::size_t i = 0; i < 4; i++) {
assignment.witness(component.W(i), row) = input_state[i];
typename BlueprintFieldType::integral_type integral_input_state_sparse =
typename BlueprintFieldType::integral_type(input_state[i].data);
std::vector<bool> input_state_sparse(32);
{
nil::marshalling::status_type status;
std::vector<bool> input_state_sparse_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
status);
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
input_state_sparse.begin());
}
Expand All @@ -1415,10 +1417,10 @@ namespace nil {
typename BlueprintFieldType::integral_type(input_state[i].data);
std::vector<bool> input_state_sparse(32);
{
nil::marshalling::status_type status;
std::vector<bool> input_state_sparse_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_input_state_sparse,
status);
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
std::copy(input_state_sparse_all.end() - 32, input_state_sparse_all.end(),
input_state_sparse.begin());
}
Expand All @@ -1444,9 +1446,9 @@ namespace nil {
assignment.witness(component.W(0), i) = message_scheduling_words[(i - row) / 5 + 1];
std::vector<bool> a(32);
{
nil::marshalling::status_type status;
std::vector<bool> a_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
std::copy(a_all.end() - 32, a_all.end(), a.begin());
}

Expand Down Expand Up @@ -1486,9 +1488,9 @@ namespace nil {
typename BlueprintFieldType::integral_type(message_scheduling_words[(i - row) / 5 + 14].data);
std::vector<bool> b(32);
{
nil::marshalling::status_type status;
std::vector<bool> b_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_b, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
std::copy(b_all.end() - 32, b_all.end(), b.begin());
}

Expand Down Expand Up @@ -1555,9 +1557,9 @@ namespace nil {
typename BlueprintFieldType::integral_type(e.data);
std::vector<bool> e_bits(32);
{
nil::marshalling::status_type status;
std::vector<bool> e_bits_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_e, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
std::copy(e_bits_all.end() - 32, e_bits_all.end(), e_bits.begin());
}

Expand Down Expand Up @@ -1655,9 +1657,9 @@ namespace nil {
typename BlueprintFieldType::integral_type(a.data);
std::vector<bool> a_bits(32);
{
nil::marshalling::status_type status;
std::vector<bool> a_bits_all =
nil::marshalling::pack<nil::marshalling::option::big_endian>(integral_a, status);
THROW_IF_ERROR_STATUS(status, "sha256_process::generate_assignments");
std::copy(a_bits_all.end() - 32, a_bits_all.end(), a_bits.begin());
}

Expand Down
Loading
Loading