diff --git a/README.md b/README.md index 8704f4b19..186c2aa9a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [[alloc] init] C++ Cryptography Suite +# [[alloc] init] C++ Cryptography Suite [![Twitter](https://img.shields.io/twitter/follow/alloc_init_)](https://twitter.com/alloc_init_) [![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=flat-square&logo=telegram&logoColor=dark)](https://t.me/alloc_init) diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/detail/edwards/element_g2.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/detail/edwards/element_g2.hpp index 2d72da2d4..e530f021f 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/detail/edwards/element_g2.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/detail/edwards/element_g2.hpp @@ -251,10 +251,9 @@ namespace nil { } template - typename std::enable_if::value && - !is_extended_field::value, - element_edwards_g2>::type - operator*=(const FieldValueType &right) { + requires Field && + (!ExtendedField) + element_edwards_g2 operator*=(const FieldValueType &right) { return (*this) *= right.data; } diff --git a/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp b/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp index 920004eba..f0347d7ad 100644 --- a/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/curves/detail/subgroup_check.hpp @@ -35,9 +35,8 @@ namespace nil { namespace detail { // TODO: temporary implementation due to absence of GroupValueType type_trait // Should be implemented as class method - template::value && - !is_field::value>::type> + template::value>::type> bool subgroup_check(const GroupValueType &p) { return (p * GroupValueType::group_type::curve_type::q).is_zero(); } diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp index a4a940772..f77da3dd0 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/fpn.hpp @@ -39,7 +39,7 @@ namespace nil::crypto3::marshalling::types::detail { template typename std::enable_if< - algebra::is_extended_field_element::value, + algebra::ExtendedFieldValue, std::array>::type fill_field_data(const FieldValueType &field_elem); } @@ -52,7 +52,7 @@ namespace nil::crypto3::algebra::fields::detail { typename T::base_field_type; { T::non_residue } -> std::convertible_to; { T::dim_unity_root } -> std::convertible_to; - } && is_field::value; + } && Field; struct FieldArchetype; @@ -92,12 +92,20 @@ namespace nil::crypto3::algebra::fields::detail { constexpr self &operator+=(const self &) { return *this; } + constexpr self operator-(const self &) const { + return {}; + } + constexpr bool is_zero() const { + return true; + } + constexpr bool is_one() const { + return true; + } constexpr self inversed() const { return *this; } - template - constexpr self pow(const PowerType &) const { + constexpr self pow(const boost::multiprecision::cpp_int &) const { return *this; } }; @@ -347,6 +355,10 @@ namespace nil::crypto3::algebra::fields::detail { return power(*this, pwr); } + constexpr element_fpn pow(const boost::multiprecision::cpp_int &pwr) const { + return power(*this, pwr); + } + constexpr element_fpn inversed() const { auto f = one(); for (std::size_t i = 1; i < dimension; ++i) { @@ -401,7 +413,7 @@ namespace nil::crypto3::algebra::fields::detail { template friend typename std::enable_if< - algebra::is_extended_field_element::value, + algebra::ExtendedFieldValue, std::array>::type nil::crypto3::marshalling::types::detail::fill_field_data(const FieldValueType &field_elem); }; @@ -432,8 +444,8 @@ namespace nil::crypto3::algebra::fields::detail { return element_fpn_details::one_instance; } - static_assert(is_field_element>::value); - static_assert(is_extended_field_element>::value); + static_assert(FieldValue>); + static_assert(ExtendedFieldValue>); } // namespace nil::crypto3::algebra::fields::detail template diff --git a/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/operations.hpp b/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/operations.hpp index b0fa4828a..0acd3dd27 100644 --- a/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/operations.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/fields/detail/element/operations.hpp @@ -33,66 +33,66 @@ namespace nil { namespace algebra { namespace fields { namespace detail { - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator+(const FieldElement &A, Integral B) { return A + FieldElement(B); } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator-(const FieldElement &A, Integral B) { return A - FieldElement(B); } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator*(const FieldElement &A, Integral B) { return A * FieldElement(B); } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator/(const FieldElement &A, Integral B) { return A / FieldElement(B); } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator+(Integral A, const FieldElement &B) { return FieldElement(A) + B; } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator-(Integral A, const FieldElement &B) { return FieldElement(A) - B; } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator*(Integral A, const FieldElement &B) { return FieldElement(A) * B; } - template< - typename FieldElement, typename Integral, - typename = typename std::enable_if::value && - std::is_constructible::value>::type> + template + requires(!std::same_as, FieldElement> && + requires { typename FieldElement::field_type; } && + std::constructible_from) constexpr FieldElement operator/(Integral A, const FieldElement &B) { return FieldElement(A) / B; } diff --git a/libs/algebra/include/nil/crypto3/algebra/marshalling.hpp b/libs/algebra/include/nil/crypto3/algebra/marshalling.hpp index 7f5eac073..fc6fc07df 100644 --- a/libs/algebra/include/nil/crypto3/algebra/marshalling.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/marshalling.hpp @@ -59,7 +59,7 @@ namespace nil { template static inline typename std::enable_if< - !algebra::is_extended_field::value && + !algebra::ExtendedField && std::is_same::value_type>::value, std::pair>::type @@ -74,7 +74,7 @@ namespace nil { template static inline typename std::enable_if< - algebra::is_extended_field::value && + algebra::ExtendedField && std::is_same::value_type>::value, std::pair>::type @@ -98,7 +98,7 @@ namespace nil { template static inline typename std::enable_if< - !algebra::is_extended_field::value && + !algebra::ExtendedField && std::is_same::value_type>::value, size_t>::type field_element_to_bytes(const field_value_type &element, OutputIterator out_first, @@ -114,7 +114,7 @@ namespace nil { template static inline typename std::enable_if< - algebra::is_extended_field::value && + algebra::ExtendedField && std::is_same::value_type>::value, size_t>::type field_element_to_bytes(const field_value_type &element, OutputIterator out_first, @@ -194,7 +194,7 @@ namespace nil { template static inline typename std::enable_if< - !algebra::is_extended_field::value && + !algebra::ExtendedField && std::is_same::value_type>::value && (std::is_same::value || std::is_same::value), @@ -205,7 +205,7 @@ namespace nil { template static inline typename std::enable_if< - algebra::is_extended_field::value && + algebra::ExtendedField && std::is_same::value_type>::value, std::pair>::type @@ -249,7 +249,7 @@ namespace nil { template static inline typename std::enable_if< - !algebra::is_extended_field::value && + !algebra::ExtendedField && (std::is_same::value || std::is_same::value) && std::is_same::value_type>::value, size_t>::type @@ -260,7 +260,7 @@ namespace nil { template static inline typename std::enable_if< - algebra::is_extended_field::value && + algebra::ExtendedField && std::is_same::value_type>::value, size_t>::type field_element_to_bytes(const typename FieldType::value_type &element, OutputIterator out_first, diff --git a/libs/algebra/include/nil/crypto3/algebra/random_element.hpp b/libs/algebra/include/nil/crypto3/algebra/random_element.hpp index 1c7ab685a..19cbd4eee 100644 --- a/libs/algebra/include/nil/crypto3/algebra/random_element.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/random_element.hpp @@ -54,8 +54,8 @@ namespace nil { typename FieldType, typename DistributionType = boost::random::uniform_int_distribution, typename UniformRandomBitGenerator = boost::random::random_device> - typename std::enable_if::value && !(is_extended_field::value), - typename FieldType::value_type>::type + requires Field && (!ExtendedField) + typename FieldType::value_type random_element(UniformRandomBitGenerator &&rng = UniformRandomBitGenerator()) { using field_type = FieldType; @@ -75,8 +75,8 @@ namespace nil { typename FieldType, typename DistributionType = boost::random::uniform_int_distribution, typename UniformRandomBitGenerator = boost::random::random_device> - typename std::enable_if::value && is_extended_field::value, - typename FieldType::value_type>::type + requires Field && ExtendedField + typename FieldType::value_type random_element(UniformRandomBitGenerator &&rng = UniformRandomBitGenerator()) { using field_type = FieldType; diff --git a/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp b/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp index c37c2470e..5ace321c5 100644 --- a/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp +++ b/libs/algebra/include/nil/crypto3/algebra/type_traits.hpp @@ -46,15 +46,11 @@ namespace nil { BOOST_TTI_HAS_TYPE(iterator) BOOST_TTI_HAS_TYPE(const_iterator) - BOOST_TTI_HAS_TYPE(extension_policy) BOOST_TTI_HAS_TYPE(params_type) BOOST_TTI_HAS_TYPE(curve_type) BOOST_TTI_HAS_TYPE(field_type) - BOOST_TTI_HAS_TYPE(underlying_type) BOOST_TTI_HAS_TYPE(value_type) - BOOST_TTI_HAS_TYPE(integral_type) BOOST_TTI_HAS_TYPE(base_field_type) - BOOST_TTI_HAS_TYPE(modular_type) BOOST_TTI_HAS_TYPE(scalar_field_type) BOOST_TTI_HAS_TYPE(gt_type) @@ -72,16 +68,10 @@ namespace nil { BOOST_TTI_HAS_TYPE(group_type) - BOOST_TTI_HAS_STATIC_MEMBER_DATA(value_bits) - - BOOST_TTI_HAS_STATIC_MEMBER_DATA(modulus_bits) - BOOST_TTI_HAS_STATIC_MEMBER_DATA(base_field_modulus) BOOST_TTI_HAS_STATIC_MEMBER_DATA(scalar_field_modulus) - BOOST_TTI_HAS_STATIC_MEMBER_DATA(arity) - BOOST_TTI_HAS_STATIC_MEMBER_DATA(p) BOOST_TTI_HAS_STATIC_MEMBER_DATA(q) @@ -91,8 +81,6 @@ namespace nil { BOOST_TTI_HAS_FUNCTION(to_special) BOOST_TTI_HAS_FUNCTION(is_special) - BOOST_TTI_HAS_FUNCTION(sqrt) - BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(zero) BOOST_TTI_HAS_STATIC_MEMBER_FUNCTION(one) @@ -105,8 +93,6 @@ namespace nil { BOOST_TTI_HAS_FUNCTION(mixed_add) - BOOST_TTI_HAS_FUNCTION(inversed) - template struct is_curve { static constexpr bool value = has_type_base_field_type::value && @@ -121,24 +107,6 @@ namespace nil { has_type_field_type::value && has_type_value_type::value; }; - /** @brief is typename T a field */ - template - struct is_field { - static const bool value = - has_type_value_type::value && has_static_member_data_value_bits::value && - has_type_integral_type::value && - has_static_member_data_modulus_bits::value && - has_type_modular_type::value && has_static_member_data_arity::value; - typedef T type; - }; - - /** @brief is typename T an extended field (e.g. Fp2) */ - template - struct is_extended_field { - static const bool value = is_field::value && has_type_extension_policy::value; - typedef T type; - }; - template struct is_curve_element { static const bool value = @@ -153,40 +121,41 @@ namespace nil { static const bool value = has_function_mixed_add>::value; }; - template - struct is_field_element { - static const bool value = has_type_field_type::value && has_function_is_zero::value && - has_function_inversed::value && - has_static_member_function_zero::value; - }; - - template - struct is_extended_field_element { - static const bool value = is_field_element::value && has_type_underlying_type::value; - }; - template concept FieldValue = requires(const T &a, const T &b, const boost::multiprecision::cpp_int &exponent) { typename T::field_type; - requires std::same_as; - { T::zero() } -> std::convertible_to; - { T::one() } -> std::convertible_to; + { T::zero() } -> std::convertible_to; + { T::one() } -> std::convertible_to; { a + b } -> std::same_as; { a - b } -> std::same_as; { a * b } -> std::same_as; + { a == b } -> std::convertible_to; + { a.is_zero() } -> std::convertible_to; + { a.is_one() } -> std::convertible_to; { a.inversed() } -> std::same_as; { a.pow(exponent) } -> std::same_as; }; template - concept Field = is_field::value && requires { + concept Field = requires { typename T::value_type; + typename T::integral_type; + typename T::modular_type; + { T::value_bits } -> std::convertible_to; + { T::modulus_bits } -> std::convertible_to; + { T::arity } -> std::convertible_to; requires FieldValue; }; + template + concept ExtendedField = Field && requires { typename T::extension_policy; }; + + template + concept ExtendedFieldValue = FieldValue && requires { typename T::underlying_type; }; + template concept FieldElementWithCoordinates = - is_field_element::value && requires(T &value, const T &const_value, std::size_t index) { + FieldValue && requires(T &value, const T &const_value, std::size_t index) { value.coordinate(index); const_value.coordinate(index); requires std::is_lvalue_reference_v; @@ -195,7 +164,7 @@ namespace nil { requires std::is_const_v>; requires std::same_as, std::remove_cvref_t>; - requires is_field_element>::value; + requires FieldValue>; }; template diff --git a/libs/algebra/test/fields_static.cpp b/libs/algebra/test/fields_static.cpp index 00cd7ee4c..fd4cdf48d 100644 --- a/libs/algebra/test/fields_static.cpp +++ b/libs/algebra/test/fields_static.cpp @@ -107,21 +107,6 @@ constexpr bool check_field_operations_static() { static_assert(-elements[e1] == elements[minus_e1], "neg error"); static_assert(elements[e2].squared() == elements[e2_pow_2], "sqr error"); - // TODO: fix this. - // - // Not all fields have .sqrt() method. - // The proper way to use has_function_sqrt is this: - // - // using field_value_type = fields::bls12_base_field<381>::value_type - // if constexpr (has_function_sqrt::value) { - // ... - // } - // - // This naiive approach with decltype does not work - the result is always false. - // We can't use direct typenames since _values_ are template arguments - if constexpr (has_function_sqrt::value) { - static_assert((elements[e2].squared()).sqrt() == elements[e2_pow_2_sqrt], "sqrt error"); - } return true; } diff --git a/libs/algebra/test/type_traits.cpp b/libs/algebra/test/type_traits.cpp index 12a2011ee..035bece02 100644 --- a/libs/algebra/test/type_traits.cpp +++ b/libs/algebra/test/type_traits.cpp @@ -66,24 +66,17 @@ void test_field_value_types() { BOOST_ASSERT(has_type_field_type::value); BOOST_ASSERT((has_function_is_zero::value)); - BOOST_ASSERT((has_function_inversed::value)); BOOST_ASSERT((has_static_member_function_zero::value)); BOOST_ASSERT((has_static_member_function_one::value)); - BOOST_ASSERT(is_field_element::value); + BOOST_ASSERT(FieldValue); } template void test_field_types() { BOOST_ASSERT(has_type_value_type::value); - BOOST_ASSERT(has_type_integral_type::value); - BOOST_ASSERT(has_type_modular_type::value); - BOOST_ASSERT((has_static_member_data_value_bits::value)); - BOOST_ASSERT((has_static_member_data_modulus_bits::value)); - BOOST_ASSERT((has_static_member_data_arity::value)); - - BOOST_ASSERT(is_field::value); + BOOST_ASSERT(Field); test_field_value_types(); } @@ -92,10 +85,9 @@ template void test_extended_field_types() { test_field_types(); - BOOST_ASSERT(has_type_extension_policy::value); - BOOST_ASSERT(is_extended_field::value); + BOOST_ASSERT(ExtendedField); - BOOST_ASSERT(is_extended_field_element::value); + BOOST_ASSERT(ExtendedFieldValue); test_field_value_types(); } @@ -220,7 +212,12 @@ BOOST_AUTO_TEST_CASE(ed25519_type_traits) { test_ordinary_curve_types(); } -#define FIELD_HAS_SQRT(field) (has_function_sqrt::value) +template +concept HasSqrt = requires(const T &value) { + { value.sqrt() } -> std::same_as; +}; + +#define FIELD_HAS_SQRT(field) (HasSqrt) BOOST_AUTO_TEST_CASE(test_extended_fields_sqrt_trait) { @@ -280,60 +277,60 @@ BOOST_AUTO_TEST_CASE(test_extended_fields_sqrt_trait) { BOOST_AUTO_TEST_CASE(test_extended_fields_trait) { - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::field_type::value_type>::value); - BOOST_ASSERT(is_extended_field_element::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::field_type::value_type>::value); - - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); - BOOST_ASSERT(!is_extended_field_element::value); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue::field_type::value_type>); + BOOST_ASSERT(ExtendedFieldValue); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue::field_type::value_type>); + + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); + BOOST_ASSERT(!ExtendedFieldValue); } BOOST_AUTO_TEST_SUITE_END() diff --git a/libs/containers/test/merkle/merkle.cpp b/libs/containers/test/merkle/merkle.cpp index 5fe1e12b8..f5ff6dc13 100644 --- a/libs/containers/test/merkle/merkle.cpp +++ b/libs/containers/test/merkle/merkle.cpp @@ -68,8 +68,8 @@ typename std::enable_if::value, std::vector -typename std::enable_if::value, std::vector>>::type - generate_random_data(std::size_t leaf_number) { + requires algebra::FieldValue +std::vector> generate_random_data(std::size_t leaf_number) { std::vector> v; for (std::size_t i = 0; i < leaf_number; ++i) { std::array leaf {}; @@ -308,14 +308,14 @@ BOOST_AUTO_TEST_CASE(merkletree_validate_test_1) { std::vector> v = {{'0'}, {'1'}, {'2'}, {'3'}, {'4'}, {'5'}, {'6'}, {'7'}}; testing_validate_template, 2>(v); - BOOST_STATIC_ASSERT_MSG(algebra::is_field_element::value, + BOOST_STATIC_ASSERT_MSG(algebra::FieldValue, "Expecting Poseidon to consume field elements"); std::vector> v_field = { {0x0_cppui_modular255}, {0x1_cppui_modular255}, {0x2_cppui_modular255}, {0x3_cppui_modular255}, {0x4_cppui_modular255}, {0x5_cppui_modular255}, {0x6_cppui_modular255}, {0x7_cppui_modular255}}; testing_validate_template(v_field); - BOOST_STATIC_ASSERT_MSG(algebra::is_field_element::value, + BOOST_STATIC_ASSERT_MSG(algebra::FieldValue, "Expecting Poseidon2 to consume field elements"); std::vector> poseidon2_v_field = { {0x0_cppui_modular254}, {0x1_cppui_modular254}, {0x2_cppui_modular254}, {0x3_cppui_modular254}, diff --git a/libs/hash/include/nil/crypto3/hash/block_to_field_elements_wrapper.hpp b/libs/hash/include/nil/crypto3/hash/block_to_field_elements_wrapper.hpp index 71abfa823..82fdcf1d8 100644 --- a/libs/hash/include/nil/crypto3/hash/block_to_field_elements_wrapper.hpp +++ b/libs/hash/include/nil/crypto3/hash/block_to_field_elements_wrapper.hpp @@ -161,7 +161,7 @@ namespace nil { typename Container, bool OverflowOnPurpose, bool Padding = true, - bool = algebra::is_field_element::value> + bool = algebra::FieldValue> struct conditional_block_to_field_elements_wrapper_helper { using type = Container; }; diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp index 289c50ba8..1f255cddf 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/inference.hpp @@ -49,7 +49,7 @@ namespace nil { template using field_element = - typename std::conditional::value, + typename std::conditional, extended_field_element, pure_field_element>::type; } // namespace types @@ -73,7 +73,8 @@ namespace nil { }; template - class is_compatible::value>::type> { + requires nil::crypto3::algebra::FieldValue + class is_compatible { using default_endianness = option::big_endian; public: @@ -86,4 +87,4 @@ namespace nil { } // namespace marshalling } // namespace nil -#endif // CRYPTO3_MARSHALLING_ALGEBRA_INFERENCE_TYPE_TRAITS_HPP \ No newline at end of file +#endif // CRYPTO3_MARSHALLING_ALGEBRA_INFERENCE_TYPE_TRAITS_HPP diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/processing/detail/curve_element.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/processing/detail/curve_element.hpp index a04d7891c..773690a5c 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/processing/detail/curve_element.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/processing/detail/curve_element.hpp @@ -46,10 +46,8 @@ namespace nil { namespace processing { namespace detail { template - typename std::enable_if::value && - !(algebra::is_extended_field::value), - bool>::type - sign_gf_p(const typename G1FieldType::value_type &v) { + requires algebra::Field && (!algebra::ExtendedField) + bool sign_gf_p(const typename G1FieldType::value_type &v) { if (v > G1FieldType::group_order_minus_one_half) { return true; @@ -58,8 +56,8 @@ namespace nil { } template - typename std::enable_if::value, bool>::type - sign_gf_p(const typename G2FieldType::value_type &v) { + requires algebra::ExtendedField + bool sign_gf_p(const typename G2FieldType::value_type &v) { if (v.data[1] == 0u) { return sign_gf_p(v.data[0]); diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp index 6706842ce..aa8923cc6 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/type_traits.hpp @@ -45,7 +45,7 @@ namespace nil { template using field_element = - typename std::conditional::value, + typename std::conditional, extended_field_element, pure_field_element>::type; } // namespace types @@ -72,39 +72,35 @@ namespace nil { }; template - struct is_field_element { - - static const bool value = false; - }; + inline constexpr bool marshalling_field_element = false; template - struct is_field_element< - nil::crypto3::marshalling::types::extended_field_element> { - - static const bool value = true; - }; + inline constexpr bool marshalling_field_element< + nil::crypto3::marshalling::types::extended_field_element> = true; template - struct is_field_element< - nil::crypto3::marshalling::types::pure_field_element> { + inline constexpr bool marshalling_field_element< + nil::crypto3::marshalling::types::pure_field_element> = true; - static const bool value = true; - }; + template + concept MarshallingFieldElement = marshalling_field_element; template struct is_container; template - struct is_container::value>::type> { + requires is_curve_element::value + struct is_container { static const bool value = false; }; template - struct is_container::value>::type> { + requires MarshallingFieldElement + struct is_container { static const bool value = false; }; } // namespace marshalling } // namespace nil -#endif // CRYPTO3_MARSHALLING_ALGEBRA_TYPE_TRAITS_HPP \ No newline at end of file +#endif // CRYPTO3_MARSHALLING_ALGEBRA_TYPE_TRAITS_HPP diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/curve_element.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/curve_element.hpp index 1bb6133d8..a760884c2 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/curve_element.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/curve_element.hpp @@ -266,18 +266,16 @@ namespace nil { } template - typename std::enable_if::value && - !(algebra::is_extended_field::value), - int>::type - compare_field_data(const typename FieldType::value_type &field_elem1, + requires algebra::Field && (!algebra::ExtendedField) + int compare_field_data(const typename FieldType::value_type &field_elem1, const typename FieldType::value_type &field_elem2) { return (field_elem1.data < field_elem2.data) ? -1 : ((field_elem1.data > field_elem2.data) ? 1 : 0); } template - typename std::enable_if::value, bool>::type - compare_field_data(const typename FieldType::value_type &field_elem1, - const typename FieldType::value_type &field_elem2) { + requires algebra::ExtendedField + bool compare_field_data(const typename FieldType::value_type &field_elem1, + const typename FieldType::value_type &field_elem2) { for (std::size_t i = 0; i < FieldType::arity; i++) { int compare_result = compare_field_data( diff --git a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/field_element.hpp b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/field_element.hpp index 9d089d70a..5ce45aa53 100644 --- a/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/field_element.hpp +++ b/libs/marshalling/algebra/include/nil/crypto3/marshalling/algebra/types/field_element.hpp @@ -49,9 +49,8 @@ namespace nil { namespace detail { template - typename std::enable_if::value), - std::array>::type + requires(!algebra::ExtendedFieldValue) + std::array fill_field_data(const FieldValueType &field_elem) { std::array - typename std::enable_if::value, - std::array>::type + requires algebra::ExtendedFieldValue + std::array fill_field_data(const FieldValueType &field_elem) { std::array - typename std::enable_if::value && - !(algebra::is_extended_field_element::value), - FieldValueType>::type - make_field_element( - typename std::array::iterator field_elem_data_iter) { + requires algebra::FieldValue && (!algebra::ExtendedFieldValue) + FieldValueType make_field_element( + typename std::array::iterator field_elem_data_iter) { return FieldValueType(*field_elem_data_iter); } template - typename std::enable_if::value, - FieldValueType>::type - make_field_element( - typename std::array::iterator field_elem_data_iter) { + requires algebra::ExtendedFieldValue + FieldValueType make_field_element( + typename std::array::iterator field_elem_data_iter) { constexpr static const std::size_t cur_arity = FieldValueType::field_type::arity / FieldValueType::underlying_type::field_type::arity; @@ -122,8 +117,8 @@ namespace nil { integral, TOptions...> { - static_assert(algebra::is_field_element::value); - static_assert(!algebra::is_extended_field_element::value); + static_assert(algebra::FieldValue); + static_assert(!algebra::ExtendedFieldValue); using base_impl_type = ::nil::marshalling::types::detail::adapt_basic_field_type< integral, @@ -324,8 +319,8 @@ namespace nil { nil::marshalling::option::fixed_size_storage>, TOptions...> { - static_assert(algebra::is_field_element::value); - static_assert(algebra::is_extended_field_element::value); + static_assert(algebra::FieldValue); + static_assert(algebra::ExtendedFieldValue); using base_impl_type = ::nil::marshalling::types::detail::adapt_basic_field_type< typename nil::marshalling::types::array_list< @@ -546,7 +541,7 @@ namespace nil { template using field_element = - typename std::conditional::value, + typename std::conditional, extended_field_element, pure_field_element>::type; @@ -573,9 +568,9 @@ namespace nil { // } // template - // typename std::enable_if::value && - // !(algebra::is_extended_field_element::value), - // int>::type + // requires algebra::FieldValue && + // (!algebra::ExtendedFieldValue) + // int // compare_field_data(const FieldValueType &field_elem1, // const FieldValueType &field_elem2) { // return (field_elem1.data < field_elem2.data) ? -1 : ((field_elem1.data > field_elem2.data) ? 1 : @@ -583,7 +578,8 @@ namespace nil { // } // template - // typename std::enable_if::value, bool>::type + // requires algebra::ExtendedFieldValue + // bool // compare_field_data(const FieldValueType &field_elem1, // const FieldValueType &field_elem2) { // for (std::size_t i = 0; i < FieldValueType::field_type::arity; i++) { diff --git a/libs/marshalling/algebra/test/field_element.cpp b/libs/marshalling/algebra/test/field_element.cpp index 8d837909e..4b16d73c4 100644 --- a/libs/marshalling/algebra/test/field_element.cpp +++ b/libs/marshalling/algebra/test/field_element.cpp @@ -62,8 +62,8 @@ void test_field_element(T val) { using unit_type = unsigned char; using field_element_type = types::field_element, T>; - static_assert(nil::crypto3::algebra::is_field_element::value); - static_assert(nil::marshalling::is_field_element::value); + static_assert(nil::crypto3::algebra::FieldValue); + static_assert(nil::marshalling::MarshallingFieldElement); static_assert(nil::marshalling::is_compatible::value); using inferenced_type = typename nil::marshalling::is_compatible::template type; diff --git a/libs/marshalling/containers/include/nil/crypto3/marshalling/containers/types/merkle_node.hpp b/libs/marshalling/containers/include/nil/crypto3/marshalling/containers/types/merkle_node.hpp index ff863a4c6..7d22384f1 100644 --- a/libs/marshalling/containers/include/nil/crypto3/marshalling/containers/types/merkle_node.hpp +++ b/libs/marshalling/containers/include/nil/crypto3/marshalling/containers/types/merkle_node.hpp @@ -65,10 +65,8 @@ namespace nil { // For Poseidon, Merkle node will contain a Group Element, not a vector of bytes. template - struct merkle_node_value< - TTypeBase, - GroupElementType, - typename std::enable_if::value>::type> { + requires nil::crypto3::algebra::FieldValue + struct merkle_node_value { using type = field_element; }; @@ -114,10 +112,8 @@ namespace nil { return filled_node_value; } - template::value, - bool>::type = true> + template + requires nil::crypto3::algebra::FieldValue typename merkle_node_value, GroupElementType>::type fill_merkle_node_value(const GroupElementType &node_value) { @@ -175,10 +171,8 @@ namespace nil { return node_value; } - template::value, - bool>::type = true> + template + requires nil::crypto3::algebra::FieldValue GroupElementType make_merkle_node_value( const typename merkle_node_value, GroupElementType>::type &filled_node_value) { diff --git a/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/common_data.hpp b/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/common_data.hpp index 954b63693..edb6768ee 100644 --- a/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/common_data.hpp +++ b/libs/marshalling/zk/include/nil/crypto3/marshalling/zk/types/placeholder/common_data.hpp @@ -148,8 +148,8 @@ namespace nil { nil::marshalling::types::integral>> filled_constraint_system_with_params_hash; - if constexpr (nil::crypto3::algebra::is_field_element< - typename CommonDataType::transcript_hash_type::word_type>::value) { + if constexpr (nil::crypto3::algebra::FieldValue< + typename CommonDataType::transcript_hash_type::word_type>) { auto integral = typename CommonDataType::field_type::integral_type( common_data.vk.constraint_system_with_params_hash.data); std::vector blob; @@ -250,8 +250,8 @@ namespace nil { typename CommonDataType::verification_key_type vk; vk.fixed_values_commitment = fixed_values; - if constexpr (nil::crypto3::algebra::is_field_element< - typename CommonDataType::transcript_hash_type::word_type>::value) { + if constexpr (nil::crypto3::algebra::FieldValue< + typename CommonDataType::transcript_hash_type::word_type>) { std::vector blob; for (std::size_t i = 0; i < std::get<13>(filled_common_data.value()).value().size(); i++) { blob.push_back(std::uint8_t(std::get<13>(filled_common_data.value()).value()[i].value())); diff --git a/libs/marshalling/zk/test/merkle_proof.cpp b/libs/marshalling/zk/test/merkle_proof.cpp index e03c3ff5d..6e70ee70a 100644 --- a/libs/marshalling/zk/test/merkle_proof.cpp +++ b/libs/marshalling/zk/test/merkle_proof.cpp @@ -113,7 +113,7 @@ void test_merkle_proof(std::size_t tree_depth) { auto data = generate_random_data(leafs_number); merkle_tree_type tree; - if constexpr (nil::crypto3::algebra::is_field_element::value) { + if constexpr (nil::crypto3::algebra::FieldValue) { // Populate the vector with wrappers, one for each block std::vector>> diff --git a/libs/marshalling/zk/test/merkle_tree.cpp b/libs/marshalling/zk/test/merkle_tree.cpp index cd6a921c6..a63753e92 100644 --- a/libs/marshalling/zk/test/merkle_tree.cpp +++ b/libs/marshalling/zk/test/merkle_tree.cpp @@ -74,7 +74,7 @@ void test_merkle_tree_marshalling(std::size_t tree_depth) { auto data = generate_random_data(leafs_number); merkle_tree_type tree; - if constexpr (nil::crypto3::algebra::is_field_element::value) { + if constexpr (nil::crypto3::algebra::FieldValue) { // Populate the vector with wrappers, one for each block std::vector>> diff --git a/libs/math/include/nil/crypto3/math/algorithms/mixed_radix_fft.hpp b/libs/math/include/nil/crypto3/math/algorithms/mixed_radix_fft.hpp index 7b3c21ce3..6c73c1842 100644 --- a/libs/math/include/nil/crypto3/math/algorithms/mixed_radix_fft.hpp +++ b/libs/math/include/nil/crypto3/math/algorithms/mixed_radix_fft.hpp @@ -59,7 +59,7 @@ namespace nil { */ template class mixed_radix_fft_plan { - static_assert(algebra::is_field::value, "FieldType must be a field"); + static_assert(algebra::Field, "FieldType must be a field"); using field_value_type = typename FieldType::value_type; diff --git a/libs/math/include/nil/crypto3/math/algorithms/unity_root.hpp b/libs/math/include/nil/crypto3/math/algorithms/unity_root.hpp index ea5e5bec6..57401eac3 100644 --- a/libs/math/include/nil/crypto3/math/algorithms/unity_root.hpp +++ b/libs/math/include/nil/crypto3/math/algorithms/unity_root.hpp @@ -86,8 +86,8 @@ namespace nil { prime q. Input: BigInteger q which is a prime. Output: A generator of prime q */ template - static typename std::enable_if::value, IntegerType>::type - find_generator(const IntegerType &q) { + requires(!algebra::FieldValue) + static IntegerType find_generator(const IntegerType &q) { std::set prime_factors; IntegerType qm1 = q - IntegerType(1); diff --git a/libs/math/include/nil/crypto3/math/domains/detail/basic_radix2_domain_aux.hpp b/libs/math/include/nil/crypto3/math/domains/detail/basic_radix2_domain_aux.hpp index 8a408b700..3ab383c0e 100644 --- a/libs/math/include/nil/crypto3/math/domains/detail/basic_radix2_domain_aux.hpp +++ b/libs/math/include/nil/crypto3/math/domains/detail/basic_radix2_domain_aux.hpp @@ -66,7 +66,7 @@ namespace nil { void basic_radix2_fft_cached(Range &a, const std::vector &omega_cache) { typedef typename std::iterator_traits()))>::value_type value_type; - BOOST_STATIC_ASSERT(algebra::is_field::value); + BOOST_STATIC_ASSERT(algebra::Field); // It now supports curve elements too, should probably some other assertion about the field type and // value type BOOST_STATIC_ASSERT(std::is_same::value); diff --git a/libs/math/include/nil/crypto3/math/polynomial/arithmetic/xgcd.hpp b/libs/math/include/nil/crypto3/math/polynomial/arithmetic/xgcd.hpp index d9a7cfd11..1ba270b4a 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/arithmetic/xgcd.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/arithmetic/xgcd.hpp @@ -56,7 +56,7 @@ namespace nil { std::same_as, std::ranges::range_value_t> && std::same_as, std::ranges::range_value_t> && std::same_as, std::ranges::range_value_t> && - algebra::is_field_element>::value && + algebra::FieldValue> && requires(const Range1 &input, Range3 &g, Range4 &u, Range5 &v, const std::vector> &coefficients) { g = input; diff --git a/libs/math/include/nil/crypto3/math/polynomial/operations/basic_operations.hpp b/libs/math/include/nil/crypto3/math/polynomial/operations/basic_operations.hpp index d1e894a0e..479ee1f69 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/operations/basic_operations.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/operations/basic_operations.hpp @@ -352,7 +352,7 @@ namespace nil { template requires requires { typename std::ranges::range_value_t::field_type; } && - algebra::is_field::field_type>::value && + algebra::Field::field_type> && std::same_as::field_type::value_type, std::ranges::range_value_t> && std::default_initializable> && @@ -469,7 +469,7 @@ namespace nil { */ template requires std::default_initializable && - algebra::is_field_element>::value && + algebra::FieldValue> && requires(const std::ranges::range_value_t &field_value) { { Backend::polynomial_type::value_type::one() * field_value @@ -504,8 +504,7 @@ namespace nil { * @pre Q and R are distinct and do not alias either input. */ template - requires algebra::is_field_element>::value && - std::copy_constructible && + requires algebra::FieldValue> && std::copy_constructible && std::constructible_from, std::ranges::range_value_t> && std::constructible_from, diff --git a/libs/math/include/nil/crypto3/math/polynomial/operations/basis_change.hpp b/libs/math/include/nil/crypto3/math/polynomial/operations/basis_change.hpp index 3e653f5ba..e21c9001d 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/operations/basis_change.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/operations/basis_change.hpp @@ -46,7 +46,7 @@ namespace nil { * page 7. */ template - requires algebra::is_field::value + requires algebra::Field void compute_subproduct_tree(std::vector>> &T, std::size_t m) { @@ -95,7 +95,7 @@ namespace nil { * 12 and 14. */ template - requires algebra::is_field::value + requires algebra::Field void monomial_to_newton_basis(Range &a, const std::vector>> &T, @@ -157,7 +157,7 @@ namespace nil { * page 11. */ template - requires algebra::is_field::value + requires algebra::Field void newton_to_monomial_basis(Range &a, const std::vector>> &T, @@ -199,7 +199,7 @@ namespace nil { detail::MutablePolynomialCoefficientRange Range1, detail::PolynomialCoefficientRange Range2, detail::PolynomialCoefficientRange Range3> - requires algebra::is_field::value && + requires algebra::Field && std::same_as, typename FieldType::value_type> && std::same_as, typename FieldType::value_type> void monomial_to_newton_basis_geometric(Range1 &a, @@ -252,7 +252,7 @@ namespace nil { detail::MutablePolynomialCoefficientRange Range1, detail::PolynomialCoefficientRange Range2, detail::PolynomialCoefficientRange Range3> - requires algebra::is_field::value && + requires algebra::Field && std::same_as, typename FieldType::value_type> && std::same_as, typename FieldType::value_type> void newton_to_monomial_basis_geometric(Range1 &a, diff --git a/libs/math/include/nil/crypto3/math/polynomial/operations/evaluate.hpp b/libs/math/include/nil/crypto3/math/polynomial/operations/evaluate.hpp index a99222165..7573f8e98 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/operations/evaluate.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/operations/evaluate.hpp @@ -84,7 +84,7 @@ namespace nil { */ template requires std::same_as, FieldValueType> && - algebra::is_field_element::value + algebra::FieldValue inline FieldValueType evaluate_lagrange_polynomial(InputIterator first, InputIterator last, const FieldValueType &t, std::size_t m, std::size_t idx) { @@ -115,7 +115,7 @@ namespace nil { template requires std::ranges::random_access_range && std::same_as, FieldValueType> && - algebra::is_field_element::value + algebra::FieldValue inline FieldValueType evaluate_lagrange_polynomial(const Range &domain, const FieldValueType &t, std::size_t m, std::size_t idx) { return evaluate_lagrange_polynomial(std::ranges::begin(domain), std::ranges::end(domain), t, m, idx); diff --git a/libs/math/include/nil/crypto3/math/polynomial/operations/lagrange_interpolation.hpp b/libs/math/include/nil/crypto3/math/polynomial/operations/lagrange_interpolation.hpp index d4d181c53..6f5868070 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/operations/lagrange_interpolation.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/operations/lagrange_interpolation.hpp @@ -52,7 +52,7 @@ namespace nil { std::ranges::sized_range && std::same_as, std::pair> && - algebra::is_field_element::value + algebra::FieldValue polynomial lagrange_interpolation(const InputRange &points) { std::size_t k = std::ranges::size(points); auto first = std::ranges::begin(points); diff --git a/libs/math/include/nil/crypto3/math/polynomial/operations/shift.hpp b/libs/math/include/nil/crypto3/math/polynomial/operations/shift.hpp index 8484a57a7..5bc14963e 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/operations/shift.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/operations/shift.hpp @@ -47,7 +47,7 @@ namespace nil { * This changes coefficient values without moving them to different degrees. */ template - requires algebra::is_field_element::value + requires algebra::FieldValue static inline polynomial polynomial_shift(const polynomial &f, const FieldValueType &x) { polynomial f_shifted(f); @@ -136,7 +136,7 @@ namespace nil { * @pre domain_size is zero, selecting f.size(), or is a positive divisor of f.size(). */ template - requires algebra::is_field_element::value + requires algebra::FieldValue static inline polynomial_dfs polynomial_shift(const polynomial_dfs &f, const int shift, std::size_t domain_size = 0) { diff --git a/libs/math/include/nil/crypto3/math/polynomial/polynomial.hpp b/libs/math/include/nil/crypto3/math/polynomial/polynomial.hpp index a549edddf..e7e21957a 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/polynomial.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/polynomial.hpp @@ -530,7 +530,7 @@ namespace nil { }; template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator+(const polynomial& A, const FieldValueType& B) { @@ -538,7 +538,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator+(const FieldValueType& A, const polynomial& B) { @@ -546,7 +546,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator-(const polynomial& A, const FieldValueType& B) { @@ -554,7 +554,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator-(const FieldValueType& A, const polynomial& B) { @@ -562,7 +562,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator*(const polynomial& A, const FieldValueType& B) { polynomial result; @@ -571,14 +571,14 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator*(const FieldValueType& A, const polynomial& B) { return B * A; } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator/(const polynomial& A, const FieldValueType& B) { polynomial result(A); @@ -591,7 +591,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial operator/(const FieldValueType& A, const polynomial& B) { @@ -601,7 +601,7 @@ namespace nil { // Used in the unit tests, so we can use BOOST_CHECK_EQUALS, and see // the values of polynomials, when the check fails. template> - requires algebra::is_field_element::value + requires algebra::FieldValue std::ostream& operator<<(std::ostream& os, const polynomial& poly) { if (poly.degree() == 0) { // If all it contains is a constant, print the constant, so it's more readable. diff --git a/libs/math/include/nil/crypto3/math/polynomial/polynomial_dfs.hpp b/libs/math/include/nil/crypto3/math/polynomial/polynomial_dfs.hpp index c25dabd14..4a29309a2 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/polynomial_dfs.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/polynomial_dfs.hpp @@ -775,7 +775,7 @@ namespace nil { }; template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator+(const polynomial_dfs& A, const FieldValueType& B) { polynomial_dfs result(A); @@ -786,7 +786,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator+(const FieldValueType& A, const polynomial_dfs& B) { polynomial_dfs result(B); @@ -797,7 +797,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator-(const polynomial_dfs& A, const FieldValueType& B) { polynomial_dfs result(A); @@ -808,7 +808,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator-(const FieldValueType& A, const polynomial_dfs& B) { polynomial_dfs result(B); @@ -819,7 +819,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator*(const polynomial_dfs& A, const FieldValueType& B) { @@ -831,7 +831,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator*(const FieldValueType& A, const polynomial_dfs& B) { // Call the upper function. @@ -839,7 +839,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator/(const polynomial_dfs& A, const FieldValueType& B) { polynomial_dfs result(A); @@ -852,7 +852,7 @@ namespace nil { } template> - requires algebra::is_field_element::value + requires algebra::FieldValue polynomial_dfs operator/(const FieldValueType& A, const polynomial_dfs& B) { @@ -862,7 +862,7 @@ namespace nil { // Used in the unit tests, so we can use BOOST_CHECK_EQUALS, and see // the values of polynomials, when the check fails. template> - requires algebra::is_field_element::value + requires algebra::FieldValue std::ostream& operator<<(std::ostream& os, const polynomial_dfs& poly) { if (poly.degree() == 0) { // If all it contains is a constant, print the constant, so it's more readable. diff --git a/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial.hpp b/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial.hpp index 30643fb3b..faeabc4b0 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial.hpp @@ -151,7 +151,7 @@ namespace nil::crypto3::math { // Used in the unit tests, so we can use BOOST_CHECK_EQUALS, and see // the values of polymorphic_polynomials, when the check fails. template - requires algebra::is_field::value + requires algebra::Field std::ostream& operator<<(std::ostream& os, const polymorphic_polynomial& poly) { return std::visit([&os](const auto& value) -> std::ostream& { return os << value; }, poly.val); } diff --git a/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial_dfs.hpp b/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial_dfs.hpp index 2a2efd67e..a7db5c1c3 100644 --- a/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial_dfs.hpp +++ b/libs/math/include/nil/crypto3/math/polynomial/types/polymorphic_polynomial_dfs.hpp @@ -173,7 +173,7 @@ namespace nil::crypto3::math { // Used in the unit tests, so we can use BOOST_CHECK_EQUALS, and see // the values of polynomials, when the check fails. template - requires algebra::is_field::value + requires algebra::Field std::ostream& operator<<(std::ostream& os, const polymorphic_polynomial_dfs& poly) { return std::visit([&os](const auto& value) -> std::ostream& { return os << value; }, poly.val); } diff --git a/libs/pkpad/include/nil/crypto3/pkpad/emsa/emsa1.hpp b/libs/pkpad/include/nil/crypto3/pkpad/emsa/emsa1.hpp index 2a02ae767..2d2054d4e 100644 --- a/libs/pkpad/include/nil/crypto3/pkpad/emsa/emsa1.hpp +++ b/libs/pkpad/include/nil/crypto3/pkpad/emsa/emsa1.hpp @@ -45,9 +45,8 @@ namespace nil { template struct emsa1_encoding_policy< MsgReprType, HashType, - typename std::enable_if< - algebra::is_field::value && - !algebra::is_extended_field::value>::type> { + typename std::enable_if && + !algebra::ExtendedField>::type> { typedef HashType hash_type; protected: @@ -108,11 +107,9 @@ namespace nil { }; template - struct emsa1_encoding_policy< - MsgReprType, HashType, - typename std::enable_if< - algebra::is_field::value && - !algebra::is_extended_field::value>::type> + struct emsa1_encoding_policy && + !algebra::ExtendedField>::type> : public emsa1_encoding_policy { }; template @@ -121,9 +118,8 @@ namespace nil { template struct emsa1_verification_policy< MsgReprType, HashType, - typename std::enable_if< - algebra::is_field::value && - !algebra::is_extended_field::value>::type> { + typename std::enable_if && + !algebra::ExtendedField>::type> { protected: typedef typename MsgReprType::field_type field_type; typedef emsa1_encoding_policy encoding_policy; @@ -156,9 +152,8 @@ namespace nil { template struct emsa1_verification_policy< MsgReprType, HashType, - typename std::enable_if< - algebra::is_field::value && - !algebra::is_extended_field::value>::type> + typename std::enable_if && + !algebra::ExtendedField>::type> : public emsa1_verification_policy { }; template diff --git a/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp b/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp index 680d4ffcc..1a5427f65 100644 --- a/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp +++ b/libs/pubkey/include/nil/crypto3/detail/type_traits.hpp @@ -437,23 +437,6 @@ namespace nil { typedef T type; }; - template - struct is_field { - static const bool value = has_value_type::value && has_value_bits::value && - has_integral_type::value && has_modulus_bits::value && - has_number_type::value && has_arity::value; - typedef T type; - }; - - template - struct is_extended_field { - static const bool value = has_value_type::value && has_value_bits::value && - has_integral_type::value && has_modulus_bits::value && - has_number_type::value && has_arity::value && - has_extension_policy::value; - typedef T type; - }; - template struct is_complex : std::false_type { }; template diff --git a/libs/random/include/nil/crypto3/random/algebraic_engine.hpp b/libs/random/include/nil/crypto3/random/algebraic_engine.hpp index 0906274f6..113ae5b8c 100644 --- a/libs/random/include/nil/crypto3/random/algebraic_engine.hpp +++ b/libs/random/include/nil/crypto3/random/algebraic_engine.hpp @@ -57,12 +57,9 @@ namespace nil { struct algebraic_engine; template - struct algebraic_engine< - AlgebraicType, - Engine, - typename std::enable_if::value && - !algebra::is_extended_field::value && - boost::is_integral::value>::type> { + requires algebra::Field && (!algebra::ExtendedField) && + boost::is_integral::value + struct algebraic_engine { protected: typedef AlgebraicType field_type; typedef typename field_type::value_type field_value_type; @@ -177,12 +174,9 @@ namespace nil { }; template - struct algebraic_engine< - AlgebraicType, - Engine, - typename std::enable_if::value && - algebra::is_extended_field::value && - boost::is_integral::value>::type> { + requires algebra::Field && algebra::ExtendedField && + boost::is_integral::value + struct algebraic_engine { protected: typedef AlgebraicType extended_field_type; typedef typename extended_field_type::value_type extended_field_value_type; diff --git a/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp b/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp index c641c1f9a..3a13a3292 100644 --- a/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp +++ b/libs/random/include/nil/crypto3/random/algebraic_random_device.hpp @@ -50,9 +50,8 @@ namespace nil { struct algebraic_random_device; template - struct algebraic_random_device< - AlgebraicType, typename std::enable_if::value && - !algebra::is_extended_field::value>::type> { + requires algebra::Field && (!algebra::ExtendedField) + struct algebraic_random_device { protected: typedef AlgebraicType field_type; typedef typename field_type::value_type field_value_type; @@ -89,9 +88,8 @@ namespace nil { }; template - struct algebraic_random_device< - AlgebraicType, typename std::enable_if::value && - algebra::is_extended_field::value>::type> { + requires algebra::Field && algebra::ExtendedField + struct algebraic_random_device { protected: typedef AlgebraicType extended_field_type; typedef typename extended_field_type::value_type extended_field_value_type; diff --git a/libs/random/include/nil/crypto3/random/hash.hpp b/libs/random/include/nil/crypto3/random/hash.hpp index 299e97338..3c923d893 100644 --- a/libs/random/include/nil/crypto3/random/hash.hpp +++ b/libs/random/include/nil/crypto3/random/hash.hpp @@ -48,11 +48,10 @@ namespace nil { // TODO: replace pack with marshalling template - struct hash::value && - !algebra::is_extended_field::value && - (ResultType::field_type::value_bits <= HashType::digest_bits)>::type> { + requires algebra::Field && + (!algebra::ExtendedField) && + (ResultType::field_type::value_bits <= HashType::digest_bits) + struct hash { typedef HashType hash_type; typedef ResultType result_type; typedef std::uint64_t input_type; diff --git a/libs/random/include/nil/crypto3/random/rfc6979.hpp b/libs/random/include/nil/crypto3/random/rfc6979.hpp index 459370e8b..57a902b55 100644 --- a/libs/random/include/nil/crypto3/random/rfc6979.hpp +++ b/libs/random/include/nil/crypto3/random/rfc6979.hpp @@ -56,11 +56,9 @@ namespace nil { struct rfc6979; template - struct rfc6979< - ResultType, - HashType, - typename std::enable_if::value && - !algebra::is_extended_field::value>::type> { + requires algebra::Field && + (!algebra::ExtendedField) + struct rfc6979 { typedef HashType hash_type; typedef mac::hmac hmac_policy; typedef mac::mac_key key_type; diff --git a/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp b/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp index a455a2ecd..ed3bc1e1e 100644 --- a/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp +++ b/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/basic_fri.hpp @@ -381,7 +381,7 @@ namespace nil { template requires(math::EvaluationPolynomial && - algebra::is_field_element::value) && + algebra::FieldValue) && std::is_base_of_v< commitments::detail::basic_batched_fri< typename FRI::field_type, typename FRI::merkle_tree_hash_type, diff --git a/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/element_knowledge_commitment.hpp b/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/element_knowledge_commitment.hpp index c709ea4dc..ddea9576a 100644 --- a/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/element_knowledge_commitment.hpp +++ b/libs/zk/include/nil/crypto3/zk/commitments/detail/polynomial/element_knowledge_commitment.hpp @@ -210,8 +210,8 @@ namespace nil { typename Type2, typename FieldValueType, typename = typename std::enable_if< - algebra::is_field::value && - !algebra::is_extended_field::value, + algebra::Field && + !algebra::ExtendedField, FieldValueType>::type> element_kc operator*(const FieldValueType &lhs, const element_kc &rhs) { @@ -222,8 +222,8 @@ namespace nil { typename Type2, typename FieldValueType, typename = typename std::enable_if< - algebra::is_field::value && - !algebra::is_extended_field::value, + algebra::Field && + !algebra::ExtendedField, FieldValueType>::type> element_kc operator*(const element_kc &lhs, const FieldValueType &rhs) { diff --git a/libs/zk/include/nil/crypto3/zk/detail/field_element_consumer.hpp b/libs/zk/include/nil/crypto3/zk/detail/field_element_consumer.hpp index b22aca7d0..ee3a15bfd 100644 --- a/libs/zk/include/nil/crypto3/zk/detail/field_element_consumer.hpp +++ b/libs/zk/include/nil/crypto3/zk/detail/field_element_consumer.hpp @@ -40,17 +40,17 @@ namespace nil { * @tparam Field * @tparam Target A type that determines whether to store Field's value_type directly or as bytes. * The decision is based on whether Target is identified as a field element by the - * `algebra::is_field_element` trait. + * `algebra::FieldValue` concept. * @tparam Marshalling A type of marshalled strucutre to use for serialization in case of keepeng * serialized values. */ template class field_element_consumer - : public std::vector::value, + : public std::vector, typename FieldType::value_type, std::uint8_t>> { public: // TODO: make private using base_class = - std::vector::value, + std::vector, typename FieldType::value_type, std::uint8_t>>; using iterator = typename base_class::iterator; @@ -60,8 +60,7 @@ namespace nil { * it multiplies by the length of the field element representation. */ static constexpr std::size_t field_element_holder_size_multiplier = - std::conditional_t::value, - std::integral_constant, + std::conditional_t, std::integral_constant, std::integral_constant>::value; // Default ctor is used for single values @@ -78,7 +77,7 @@ namespace nil { void consume(const typename FieldType::value_type &field_element) { BOOST_ASSERT(current_iter <= this->end() - field_element_holder_size_multiplier); - if constexpr (algebra::is_field_element::value) { + if constexpr (algebra::FieldValue) { *current_iter++ = field_element; } else { Marshalling field_val(field_element); diff --git a/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp b/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp index 97fbbd288..52d308c93 100644 --- a/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp +++ b/libs/zk/include/nil/crypto3/zk/transcript/fiat_shamir.hpp @@ -83,9 +83,9 @@ namespace nil { template void operator()(TAny data) { - if constexpr (algebra::is_field_element::value) { + if constexpr (algebra::FieldValue) { BOOST_STATIC_ASSERT_MSG( - algebra::is_field_element::value, + algebra::FieldValue, "HashType type consumes field elements, but provided value is not a field element"); acc(data); } else { @@ -150,7 +150,7 @@ namespace nil { template typename std::enable_if_t::value && - !algebra::is_field_element::value> + !algebra::FieldValue> operator()(const InputRange &r) { auto acc_convertible = hash(state); state = accumulators::extract::hash( @@ -165,8 +165,7 @@ namespace nil { } template - typename std::enable_if_t::value || - algebra::is_field_element::value> + typename std::enable_if_t::value || algebra::FieldValue> operator()(element const &data) { nil::marshalling::status_type status; std::vector byte_data =