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

Commit 8e3ae3c

Browse files
committed
Use policy's chop_non_native for tests instead of hardcoded
1 parent 1621171 commit 8e3ae3c

File tree

6 files changed

+63
-48
lines changed

6 files changed

+63
-48
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
4545
#include <nil/blueprint/components/algebra/fields/plonk/non_native/addition.hpp>
4646

47-
#include <../test/algebra/fields/plonk/non_native/chop_and_glue_non_native.hpp>
47+
#include <../test/algebra/fields/plonk/non_native/glue_non_native.hpp>
4848

4949
#include "../../../../test_plonk_component.hpp"
5050

@@ -95,10 +95,16 @@ void test_field_add(std::vector<typename BlueprintFieldType::value_type> public_
9595

9696
template <typename FieldType, typename NonNativeFieldType>
9797
void test_field_add_useable(typename NonNativeFieldType::value_type a, typename NonNativeFieldType::value_type b){
98-
using chunked_non_native_type = std::array<typename FieldType::value_type, 4>;
99-
chunked_non_native_type first = chop_non_native<FieldType, NonNativeFieldType>(a);
100-
chunked_non_native_type second = chop_non_native<FieldType, NonNativeFieldType>(b);
101-
chunked_non_native_type expected_result = chop_non_native<FieldType, NonNativeFieldType>(a + b);
98+
using non_native_policy_type =
99+
blueprint::detail::basic_non_native_policy_field_type<
100+
FieldType,
101+
NonNativeFieldType
102+
>;
103+
using chunked_non_native_type = typename non_native_policy_type::chopped_value_type;
104+
105+
chunked_non_native_type first = non_native_policy_type::chop_non_native(a);
106+
chunked_non_native_type second = non_native_policy_type::chop_non_native(b);
107+
chunked_non_native_type expected_result = non_native_policy_type::chop_non_native(a + b);
102108
std::vector<typename FieldType::value_type> public_input = create_public_input<FieldType, NonNativeFieldType>(first, second);
103109
test_field_add<FieldType, NonNativeFieldType>(public_input, expected_result);
104110
}
@@ -146,4 +152,4 @@ BOOST_AUTO_TEST_CASE(blueprint_non_native_addition_pallas) {
146152
test_field_add_all_cases<field_type, non_native_field_type>();
147153
}
148154

149-
BOOST_AUTO_TEST_SUITE_END()
155+
BOOST_AUTO_TEST_SUITE_END()

test/algebra/fields/plonk/non_native/chop_and_glue_non_native.hpp renamed to test/algebra/fields/plonk/non_native/glue_non_native.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
template<typename FieldType, typename NonNativeFieldType>
2-
std::array<typename FieldType::value_type, 4> chop_non_native(typename NonNativeFieldType::value_type input) {
3-
typename NonNativeFieldType::integral_type input_integral = typename NonNativeFieldType::integral_type(input.data);
4-
5-
std::array<typename FieldType::value_type, 4> output;
6-
7-
typename NonNativeFieldType::integral_type base = 1;
8-
typename NonNativeFieldType::integral_type mask = (base << 66) - 1;
9-
10-
output[0] = input_integral & mask;
11-
output[1] = (input_integral >> 66) & mask;
12-
output[2] = (input_integral >> 132) & mask;
13-
output[3] = (input_integral >> 198) & mask;
14-
15-
return output;
16-
}
17-
181
template<typename FieldType, typename NonNativeFieldType>
192
typename NonNativeFieldType::value_type glue_non_native(std::array<typename FieldType::value_type, 4> input) {
203
typename NonNativeFieldType::integral_type base = 1;
@@ -56,4 +39,4 @@ std::vector<typename FieldType::value_type>
5639
public_input.push_back(b[i]);
5740
}
5841
return public_input;
59-
}
42+
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include <nil/blueprint/components/algebra/fields/plonk/non_native/multiplication.hpp>
4444

4545
#include <nil/crypto3/random/algebraic_engine.hpp>
46-
#include <../test/algebra/fields/plonk/non_native/chop_and_glue_non_native.hpp>
46+
#include <../test/algebra/fields/plonk/non_native/glue_non_native.hpp>
4747

4848
#include "../../../../test_plonk_component.hpp"
4949

@@ -137,10 +137,15 @@ BOOST_AUTO_TEST_SUITE(blueprint_plonk_test_suite)
137137

138138
template<typename FieldType, typename NonNativeFieldType>
139139
void test_field_mul_useable(typename NonNativeFieldType::value_type a, typename NonNativeFieldType::value_type b) {
140-
using chunked_non_native_type = std::array<typename FieldType::value_type, 4>;
141-
chunked_non_native_type first = chop_non_native<FieldType, NonNativeFieldType>(a);
142-
chunked_non_native_type second = chop_non_native<FieldType, NonNativeFieldType>(b);
143-
chunked_non_native_type expected_result = chop_non_native<FieldType, NonNativeFieldType>(a * b);
140+
using non_native_policy_type =
141+
blueprint::detail::basic_non_native_policy_field_type<
142+
FieldType,
143+
NonNativeFieldType
144+
>;
145+
using chunked_non_native_type = typename non_native_policy_type::chopped_value_type;
146+
chunked_non_native_type first = non_native_policy_type::chop_non_native(a);
147+
chunked_non_native_type second = non_native_policy_type::chop_non_native(b);
148+
chunked_non_native_type expected_result = non_native_policy_type::chop_non_native(a * b);
144149
std::vector<typename FieldType::value_type> public_input =
145150
create_public_input<FieldType, NonNativeFieldType>(first, second);
146151
test_field_mul<FieldType, NonNativeFieldType>(public_input, expected_result);
@@ -203,4 +208,4 @@ BOOST_AUTO_TEST_CASE(blueprint_non_native_multiplication_pallas) {
203208
test_field_mul_all_cases<field_type, non_native_field_type>();
204209
}
205210

206-
BOOST_AUTO_TEST_SUITE_END()
211+
BOOST_AUTO_TEST_SUITE_END()

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <nil/blueprint/components/algebra/fields/plonk/non_native/range.hpp>
4040

4141
#include <nil/crypto3/random/algebraic_engine.hpp>
42-
#include <../test/algebra/fields/plonk/non_native/chop_and_glue_non_native.hpp>
42+
#include <../test/algebra/fields/plonk/non_native/glue_non_native.hpp>
4343

4444
#include "../../../../test_plonk_component.hpp"
4545

@@ -98,21 +98,27 @@ BOOST_AUTO_TEST_SUITE(blueprint_plonk_test_suite)
9898
BOOST_AUTO_TEST_CASE(blueprint_non_native_range_test0) {
9999
using non_native_field_type = typename crypto3::algebra::fields::curve25519_base_field;
100100
using field_type = crypto3::algebra::curves::pallas::base_field_type;
101+
using non_native_policy_type =
102+
blueprint::detail::basic_non_native_policy_field_type<
103+
field_type,
104+
non_native_field_type
105+
>;
106+
using chunked_non_native_type = typename non_native_policy_type::chopped_value_type;
101107

102108
test_field_range<typename crypto3::algebra::curves::pallas::base_field_type>(
103109
{455245345345345, 523553453454343, 68753453534534689, 54355345344544}, true);
104110

105111
test_field_range<typename crypto3::algebra::curves::pallas::base_field_type>(
106112
create_public_input_1_value<field_type, non_native_field_type>(
107-
chop_non_native<field_type, non_native_field_type>(1)
113+
non_native_policy_type::chop_non_native(1)
108114
), true);
109115
test_field_range<typename crypto3::algebra::curves::pallas::base_field_type>(
110116
create_public_input_1_value<field_type, non_native_field_type>(
111-
chop_non_native<field_type, non_native_field_type>(0)
117+
non_native_policy_type::chop_non_native(0)
112118
), true);
113119
test_field_range<typename crypto3::algebra::curves::pallas::base_field_type>(
114120
create_public_input_1_value<field_type, non_native_field_type>(
115-
chop_non_native<field_type, non_native_field_type>(-1)
121+
non_native_policy_type::chop_non_native(-1)
116122
), true);
117123

118124
nil::crypto3::random::algebraic_engine<non_native_field_type> rand;
@@ -122,7 +128,7 @@ BOOST_AUTO_TEST_CASE(blueprint_non_native_range_test0) {
122128
for (std::size_t i = 0; i < 10; i++) {
123129
test_field_range<field_type>(
124130
create_public_input_1_value<field_type, non_native_field_type>(
125-
chop_non_native<field_type, non_native_field_type>(rand())
131+
non_native_policy_type::chop_non_native(rand())
126132
), true);
127133
}
128134
}
@@ -141,4 +147,4 @@ BOOST_AUTO_TEST_CASE(blueprint_non_native_range_test_must_fail) {
141147

142148
}
143149

144-
BOOST_AUTO_TEST_SUITE_END()
150+
BOOST_AUTO_TEST_SUITE_END()

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <nil/blueprint/blueprint/plonk/assignment.hpp>
4343
#include <nil/blueprint/components/algebra/fields/plonk/non_native/subtraction.hpp>
4444

45-
#include <../test/algebra/fields/plonk/non_native/chop_and_glue_non_native.hpp>
45+
#include <../test/algebra/fields/plonk/non_native/glue_non_native.hpp>
4646
#include <nil/crypto3/random/algebraic_engine.hpp>
4747

4848
#include "../../../../test_plonk_component.hpp"
@@ -125,10 +125,15 @@ BOOST_AUTO_TEST_SUITE(blueprint_plonk_test_suite)
125125

126126
template <typename FieldType, typename NonNativeFieldType>
127127
void test_field_sub_useable(typename NonNativeFieldType::value_type a, typename NonNativeFieldType::value_type b){
128-
using chunked_non_native_type = std::array<typename FieldType::value_type, 4>;
129-
chunked_non_native_type first = chop_non_native<FieldType, NonNativeFieldType>(a);
130-
chunked_non_native_type second = chop_non_native<FieldType, NonNativeFieldType>(b);
131-
chunked_non_native_type expected_result = chop_non_native<FieldType, NonNativeFieldType>(a - b);
128+
using non_native_policy_type =
129+
blueprint::detail::basic_non_native_policy_field_type<
130+
FieldType,
131+
NonNativeFieldType
132+
>;
133+
using chunked_non_native_type = typename non_native_policy_type::chopped_value_type;
134+
chunked_non_native_type first = non_native_policy_type::chop_non_native(a);
135+
chunked_non_native_type second = non_native_policy_type::chop_non_native(b);
136+
chunked_non_native_type expected_result = non_native_policy_type::chop_non_native(a - b);
132137
std::vector<typename FieldType::value_type> public_input = create_public_input<FieldType, NonNativeFieldType>(first, second);
133138
test_field_sub<FieldType, NonNativeFieldType>(public_input, expected_result);
134139
}
@@ -182,4 +187,4 @@ BOOST_AUTO_TEST_CASE(blueprint_non_native_subtraction_pallas) {
182187
test_field_sub_all_cases<field_type, non_native_field_type>();
183188
}
184189

185-
BOOST_AUTO_TEST_SUITE_END()
190+
BOOST_AUTO_TEST_SUITE_END()

test/non_native/plonk/bool_scalar_multiplication.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <nil/crypto3/algebra/curves/ed25519.hpp>
3333
#include <nil/crypto3/algebra/fields/arithmetic_params/ed25519.hpp>
3434
#include <nil/crypto3/random/algebraic_engine.hpp>
35-
#include <../test/algebra/fields/plonk/non_native/chop_and_glue_non_native.hpp>
35+
#include <../test/algebra/fields/plonk/non_native/glue_non_native.hpp>
3636

3737
#include <nil/crypto3/hash/keccak.hpp>
3838

@@ -157,14 +157,24 @@ void test_bool_scalar_multiplication(const std::vector<typename BlueprintFieldTy
157157

158158
template<typename FieldType, typename NonNativeCurveType>
159159
void test_bool_scalar_multiplication_usable(
160-
typename NonNativeCurveType::template g1_type<crypto3::algebra::curves::coordinates::affine>::value_type point,
160+
typename NonNativeCurveType::template g1_type<
161+
crypto3::algebra::curves::coordinates::affine
162+
>::value_type point,
161163
typename FieldType::value_type scalar_bool,
162-
const bool expected_to_pass) {
164+
const bool expected_to_pass
165+
) {
166+
167+
using non_native_policy_type =
168+
blueprint::detail::basic_non_native_policy_field_type<
169+
FieldType,
170+
typename NonNativeCurveType::base_field_type
171+
>;
163172

164173
std::vector<typename FieldType::value_type> public_input =
165174
create_public_input<FieldType, typename NonNativeCurveType::base_field_type>(
166-
chop_non_native<FieldType, typename NonNativeCurveType::base_field_type>(point.X),
167-
chop_non_native<FieldType, typename NonNativeCurveType::base_field_type>(point.Y));
175+
non_native_policy_type::chop_non_native(point.X),
176+
non_native_policy_type::chop_non_native(point.Y)
177+
);
168178

169179
std::vector<typename FieldType::value_type> expected_res;
170180
if (scalar_bool == 1) {
@@ -220,4 +230,4 @@ BOOST_AUTO_TEST_CASE(blueprint_non_native_bool_scalar_mul_must_fail) {
220230
test_bool_scalar_multiplication_usable<field_type, non_native_curve_type>(rand(), -1, false);
221231
}
222232

223-
BOOST_AUTO_TEST_SUITE_END()
233+
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)