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

Replaced asserts with exceptions so they are thrown at release #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -176,7 +176,12 @@ namespace nil {
make_merkle_node_value(const typename merkle_node_value<nil::marshalling::field_type<Endianness>,
ValueType>::type &filled_node_value) {
ValueType node_value;
BOOST_ASSERT(node_value.size() == filled_node_value.value().size());
if (node_value.size() != filled_node_value.value().size()) {
throw std::invalid_argument(
std::string("Invalid number of elements for merkle tree nodes. Expected: ") +
std::to_string(node_value.size()) + " got: " +
std::to_string(filled_node_value.value().size()));
}
for (std::size_t i = 0; i < filled_node_value.value().size(); ++i) {
node_value.at(i) = filled_node_value.value().at(i).value();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ namespace nil {
typename FRI::round_proof_type round_proof;
// std::vector<std::array<typename FRI::field_type::value_type, FRI::m>> y;
const std::size_t size = std::get<0>(filled.value()).value().size();
BOOST_ASSERT(size % FRI::m == 0);
if (size % FRI::m != 0) {
throw std::invalid_argument(
std::string("Number of elements should be multiple of m = ") +
std::to_string(FRI::m) + " got: " +
std::to_string(size));
}
const std::size_t coset_size = size / FRI::m;
std::size_t cur = 0;
round_proof.y.resize(coset_size);
Expand Down Expand Up @@ -415,14 +420,24 @@ namespace nil {
auto &query_proof = proof.query_proofs[i];
for( const auto &it: query_proof.initial_proof){
auto &initial_proof = it.second;
BOOST_ASSERT(initial_proof.values.size() == batch_info.at(it.first));
if (initial_proof.values.size() != batch_info.at(it.first)) {
throw std::invalid_argument(
std::string("Initial proof has wrong size. Expected: ") +
std::to_string(initial_proof.values.size()) + " got: " +
std::to_string(batch_info.at(it.first)));
}
for( std::size_t j = 0; j < initial_proof.values.size(); j++ ){
for(std::size_t k = 0; k < initial_proof.values[j].size(); k++ ){
for( std::size_t l = 0; l < FRI::m; l++ ){
initial_val.push_back(initial_proof.values[j][k][l]);
}
}
BOOST_ASSERT(std::size_t(1 << (params.step_list[0] - 1)) == initial_proof.values[j].size());
if (std::size_t(1 << (params.step_list[0] - 1)) != initial_proof.values[j].size()) {
throw std::invalid_argument(
std::string("Initial proof element has wrong size. Expected: ") +
std::to_string(std::size_t(1 << (params.step_list[0] - 1))) + " got: " +
std::to_string(initial_proof.values[j].size()));
}
}
}
}
Expand Down Expand Up @@ -538,8 +553,13 @@ namespace nil {
proof.query_proofs[i].initial_proof[it.first].values[j].resize(coset_size);
for( std::size_t k = 0; k < coset_size; k++){
for( std::size_t l = 0; l < FRI::m; l++, cur++ ){
BOOST_ASSERT(cur < std::get<2>(filled_proof.value()).value().size());
proof.query_proofs[i].initial_proof[it.first].values[j][k][l] = std::get<2>(filled_proof.value()).value()[cur].value();
if (cur >= std::get<2>(filled_proof.value()).value().size()) {
throw std::invalid_argument(
std::string("Too few elements provided for initial_polynomials values: ") +
std::to_string(std::get<2>(filled_proof.value()).value().size()));
}
proof.query_proofs[i].initial_proof[it.first].values[j][k][l] =
std::get<2>(filled_proof.value()).value()[cur].value();
}
}
}
Expand All @@ -555,7 +575,11 @@ namespace nil {
proof.query_proofs[i].round_proofs[r].y.resize(coset_size);
for( std::size_t j = 0; j < coset_size; j++){
for( std::size_t k = 0; k < FRI::m; k++, cur++){
BOOST_ASSERT(cur < std::get<3>(filled_proof.value()).value().size());
if (cur >= std::get<3>(filled_proof.value()).value().size()) {
throw std::invalid_argument(
std::string("Too few elements provided for round polynomials values: ") +
std::to_string(std::get<3>(filled_proof.value()).value().size()));
}
proof.query_proofs[i].round_proofs[r].y[j][k] = std::get<3>(filled_proof.value()).value()[cur].value();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#ifndef CRYPTO3_MARSHALLING_ZK_PLONK_ASSIGNMENT_TABLE_HPP
#define CRYPTO3_MARSHALLING_ZK_PLONK_ASSIGNMENT_TABLE_HPP

#include <type_traits>

#include <nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/table_description.hpp>
#include <nil/crypto3/zk/snark/arithmetization/plonk/assignment.hpp>
Expand Down Expand Up @@ -182,9 +180,16 @@ namespace nil {
const std::size_t columns_amount,
const std::size_t rows_amount) {

if (field_elem_vector.value().size() != columns_amount * rows_amount) {
throw std::invalid_argument(
"Size of vector does not match the expected data size. Expected: " +
std::to_string(columns_amount * rows_amount) + " got " +
std::to_string(field_elem_vector.value().size()));
}

std::vector<std::vector<FieldValueType>> result(
columns_amount, std::vector<FieldValueType>(rows_amount));
BOOST_ASSERT(field_elem_vector.value().size() == columns_amount * rows_amount);

std::size_t cur = 0;
for (std::size_t i = 0; i < columns_amount; i++) {
for (std::size_t j = 0; j < rows_amount; j++, cur++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ namespace nil {
> filled_options;

for( std::size_t i = 0; i < table.lookup_options.size(); i++ ){
BOOST_ASSERT(table.lookup_options[i].size() == table.columns_number);
if (table.lookup_options[i].size() != table.columns_number) {
throw std::invalid_argument(
std::string("Number of columns do not match. Expected: ") +
std::to_string(table.lookup_options[i].size()) + " got: " +
std::to_string(table.columns_number));
}
for( std::size_t j = 0; j < table.lookup_options[i].size(); j++){
filled_options.value().push_back(
fill_variable<Endianness, variable_type>(table.lookup_options[i][j])
Expand All @@ -92,8 +97,14 @@ namespace nil {
std::size_t columns_number = std::get<1>(filled_table.value()).value();
LookupTable result(columns_number, tag_index);

if (std::get<2>(filled_table.value()).value().size() % columns_number != 0) {
throw std::invalid_argument(
std::string("Number of elements in array should be multiple of columns number = ") +
std::to_string(columns_number) + " got: " +
std::to_string(std::get<2>(filled_table.value()).value().size()));

}
std::size_t op_n = std::get<2>(filled_table.value()).value().size() / columns_number;
BOOST_ASSERT(std::get<2>(filled_table.value()).value().size() % columns_number == 0);

std::size_t cur = 0;
for (std::size_t i = 0; i < op_n; i++) {
Expand Down
Loading