2828
2929#include < nil/crypto3/algebra/curves/pallas.hpp>
3030#include < nil/crypto3/algebra/curves/ed25519.hpp>
31- #include < nil/crypto3/algebra/marshalling.hpp>
32-
31+ #include < nil/crypto3/marshalling/algebra/types/field_element.hpp>
3332#include < nil/crypto3/zk/snark/arithmetization/plonk/constraint_system.hpp>
3433
34+ #include < nil/blueprint/detail/basic_non_native_policy.hpp>
35+
36+
3537namespace nil {
3638 namespace blueprint {
3739 namespace detail {
40+
3841 template <typename BlueprintFieldType, typename OperatingFieldType>
39- struct basic_non_native_policy_field_type ;
42+ struct basic_non_native_policy_field_type : public basic_non_native_policy_field_type_base <BlueprintFieldType, OperatingFieldType, chopped_lengths_storage<>> {
43+ };
4044
4145 /*
4246 * Specialization for non-native Ed25519 base field element on Pallas base field
@@ -45,38 +49,9 @@ namespace nil {
4549 struct basic_non_native_policy_field_type <
4650 typename crypto3::algebra::curves::pallas::base_field_type,
4751 typename crypto3::algebra::curves::ed25519::base_field_type
48- > {
49- using non_native_field_type = typename crypto3::algebra::curves::ed25519::base_field_type;
50- using native_field_type = typename crypto3::algebra::curves::pallas::base_field_type;
51- using var = crypto3::zk::snark::plonk_variable<typename native_field_type::value_type>;
52-
53- constexpr static const std::uint32_t native_type_element_bit_length = 66 ;
54- constexpr static const std::uint32_t native_type_elements_needed =
55- (non_native_field_type::value_bits + (native_type_element_bit_length - 1 ))
56- / native_type_element_bit_length
57- ;
58-
59- using non_native_var_type = std::array<var, native_type_elements_needed>;
60- using chopped_value_type = std::array<native_field_type::value_type, native_type_elements_needed>;
61-
62- static chopped_value_type chop_non_native (non_native_field_type::value_type input) {
63- return marshalling::bincode::field<non_native_field_type>
64- ::split_field_element<native_field_type, native_type_element_bit_length>(input);
65- }
66-
67- static non_native_field_type::value_type glue_non_native (chopped_value_type input) {
68- non_native_field_type::value_type result;
69- native_field_type::integral_type integral_input;
70- result = non_native_field_type::value_type (native_field_type::integral_type (input[0 ].data ));
71- for (std::size_t i = 1 ; i < ratio; i++) {
72- std::size_t shift = 0 ;
73- for (std::size_t j = 0 ; j < i; j++) {
74- shift += chunk_sizes[j];
75- }
76- result += non_native_field_type::value_type (native_field_type::integral_type (input[i].data ) << shift);
77- }
78- return result;
79- }
52+ > : public basic_non_native_policy_field_type_base<typename crypto3::algebra::curves::pallas::base_field_type, typename crypto3::algebra::curves::ed25519::base_field_type, chopped_lengths_storage<58 , 66 , 66 , 66 >> {
53+
54+ using basic_non_native_policy_field_type_base::chopped_value_type;
8055
8156 };
8257
@@ -90,50 +65,22 @@ namespace nil {
9065 using non_native_var_type = crypto3::zk::snark::plonk_variable<typename crypto3::algebra::curves::pallas::base_field_type::value_type>;
9166 };
9267
93- /*
94- * Specialization for non-native Pallas scalar field element on Pallas base field
95- */
68+ // / *
69+ // * Specialization for non-native Pallas scalar field element on Pallas base field
70+ // */
9671 template <>
97- struct basic_non_native_policy_field_type <typename crypto3::algebra::curves::pallas::base_field_type,
98- typename crypto3::algebra::curves::pallas::scalar_field_type> {
99-
100- using non_native_field_type = typename crypto3::algebra::curves::pallas::scalar_field_type;
101- using native_field_type = typename crypto3::algebra::curves::pallas::base_field_type;
102- using var = crypto3::zk::snark::plonk_variable<native_field_type>;
103-
104- constexpr static const std::uint32_t native_type_element_bit_length = 254 ;
105- constexpr static const std::uint32_t native_type_elements_needed =
106- (non_native_field_type::value_bits + (native_type_element_bit_length - 1 ))
107- / native_type_element_bit_length
108- ;
109-
110- using non_native_var_type = std::array<var, native_type_elements_needed>;
111- using chopped_value_type = std::array<native_field_type::value_type, native_type_elements_needed>;
112-
113- static chopped_value_type chop_non_native (non_native_field_type::value_type input) {
114- return marshalling::bincode::field<non_native_field_type>
115- ::split_field_element<native_field_type, native_type_element_bit_length>(input);
116- }
117-
118- static non_native_field_type::value_type glue_non_native (chopped_value_type input) {
119- non_native_field_type::value_type result;
120- native_field_type::integral_type integral_input;
121- result = non_native_field_type::value_type (native_field_type::integral_type (input[0 ].data ));
122- for (std::size_t i = 1 ; i < ratio; i++) {
123- std::size_t shift = 0 ;
124- for (std::size_t j = 0 ; j < i; j++) {
125- shift += chunk_sizes[j];
126- }
127- result += non_native_field_type::value_type (native_field_type::integral_type (input[i].data ) << shift);
128- }
129- return result;
130- }
72+ struct basic_non_native_policy_field_type <
73+ typename crypto3::algebra::curves::pallas::base_field_type,
74+ typename crypto3::algebra::curves::pallas::scalar_field_type
75+ > : public basic_non_native_policy_field_type_base<typename crypto3::algebra::curves::pallas::base_field_type, typename crypto3::algebra::curves::pallas::scalar_field_type, chopped_lengths_storage<2 , 254 >> {
76+
77+ using basic_non_native_policy_field_type_base::chopped_value_type;
13178
13279 };
13380
134- /*
135- * Native element type.
136- */
81+ // / *
82+ // * Native element type.
83+ // */
13784 template <typename BlueprintFieldType>
13885 struct basic_non_native_policy_field_type <BlueprintFieldType, BlueprintFieldType> {
13986
@@ -155,8 +102,6 @@ namespace nil {
155102 using field = typename detail::basic_non_native_policy_field_type<BlueprintFieldType, OperatingFieldType>;
156103 };
157104
158-
159-
160105 } // namespace blueprint
161106} // namespace nil
162107
0 commit comments