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

Commit 0afb3af

Browse files
authored
Merge pull request #24 from NilFoundation/multiprecision_changes
Changes related to creation of a modular backend in multiprecision [SyncWith: crypto3-multiprecision#70]
2 parents 17b641d + e483deb commit 0afb3af

9 files changed

+67
-27
lines changed

.github/workflows/publish-results.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ on:
1010
jobs:
1111
call-reusable-workflow:
1212
name: Call Reusable Testing Callback Workflow
13-
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-publish-result.yml@v1
13+
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-publish-result.yml@v1.2.1
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Reusable PR testing for mac and linux
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
targets:
7+
type: string
8+
description: "Make and CTest targets. If not specified, everything is tested"
9+
required: false
10+
11+
jobs:
12+
handle-syncwith:
13+
name: Call Reusable SyncWith Handler
14+
uses: NilFoundation/ci-cd/.github/workflows/[email protected]
15+
with:
16+
ci-cd-ref: 'v1.2.1'
17+
secrets: inherit
18+
19+
matrix-test-linux:
20+
name: Linux Reusable Crypto3 Testing
21+
needs:
22+
- handle-syncwith
23+
uses: NilFoundation/ci-cd/.github/workflows/[email protected]
24+
25+
secrets: inherit
26+
with:
27+
submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }}
28+
29+
targets: ${{ inputs.targets }}
30+
31+
matrix-test-mac:
32+
name: Mac Reusable Crypto3 Testing
33+
needs:
34+
- handle-syncwith
35+
uses: NilFoundation/ci-cd/.github/workflows/[email protected]
36+
37+
secrets: inherit
38+
with:
39+
submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }}
40+
41+
targets: ${{ inputs.targets }}
42+

.github/workflows/pull-request.yml

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,8 @@ on:
77
- synchronize
88

99
jobs:
10-
handle-syncwith:
11-
name: Call Reusable SyncWith Handler
12-
uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1
13-
with:
14-
ci-cd-ref: 'v1'
15-
secrets: inherit
10+
run-pull-request-actions:
11+
name: Reusable Crypto3 Testing
12+
uses: ./.github/workflows/pull-request-action.yml
1613

17-
matrix-test:
18-
name: Call Reusable Crypto3 Testing
19-
needs:
20-
- handle-syncwith
21-
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-testing.yml@v1
22-
with:
23-
submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }}
2414
secrets: inherit

include/nil/crypto3/marshalling/algebra/processing/curve_element.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ namespace nil {
653653
std::is_same<bool, typename std::iterator_traits<TIter>::value_type>::value,
654654
nil::marshalling::status_type>::type
655655
process(const group_value_type &point, TIter &iter) {
656-
auto X_affine =
657-
static_cast<typename group_value_type::field_type::integral_type>(point.to_affine().X.data);
656+
auto X_affine = static_cast<typename group_value_type::field_type::integral_type>(
657+
point.to_affine().X.data);
658658
for (std::size_t i = 0; i < params_type::bit_length(); ++i) {
659659
*iter++ = bit_test(X_affine, 0);
660660
X_affine >>= 1;
@@ -708,7 +708,7 @@ namespace nil {
708708
integral_type x = read_data<sizeof_field_element, integral_type, endianness>(iter);
709709

710710
g1_field_value_type x_mod(x);
711-
g1_field_value_type y2_mod = x_mod.pow(3) + g1_field_value_type(4);
711+
g1_field_value_type y2_mod = x_mod.pow(3u) + g1_field_value_type(4u);
712712
BOOST_ASSERT(y2_mod.is_square());
713713
g1_field_value_type y_mod = y2_mod.sqrt();
714714
bool Y_bit = detail::sign_gf_p<g1_field_type>(y_mod);
@@ -775,7 +775,7 @@ namespace nil {
775775
integral_type x_0 = read_data<sizeof_field_element, integral_type, endianness>(read_iter);
776776

777777
g2_field_value_type x_mod(x_0, x_1);
778-
g2_field_value_type y2_mod = x_mod.pow(3) + g2_field_value_type(4, 4);
778+
g2_field_value_type y2_mod = x_mod.pow(3u) + g2_field_value_type(4u, 4u);
779779
BOOST_ASSERT(y2_mod.is_square());
780780
g2_field_value_type y_mod = y2_mod.sqrt();
781781
bool Y_bit = detail::sign_gf_p<g2_field_type>(y_mod);
@@ -1249,7 +1249,8 @@ namespace nil {
12491249
u = field_type::value_type::zero();
12501250
} else {
12511251
u = fraction.sqrt();
1252-
if (u == field_type::value_type(field_type::modulus - 1)) {
1252+
// Sqrt now returns 0 on error. We will change this when proper error handling is implemented.
1253+
if (u == field_type::value_type::zero()) {
12531254
return nil::marshalling::status_type::invalid_msg_data;
12541255
}
12551256
}

include/nil/crypto3/marshalling/algebra/processing/detail/curve_element.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace nil {
6464
typename std::enable_if<algebra::is_extended_field<G2FieldType>::value, bool>::type
6565
sign_gf_p(const typename G2FieldType::value_type &v) {
6666

67-
if (v.data[1] == 0) {
67+
if (v.data[1] == 0u) {
6868
return sign_gf_p<typename G2FieldType::underlying_field_type>(v.data[0]);
6969
}
7070
return sign_gf_p<typename G2FieldType::underlying_field_type>(v.data[1]);
@@ -113,9 +113,9 @@ namespace nil {
113113
assert(!sign);
114114
return group_affine_value_type(base_field_value_type::zero(), y);
115115
}
116-
base_field_value_type x = x2.pow((base_field_type::modulus + 3) / 8);
116+
base_field_value_type x = x2.pow((base_field_type::modulus + 3u) / 8);
117117
if (!(x * x - x2).is_zero()) {
118-
x = x * base_field_value_type(2).pow((base_field_type::modulus - 1) / 4);
118+
x = x * base_field_value_type(2u).pow((base_field_type::modulus - 1u) / 4);
119119
// TODO: throw catchable error, for example return status
120120
assert((x * x - x2).is_zero());
121121
}

test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ macro(define_marshalling_test name)
5454

5555
endif()
5656
endif()
57+
58+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
59+
target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647")
60+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
61+
target_compile_options(${test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
62+
endif()
63+
5764
endmacro()
5865

5966
set(TESTS_NAMES

test/curve_element.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <boost/random/uniform_int.hpp>
3333
#include <iostream>
3434
#include <iomanip>
35-
#include <nil/crypto3/multiprecision/number.hpp>
35+
#include <boost/multiprecision/number.hpp>
3636

3737
#include <nil/marshalling/status_type.hpp>
3838
#include <nil/marshalling/field_type.hpp>

test/field_element.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
#include <nil/marshalling/field_type.hpp>
3737
#include <nil/marshalling/endianness.hpp>
3838

39-
#include <nil/crypto3/multiprecision/cpp_int.hpp>
40-
#include <nil/crypto3/multiprecision/number.hpp>
39+
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
40+
#include <boost/multiprecision/number.hpp>
4141

4242
#include <nil/crypto3/algebra/random_element.hpp>
4343
#include <nil/crypto3/algebra/curves/bls12.hpp>

test/field_element_non_fixed_size_container.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
#include <nil/marshalling/field_type.hpp>
3838
#include <nil/marshalling/endianness.hpp>
3939

40-
#include <nil/crypto3/multiprecision/cpp_int.hpp>
41-
#include <nil/crypto3/multiprecision/number.hpp>
40+
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
41+
#include <boost/multiprecision/number.hpp>
4242

4343
#include <nil/crypto3/algebra/random_element.hpp>
4444
#include <nil/crypto3/algebra/curves/bls12.hpp>

0 commit comments

Comments
 (0)