Skip to content
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
8 changes: 7 additions & 1 deletion libiop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ add_library(
algebra/fields/gf192.cpp
algebra/fields/gf256.cpp
snark/common/hashing.cpp
protocols/ldt/ldt_reducer.cpp
protocols/ldt/fri/fri_ldt.cpp
protocols/ldt/fri/fri_aux.cpp
relations/sparse_matrix.cpp
iop/utilities/batching.cpp
algebra/utils.cpp
)

target_link_libraries(
Expand Down Expand Up @@ -214,7 +220,7 @@ target_link_libraries(test_bcs_transformation iop gtest_main)
add_executable(test_aurora_snark tests/snark/test_aurora_snark.cpp)
target_link_libraries(test_aurora_snark iop gtest_main)

add_executable(test_fractal_snark tests/snark/test_fractal_snark.cpp)
add_executable(test_fractal_snark tests/snark/test_fractal_snark.cpp )
target_link_libraries(test_fractal_snark iop gtest_main)

add_executable(test_ligero_snark tests/snark/test_ligero_snark.cpp)
Expand Down
11 changes: 11 additions & 0 deletions libiop/algebra/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "libiop/algebra/utils.hpp"


namespace libiop {

size_t gcd(const size_t a, const size_t b)
{
return b == 0 ? a : gcd(b, a % b);
}

}
5 changes: 1 addition & 4 deletions libiop/algebra/utils.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ std::vector<FieldT> random_FieldT_vector(const std::size_t count)
return result;
}

size_t gcd(const size_t a, const size_t b)
{
return b == 0 ? a : gcd(b, a % b);
}


} // namespace libiop
21 changes: 0 additions & 21 deletions libiop/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,5 @@ long double add_soundness_error_bits(const long double bits1, const long double
return -1 * log2l(result);
}

template<typename T>
void print_vector(std::vector<T> &vec)
{
printf("{ ");
for (auto const& elem : vec)
{
std::cout << elem << " ";
}
printf("}\n");
}

template<typename T>
void print_vector(std::vector<T> vec)
{
printf("{ ");
for (auto const& elem : vec)
{
std::cout << elem << " ";
}
printf("}\n");
}

} // namespace libiop
26 changes: 24 additions & 2 deletions libiop/common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,33 @@ long double add_soundness_error_bits(const long double bits1, const long double
template<typename ... Types>
void UNUSED(Types&&...) {}

/* Print a vector in the form { elem0 elem1 elem2 ... }, with a newline at the end*/
/* Print a vector in the form { elem0 elem1 elem2 ... }, with a newline at the end
template<typename T>
void print_vector(std::vector<T> &vec);
template<typename T>
void print_vector(std::vector<T> vec);
void print_vector(std::vector<T> vec);*/

template<typename T>
void print_vector(std::vector<T> &vec)
{
printf("{ ");
for (auto const& elem : vec)
{
std::cout << elem << " ";
}
printf("}\n");
}

template<typename T>
void print_vector(std::vector<T> vec)
{
printf("{ ");
for (auto const& elem : vec)
{
std::cout << elem << " ";
}
printf("}\n");
}

} // namespace libiop

Expand Down
20 changes: 20 additions & 0 deletions libiop/iop/utilities/batching.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "batching.hpp"

namespace libiop {



std::vector<oracle_handle_ptr> virtual_oracle_handles_to_handle_ptrs(
const std::vector<virtual_oracle_handle> handles)
{
std::vector<oracle_handle_ptr> oracles;
oracles.reserve(handles.size());
for (size_t i = 0; i < handles.size(); i++)
{
oracles.emplace_back(std::make_shared<virtual_oracle_handle>(handles[i]));
}
return oracles;
}


} // namespace libiop
12 changes: 1 addition & 11 deletions libiop/iop/utilities/batching.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,7 @@ std::vector<oracle_handle_ptr> register_n_oracles(
return oracles;
}

std::vector<oracle_handle_ptr> virtual_oracle_handles_to_handle_ptrs(
const std::vector<virtual_oracle_handle> handles)
{
std::vector<oracle_handle_ptr> oracles;
oracles.reserve(handles.size());
for (size_t i = 0; i < handles.size(); i++)
{
oracles.emplace_back(std::make_shared<virtual_oracle_handle>(handles[i]));
}
return oracles;
}


template<typename FieldT>
std::vector<query_handle> register_queries_for_same_pos(
Expand Down
43 changes: 43 additions & 0 deletions libiop/protocols/ldt/fri/fri_aux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <cstdint>
#include "fri_aux.hpp"

namespace libiop {


// -------------------------------------------------
// Optimizer utils

/** Generate all possible localization vectors that begin with starting,
* and reduce up to max_reducable_dimensions dimensions.
*/
std::vector<std::vector<size_t>> localization_vector_generator(
size_t max_reducable_dimensions,
std::vector<size_t> starting)
{
std::vector<std::vector<size_t>> options;
options.push_back(starting);
if (max_reducable_dimensions == 0)
{
return options;
}
for (size_t i = 1; i <= max_reducable_dimensions; ++i)
{
std::vector<size_t> new_starting = starting;
new_starting.push_back(i);
std::vector<std::vector<size_t>> new_options =
localization_vector_generator(max_reducable_dimensions - i, new_starting);
options.insert(options.end(), new_options.begin(), new_options.end());
}
return options;
}

/* return all partitions of this number (that is, all possible FRI localization parameter vectors
for this codeword domain dimension) */
std::vector<std::vector<size_t>> all_localization_vectors(size_t dimension_to_reduce)
{
/* Fix the start as 1 */
std::vector<size_t> starting({1});
return localization_vector_generator(dimension_to_reduce - 1, starting);
}

} // namespace libiop
34 changes: 0 additions & 34 deletions libiop/protocols/ldt/fri/fri_aux.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -386,40 +386,6 @@ std::vector<query_position_handle> calculate_next_coset_query_positions(
return query_pos;
}

// -------------------------------------------------
// Optimizer utils

/** Generate all possible localization vectors that begin with starting,
* and reduce up to max_reducable_dimensions dimensions.
*/
std::vector<std::vector<size_t>> localization_vector_generator(
size_t max_reducable_dimensions,
std::vector<size_t> starting)
{
std::vector<std::vector<size_t>> options;
options.push_back(starting);
if (max_reducable_dimensions == 0)
{
return options;
}
for (size_t i = 1; i <= max_reducable_dimensions; ++i)
{
std::vector<size_t> new_starting = starting;
new_starting.push_back(i);
std::vector<std::vector<size_t>> new_options =
localization_vector_generator(max_reducable_dimensions - i, new_starting);
options.insert(options.end(), new_options.begin(), new_options.end());
}
return options;
}

/* return all partitions of this number (that is, all possible FRI localization parameter vectors
for this codeword domain dimension) */
std::vector<std::vector<size_t>> all_localization_vectors(size_t dimension_to_reduce)
{
/* Fix the start as 1 */
std::vector<size_t> starting({1});
return localization_vector_generator(dimension_to_reduce - 1, starting);
}

} // namespace libiop
19 changes: 19 additions & 0 deletions libiop/protocols/ldt/fri/fri_ldt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//#include "libiop/common/common.hpp"
#include "libiop/protocols/ldt/fri/fri_ldt.hpp"

namespace libiop {


const char* FRI_soundness_type_to_string(FRI_soundness_type soundness_type)
{
if (soundness_type == FRI_soundness_type::heuristic)
{
return "heuristic";
} else if (soundness_type == FRI_soundness_type::proven)
{
return "proven";
}
return "Invalid soundness type";
}

} // namespace libiop
14 changes: 1 addition & 13 deletions libiop/protocols/ldt/fri/fri_ldt.tcc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "libiop/algebra/field_subset/subgroup.hpp"
#include "libiop/common/common.cpp"
#include "libiop/common/common.hpp"
#include "libiop/common/profiling.hpp"

namespace libiop {
Expand Down Expand Up @@ -231,18 +231,6 @@ long double FRI_protocol_parameters<FieldT>::achieved_query_soundness() const
return -1.0 * (long double)(this->num_query_repetitions_) * soundness_per_query;
}

const char* FRI_soundness_type_to_string(FRI_soundness_type soundness_type)
{
if (soundness_type == FRI_soundness_type::heuristic)
{
return "heuristic";
} else if (soundness_type == FRI_soundness_type::proven)
{
return "proven";
}
return "Invalid soundness type";
}

template<typename FieldT>
void FRI_protocol_parameters<FieldT>::print() const
{
Expand Down
21 changes: 21 additions & 0 deletions libiop/protocols/ldt/ldt_reducer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "libiop/protocols/ldt/ldt_reducer.hpp"
#include <cassert>
#include <stdexcept>

namespace libiop {


const char* LDT_reducer_soundness_type_to_string(LDT_reducer_soundness_type soundness_type)
{
if (soundness_type == LDT_reducer_soundness_type::proven)
{
return "proven";
} else if (soundness_type == LDT_reducer_soundness_type::optimistic_heuristic)
{
return "heuristic";
}
return "Invalid soundness type";
}


} // libiop
11 changes: 0 additions & 11 deletions libiop/protocols/ldt/ldt_reducer.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ size_t LDT_instance_reducer_params<FieldT>::num_output_LDT_instances() const
return this->num_output_LDT_instances_;
}

const char* LDT_reducer_soundness_type_to_string(LDT_reducer_soundness_type soundness_type)
{
if (soundness_type == LDT_reducer_soundness_type::proven)
{
return "proven";
} else if (soundness_type == LDT_reducer_soundness_type::optimistic_heuristic)
{
return "heuristic";
}
return "Invalid soundness type";
}

template<typename FieldT>
void LDT_instance_reducer_params<FieldT>::print() const
Expand Down
9 changes: 9 additions & 0 deletions libiop/relations/sparse_matrix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "libiop/relations/sparse_matrix.hpp"

namespace libiop {


std::vector<r1cs_sparse_matrix_type> all_r1cs_sparse_matrix_types(
{r1cs_sparse_matrix_A, r1cs_sparse_matrix_B, r1cs_sparse_matrix_C});

} // libiop
3 changes: 1 addition & 2 deletions libiop/relations/sparse_matrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ enum r1cs_sparse_matrix_type {
r1cs_sparse_matrix_C = 3
};

std::vector<r1cs_sparse_matrix_type> all_r1cs_sparse_matrix_types(
{r1cs_sparse_matrix_A, r1cs_sparse_matrix_B, r1cs_sparse_matrix_C});
extern std::vector<r1cs_sparse_matrix_type> all_r1cs_sparse_matrix_types;

template<typename FieldT>
class r1cs_sparse_matrix : public sparse_matrix<FieldT> {
Expand Down