Skip to content

Commit

Permalink
Fixing usage of constructor of fri_params.
Browse files Browse the repository at this point in the history
  • Loading branch information
martun committed Sep 3, 2024
1 parent 4cb22cc commit aff83bc
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,25 @@ namespace nil {
///////////////////////////////////////////////
// math::polynomial marshalling.
///////////////////////////////////////////////
template<typename TTypeBase, typename PolynomialType, typename Enable = void>
struct polynomial;

template<typename TTypeBase, typename PolynomialType>
using polynomial = nil::marshalling::types::array_list<
TTypeBase,
field_element<TTypeBase, typename PolynomialType::value_type>,
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<
TTypeBase, std::size_t>>
>;
struct polynomial<TTypeBase, PolynomialType, std::enable_if_t<
std::is_same<PolynomialType, math::polynomial<typename PolynomialType::value_type>>::value>> {
using type = nil::marshalling::types::array_list<
TTypeBase,
field_element<TTypeBase, typename PolynomialType::value_type>,
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<
TTypeBase, std::size_t>>
>;
};

template<typename Endianness, typename PolynomialType>
polynomial<nil::marshalling::field_type<Endianness>, PolynomialType>
typename polynomial<nil::marshalling::field_type<Endianness>, PolynomialType, std::enable_if_t<
std::is_same<PolynomialType, math::polynomial<typename PolynomialType::value_type>>::value>>::type
fill_polynomial(const PolynomialType &f) {
using TTypeBase = nil::marshalling::field_type<Endianness>;
using result_type = polynomial<nil::marshalling::field_type<Endianness>, PolynomialType>;

std::vector<typename PolynomialType::value_type> val;
for( auto it=f.begin(); it != f.end(); it++){ val.push_back(*it); }
Expand All @@ -70,7 +76,13 @@ namespace nil {

template<typename Endianness, typename PolynomialType>
PolynomialType
make_polynomial(const polynomial<nil::marshalling::field_type<Endianness>, PolynomialType> &filled_polynomial) {
make_polynomial(
const typename polynomial<
nil::marshalling::field_type<Endianness>,
PolynomialType,
std::enable_if_t<
std::is_same<PolynomialType, math::polynomial<typename PolynomialType::value_type>>::value>
>::type &filled_polynomial) {
auto val = nil::crypto3::marshalling::types::make_field_element_vector<
typename PolynomialType::value_type,
Endianness
Expand All @@ -80,19 +92,76 @@ namespace nil {
}

///////////////////////////////////////////////
// vector<math::polynomial> marshalling.
// math::polynomial_dfs marshalling.
///////////////////////////////////////////////
template<typename TTypeBase, typename PolynomialDFSType>
struct polynomial<TTypeBase, PolynomialDFSType, std::enable_if_t<
std::is_same<PolynomialDFSType, math::polynomial_dfs<typename PolynomialDFSType::value_type>>::value>> {
using type = nil::marshalling::types::bundle<
TTypeBase,
std::tuple<
// degree
nil::marshalling::types::integral<TTypeBase, std::size_t>,
// values
nil::marshalling::types::array_list<
TTypeBase,
field_element<TTypeBase, typename PolynomialDFSType::value_type>,
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<
TTypeBase, std::size_t>>
>
>
>;
};

template<typename Endianness, typename PolynomialDFSType>
typename polynomial<nil::marshalling::field_type<Endianness>, PolynomialDFSType, std::enable_if_t<
std::is_same<PolynomialDFSType, math::polynomial_dfs<typename PolynomialDFSType::value_type>>::value>>::type
fill_polynomial(const PolynomialDFSType &f) {
using TTypeBase = nil::marshalling::field_type<Endianness>;
using result_type = typename polynomial<nil::marshalling::field_type<Endianness>, PolynomialDFSType>::type;

std::vector<typename PolynomialDFSType::value_type> val;
for( auto it=f.begin(); it != f.end(); it++){ val.push_back(*it); }

return result_type(std::make_tuple(
nil::marshalling::types::integral<TTypeBase, std::size_t>(f.degree()),
nil::crypto3::marshalling::types::fill_field_element_vector<
typename PolynomialDFSType::value_type,
Endianness
>(val)
));
}

template<typename Endianness, typename PolynomialDFSType>
PolynomialDFSType
make_polynomial(const typename polynomial<
nil::marshalling::field_type<Endianness>,
PolynomialDFSType,
std::enable_if_t<
std::is_same<PolynomialDFSType, math::polynomial_dfs<typename PolynomialDFSType::value_type>>::value>
>::type &filled_polynomial) {
auto val = nil::crypto3::marshalling::types::make_field_element_vector<
typename PolynomialDFSType::value_type,
Endianness
>(std::get<1>(filled_polynomial.value()));

return PolynomialDFSType(std::get<0>(filled_polynomial.value()).value(), val.begin(), val.end());
}

///////////////////////////////////////////////
// Polynomial vector marshalling, regardless of the form of the polynomial.
///////////////////////////////////////////////
template<typename TTypeBase, typename PolynomialType>
using polynomial_vector = nil::marshalling::types::array_list<
TTypeBase,
polynomial<TTypeBase, PolynomialType>,
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<
TTypeBase, std::size_t>>
typename polynomial<TTypeBase, PolynomialType>::type,
nil::marshalling::option::sequence_size_field_prefix<
nil::marshalling::types::integral<TTypeBase, std::size_t>>
>;

template<typename Endianness, typename PolynomialType>
polynomial_vector<nil::marshalling::field_type<Endianness>, PolynomialType>
fill_polynomial_vector(const std::vector<PolynomialType> &f){
fill_polynomial_vector(const std::vector<PolynomialType> &f) {
polynomial_vector<nil::marshalling::field_type<Endianness>, PolynomialType> result;
for (auto it=f.begin(); it != f.end(); it++) {
result.value().push_back(fill_polynomial<Endianness, PolynomialType>(*it));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace nil {

// std::select_container<math::polynomial> final_polynomials
// May be different size, because real degree may be less than before. So put int in the end
polynomial<TTypeBase, typename FRI::polynomial_type>,
typename polynomial<TTypeBase, typename FRI::polynomial_type>::type,

// proof of work. TODO: how to do it optional?
nil::marshalling::types::integral<TTypeBase, typename FRI::grinding_type::output_type> //proof of work*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright (c) 2021-2022 Nikita Kaskov <[email protected]>
// Copyright (c) 2021-2022 Ilias Khairullin <[email protected]>
// Copyright (c) 2022-2023 Elena Tatuzova <[email protected]>
// Copyright (c) 2024 Martun Karapetyan <[email protected]>
//
// MIT License
//
Expand Down Expand Up @@ -220,7 +221,7 @@ namespace nil {
return proof;
}

template <typename TTypeBase, typename LPCScheme, typename enable = void>
template <typename TTypeBase, typename LPCScheme, typename Enable = void>
struct precommitment_type;

// Will be used to store precommitment type of a commitment scheme. It's useful only for LPC for now,
Expand Down
Loading

0 comments on commit aff83bc

Please sign in to comment.