diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..eeb37b57 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,14 @@ +try-import user.bazelrc + +# enable platform-based toolchain resolution: +build --incompatible_enable_cc_toolchain_resolution + +build --color=yes +# build --subcommands=pretty_print +# build --verbose_failures +# build --sandbox_debug +# build --toolchain_resolution_debug +# build --show_timestamps +# build --keep_going +# build --jobs 600 +# query --keep_going diff --git a/.gitignore b/.gitignore index add2a728..edb54345 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,11 @@ +.bazel +bazel-* +user.bazelrc + +confdefs.h +config.log +conftest.one +conftest.two + /build/ /.idea/ \ No newline at end of file diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..ab44171f --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,28 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +## PLATFORMS (for cross-platform builds) + +platform( + name = "x86_64-unknown-linux-gnu", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) + +platform( + name = "armv8-rpi3-linux-gnueabihf", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:arm", + ], +) + +platform( + name = "x86_64-linux-musl", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + "//tc:clib_musl", + ], +) diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 00000000..e621ddad --- /dev/null +++ b/WORKSPACE @@ -0,0 +1,53 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +http_archive( + name = "rules_foreign_cc", + strip_prefix="rules_foreign_cc-master", + url = "https://github.com/bazelbuild/rules_foreign_cc/archive/master.zip", + # sha256 = "3fc764c7084da14cff812ae42327d19c8d6e99379f8b3e310b3213e1d5f0e7e8" +) + +load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies") +rules_foreign_cc_dependencies() + +all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])""" + +# ate-pairing already includes libgmp, but Bazel does not yet support +# transitive external deps, so we need to repeat the dep here. +# Specifically, ate-pairing build rules refer to @libgmp, which bazel +# resolves to the root repo, which is determined by this WORKSPACE +# file, rather than the one in the ate-pairing repo. So we need to +# copy ate-pairing's repo rule into this file. The build logic will +# come from ate-pairing; we just need to make the repo available here, +# in the root repo. Build rules for this repo can then refer to +# libgmp using '@libgmp//:libgmp' (here) or '@ate-pairing//:libgmp' (a +# target that indirectly refers to the repo defined here). We use the +# latter, in case Bazel ever gets around to supporting transitive +# workspaces. +http_archive( + name="libgmp", + url="https://gmplib.org/download/gmp/gmp-6.2.0.tar.xz", + sha256="258e6cd51b3fbdfc185c716d55f82c08aff57df0c6fbd143cf6ed561267a1526", + strip_prefix = "gmp-6.2.0", + build_file_content = all_content + # build_file = "@//external:libgmp.BUILD" +) + +http_archive( + name="openssl", + url="https://www.openssl.org/source/openssl-1.1.1g.tar.gz", + sha256="ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46", + strip_prefix="openssl-1.1.1g", + build_file_content = all_content +) + +################################################################ +http_archive( + name = "ate_pairing", + urls = ["https://github.com/obazl/ate-pairing/archive/bazel-e698901.zip"], + strip_prefix = "ate-pairing-bazel-e698901", + sha256 = "26002e265ace5c636af4c22af36deb825b9f70a29c6da7903c5a228b89b75665" +) + + diff --git a/bzl/BUILD.bazel b/bzl/BUILD.bazel new file mode 100644 index 00000000..75ef279c --- /dev/null +++ b/bzl/BUILD.bazel @@ -0,0 +1,33 @@ +load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make") + +configure_make( + name = "openssl", + configure_command = "config", + configure_env_vars = + select({ + "//bzl/host:macos": { "AR": "" }, + "//conditions:default": {} + }), + configure_options = [ + "no-shared", + ] + select({ + "//conditions:default": [], + }), + # select({ + # ":darwin_build": [ + # "shared", + # "ARFLAGS=r", + # "enable-ec_nistp_64_gcc_128", + # "no-ssl2", "no-ssl3", "no-comp" + # ], + # "//conditions:default": [ + # ]}), + # #defines = ["NDEBUG"], Don't know how to use -D; NDEBUG seems to be the default anyway + lib_source = "@openssl//:all", + static_libraries = [ + "libssl.a", + "libcrypto.a", + ], + visibility = ["//visibility:public"], +) + diff --git a/bzl/host/BUILD.bazel b/bzl/host/BUILD.bazel new file mode 100644 index 00000000..bffdafe4 --- /dev/null +++ b/bzl/host/BUILD.bazel @@ -0,0 +1,23 @@ +config_setting( + name = "linux_arm", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:arm", + ] +) + +config_setting( + name = "linux_x64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ] +) + +config_setting( + name = "macos", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ] +) diff --git a/depends/CMakeLists.txt b/depends/CMakeLists.txt deleted file mode 100755 index fa8ccef1..00000000 --- a/depends/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -if(${CURVE} STREQUAL "BN128") - include_directories(ate-pairing/include) - include_directories(xbyak) - add_library( - zm - STATIC - - ate-pairing/src/zm.cpp - ate-pairing/src/zm2.cpp - ) -endif() diff --git a/libff/BUILD.bazel b/libff/BUILD.bazel new file mode 100644 index 00000000..da88b257 --- /dev/null +++ b/libff/BUILD.bazel @@ -0,0 +1,64 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") + +string_flag( + name = "curve", + values = ["bn128", "alt_bn128", "edwards", ""], + build_setting_default = "", +) + +config_setting( + name = "curve_bn128", + flag_values = { + ":curve": "bn128" + } +) + +cc_library( + name = "libff", + visibility = ["//visibility:public"], + # srcs = ["zm.cpp", "zm2.cpp"], + # strip_include_prefix = "bzl", + # include_prefix = "depends/ate-pairing/include", + include_prefix = "depends/ate-pairing/include", + includes = ["depends/ate-pairing/include"], + # srcs = ["foo.cpp", "foo.h"], + hdrs = glob(["external/ate_pairing/include/bn.h", + ]), + # includes = ["external/ate_pairing/include"], + copts = ["-Iexternal/ate_pairing/include", + ], + deps = [ + "@ate_pairing//ate-pairing", + # "@ate_pairing//bzl/third_party:libgmp", + "//libff/algebra/curves/alt_bn128", + "//libff/algebra/curves/edwards", + "//libff/algebra/curves/mnt/mnt4", + "//libff/algebra/curves/mnt/mnt6", + "//libff/common", + ] + select({ + # if(${CURVE} STREQUAL "BN128") + # bazel flag: --//libff:curve=bn128 + "//libff:curve_bn128": ["//libff/algebra/curves/bn128"], + "//conditions:default": [], + }) +) + +# cc_library( +# name = "foobar", +# visibility = ["//libff/algebra/curves/bn128:__pkg__"], +# # srcs = ["zm.cpp", "zm2.cpp"], +# # strip_include_prefix = "bzl", +# # include_prefix = "depends/ate-pairing/include", +# include_prefix = "depends/ate-pairing/include", +# includes = ["depends/ate-pairing/include"], +# srcs = ["foo.cpp", "foo.h"], +# hdrs = glob(["external/ate_pairing/include/bn.h", +# ]) + ["foo.h"], +# # includes = ["external/ate_pairing/include"], +# copts = ["-Iexternal/ate_pairing/include", +# ], +# deps = ["@ate_pairing//src:libzm"] +# # data = ["@ate_pairing//src:libzm"] +# ) diff --git a/libff/algebra/curves/BUILD.bazel b/libff/algebra/curves/BUILD.bazel new file mode 100644 index 00000000..f3dc86ae --- /dev/null +++ b/libff/algebra/curves/BUILD.bazel @@ -0,0 +1,11 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +cc_library( + name = "curves", + visibility = ["//visibility:public"], + hdrs = ["curve_utils.hpp", + "curve_utils.tcc", + "public_params.hpp"], + include_prefix = "libff/algebra/curves", + deps = ["//libff/algebra/fields:bigint"] +) diff --git a/libff/algebra/curves/alt_bn128/BUILD.bazel b/libff/algebra/curves/alt_bn128/BUILD.bazel new file mode 100644 index 00000000..1dc8d631 --- /dev/null +++ b/libff/algebra/curves/alt_bn128/BUILD.bazel @@ -0,0 +1,27 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "alt_bn128", + srcs = [ + "alt_bn128_g1.cpp", + "alt_bn128_g2.cpp", + "alt_bn128_init.cpp", + "alt_bn128_pairing.cpp", + "alt_bn128_pp.cpp", + ], + hdrs = [ + "alt_bn128_g1.hpp", + "alt_bn128_g2.hpp", + "alt_bn128_init.hpp", + "alt_bn128_pairing.hpp", + "alt_bn128_pp.hpp", + ], + copts = ["-I."], + include_prefix = "libff/algebra/curves/alt_bn128", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/curves", + "//libff/algebra/fields", + ], +) diff --git a/libff/algebra/curves/bn128/BUILD.bazel b/libff/algebra/curves/bn128/BUILD.bazel new file mode 100644 index 00000000..1c2147a8 --- /dev/null +++ b/libff/algebra/curves/bn128/BUILD.bazel @@ -0,0 +1,34 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "bn128", + srcs = glob([ + "bn128_g1.cpp", + "bn128_g2.cpp", + "bn128_gt.cpp", + "bn128_init.cpp", + "bn128_pairing.cpp", + "bn128_pp.cpp", + "bn_utils.cpp", + "bn_utils.tcc", + ]), + hdrs = glob([ + "bn128_g1.hpp", + "bn128_g2.hpp", + "bn128_gt.hpp", + "bn128_init.hpp", + "bn128_pairing.hpp", + "bn128_pp.hpp", + "bn_utils.hpp", + "bn_utils.tcc", + ]), + copts = ["-I."], + include_prefix = "libff/algebra/curves/bn128", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/curves", + "//libff/algebra/fields:utils", + "@ate_pairing//ate-pairing", + ], +) diff --git a/libff/algebra/curves/bn128/bn128_g1.hpp b/libff/algebra/curves/bn128/bn128_g1.hpp index 02a4ad0a..cc69e860 100755 --- a/libff/algebra/curves/bn128/bn128_g1.hpp +++ b/libff/algebra/curves/bn128/bn128_g1.hpp @@ -9,7 +9,7 @@ #define BN128_G1_HPP_ #include -#include "depends/ate-pairing/include/bn.h" +#include "ate-pairing/include/bn.h" #include #include diff --git a/libff/algebra/curves/bn128/bn128_g2.hpp b/libff/algebra/curves/bn128/bn128_g2.hpp index df06bf6d..4382b2f1 100755 --- a/libff/algebra/curves/bn128/bn128_g2.hpp +++ b/libff/algebra/curves/bn128/bn128_g2.hpp @@ -10,7 +10,7 @@ #include #include -#include "depends/ate-pairing/include/bn.h" +#include "ate-pairing/include/bn.h" #include #include diff --git a/libff/algebra/curves/bn128/bn128_gt.hpp b/libff/algebra/curves/bn128/bn128_gt.hpp index a4e18548..23a8be85 100755 --- a/libff/algebra/curves/bn128/bn128_gt.hpp +++ b/libff/algebra/curves/bn128/bn128_gt.hpp @@ -9,7 +9,7 @@ #define BN128_GT_HPP_ #include -#include "depends/ate-pairing/include/bn.h" +#include "ate-pairing/include/bn.h" #include #include diff --git a/libff/algebra/curves/bn128/bn128_init.hpp b/libff/algebra/curves/bn128/bn128_init.hpp index dc7fdbf8..e79827c9 100755 --- a/libff/algebra/curves/bn128/bn128_init.hpp +++ b/libff/algebra/curves/bn128/bn128_init.hpp @@ -7,7 +7,7 @@ #ifndef BN128_INIT_HPP_ #define BN128_INIT_HPP_ -#include "depends/ate-pairing/include/bn.h" +#include "ate-pairing/include/bn.h" #include #include diff --git a/libff/algebra/curves/bn128/bn128_pairing.hpp b/libff/algebra/curves/bn128/bn128_pairing.hpp index d5543da4..38f3bc13 100755 --- a/libff/algebra/curves/bn128/bn128_pairing.hpp +++ b/libff/algebra/curves/bn128/bn128_pairing.hpp @@ -10,7 +10,7 @@ #ifndef BN128_PAIRING_HPP_ #define BN128_PAIRING_HPP_ -#include "depends/ate-pairing/include/bn.h" +#include "ate-pairing/include/bn.h" #include #include diff --git a/libff/algebra/curves/bn128/bn_utils.hpp b/libff/algebra/curves/bn128/bn_utils.hpp index b1d21aa1..3428316e 100755 --- a/libff/algebra/curves/bn128/bn_utils.hpp +++ b/libff/algebra/curves/bn128/bn_utils.hpp @@ -9,7 +9,7 @@ #define BN_UTILS_HPP_ #include -#include "depends/ate-pairing/include/bn.h" +#include "ate-pairing/include/bn.h" namespace libff { diff --git a/libff/algebra/curves/edwards/BUILD.bazel b/libff/algebra/curves/edwards/BUILD.bazel new file mode 100644 index 00000000..8f2a6833 --- /dev/null +++ b/libff/algebra/curves/edwards/BUILD.bazel @@ -0,0 +1,27 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "edwards", + srcs = [ + "edwards_g1.cpp", + "edwards_g2.cpp", + "edwards_init.cpp", + "edwards_pairing.cpp", + "edwards_pp.cpp", + ], + hdrs = [ + "edwards_g1.hpp", + "edwards_g2.hpp", + "edwards_init.hpp", + "edwards_pairing.hpp", + "edwards_pp.hpp", + ], + copts = ["-I."], + include_prefix = "libff/algebra/curves/edwards", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/curves", + "//libff/algebra/fields", + ], +) diff --git a/libff/algebra/curves/mnt/BUILD.bazel b/libff/algebra/curves/mnt/BUILD.bazel new file mode 100644 index 00000000..13bb8017 --- /dev/null +++ b/libff/algebra/curves/mnt/BUILD.bazel @@ -0,0 +1,13 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "mnt", + srcs = ["mnt46_common.cpp"], + hdrs = ["mnt46_common.hpp"], + copts = ["-I."], + include_prefix = "libff/algebra/curves/mnt", + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/fields", + ], +) diff --git a/libff/algebra/curves/mnt/mnt4/BUILD.bazel b/libff/algebra/curves/mnt/mnt4/BUILD.bazel new file mode 100644 index 00000000..2698cf3d --- /dev/null +++ b/libff/algebra/curves/mnt/mnt4/BUILD.bazel @@ -0,0 +1,27 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "mnt4", + srcs = glob([ + "mnt4_g1.cpp", + "mnt4_g2.cpp", + "mnt4_init.cpp", + "mnt4_pairing.cpp", + "mnt4_pp.cpp", + ]), + hdrs = [ + "mnt4_g1.hpp", + "mnt4_g2.hpp", + "mnt4_init.hpp", + "mnt4_pairing.hpp", + "mnt4_pp.hpp", + ], + copts = ["-I."], + include_prefix = "libff/algebra/curves/mnt/mnt4", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/curves", + "//libff/algebra/curves/mnt", + ], +) diff --git a/libff/algebra/curves/mnt/mnt6/BUILD.bazel b/libff/algebra/curves/mnt/mnt6/BUILD.bazel new file mode 100644 index 00000000..bea8c75f --- /dev/null +++ b/libff/algebra/curves/mnt/mnt6/BUILD.bazel @@ -0,0 +1,27 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "mnt6", + srcs = glob([ + "mnt6_g1.cpp", + "mnt6_g2.cpp", + "mnt6_init.cpp", + "mnt6_pairing.cpp", + "mnt6_pp.cpp", + ]), + hdrs = glob([ + "mnt6_g1.hpp", + "mnt6_g2.hpp", + "mnt6_init.hpp", + "mnt6_pairing.hpp", + "mnt6_pp.hpp", + ]), + copts = ["-I."], + include_prefix = "libff/algebra/curves/mnt/mnt6", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/curves", + "//libff/algebra/curves/mnt", + ], +) diff --git a/libff/algebra/curves/tests/BUILD.bazel b/libff/algebra/curves/tests/BUILD.bazel new file mode 100644 index 00000000..6508e3e3 --- /dev/null +++ b/libff/algebra/curves/tests/BUILD.bazel @@ -0,0 +1,81 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +CFLAGS_WARN = ["-Wall", "-Wextra", "-Wformat=2", + "-Wcast-qual", "-Wcast-align", "-Wwrite-strings", + "-Wfloat-equal", "-Wpointer-arith"] + +# if ("${IS_LIBFF_PARENT}") +cc_binary( + name = "algebra_bilinearity_test", + visibility = ["//visibility:public"], + srcs = ["test_bilinearity.cpp"], + copts = ["-UNDEBUG", + "-stdlib=libc++", + "-std=c++11", + "-I.", + ] + CFLAGS_WARN, + linkopts = ["-L/usr/local/lib", + "-lgmpxx", + # "-std=c++11", + # "-lstdc++", + # "-Wl,-no_pie", + # "-undefined", + # "dynamic_lookup", + # "-headerpad_max_install_names" + ], + deps = [ + "//libff/algebra/curves/edwards", + "//libff/algebra/curves/mnt/mnt4", + "//libff/algebra/curves/mnt/mnt6", + "//libff/algebra/curves/alt_bn128", + "//libff/algebra/curves", + "//libff/algebra/exponentiation", + "//libff/algebra/fields", + "//libff/algebra/fields:utils", + "//libff/common", + "//libff/common:serialization", + "//libff", + # "@ate_pairing//:libgmp", + # "@//:openssl" + ] +) + +cc_binary( + name = "algebra_groups_test", + visibility = ["//visibility:public"], + srcs = ["test_groups.cpp"], + defines = select({ + "//libff:curve_bn128": ["CURVE_BN128"], + "//conditions:default": [], + }), + copts = ["-UNDEBUG", + "-stdlib=libc++", + "-std=c++11", + "-I." + ] + CFLAGS_WARN, + linkopts = ["-L/usr/local/lib", + "-lgmpxx", + # "-std=c++11", + # "-lstdc++", + # "-Wl,-no_pie", + # "-undefined", + # "dynamic_lookup", + # "-headerpad_max_install_names" + ], + deps = [ + "//libff/algebra/curves/edwards", + "//libff/algebra/curves/mnt/mnt4", + "//libff/algebra/curves/mnt/mnt6", + "//libff/algebra/curves/alt_bn128", + "//libff/algebra/curves", + "//libff/algebra/exponentiation", + "//libff/algebra/fields", + "//libff/algebra/fields:utils", + "//libff/common", + "//libff/common:serialization", + "//libff", + # "@ate_pairing//:libgmp", + # "@//:openssl" + ] +) + diff --git a/libff/algebra/exponentiation/BUILD.bazel b/libff/algebra/exponentiation/BUILD.bazel new file mode 100644 index 00000000..d7440cda --- /dev/null +++ b/libff/algebra/exponentiation/BUILD.bazel @@ -0,0 +1,14 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "exponentiation", + hdrs = [ + "exponentiation.hpp", + "exponentiation.tcc", + ], + include_prefix = "libff/algebra/exponentiation", + visibility = ["//visibility:public"], + deps = [ + "@ate_pairing//:libgmp", + ], +) diff --git a/libff/algebra/fields/BUILD.bazel b/libff/algebra/fields/BUILD.bazel new file mode 100644 index 00000000..a05b6fb4 --- /dev/null +++ b/libff/algebra/fields/BUILD.bazel @@ -0,0 +1,68 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "fields", + hdrs = [ + "bigint.hpp", + "bigint.tcc", + "fp.hpp", + "fp.tcc", + "fp12_2over3over2.hpp", + "fp12_2over3over2.tcc", + "fp2.hpp", + "fp2.tcc", + "fp3.hpp", + "fp3.tcc", + "fp4.hpp", + "fp4.tcc", + "fp6_2over3.hpp", + "fp6_2over3.tcc", + "fp6_3over2.hpp", + "fp6_3over2.tcc", + "fp_aux.tcc", + ], + copts = ["-I."], + include_prefix = "libff/algebra/fields", + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/exponentiation", + "//libff/algebra/scalar_multiplication", + "//libff/common:serialization", + "@ate_pairing//ate-pairing", + ], +) + +cc_library( + name = "bigint", + hdrs = [ + "bigint.hpp", + "bigint.tcc", + ], + copts = ["-I."], + include_prefix = "libff/algebra/fields", + visibility = ["//visibility:public"], + deps = [ + "//libff/common:serialization", + "@ate_pairing//:libgmp", + ], +) + +cc_library( + name = "utils", + hdrs = [ + "bigint.hpp", + "bigint.tcc", + "field_utils.hpp", + "field_utils.tcc", + "fp.hpp", + "fp.tcc", + "fp_aux.tcc", + ], + copts = ["-I."], + include_prefix = "libff/algebra/fields", + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/exponentiation", + "//libff/common:serialization", + ], +) diff --git a/libff/algebra/fields/tests/BUILD.bazel b/libff/algebra/fields/tests/BUILD.bazel new file mode 100644 index 00000000..5f55abdc --- /dev/null +++ b/libff/algebra/fields/tests/BUILD.bazel @@ -0,0 +1,43 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +CFLAGS_WARN = ["-Wall", "-Wextra", "-Wformat=2", + "-Wcast-qual", "-Wcast-align", "-Wwrite-strings", + "-Wfloat-equal", "-Wpointer-arith"] + +cc_binary( + name = "tests", + visibility = ["//visibility:public"], + srcs = ["test_fields.cpp"], + copts = ["-UNDEBUG", + "-stdlib=libc++", + # "-mmacosx-version-min=10.13", + "-std=c++11", + "-I.", + # "-Ilibff/algebra/curves/edwards" + ] + CFLAGS_WARN, + linkopts = ["-L/usr/local/lib", + "-lgmpxx", + # "-std=c++11", + # "-lstdc++", + # "-Wl,-no_pie", + # "-undefined", + # "dynamic_lookup", + # "-headerpad_max_install_names" + ], + deps = [ + # "//libff/algebra/curves/edwards", + # "//libff/algebra/curves/mnt:mnt4", + # "//libff/algebra/curves/mnt:mnt6", + # "//libff/algebra/curves/alt_bn128", + # "//libff/algebra/curves", + # "//libff/algebra/exponentiation", + "//libff/algebra/fields", + "//libff/algebra/fields:utils", + "//libff/common", + "//libff/common:serialization", + "//libff:ff", + # "@ate_pairing//:libgmp", + # "@//:openssl" + ] +) + diff --git a/libff/algebra/scalar_multiplication/BUILD.bazel b/libff/algebra/scalar_multiplication/BUILD.bazel new file mode 100644 index 00000000..398cb5ee --- /dev/null +++ b/libff/algebra/scalar_multiplication/BUILD.bazel @@ -0,0 +1,42 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + +CFLAGS_WARN = [ + "-Wall", + "-Wextra", + "-Wformat=2", + "-Wcast-qual", + "-Wcast-align", + "-Wwrite-strings", + "-Wfloat-equal", + "-Wpointer-arith", +] + +cc_library( + name = "scalar_multiplication", + hdrs = [ + "multiexp.hpp", + "multiexp.tcc", + "wnaf.hpp", + "wnaf.tcc", + ], + copts = ["-I."], + include_prefix = "libff/algebra/scalar_multiplication", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//libff/algebra/curves/bn128", + "//libff/common:rng", + ], +) + +cc_binary( + name = "multiexp_profile", + srcs = ["multiexp_profile.cpp"], + copts = ["-I."] + CFLAGS_WARN, + visibility = ["//visibility:public"], + deps = [ + ":scalar_multiplication", + "//libff/algebra/curves/bn128", + "//libff/common", + ], +) diff --git a/libff/common/BUILD.bazel b/libff/common/BUILD.bazel new file mode 100644 index 00000000..6b7d0898 --- /dev/null +++ b/libff/common/BUILD.bazel @@ -0,0 +1,78 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "common", + srcs = [ + "double.cpp", + "profiling.cpp", + "utils.cpp", + ], + hdrs = [ + "default_types/ec_pp.hpp", + "double.hpp", + "rng.hpp", + "rng.tcc", + "serialization.hpp", + "serialization.tcc", + "template_utils.hpp", + "utils.hpp", + "utils.tcc", + "//libff/algebra/fields:utils", + ], + copts = ["-I."], + defines = [ + "NO_PROCPS", + "CURVE_BN128", + ], + include_prefix = "libff/common", + linkstatic = True, + visibility = ["//visibility:public"], + deps = [ + "//bzl:openssl", + "//libff/algebra/curves/bn128", + "//libff/algebra/fields", + "@ate_pairing//:libgmp", + ], +) + +## headers only: serialization and ran +## packaged separately to avoid circurlar deps. +cc_library( + name = "serialization", + hdrs = [ + "double.hpp", + "profiling.hpp", + "serialization.hpp", + "serialization.tcc", + "utils.hpp", + "utils.tcc", + ], + copts = [ + "-Ilibff/common", + "-Ilibff", + "-I.", + "-Ilibff/algebra/fields", + "-Ilibff/algebra/curves/bn128", + ], + defines = [ + "NO_PROCPS", + "CURVE_BN128", + ], + include_prefix = "libff/common", + visibility = ["//visibility:public"], +) + +cc_library( + name = "rng", + hdrs = [ + "rng.hpp", + "rng.tcc", + ], + defines = [ + "NO_PROCPS", + "CURVE_BN128", + ], + include_prefix = "libff/common", + visibility = ["//visibility:public"], + deps = ["//bzl:openssl"], +)