Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit be019b8

Browse files
committed
Apply clang-format
1 parent 7b1c023 commit be019b8

File tree

3 files changed

+63
-77
lines changed

3 files changed

+63
-77
lines changed

include/nil/blueprint/basic_non_native_policy.hpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,27 @@
3333

3434
#include <nil/blueprint/detail/basic_non_native_policy.hpp>
3535

36-
3736
namespace nil {
3837
namespace blueprint {
3938
namespace detail {
4039

4140
template<typename BlueprintFieldType, typename OperatingFieldType>
42-
struct basic_non_native_policy_field_type : public basic_non_native_policy_field_type_base<BlueprintFieldType, OperatingFieldType, chopped_lengths_storage<>> {
43-
};
41+
struct basic_non_native_policy_field_type
42+
: public basic_non_native_policy_field_type_base<BlueprintFieldType, OperatingFieldType,
43+
chopped_lengths_storage<>> { };
4444

4545
/*
4646
* Specialization for non-native Ed25519 base field element on Pallas base field
4747
*/
4848
template<>
49-
struct basic_non_native_policy_field_type<
50-
typename crypto3::algebra::curves::pallas::base_field_type,
51-
typename crypto3::algebra::curves::ed25519::base_field_type
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>> {
49+
struct basic_non_native_policy_field_type<typename crypto3::algebra::curves::pallas::base_field_type,
50+
typename crypto3::algebra::curves::ed25519::base_field_type>
51+
: public basic_non_native_policy_field_type_base<
52+
typename crypto3::algebra::curves::pallas::base_field_type,
53+
typename crypto3::algebra::curves::ed25519::base_field_type,
54+
chopped_lengths_storage<58, 66, 66, 66>> {
5355

5456
using basic_non_native_policy_field_type_base::chopped_value_type;
55-
5657
};
5758

5859
/*
@@ -62,20 +63,21 @@ namespace nil {
6263
struct basic_non_native_policy_field_type<typename crypto3::algebra::curves::pallas::base_field_type,
6364
typename crypto3::algebra::curves::ed25519::scalar_field_type> {
6465

65-
using non_native_var_type = crypto3::zk::snark::plonk_variable<typename crypto3::algebra::curves::pallas::base_field_type::value_type>;
66+
using non_native_var_type = crypto3::zk::snark::plonk_variable<
67+
typename crypto3::algebra::curves::pallas::base_field_type::value_type>;
6668
};
6769

6870
// /*
6971
// * Specialization for non-native Pallas scalar field element on Pallas base field
7072
// */
7173
template<>
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>> {
74+
struct basic_non_native_policy_field_type<typename crypto3::algebra::curves::pallas::base_field_type,
75+
typename crypto3::algebra::curves::pallas::scalar_field_type>
76+
: public basic_non_native_policy_field_type_base<
77+
typename crypto3::algebra::curves::pallas::base_field_type,
78+
typename crypto3::algebra::curves::pallas::scalar_field_type, chopped_lengths_storage<2, 254>> {
7679

7780
using basic_non_native_policy_field_type_base::chopped_value_type;
78-
7981
};
8082

8183
// /*
@@ -85,7 +87,6 @@ namespace nil {
8587
struct basic_non_native_policy_field_type<BlueprintFieldType, BlueprintFieldType> {
8688

8789
using value_type = crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>;
88-
8990
};
9091
} // namespace detail
9192

include/nil/blueprint/detail/basic_non_native_policy.hpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <nil/marshalling/status_type.hpp>
3535
#include <nil/crypto3/marshalling/multiprecision/types/bitfield.hpp>
3636

37-
3837
namespace nil {
3938
namespace blueprint {
4039
namespace detail {
@@ -50,8 +49,10 @@ namespace nil {
5049
using native_field_t = BlueprintFieldType;
5150
using var_t = crypto3::zk::snark::plonk_variable<typename native_field_t::value_type>;
5251

53-
static constexpr std::size_t chopped_elements_amount = sizeof(chopped_lengths_storage::values)/sizeof(std::size_t);
54-
static_assert(chopped_elements_amount != 0, "native_bit_lengths must be specialized for the field types");
52+
static constexpr std::size_t chopped_elements_amount =
53+
sizeof(chopped_lengths_storage::values) / sizeof(std::size_t);
54+
static_assert(chopped_elements_amount != 0,
55+
"native_bit_lengths must be specialized for the field types");
5556

5657
using chopped_value_type = std::array<typename native_field_t::value_type, chopped_elements_amount>;
5758
using non_native_var_t = std::array<var_t, chopped_elements_amount>;
@@ -69,41 +70,44 @@ namespace nil {
6970
// TODO: Check status here?
7071

7172
auto &members = chopping_field_instance.value();
72-
return convert_to_chopped_value_type(members, std::make_index_sequence<chopped_elements_amount>{});
73+
return convert_to_chopped_value_type(members, std::make_index_sequence<chopped_elements_amount> {});
74+
}
75+
76+
private:
77+
using be_field_base_t = marshalling::field_type<marshalling::option::big_endian>;
78+
79+
template<std::size_t bit_length>
80+
using intermediate_t =
81+
crypto3::marshalling::types::pure_field_element<be_field_base_t,
82+
typename native_field_t::value_type,
83+
marshalling::option::fixed_bit_length<bit_length>>;
84+
85+
// We need to reverse the lengths, because that's how the serialization works. Fields are written from
86+
// right to left
87+
template<std::size_t Index>
88+
using intermediate_for_index_t =
89+
intermediate_t<chopped_lengths_storage::values[chopped_elements_amount - Index - 1]>;
90+
91+
template<std::size_t... Indices>
92+
static constexpr std::tuple<intermediate_for_index_t<Indices>...>
93+
generate_bitfield_tuple(std::index_sequence<Indices...>) {
94+
return {};
7395
}
7496

75-
private:
76-
using be_field_base_t = marshalling::field_type<marshalling::option::big_endian>;
77-
78-
template <std::size_t bit_length>
79-
using intermediate_t = crypto3::marshalling::types::pure_field_element<
80-
be_field_base_t,
81-
typename native_field_t::value_type,
82-
marshalling::option::fixed_bit_length<bit_length>
83-
>;
84-
85-
// We need to reverse the lengths, because that's how the serialization works. Fields are written from right to left
86-
template <std::size_t Index>
87-
using intermediate_for_index_t = intermediate_t<chopped_lengths_storage::values[chopped_elements_amount-Index-1]>;
88-
89-
template <std::size_t... Indices>
90-
static constexpr std::tuple<intermediate_for_index_t<Indices>...> generate_bitfield_tuple(std::index_sequence<Indices...>) {
91-
return {};
92-
}
93-
94-
using chopping_field = nil::crypto3::marshalling::types::bitfield<
95-
be_field_base_t,
96-
decltype(generate_bitfield_tuple(std::make_index_sequence<chopped_elements_amount>{}))
97-
>;
98-
99-
template <std::size_t... Indices>
100-
static chopped_value_type convert_to_chopped_value_type(const typename chopping_field::value_type& members, std::index_sequence<Indices...>) {
101-
return {std::get<Indices>(members).value()...};
102-
}
97+
using chopping_field = nil::crypto3::marshalling::types::bitfield<
98+
be_field_base_t,
99+
decltype(generate_bitfield_tuple(std::make_index_sequence<chopped_elements_amount> {}))>;
100+
101+
template<std::size_t... Indices>
102+
static chopped_value_type
103+
convert_to_chopped_value_type(const typename chopping_field::value_type &members,
104+
std::index_sequence<Indices...>) {
105+
return {std::get<Indices>(members).value()...};
106+
}
103107
};
104108

105109
} // namespace detail
106-
} // namespace blueprint
110+
} // namespace blueprint
107111
} // namespace nil
108112

109113
#endif // CRYPTO3_BLUEPRINT_BASIC_NON_NATIVE_POLICY_DETAIL_HPP

test/algebra/fields/plonk/non_native/non_native_policy.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,39 @@
77
#include <nil/blueprint/basic_non_native_policy.hpp>
88
#include <../test/algebra/fields/plonk/non_native/glue_non_native.hpp>
99

10-
1110
using namespace nil;
1211

1312
template<typename NativeFieldType, typename NonNativeFieldType>
14-
void test_chopping(
15-
const typename NonNativeFieldType::value_type& non_native_field_el
16-
) {
13+
void test_chopping(const typename NonNativeFieldType::value_type &non_native_field_el) {
1714
using non_native_policy_type =
18-
blueprint::detail::basic_non_native_policy_field_type<
19-
NativeFieldType,
20-
NonNativeFieldType
21-
>;
15+
blueprint::detail::basic_non_native_policy_field_type<NativeFieldType, NonNativeFieldType>;
2216
using chunked_non_native_type = typename non_native_policy_type::chopped_value_type;
2317

2418
auto chopping_result = non_native_policy_type::chop_non_native(non_native_field_el);
25-
std::cout << std::hex;
19+
std::cout << std::hex;
2620

2721
for (std::size_t i = 0; i < 4; i++) {
2822
std::cout << chopping_result[i].data << " ";
2923
}
3024

31-
assert(
32-
(glue_non_native<
33-
NativeFieldType,
34-
NonNativeFieldType
35-
>(chopping_result)) == non_native_field_el
36-
);
25+
assert((glue_non_native<NativeFieldType, NonNativeFieldType>(chopping_result)) == non_native_field_el);
3726
}
3827

3928
BOOST_AUTO_TEST_SUITE(blueprint_non_native_policy_test_suite)
4029

4130
BOOST_AUTO_TEST_CASE(blueprint_non_native_policy_25519) {
4231
using non_native_field_type = typename crypto3::algebra::curves::ed25519::base_field_type;
4332
using native_field_type = crypto3::algebra::curves::pallas::base_field_type;
33+
test_chopping<native_field_type, non_native_field_type>(0x0);
4434
test_chopping<native_field_type, non_native_field_type>(
45-
0x0
46-
);
47-
test_chopping<native_field_type, non_native_field_type>(
48-
0x274dbce8d15179969bc0d49fa725bddf9de555e0ba6a693c6adb52fc9ee7a82c_cppui252
49-
);
50-
test_chopping<native_field_type, non_native_field_type>(
51-
0x5ce98c61b05f47fe2eae9a542bd99f6b2e78246231640b54595febfd51eb853_cppui252
52-
);
35+
0x274dbce8d15179969bc0d49fa725bddf9de555e0ba6a693c6adb52fc9ee7a82c_cppui252);
5336
test_chopping<native_field_type, non_native_field_type>(
54-
0x2ad46cbfb78773b6254adc1d80c6efa02f3bf948c37e5a2222136421d7bec942_cppui252
55-
);
37+
0x5ce98c61b05f47fe2eae9a542bd99f6b2e78246231640b54595febfd51eb853_cppui252);
5638
test_chopping<native_field_type, non_native_field_type>(
57-
0x14e9693f16d75f7065ce51e1f46ae6c60841ca1e0cf264eda26398e36ca2ed69_cppui252
58-
);
39+
0x2ad46cbfb78773b6254adc1d80c6efa02f3bf948c37e5a2222136421d7bec942_cppui252);
5940
test_chopping<native_field_type, non_native_field_type>(
60-
non_native_field_type::modulus - 1
61-
);
41+
0x14e9693f16d75f7065ce51e1f46ae6c60841ca1e0cf264eda26398e36ca2ed69_cppui252);
42+
test_chopping<native_field_type, non_native_field_type>(non_native_field_type::modulus - 1);
6243
}
6344

6445
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)