Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency com_github_herumi_mcl to v1.99 #339

Merged
merged 9 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bazel/mcl.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
load("@yacl//bazel:yacl.bzl", "yacl_cmake_external")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "make")
load("@bazel_skylib//lib:selects.bzl", "selects")

package(default_visibility = ["//visibility:public"])

Expand Down
86 changes: 75 additions & 11 deletions bazel/patches/mcl.patch
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b54b261..5c1f14c7 100644
index f2ee05c5..8fcb4f23 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -145,6 +145,10 @@ target_compile_options(mcl_st PRIVATE ${MCL_COMPILE_OPTIONS})
# target_compile_features(mcl PUBLIC cxx_std_11)
# target_compile_features(mcl_st PUBLIC cxx_std_11)
@@ -134,6 +134,11 @@ endif()
target_compile_options(mcl PRIVATE ${MCL_COMPILE_OPTIONS})
target_compile_options(mcl_st PRIVATE ${MCL_COMPILE_OPTIONS})

+set(TARGET_FLAG "")
+if(DEFINED CMAKE_ANDROID_ARCH_LLVM_TRIPLE)
+ set(TARGET_FLAG "--target=${CMAKE_ANDROID_ARCH_LLVM_TRIPLE}")
+endif()

# use bint-x64 on x64, bint${BIT}.ll on the other CPU
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
@@ -163,16 +167,16 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
target_sources(mcl PRIVATE src/asm/bint-x64-amd64.S)
target_sources(mcl_st PRIVATE src/asm/bint-x64-amd64.S)
+
# set_target_properties(mcl PROPERTIES
# CXX_STANDARD 11
# CXX_STANDARD_REQUIRED YES
@@ -168,16 +173,16 @@ elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
target_sources(mcl_st PRIVATE src/asm/bint-x64-amd64.S)
endif()
else()
- if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
- message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ..")
Expand All @@ -34,7 +35,7 @@ index 2b54b261..5c1f14c7 100644
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(gen_bint.o
SOURCES ${BINT_OBJ})
@@ -199,7 +203,7 @@ elseif(${MCL_USE_LLVM})
@@ -210,7 +215,7 @@ elseif(${MCL_USE_LLVM})
target_compile_definitions(mcl_st PUBLIC MCL_USE_LLVM=1)

add_custom_command(OUTPUT ${BASE_OBJ}
Expand All @@ -43,6 +44,69 @@ index 2b54b261..5c1f14c7 100644
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_custom_target(gen_base.o
SOURCES ${BASE_OBJ})
@@ -222,7 +227,7 @@ elseif(${MCL_USE_LLVM})
endif()

# use src/msm_avx.cpp on x64
-if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
+# if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
# set(MSM_OBJ "${CMAKE_CURRENT_BINARY_DIR}/msm_avx.obj")

# add_custom_command(OUTPUT ${MSM_OBJ}
@@ -236,20 +241,20 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
# add_dependencies(mcl_st msm_avx.o)
# target_sources(mcl_st PRIVATE ${MSM_OBJ})

-elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
- set(MSM_OBJ "${CMAKE_CURRENT_BINARY_DIR}/msm_avx.o")
-
- add_custom_command(OUTPUT ${MSM_OBJ}
- COMMAND ${CMAKE_CXX_COMPILER} -c -o ${MSM_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/msm_avx.cpp ${MCL_COMPILE_OPTIONS} -I ${CMAKE_CURRENT_SOURCE_DIR}/include -mavx512f -mavx512ifma -std=c++11 -fno-exceptions -fno-rtti -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
- add_custom_target(msm_avx.o
- SOURCES ${MSM_OBJ})
- target_link_libraries(mcl PUBLIC ${MSM_OBJ})
- add_dependencies(mcl msm_avx.o)
- target_link_libraries(mcl_st PUBLIC ${MSM_OBJ})
- add_dependencies(mcl_st msm_avx.o)
- target_sources(mcl_st PRIVATE ${MSM_OBJ})
-endif()
+# elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
+# set(MSM_OBJ "${CMAKE_CURRENT_BINARY_DIR}/msm_avx.o")
+
+# add_custom_command(OUTPUT ${MSM_OBJ}
+# COMMAND ${CMAKE_CXX_COMPILER} -c -o ${MSM_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/msm_avx.cpp ${MCL_COMPILE_OPTIONS} -I ${CMAKE_CURRENT_SOURCE_DIR}/include -mavx512f -mavx512ifma -std=c++11 -fno-exceptions -fno-rtti -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG
+# WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
+# add_custom_target(msm_avx.o
+# SOURCES ${MSM_OBJ})
+# target_link_libraries(mcl PUBLIC ${MSM_OBJ})
+# add_dependencies(mcl msm_avx.o)
+# target_link_libraries(mcl_st PUBLIC ${MSM_OBJ})
+# add_dependencies(mcl_st msm_avx.o)
+# target_sources(mcl_st PRIVATE ${MSM_OBJ})
+# endif()

if(MCL_TEST_WITH_GMP)
if(NOT MSVC)
diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp
index 5bf4bc7b..1da38f1d 100644
--- a/include/mcl/op.hpp
+++ b/include/mcl/op.hpp
@@ -411,13 +411,7 @@ inline void dump(const std::string& s)

} } // mcl::fp

-#ifndef MCL_MSM
- #if (/*defined(_WIN64) ||*/ defined(__x86_64__)) && !defined(__APPLE__) && (MCL_SIZEOF_UNIT == 8)
- #define MCL_MSM 1
- #else
- #define MCL_MSM 0
- #endif
-#endif
+#define MCL_MSM 0

#if MCL_MSM == 1
namespace mcl { namespace msm {
diff --git a/Makefile b/Makefile
index a60dbf59..0d27036b 100644
--- a/Makefile
Expand Down
6 changes: 3 additions & 3 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,15 @@ def _com_github_herumi_mcl():
maybe(
http_archive,
name = "com_github_herumi_mcl",
strip_prefix = "mcl-1.88",
sha256 = "7fcc630c008e973dda88dd1d1cd2bb14face95ee3ed3b2f717fbb25d340d6ba5",
strip_prefix = "mcl-1.99",
sha256 = "5ff9702c1f1b021925d1334ca0a03c87783174075aeaf87801842d3c08b3d39e",
type = "tar.gz",
build_file = "@yacl//bazel:mcl.BUILD",
patch_args = ["-p1"],
patches = [
"@yacl//bazel:patches/mcl.patch",
],
urls = ["https://github.com/herumi/mcl/archive/refs/tags/v1.88.tar.gz"],
urls = ["https://github.com/herumi/mcl/archive/refs/tags/v1.99.tar.gz"],
)

def _lib25519():
Expand Down
22 changes: 11 additions & 11 deletions yacl/crypto/ecc/mcl/mcl_ec_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ std::map<CurveName, int> Name2MclCurveEnum = {
{"secp160k1", MCL_SECP160K1},
};

#define CASE_DEFINE(mcl_curve_macro, class_name) \
case mcl_curve_macro: { \
static auto generator = [&] { \
auto p = std::make_shared<class_name::Ec>(); \
mcl::initCurve<class_name::Ec, class_name::Fr>( \
curve_type, p.get(), mcl::fp::Mode::FP_AUTO, mcl::ec::Jacobi); \
return p; \
}(); \
YACL_ENFORCE(!generator->isZero()); \
return std::unique_ptr<EcGroup>( \
new class_name(meta, curve_type, AnyPtr(generator))); \
#define CASE_DEFINE(mcl_curve_macro, class_name) \
case mcl_curve_macro: { \
static auto generator = [&] { \
auto p = std::make_shared<class_name::Ec>(); \
mcl::initCurve<class_name::Ec>(curve_type, p.get(), \
mcl::fp::Mode::FP_AUTO, mcl::ec::Jacobi); \
return p; \
}(); \
YACL_ENFORCE(!generator->isZero()); \
return std::unique_ptr<EcGroup>( \
new class_name(meta, curve_type, AnyPtr(generator))); \
}

std::unique_ptr<EcGroup> MclEGFactory::Create(const CurveMeta& meta) {
Expand Down
2 changes: 1 addition & 1 deletion yacl/crypto/ecc/mcl/mcl_ec_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MclEGFactory {
template <typename Fp_, typename Zn_>
class MclGroupT : public EcGroupSketch {
public:
using Ec = mcl::EcT<Fp_>;
using Ec = mcl::EcT<Fp_, Zn_>;
using Fr = Zn_;
using Fp = Fp_;
using BaseFp = typename Fp::BaseFp;
Expand Down
4 changes: 3 additions & 1 deletion yacl/math/galois_field/factory/mcl_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ std::unique_ptr<GaloisField> MclFieldFactory::Create(
new MclField<mcl::Fp6T<mcl::FpT<mcl::FpTag, 512>>, 6>(mod));
case 12:
return std::unique_ptr<GaloisField>(
new MclField<mcl::Fp12T<mcl::FpT<mcl::FpTag, 512>>, 12>(mod));
new MclField<mcl::Fp12T<mcl::FpT<mcl::FpTag, 512>,
mcl::FpT<mcl::bn::local::FrTag, 512>>,
12>(mod));
default:
YACL_THROW("Not supported Field by {}", kMclLib);
}
Expand Down
7 changes: 6 additions & 1 deletion yacl/math/galois_field/factory/mcl_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#include "yacl/math/galois_field/factory/gf_scalar.h"

namespace mcl::bn::local {
struct FrTag;
}

namespace yacl::math {

class MclFieldFactory {
Expand Down Expand Up @@ -121,6 +125,7 @@ using DefaultFp = mcl::FpT<>; // size 512
using FpWithSize256 = mcl::FpT<mcl::FpTag, 256>; // Max element size 256 bits
using DefaultFp2 = mcl::Fp2T<mcl::FpT<>>;
using DefaultFp6 = mcl::Fp6T<mcl::FpT<>>;
using DefaultFp12 = mcl::Fp12T<mcl::FpT<>>; // size 512
using DefaultFp12 =
mcl::Fp12T<mcl::FpT<>, mcl::FpT<mcl::bn::local::FrTag>>; // size 512

} // namespace yacl::math
Loading