From 18a346f22b61ac415f23957afeadb8a6b68c7d87 Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 19 Oct 2024 08:14:39 +0800 Subject: [PATCH] repo-sync-2024-10-18T16:46:31+0800 (#408) --- .bazelignore | 1 + .licenserc.yaml | 1 + WORKSPACE | 13 +----- bazel/repositories.bzl | 38 ---------------- examples/.bazelrc | 41 +++++++++++++++++ examples/.bazelversion | 1 + examples/BUILD.bazel | 13 ++++++ examples/WORKSPACE | 63 ++++++++++++++++++++++++++ examples/hesm2/BUILD.bazel | 12 ++--- examples/hesm2/README.md | 6 +-- examples/hesm2/ahesm2.cc | 14 +++--- examples/hesm2/ahesm2.h | 4 +- examples/hesm2/config.cc | 6 +-- examples/hesm2/main.cc | 6 +-- examples/hesm2/private_key.h | 2 +- examples/hesm2/t1.h | 2 +- examples/hesm2/t2.h | 2 +- examples/psi/cpp/BUILD.bazel | 10 ++-- examples/psi/cpp/ecdh_psi.cc | 2 +- examples/psi/cpp/ecdh_psi_main.cc | 4 +- examples/psi/cpp/ecdh_psi_test.cc | 2 +- examples/psi/java/BUILD.bazel | 22 ++++++--- examples/psi/java/ecdh_psi_jni.cc | 6 +-- examples/psi/python/BUILD.bazel | 8 ++-- examples/psi/python/ecdh_psi_pybind.cc | 2 +- examples/psu/BUILD.bazel | 20 ++++---- examples/psu/krtw19_psu.cc | 2 +- examples/psu/krtw19_psu_test.cc | 2 +- examples/repositories.bzl | 48 ++++++++++++++++++++ examples/zkp/BUILD.bazel | 16 +++---- examples/zkp/pedersen_commit.h | 19 ++++---- examples/zkp/pedersen_commit_test.cc | 13 ++++-- examples/zkp/sigma.cc | 5 +- examples/zkp/sigma.h | 6 +-- examples/zkp/sigma_config.cc | 9 ++-- examples/zkp/sigma_config.h | 7 ++- examples/zkp/sigma_owh.cc | 9 ++-- examples/zkp/sigma_owh.h | 9 ++-- examples/zkp/sigma_test.cc | 5 +- 39 files changed, 303 insertions(+), 148 deletions(-) create mode 100644 .bazelignore create mode 100644 examples/.bazelrc create mode 100644 examples/.bazelversion create mode 100644 examples/BUILD.bazel create mode 100644 examples/WORKSPACE create mode 100644 examples/repositories.bzl diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 00000000..1e107f52 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +examples diff --git a/.licenserc.yaml b/.licenserc.yaml index b816d0b9..84362c99 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -35,6 +35,7 @@ header: # <1> - 'LICENSE' - 'NOTICE' - '.bazelversion' + - '.bazelignore' - '.clang-format' - '.clang-tidy' - '.gitattributes' diff --git a/WORKSPACE b/WORKSPACE index 458228ae..269d39c5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -14,6 +14,8 @@ workspace(name = "yacl") +# yacl's dependencies + load("//bazel:repositories.bzl", "yacl_deps") yacl_deps() @@ -22,13 +24,6 @@ load("@rules_python//python:repositories.bzl", "py_repositories") py_repositories() -load("@pybind11_bazel//:python_configure.bzl", "python_configure") - -python_configure( - name = "local_config_python", - python_version = "3", -) - load( "@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies", @@ -47,7 +42,3 @@ bazel_features_deps() load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() - -load("@rules_jni//jni:repositories.bzl", "rules_jni_dependencies") - -rules_jni_dependencies() diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 46da7868..9303e381 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -19,7 +19,6 @@ def yacl_deps(): _rule_proto() _rule_python() _rules_foreign_cc() - _rules_jni() _com_github_madler_zlib() _com_google_protobuf() _com_github_gflags_gflags() @@ -35,9 +34,6 @@ def yacl_deps(): _com_github_msgpack_msgpack() _com_github_greendow_hash_drbg() - _com_github_pybind11_bazel() - _com_github_pybind11() - # ssl _com_github_tongsuo_tongsuo() _com_github_openssl_openssl() @@ -88,29 +84,6 @@ def _org_interconnection(): path = "/opt/homebrew/opt/libomp/", ) -def _com_github_pybind11_bazel(): - maybe( - http_archive, - name = "pybind11_bazel", - sha256 = "dc4882b23a617575d0fd822aba88aa4a14133c3d428b5a8fb83d81d03444a475", - strip_prefix = "pybind11_bazel-8889d39b2b925b2a47519ae09402a96f00ccf2b4", - urls = [ - "https://github.com/pybind/pybind11_bazel/archive/8889d39b2b925b2a47519ae09402a96f00ccf2b4.zip", - ], - ) - -def _com_github_pybind11(): - maybe( - http_archive, - name = "pybind11", - build_file = "@pybind11_bazel//:pybind11.BUILD", - sha256 = "bf8f242abd1abcd375d516a7067490fb71abd79519a282d22b6e4d19282185a7", - strip_prefix = "pybind11-2.12.0", - urls = [ - "https://github.com/pybind/pybind11/archive/refs/tags/v2.12.0.tar.gz", - ], - ) - def _com_github_brpc_brpc(): maybe( http_archive, @@ -314,17 +287,6 @@ def _rules_foreign_cc(): url = "https://github.com/bazelbuild/rules_foreign_cc/releases/download/0.12.0/rules_foreign_cc-0.12.0.tar.gz", ) -def _rules_jni(): - maybe( - http_archive, - name = "rules_jni", - sha256 = "a84863992f425220e1b5e7dfd4663ef1f7c69d63aff6e09a154880744ce0bab0", - strip_prefix = "rules_jni-0.10.1", - urls = [ - "https://github.com/fmeum/rules_jni/archive/refs/tags/v0.10.1.tar.gz", - ], - ) - def _com_github_libsodium(): maybe( http_archive, diff --git a/examples/.bazelrc b/examples/.bazelrc new file mode 100644 index 00000000..7dd7e037 --- /dev/null +++ b/examples/.bazelrc @@ -0,0 +1,41 @@ +# Copyright 2024 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +common --experimental_repo_remote_exec +common --experimental_cc_shared_library + +build --incompatible_new_actions_api=false +build --copt=-fdiagnostics-color=always +build --enable_platform_specific_config + +build --cxxopt=-std=c++17 +build --host_cxxopt=-std=c++17 +build --linkopt -lm + +# Binary safety flags +build --host_copt=-fPIE +build --host_copt=-fstack-protector-strong +build:linux --host_copt=-Wl,-z,noexecstack +build:macos --host_copt=-Wa,--noexecstack + +# platform specific config +# Bazel will automatic pick platform config since we have enable_platform_specific_config set +build:macos --features=-supports_dynamic_linker +build:macos --copt=-Wno-unused-command-line-argument +build:macos --macos_minimum_os=13.0 +build:macos --host_macos_minimum_os=13.0 +build:macos --action_env MACOSX_DEPLOYMENT_TARGET=13.0 + +test --keep_going +test --test_output=errors diff --git a/examples/.bazelversion b/examples/.bazelversion new file mode 100644 index 00000000..f22d756d --- /dev/null +++ b/examples/.bazelversion @@ -0,0 +1 @@ +6.5.0 diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel new file mode 100644 index 00000000..8289c83e --- /dev/null +++ b/examples/BUILD.bazel @@ -0,0 +1,13 @@ +# Copyright 2024 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/examples/WORKSPACE b/examples/WORKSPACE new file mode 100644 index 00000000..09bffb86 --- /dev/null +++ b/examples/WORKSPACE @@ -0,0 +1,63 @@ +# Copyright 2024 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +workspace(name = "yacl-examples") + +new_local_repository( + name = "yacl", + build_file = "BUILD.bazel", + path = "..", +) + +load("//repositories.bzl", "example_deps") + +example_deps() + +load("@yacl//bazel:repositories.bzl", "yacl_deps") + +yacl_deps() + +load("@rules_python//python:repositories.bzl", "py_repositories") + +py_repositories() + +load("@pybind11_bazel//:python_configure.bzl", "python_configure") + +python_configure( + name = "local_config_python", + python_version = "3", +) + +load( + "@rules_foreign_cc//foreign_cc:repositories.bzl", + "rules_foreign_cc_dependencies", +) + +rules_foreign_cc_dependencies( + register_built_tools = False, + register_default_tools = False, + register_preinstalled_tools = True, +) + +load("@bazel_features//:deps.bzl", "bazel_features_deps") + +bazel_features_deps() + +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") + +protobuf_deps() + +load("@rules_jni//jni:repositories.bzl", "rules_jni_dependencies") + +rules_jni_dependencies() diff --git a/examples/hesm2/BUILD.bazel b/examples/hesm2/BUILD.bazel index edaf18be..8df33420 100644 --- a/examples/hesm2/BUILD.bazel +++ b/examples/hesm2/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "yacl_cc_binary") +load("@yacl//bazel:yacl.bzl", "yacl_cc_binary") package(default_visibility = ["//visibility:public"]) @@ -31,10 +31,10 @@ yacl_cc_binary( "t2.h", ], deps = [ - "//yacl/crypto/ecc:spi", - "//yacl/crypto/ecc/openssl", - "//yacl/math/mpint", - "//yacl/utils:cuckoo_index", # 添加 cuckoo_index 依赖 - "//yacl/utils/spi", + "@yacl//yacl/crypto/ecc:spi", + "@yacl//yacl/crypto/ecc/openssl", + "@yacl//yacl/math/mpint", + "@yacl//yacl/utils:cuckoo_index", # 添加 cuckoo_index 依赖 + "@yacl//yacl/utils/spi", ], ) diff --git a/examples/hesm2/README.md b/examples/hesm2/README.md index 17deaad9..38709cfd 100644 --- a/examples/hesm2/README.md +++ b/examples/hesm2/README.md @@ -29,9 +29,9 @@ cd bazel-bin/examples/hesm2 ```cpp #include -#include "examples/hesm2/ahesm2.h" -#include "examples/hesm2/config.h" -#include "examples/hesm2/private_key.h" +#include "hesm2/ahesm2.h" +#include "hesm2/config.h" +#include "hesm2/private_key.h" #include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/math/mpint/mp_int.h" diff --git a/examples/hesm2/ahesm2.cc b/examples/hesm2/ahesm2.cc index 633fad11..1e36eade 100644 --- a/examples/hesm2/ahesm2.cc +++ b/examples/hesm2/ahesm2.cc @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/hesm2/ahesm2.h" +#include "hesm2/ahesm2.h" #include -#include "examples/hesm2/ciphertext.h" -#include "examples/hesm2/config.h" -#include "examples/hesm2/private_key.h" -#include "examples/hesm2/t1.h" -#include "examples/hesm2/t2.h" +#include "hesm2/ciphertext.h" +#include "hesm2/config.h" +#include "hesm2/private_key.h" +#include "hesm2/t1.h" +#include "hesm2/t2.h" #include "yacl/crypto/ecc/ec_point.h" #include "yacl/math/mpint/mp_int.h" @@ -371,4 +371,4 @@ Ciphertext HMul(const Ciphertext& ciphertext1, const yacl::math::MPInt& scalar, auto c2 = ec_group->Mul(ciphertext1.GetC2(), scalar); return Ciphertext{c1, c2}; } -} // namespace examples::hesm2 \ No newline at end of file +} // namespace examples::hesm2 diff --git a/examples/hesm2/ahesm2.h b/examples/hesm2/ahesm2.h index 528f0fc2..4c02483c 100644 --- a/examples/hesm2/ahesm2.h +++ b/examples/hesm2/ahesm2.h @@ -14,8 +14,8 @@ #pragma once -#include "examples/hesm2/ciphertext.h" -#include "examples/hesm2/private_key.h" +#include "hesm2/ciphertext.h" +#include "hesm2/private_key.h" namespace examples::hesm2 { diff --git a/examples/hesm2/config.cc b/examples/hesm2/config.cc index 33b29af9..861447c1 100644 --- a/examples/hesm2/config.cc +++ b/examples/hesm2/config.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/hesm2/config.h" +#include "hesm2/config.h" -#include "examples/hesm2/t1.h" -#include "examples/hesm2/t2.h" +#include "hesm2/t1.h" +#include "hesm2/t2.h" namespace examples::hesm2 { diff --git a/examples/hesm2/main.cc b/examples/hesm2/main.cc index 3aed5de7..9362602f 100644 --- a/examples/hesm2/main.cc +++ b/examples/hesm2/main.cc @@ -14,9 +14,9 @@ #include -#include "examples/hesm2/ahesm2.h" -#include "examples/hesm2/config.h" -#include "examples/hesm2/private_key.h" +#include "hesm2/ahesm2.h" +#include "hesm2/config.h" +#include "hesm2/private_key.h" #include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/math/mpint/mp_int.h" diff --git a/examples/hesm2/private_key.h b/examples/hesm2/private_key.h index fce775ad..1bcc304a 100644 --- a/examples/hesm2/private_key.h +++ b/examples/hesm2/private_key.h @@ -14,7 +14,7 @@ #pragma once -#include "examples/hesm2/public_key.h" +#include "hesm2/public_key.h" #include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/math/mpint/mp_int.h" diff --git a/examples/hesm2/t1.h b/examples/hesm2/t1.h index 495839c6..25ced4f1 100644 --- a/examples/hesm2/t1.h +++ b/examples/hesm2/t1.h @@ -21,7 +21,7 @@ #include #include -#include "examples/hesm2/config.h" +#include "hesm2/config.h" #include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/math/mpint/mp_int.h" diff --git a/examples/hesm2/t2.h b/examples/hesm2/t2.h index d75144ef..8cc8da3d 100644 --- a/examples/hesm2/t2.h +++ b/examples/hesm2/t2.h @@ -20,7 +20,7 @@ #include #include -#include "examples/hesm2/config.h" +#include "hesm2/config.h" #include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/math/mpint/mp_int.h" diff --git a/examples/psi/cpp/BUILD.bazel b/examples/psi/cpp/BUILD.bazel index 4b5566a9..97e681e6 100644 --- a/examples/psi/cpp/BUILD.bazel +++ b/examples/psi/cpp/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "yacl_cc_binary", "yacl_cc_library", "yacl_cc_test") +load("@yacl//bazel:yacl.bzl", "yacl_cc_binary", "yacl_cc_library", "yacl_cc_test") package(default_visibility = ["//visibility:public"]) @@ -25,8 +25,8 @@ yacl_cc_library( "ecdh_psi.h", ], deps = [ - "//yacl/crypto/ecc", - "//yacl/link", + "@yacl//yacl/crypto/ecc", + "@yacl//yacl/link", ], ) @@ -43,10 +43,10 @@ yacl_cc_binary( "main_utils.h", ], data = [ - "//examples/psi:psi_data", + "//psi:psi_data", ], deps = [ ":ecdh_psi", - "//yacl/io/rw:csv_reader", + "@yacl//yacl/io/rw:csv_reader", ], ) diff --git a/examples/psi/cpp/ecdh_psi.cc b/examples/psi/cpp/ecdh_psi.cc index d52192ca..9f28a12c 100644 --- a/examples/psi/cpp/ecdh_psi.cc +++ b/examples/psi/cpp/ecdh_psi.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/psi/cpp/ecdh_psi.h" +#include "psi/cpp/ecdh_psi.h" #include #include diff --git a/examples/psi/cpp/ecdh_psi_main.cc b/examples/psi/cpp/ecdh_psi_main.cc index b0b55af4..d79c11c7 100644 --- a/examples/psi/cpp/ecdh_psi_main.cc +++ b/examples/psi/cpp/ecdh_psi_main.cc @@ -15,9 +15,9 @@ #include #include -#include "examples/psi/cpp/ecdh_psi.h" -#include "examples/psi/cpp/main_utils.h" #include "gflags/gflags.h" +#include "psi/cpp/ecdh_psi.h" +#include "psi/cpp/main_utils.h" #include "yacl/link/context.h" #include "yacl/utils/serialize.h" diff --git a/examples/psi/cpp/ecdh_psi_test.cc b/examples/psi/cpp/ecdh_psi_test.cc index a1421f04..ad89ec0e 100644 --- a/examples/psi/cpp/ecdh_psi_test.cc +++ b/examples/psi/cpp/ecdh_psi_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/psi/cpp/ecdh_psi.h" +#include "psi/cpp/ecdh_psi.h" #include diff --git a/examples/psi/java/BUILD.bazel b/examples/psi/java/BUILD.bazel index 77466272..91118a30 100644 --- a/examples/psi/java/BUILD.bazel +++ b/examples/psi/java/BUILD.bazel @@ -45,10 +45,10 @@ cc_library( name = "jni_wrappers", hdrs = ["jni_wrappers.h"], deps = [ - "//yacl/base:exception", - "//yacl/base:int128", - "//yacl/crypto/hash:hash_utils", - "//yacl/math/mpint", + "@yacl//yacl/base:exception", + "@yacl//yacl/base:int128", + "@yacl//yacl/crypto/hash:hash_utils", + "@yacl//yacl/math/mpint", ], ) @@ -60,7 +60,17 @@ cc_jni_library( deps = [ ":EcdhPsi.hdrs", # the generated headers ":jni_wrappers", - "//examples/psi/cpp:ecdh_psi", - "//yacl/utils:serialize", + "//psi/cpp:ecdh_psi", + "@yacl//yacl/utils:serialize", ], ) + +# To generate a LibEcdhPsi_deploy.jar, simply call +# ------------------------------------------------ +# bazel build //examples/psi/java:LibEcdhPsi_deploy.jar +# +# Then the generated jar file should be located in bazel-out/... +java_binary( + name = "LibEcdhPsi", + runtime_deps = [":EcdhPsi"], +) diff --git a/examples/psi/java/ecdh_psi_jni.cc b/examples/psi/java/ecdh_psi_jni.cc index a5c2b72a..267fe308 100644 --- a/examples/psi/java/ecdh_psi_jni.cc +++ b/examples/psi/java/ecdh_psi_jni.cc @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/psi/cpp/ecdh_psi.h" -#include "examples/psi/java/EcdhPsi.hdrs.h/EcdhPsi.h" -#include "examples/psi/java/jni_wrappers.h" +#include "psi/cpp/ecdh_psi.h" +#include "psi/java/EcdhPsi.hdrs.h/EcdhPsi.h" +#include "psi/java/jni_wrappers.h" #include "yacl/math/mpint/mp_int.h" #include "yacl/utils/serialize.h" diff --git a/examples/psi/python/BUILD.bazel b/examples/psi/python/BUILD.bazel index 35756d5b..a29d56da 100644 --- a/examples/psi/python/BUILD.bazel +++ b/examples/psi/python/BUILD.bazel @@ -33,17 +33,17 @@ pybind_extension( ], linkopts = select({ "@bazel_tools//src/conditions:darwin": [ - "-Wl,-exported_symbols_list,$(location //examples/psi/python:exported_symbols.lds)", + "-Wl,-exported_symbols_list,$(location //psi/python:exported_symbols.lds)", ], "//conditions:default": [ - "-Wl,--version-script,$(location //examples/psi/python:version_script.lds)", + "-Wl,--version-script,$(location //psi/python:version_script.lds)", ], }), deps = [ ":exported_symbols.lds", ":version_script.lds", - "//yacl/crypto/ecc", - "//yacl/crypto/hash:hash_utils", + "@yacl//yacl/crypto/ecc", + "@yacl//yacl/crypto/hash:hash_utils", ], ) diff --git a/examples/psi/python/ecdh_psi_pybind.cc b/examples/psi/python/ecdh_psi_pybind.cc index c38bc5be..ed8bd628 100644 --- a/examples/psi/python/ecdh_psi_pybind.cc +++ b/examples/psi/python/ecdh_psi_pybind.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/psi/python/ecdh_psi_pybind.h" +#include "psi/python/ecdh_psi_pybind.h" #include "pybind11/complex.h" #include "pybind11/functional.h" diff --git a/examples/psu/BUILD.bazel b/examples/psu/BUILD.bazel index fa40f93f..5f73b2c1 100644 --- a/examples/psu/BUILD.bazel +++ b/examples/psu/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_library", "yacl_cc_test") +load("@yacl//bazel:yacl.bzl", "AES_COPT_FLAGS", "yacl_cc_library", "yacl_cc_test") package(default_visibility = ["//visibility:public"]) @@ -26,16 +26,16 @@ yacl_cc_library( ], copts = AES_COPT_FLAGS, deps = [ - "//yacl/base:exception", - "//yacl/base:int128", - "//yacl/crypto/hash:hash_utils", - "//yacl/crypto/rand", - "//yacl/kernel/algorithms:base_ot", - "//yacl/kernel/algorithms:kkrt_ote", - "//yacl/kernel/algorithms:softspoken_ote", - "//yacl/link", - "//yacl/math/galois_field:gf_intrinsic", "@com_google_absl//absl/types:span", + "@yacl//yacl/base:exception", + "@yacl//yacl/base:int128", + "@yacl//yacl/crypto/hash:hash_utils", + "@yacl//yacl/crypto/rand", + "@yacl//yacl/kernel/algorithms:base_ot", + "@yacl//yacl/kernel/algorithms:kkrt_ote", + "@yacl//yacl/kernel/algorithms:softspoken_ote", + "@yacl//yacl/link", + "@yacl//yacl/math/galois_field:gf_intrinsic", ], ) diff --git a/examples/psu/krtw19_psu.cc b/examples/psu/krtw19_psu.cc index 19817cc1..bac16ddb 100644 --- a/examples/psu/krtw19_psu.cc +++ b/examples/psu/krtw19_psu.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/psu/krtw19_psu.h" +#include "psu/krtw19_psu.h" #include #include diff --git a/examples/psu/krtw19_psu_test.cc b/examples/psu/krtw19_psu_test.cc index 3edbef25..92e1ac57 100644 --- a/examples/psu/krtw19_psu_test.cc +++ b/examples/psu/krtw19_psu_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/psu/krtw19_psu.h" +#include "psu/krtw19_psu.h" #include #include diff --git a/examples/repositories.bzl b/examples/repositories.bzl new file mode 100644 index 00000000..5fd03cb1 --- /dev/null +++ b/examples/repositories.bzl @@ -0,0 +1,48 @@ +# Copyright 2024 Ant Group Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") + +def example_deps(): + maybe( + http_archive, + name = "rules_jni", + sha256 = "a84863992f425220e1b5e7dfd4663ef1f7c69d63aff6e09a154880744ce0bab0", + strip_prefix = "rules_jni-0.10.1", + urls = [ + "https://github.com/fmeum/rules_jni/archive/refs/tags/v0.10.1.tar.gz", + ], + ) + + maybe( + http_archive, + name = "pybind11_bazel", + sha256 = "dc4882b23a617575d0fd822aba88aa4a14133c3d428b5a8fb83d81d03444a475", + strip_prefix = "pybind11_bazel-8889d39b2b925b2a47519ae09402a96f00ccf2b4", + urls = [ + "https://github.com/pybind/pybind11_bazel/archive/8889d39b2b925b2a47519ae09402a96f00ccf2b4.zip", + ], + ) + + maybe( + http_archive, + name = "pybind11", + build_file = "@pybind11_bazel//:pybind11.BUILD", + sha256 = "bf8f242abd1abcd375d516a7067490fb71abd79519a282d22b6e4d19282185a7", + strip_prefix = "pybind11-2.12.0", + urls = [ + "https://github.com/pybind/pybind11/archive/refs/tags/v2.12.0.tar.gz", + ], + ) diff --git a/examples/zkp/BUILD.bazel b/examples/zkp/BUILD.bazel index 610b7599..a2be6266 100644 --- a/examples/zkp/BUILD.bazel +++ b/examples/zkp/BUILD.bazel @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -load("//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") +load("@yacl//bazel:yacl.bzl", "yacl_cc_library", "yacl_cc_test") package(default_visibility = ["//visibility:public"]) @@ -23,7 +23,7 @@ yacl_cc_library( ], deps = [ ":sigma_owh", - "//yacl/crypto/hash:hash_utils", + "@yacl//yacl/crypto/hash:hash_utils", ], ) @@ -43,8 +43,8 @@ yacl_cc_library( ], deps = [ ":sigma_owh", - "//yacl/crypto/tools:ro", - "//yacl/utils:parallel", + "@yacl//yacl/crypto/tools:ro", + "@yacl//yacl/utils:parallel", ], ) @@ -53,7 +53,7 @@ yacl_cc_test( srcs = ["sigma_test.cc"], deps = [ ":sigma", - "//yacl/crypto/rand", + "@yacl//yacl/crypto/rand", ], ) @@ -64,8 +64,8 @@ yacl_cc_library( "sigma_config.h", ], deps = [ - "//yacl/crypto/ecc", - "//yacl/crypto/hash:hash_interface", + "@yacl//yacl/crypto/ecc", + "@yacl//yacl/crypto/hash:hash_interface", ], ) @@ -77,6 +77,6 @@ yacl_cc_library( ], deps = [ ":sigma_config", - "//yacl/crypto/rand", + "@yacl//yacl/crypto/rand", ], ) diff --git a/examples/zkp/pedersen_commit.h b/examples/zkp/pedersen_commit.h index 67ba3f09..0ac839fc 100644 --- a/examples/zkp/pedersen_commit.h +++ b/examples/zkp/pedersen_commit.h @@ -14,11 +14,14 @@ #pragma once -#include "examples/zkp/sigma_owh.h" +#include "zkp/sigma_owh.h" #include "yacl/crypto/hash/hash_utils.h" -namespace yacl::crypto { +namespace examples::zkp { + +using namespace yacl::crypto; +using namespace yacl::math; // This is an implementation of Pedersen commitment scheme depended on the // `SigmaOWH`. @@ -70,7 +73,7 @@ class PedersenCommit { // // utility functions // - static MPInt HashInput(ByteContainerView input) { + static MPInt HashInput(yacl::ByteContainerView input) { auto hashed_input = Sha256(input); MPInt input_bn; input_bn.Deserialize(hashed_input); @@ -78,8 +81,8 @@ class PedersenCommit { } static PedersenCommit &GetDefault() { - static std::shared_ptr group = - EcGroupFactory::Instance().Create(kSigmaEcName, ArgLib = kSigmaEcLib); + static std::shared_ptr group = EcGroupFactory::Instance().Create( + kSigmaEcName, yacl::ArgLib = kSigmaEcLib); static PedersenCommit ctx(group); return ctx; } @@ -89,17 +92,17 @@ class PedersenCommit { SigmaGenerator generators_; }; -inline EcPoint PedersenHashAndCommit(const ByteContainerView &input, +inline EcPoint PedersenHashAndCommit(const yacl::ByteContainerView &input, const MPInt &blind) { return PedersenCommit::GetDefault().Commit(PedersenCommit::HashInput(input), blind); } inline bool PedersenHashAndOpen(const EcPoint &commit, - const ByteContainerView &input, + const yacl::ByteContainerView &input, const MPInt &blind) { auto input_bn = PedersenCommit::HashInput(input); return PedersenCommit::GetDefault().Open(commit, input_bn, blind); } -} // namespace yacl::crypto +} // namespace examples::zkp diff --git a/examples/zkp/pedersen_commit_test.cc b/examples/zkp/pedersen_commit_test.cc index 4ee78e8b..566e27b5 100644 --- a/examples/zkp/pedersen_commit_test.cc +++ b/examples/zkp/pedersen_commit_test.cc @@ -12,13 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/zkp/pedersen_commit.h" +#include "zkp/pedersen_commit.h" #include "gtest/gtest.h" #include "yacl/crypto/rand/rand.h" -namespace yacl::crypto { +namespace examples::zkp { + +using namespace yacl::crypto; +using namespace yacl::math; TEST(PedersenCommit, OpenTest) { MPInt blind1; @@ -38,8 +41,8 @@ TEST(PedersenCommit, OpenTest) { } TEST(PedersenCommit, PedersenCommitTest) { - std::shared_ptr group = - EcGroupFactory::Instance().Create(kSigmaEcName, ArgLib = kSigmaEcLib); + std::shared_ptr group = EcGroupFactory::Instance().Create( + kSigmaEcName, yacl::ArgLib = kSigmaEcLib); auto rnd_seed1 = RandBytes(32); auto rnd_seed2 = RandBytes(32); @@ -60,4 +63,4 @@ TEST(PedersenCommit, PedersenCommitTest) { EXPECT_FALSE(ctx.Open(commit, input2, blind2)); } -} // namespace yacl::crypto +} // namespace examples::zkp diff --git a/examples/zkp/sigma.cc b/examples/zkp/sigma.cc index af1e5a96..d63ea93f 100644 --- a/examples/zkp/sigma.cc +++ b/examples/zkp/sigma.cc @@ -12,13 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/zkp/sigma.h" +#include "zkp/sigma.h" #include "yacl/crypto/tools/ro.h" #include "yacl/utils/parallel.h" namespace examples::zkp { +using namespace yacl::crypto; +using namespace yacl::math; + SigmaProtocol::SigmaProtocol(SigmaType type, const std::shared_ptr& group, uint128_t seed, HashToCurveStrategy strategy) diff --git a/examples/zkp/sigma.h b/examples/zkp/sigma.h index d8252a83..f94a3dea 100644 --- a/examples/zkp/sigma.h +++ b/examples/zkp/sigma.h @@ -14,13 +14,13 @@ #pragma once -#include "examples/zkp/sigma_config.h" -#include "examples/zkp/sigma_owh.h" +#include "zkp/sigma_config.h" +#include "zkp/sigma_owh.h" namespace examples::zkp { using namespace yacl::crypto; -using yacl::math::MPInt; +using namespace yacl::math; // We abide an unifying view to implment the common Sigma-type zero-knowledge // proof (ZKP) schemes, in which we view the ZKP schemes as proof of knowledge diff --git a/examples/zkp/sigma_config.cc b/examples/zkp/sigma_config.cc index 608431f6..b458f6e4 100644 --- a/examples/zkp/sigma_config.cc +++ b/examples/zkp/sigma_config.cc @@ -12,9 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/zkp/sigma_config.h" +#include "zkp/sigma_config.h" -namespace yacl::crypto { +namespace examples::zkp { + +using namespace yacl::crypto; +using namespace yacl::math; // 0 means n, user should assign these to actual numbers const std::vector kSigmaConfig = { @@ -138,4 +141,4 @@ SigmaConfig GetSeveralDlog(uint64_t num) { return GetSigmaConfig(SigmaType::SeveralDlog).SetDynNum(num); } -} // namespace yacl::crypto +} // namespace examples::zkp diff --git a/examples/zkp/sigma_config.h b/examples/zkp/sigma_config.h index aa1221ed..99f173ac 100644 --- a/examples/zkp/sigma_config.h +++ b/examples/zkp/sigma_config.h @@ -17,7 +17,10 @@ #include "yacl/crypto/ecc/ecc_spi.h" #include "yacl/crypto/hash/hash_interface.h" -namespace yacl::crypto { +namespace examples::zkp { + +using namespace yacl::crypto; +using namespace yacl::math; // EC-based Sigma proof systems should be implemented over prime-order ecc // groups. @@ -132,4 +135,4 @@ struct SigmaShortProof { Challenge challenge; }; -} // namespace yacl::crypto +} // namespace examples::zkp diff --git a/examples/zkp/sigma_owh.cc b/examples/zkp/sigma_owh.cc index 5878a3c2..1f8c47ec 100644 --- a/examples/zkp/sigma_owh.cc +++ b/examples/zkp/sigma_owh.cc @@ -12,9 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/zkp/sigma_owh.h" +#include "zkp/sigma_owh.h" -namespace yacl::crypto { +namespace examples::zkp { + +using namespace yacl::crypto; +using namespace yacl::math; const std::string kSigmaDefaultSeedPrefix = "YACL-SIGMA-PROOF-SEED"; @@ -108,4 +111,4 @@ SigmaStatement SigmaOWH::ToStatement(const SigmaConfig& config, } } -} // namespace yacl::crypto +} // namespace examples::zkp diff --git a/examples/zkp/sigma_owh.h b/examples/zkp/sigma_owh.h index 6102d2d9..546d0805 100644 --- a/examples/zkp/sigma_owh.h +++ b/examples/zkp/sigma_owh.h @@ -14,12 +14,15 @@ #pragma once -#include "examples/zkp/sigma_config.h" +#include "zkp/sigma_config.h" #include "yacl/crypto/ecc/group_sketch.h" #include "yacl/crypto/rand/rand.h" -namespace yacl::crypto { +namespace examples::zkp { + +using namespace yacl::crypto; +using namespace yacl::math; // As we abide an unifying view to implement the Sigma-type zero-knowledge // proof (ZKP) schemes, in which a one-way group homomorphism(OWH) would @@ -40,4 +43,4 @@ class SigmaOWH { const Witness& witness); }; -} // namespace yacl::crypto +} // namespace examples::zkp diff --git a/examples/zkp/sigma_test.cc b/examples/zkp/sigma_test.cc index 28b4b722..22e452d7 100644 --- a/examples/zkp/sigma_test.cc +++ b/examples/zkp/sigma_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "examples/zkp/sigma.h" +#include "zkp/sigma.h" #include "gtest/gtest.h" @@ -20,6 +20,9 @@ namespace examples::zkp { +using namespace yacl::crypto; +using namespace yacl::math; + namespace { Witness GenRandomWitness(const std::shared_ptr& group, uint32_t num) {