Skip to content

Commit

Permalink
Merge pull request #24 from NilFoundation/multiprecision_changes
Browse files Browse the repository at this point in the history
Changes related to creation of a modular backend in multiprecision [SyncWith: crypto3-multiprecision#70]
  • Loading branch information
martun authored May 15, 2024
2 parents 17b641d + e483deb commit 0afb3af
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ on:
jobs:
call-reusable-workflow:
name: Call Reusable Testing Callback Workflow
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-publish-result.yml@v1
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-publish-result.yml@v1.2.1
42 changes: 42 additions & 0 deletions .github/workflows/pull-request-action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Reusable PR testing for mac and linux

on:
workflow_call:
inputs:
targets:
type: string
description: "Make and CTest targets. If not specified, everything is tested"
required: false

jobs:
handle-syncwith:
name: Call Reusable SyncWith Handler
uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1.2.1
with:
ci-cd-ref: 'v1.2.1'
secrets: inherit

matrix-test-linux:
name: Linux Reusable Crypto3 Testing
needs:
- handle-syncwith
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-testing-linux.yml@v1.2.1

secrets: inherit
with:
submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }}

targets: ${{ inputs.targets }}

matrix-test-mac:
name: Mac Reusable Crypto3 Testing
needs:
- handle-syncwith
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-testing-mac.yml@v1.2.1

secrets: inherit
with:
submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }}

targets: ${{ inputs.targets }}

16 changes: 3 additions & 13 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,8 @@ on:
- synchronize

jobs:
handle-syncwith:
name: Call Reusable SyncWith Handler
uses: NilFoundation/ci-cd/.github/workflows/reusable-handle-syncwith.yml@v1
with:
ci-cd-ref: 'v1'
secrets: inherit
run-pull-request-actions:
name: Reusable Crypto3 Testing
uses: ./.github/workflows/pull-request-action.yml

matrix-test:
name: Call Reusable Crypto3 Testing
needs:
- handle-syncwith
uses: NilFoundation/ci-cd/.github/workflows/reusable-crypto3-testing.yml@v1
with:
submodules-refs: ${{ needs.handle-syncwith.outputs.prs-refs }}
secrets: inherit
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ namespace nil {
std::is_same<bool, typename std::iterator_traits<TIter>::value_type>::value,
nil::marshalling::status_type>::type
process(const group_value_type &point, TIter &iter) {
auto X_affine =
static_cast<typename group_value_type::field_type::integral_type>(point.to_affine().X.data);
auto X_affine = static_cast<typename group_value_type::field_type::integral_type>(
point.to_affine().X.data);
for (std::size_t i = 0; i < params_type::bit_length(); ++i) {
*iter++ = bit_test(X_affine, 0);
X_affine >>= 1;
Expand Down Expand Up @@ -708,7 +708,7 @@ namespace nil {
integral_type x = read_data<sizeof_field_element, integral_type, endianness>(iter);

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

g2_field_value_type x_mod(x_0, x_1);
g2_field_value_type y2_mod = x_mod.pow(3) + g2_field_value_type(4, 4);
g2_field_value_type y2_mod = x_mod.pow(3u) + g2_field_value_type(4u, 4u);
BOOST_ASSERT(y2_mod.is_square());
g2_field_value_type y_mod = y2_mod.sqrt();
bool Y_bit = detail::sign_gf_p<g2_field_type>(y_mod);
Expand Down Expand Up @@ -1249,7 +1249,8 @@ namespace nil {
u = field_type::value_type::zero();
} else {
u = fraction.sqrt();
if (u == field_type::value_type(field_type::modulus - 1)) {
// Sqrt now returns 0 on error. We will change this when proper error handling is implemented.
if (u == field_type::value_type::zero()) {
return nil::marshalling::status_type::invalid_msg_data;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace nil {
typename std::enable_if<algebra::is_extended_field<G2FieldType>::value, bool>::type
sign_gf_p(const typename G2FieldType::value_type &v) {

if (v.data[1] == 0) {
if (v.data[1] == 0u) {
return sign_gf_p<typename G2FieldType::underlying_field_type>(v.data[0]);
}
return sign_gf_p<typename G2FieldType::underlying_field_type>(v.data[1]);
Expand Down Expand Up @@ -113,9 +113,9 @@ namespace nil {
assert(!sign);
return group_affine_value_type(base_field_value_type::zero(), y);
}
base_field_value_type x = x2.pow((base_field_type::modulus + 3) / 8);
base_field_value_type x = x2.pow((base_field_type::modulus + 3u) / 8);
if (!(x * x - x2).is_zero()) {
x = x * base_field_value_type(2).pow((base_field_type::modulus - 1) / 4);
x = x * base_field_value_type(2u).pow((base_field_type::modulus - 1u) / 4);
// TODO: throw catchable error, for example return status
assert((x * x - x2).is_zero());
}
Expand Down
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ macro(define_marshalling_test name)

endif()
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(${test_name} PRIVATE "-fconstexpr-steps=2147483647")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${test_name} PRIVATE "-fconstexpr-ops-limit=4294967295")
endif()

endmacro()

set(TESTS_NAMES
Expand Down
2 changes: 1 addition & 1 deletion test/curve_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <boost/random/uniform_int.hpp>
#include <iostream>
#include <iomanip>
#include <nil/crypto3/multiprecision/number.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/marshalling/status_type.hpp>
#include <nil/marshalling/field_type.hpp>
Expand Down
4 changes: 2 additions & 2 deletions test/field_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down
4 changes: 2 additions & 2 deletions test/field_element_non_fixed_size_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <nil/marshalling/field_type.hpp>
#include <nil/marshalling/endianness.hpp>

#include <nil/crypto3/multiprecision/cpp_int.hpp>
#include <nil/crypto3/multiprecision/number.hpp>
#include <nil/crypto3/multiprecision/cpp_int_modular.hpp>
#include <boost/multiprecision/number.hpp>

#include <nil/crypto3/algebra/random_element.hpp>
#include <nil/crypto3/algebra/curves/bls12.hpp>
Expand Down

0 comments on commit 0afb3af

Please sign in to comment.