From 918a85ecb1a7aeac6b657228ee91402a2f6fb77c Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Sun, 7 Mar 2021 10:56:04 -0800 Subject: [PATCH 01/27] correct relic nightly cron --- .github/workflows/relic-nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/relic-nightly.yml b/.github/workflows/relic-nightly.yml index f4a208d655f55a..1e2428fa56e6c5 100644 --- a/.github/workflows/relic-nightly.yml +++ b/.github/workflows/relic-nightly.yml @@ -2,7 +2,7 @@ name: Build and Test C++ with Relic Nightly on: schedule: - - cron: "* 14 * * *" + - cron: "0 11 * * *" workflow_dispatch: jobs: From 9cc86295dc2db34549f38f748c9f66e8d3e3bbf8 Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Sun, 7 Mar 2021 11:41:28 -0800 Subject: [PATCH 02/27] record which commit was built --- .github/workflows/relic-nightly.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/relic-nightly.yml b/.github/workflows/relic-nightly.yml index 1e2428fa56e6c5..b6863ce4cfe5d8 100644 --- a/.github/workflows/relic-nightly.yml +++ b/.github/workflows/relic-nightly.yml @@ -51,3 +51,4 @@ jobs: cmake --build . -- -j 6 echo "Running ./src/runtest" ./src/runtest + git log -n 1 --format=fuller From 5b020f95a816715cea5efc1c2439f6bc1f8081d0 Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Sun, 7 Mar 2021 12:32:38 -0800 Subject: [PATCH 03/27] Correctly grab relic commit sha --- .github/workflows/relic-nightly.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/relic-nightly.yml b/.github/workflows/relic-nightly.yml index b6863ce4cfe5d8..63e0421618cd2e 100644 --- a/.github/workflows/relic-nightly.yml +++ b/.github/workflows/relic-nightly.yml @@ -51,4 +51,6 @@ jobs: cmake --build . -- -j 6 echo "Running ./src/runtest" ./src/runtest - git log -n 1 --format=fuller + curl -H "application/vnd.github.v3.sha" \ + https://api.github.com/repos/relic-toolkit/relic/commits/master | \ + head -10 From 618514634dd29223f67866f42682f34cb745a8d1 Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Sun, 7 Mar 2021 12:40:46 -0800 Subject: [PATCH 04/27] grab the relic commit first for failures --- .github/workflows/relic-nightly.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/relic-nightly.yml b/.github/workflows/relic-nightly.yml index 63e0421618cd2e..7286cdfc4eb556 100644 --- a/.github/workflows/relic-nightly.yml +++ b/.github/workflows/relic-nightly.yml @@ -27,6 +27,10 @@ jobs: - name: Ubuntu build C++ and test Relic at origin/master if: startsWith(matrix.os, 'ubuntu') run: | + echo "Relic origin/master commit:" + curl -H "application/vnd.github.v3.sha" \ + https://api.github.com/repos/relic-toolkit/relic/commits/master | \ + head -10 sudo apt-get update sudo apt-get install snap -y sudo apt-get remove --purge cmake -y @@ -51,6 +55,3 @@ jobs: cmake --build . -- -j 6 echo "Running ./src/runtest" ./src/runtest - curl -H "application/vnd.github.v3.sha" \ - https://api.github.com/repos/relic-toolkit/relic/commits/master | \ - head -10 From 8f19ab71dab3664f7054b94773ed4febb004cec2 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Mon, 8 Mar 2021 21:56:18 +0100 Subject: [PATCH 05/27] git|contrib: Drop relic submodule This is just confusing because its the `Chia-Network` fork and its not really related to the relic version that cmake pulls. --- .gitmodules | 3 --- contrib/relic | 1 - 2 files changed, 4 deletions(-) delete mode 160000 contrib/relic diff --git a/.gitmodules b/.gitmodules index c21c793e7a4b21..a00504bd4f7268 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "contrib/pybind11"] path = contrib/pybind11 url = https://github.com/pybind/pybind11.git -[submodule "contrib/relic"] - path = contrib/relic - url = https://github.com/Chia-Network/relic diff --git a/contrib/relic b/contrib/relic deleted file mode 160000 index 6e90cdd3b003b8..00000000000000 --- a/contrib/relic +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6e90cdd3b003b84861ebb3c5982a4722b6c069b4 From aa515f705338d0e18594fb339c504f2827326dfe Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 5 Mar 2021 17:50:10 +0100 Subject: [PATCH 06/27] cmake: Only include GMP_INCLUDES if gmp has been found Otherwise it fails with the following if gmp wasn't found: CMake Error in src/CMakeLists.txt: Found relative path while evaluating include directories of : "GMP_INCLUDES-NOTFOUND" --- python-bindings/CMakeLists.txt | 5 ++++- src/CMakeLists.txt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/python-bindings/CMakeLists.txt b/python-bindings/CMakeLists.txt index df8a414bcc510e..255e3bbae5bbdd 100644 --- a/python-bindings/CMakeLists.txt +++ b/python-bindings/CMakeLists.txt @@ -17,9 +17,12 @@ include_directories( ${relic_SOURCE_DIR}/include ${relic_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch - ${GMP_INCLUDES} ) +if (GMP_FOUND) + include_directories(${GMP_INCLUDES}) +endif(GMP_FOUND) + pybind11_add_module(blspy ${CMAKE_CURRENT_SOURCE_DIR}/pythonbindings.cpp) if (SODIUM_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e0f1f7f3e9957a..e4a3ec05b384d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,9 +27,12 @@ include_directories( ${relic_SOURCE_DIR}/include ${relic_BINARY_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch - ${GMP_INCLUDES} ) +if (GMP_FOUND) + include_directories(${GMP_INCLUDES}) +endif(GMP_FOUND) + set(C_LIB ${CMAKE_BINARY_DIR}/libbls.a) add_library(bls ${CMAKE_CURRENT_SOURCE_DIR}/privatekey.cpp) From c2b1eaa7cd376cf06fd6787e4c5ce08126a2cb7e Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 5 Mar 2021 17:50:10 +0100 Subject: [PATCH 07/27] cmake: Drop broken gmp include This seems to be broken because `GMP_INCLUDE_DIR` isn't set at all by `Findgmp.cmake`, it sets `GMP_INCLUDES` instead. It's however set by relic's script which isn't configured at this point though. If you want to keep this include it should be `include_directories(${GMP_INCLUDES})` rather i guess? --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f8ffbd0c9fa25..7a8b8f02318942 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ set(STBIN TRUE) find_package(gmp) if (GMP_FOUND) message(STATUS "Found libgmp") - include_directories(${GMP_INCLUDE_DIR}) set(ARITH "gmp" CACHE STRING "") else() set(ARITH "easy" CACHE STRING "") From 4e3ff76a0dd4b28509dbdaa8164a9b734404856c Mon Sep 17 00:00:00 2001 From: xdustinface Date: Sat, 6 Mar 2021 15:12:07 +0100 Subject: [PATCH 08/27] cmake: Install relic headers into chiabls I think this should be done because chiabls depends on how relic was configure. --- src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e4a3ec05b384d8..b4a49a318ebcd3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,6 +81,8 @@ set_target_properties(combined ) file(GLOB includes "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") +install(DIRECTORY ${relic_SOURCE_DIR}/include/ DESTINATION include/chiabls) +install(DIRECTORY ${relic_BINARY_DIR}/include/ DESTINATION include/chiabls) install(FILES ${includes} DESTINATION include/chiabls) install(FILES ${C_LIB} DESTINATION lib) From 7995e3da33c2444ef8ddd6b28e0bb16a3584a34b Mon Sep 17 00:00:00 2001 From: xdustinface Date: Fri, 5 Mar 2021 19:13:39 +0100 Subject: [PATCH 09/27] cmake: Make blspy optional --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a8b8f02318942..42b5670a3d80f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,9 @@ ENDIF() project(BLS) +set(BUILD_BLS_PYTHON_BINDINGS 1 CACHE INTEGER "") +message(STATUS "Build python bindings: ${BUILD_BLS_PYTHON_BINDINGS}") + # Add path for custom modules set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} @@ -89,5 +92,7 @@ if (EMSCRIPTEN) else() # emscripten can't build python bindings, it produces only javascript # add_subdirectory(contrib/pybind11) - add_subdirectory(python-bindings) + if (BUILD_BLS_PYTHON_BINDINGS) + add_subdirectory(python-bindings) + endif() endif() From 2213db51ba8edd2671d85db7008131a027fa1a58 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Sat, 6 Mar 2021 22:15:40 +0100 Subject: [PATCH 10/27] cmake: Make runbench/runtest optional --- CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42b5670a3d80f5..e7b192702e90bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,12 @@ ENDIF() project(BLS) set(BUILD_BLS_PYTHON_BINDINGS 1 CACHE INTEGER "") +set(BUILD_BLS_TESTS 1 CACHE INTEGER "") +set(BUILD_BLS_BENCHMARKS 1 CACHE INTEGER "") + message(STATUS "Build python bindings: ${BUILD_BLS_PYTHON_BINDINGS}") +message(STATUS "Build tests: ${BUILD_BLS_TESTS}") +message(STATUS "Build benchmarks: ${BUILD_BLS_BENCHMARKS}") # Add path for custom modules set(CMAKE_MODULE_PATH diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4a49a318ebcd3..acc9497825e916 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,7 +26,6 @@ include_directories( ${INCLUDE_DIRECTORIES} ${relic_SOURCE_DIR}/include ${relic_BINARY_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch ) if (GMP_FOUND) @@ -86,13 +85,21 @@ install(DIRECTORY ${relic_BINARY_DIR}/include/ DESTINATION include/chiabls) install(FILES ${includes} DESTINATION include/chiabls) install(FILES ${C_LIB} DESTINATION lib) -add_executable(runtest test.cpp) -add_executable(runbench test-bench.cpp) +if (BUILD_BLS_TESTS) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/catch) + add_executable(runtest test.cpp) + if (SODIUM_FOUND) + target_link_libraries(runtest blstmp relic_s sodium) + else() + target_link_libraries(runtest blstmp relic_s) + endif() +endif() -if (SODIUM_FOUND) - target_link_libraries(runtest blstmp relic_s sodium) - target_link_libraries(runbench blstmp relic_s sodium) -else() - target_link_libraries(runtest blstmp relic_s) - target_link_libraries(runbench blstmp relic_s) +if (BUILD_BLS_BENCHMARKS) + add_executable(runbench test-bench.cpp) + if (SODIUM_FOUND) + target_link_libraries(runbench blstmp relic_s sodium) + else() + target_link_libraries(runbench blstmp relic_s) + endif() endif() From 6f12363a8b41f69aacb5d94aaa4c1a8fb6ee3b7b Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Mon, 8 Mar 2021 18:21:55 -0800 Subject: [PATCH 11/27] Typo in CMakeLists.txt --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index acc9497825e916..322ce0cb41998e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ else () set(RELIC_GIT_TAG "9384f1c80cb80878aaafa7a64b7a6703d8d94f4c") endif () -message(STATUS "Relic will be build from: ${RELIC_GIT_TAG}") +message(STATUS "Relic will be built from: ${RELIC_GIT_TAG}") FetchContent_Declare( relic From 79e772315def72010f1168c0d8faca2b3d1480f9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 9 Mar 2021 02:20:20 +0000 Subject: [PATCH 12/27] build(deps): bump elliptic from 6.5.3 to 6.5.4 in /js-bindings Bumps [elliptic](https://github.com/indutny/elliptic) from 6.5.3 to 6.5.4. - [Release notes](https://github.com/indutny/elliptic/releases) - [Commits](https://github.com/indutny/elliptic/compare/v6.5.3...v6.5.4) Signed-off-by: dependabot[bot] --- js-bindings/package-lock.json | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/js-bindings/package-lock.json b/js-bindings/package-lock.json index 736292d1fd4cfb..91b39c06a40930 100644 --- a/js-bindings/package-lock.json +++ b/js-bindings/package-lock.json @@ -1322,24 +1322,30 @@ "dev": true }, "elliptic": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.3.tgz", - "integrity": "sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", "dev": true, "requires": { - "bn.js": "^4.4.0", - "brorand": "^1.0.1", + "bn.js": "^4.11.9", + "brorand": "^1.1.0", "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.0", - "inherits": "^2.0.1", - "minimalistic-assert": "^1.0.0", - "minimalistic-crypto-utils": "^1.0.0" + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" }, "dependencies": { "bn.js": { - "version": "4.11.9", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.9.tgz", - "integrity": "sha512-E6QoYqCKZfgatHTdHzs1RRKP7ip4vvm+EyRUeE2RF0NblwVvb0p6jSVeNTOFxPn26QXN2o6SMfNxKp6kU8zQaw==", + "version": "4.12.0", + "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "dev": true + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true } } From 82dabf5402a1d0c43f522c23222371d97f1f631c Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Tue, 9 Mar 2021 15:50:27 -0800 Subject: [PATCH 13/27] Update to Relic @ master 03a7c3b7fa43c0da6f3720e341f7d4f6a6d6f21e specifically --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 322ce0cb41998e..c9e1056ec8cdb4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ include(FetchContent) if (DEFINED ENV{RELIC_MASTER}) set(RELIC_GIT_TAG "origin/master") else () - set(RELIC_GIT_TAG "9384f1c80cb80878aaafa7a64b7a6703d8d94f4c") + set(RELIC_GIT_TAG "03a7c3b7fa43c0da6f3720e341f7d4f6a6d6f21e") endif () message(STATUS "Relic will be built from: ${RELIC_GIT_TAG}") From e095a3ea0d92c0f59725d37cc582188b0e659a2e Mon Sep 17 00:00:00 2001 From: Gene Hoffman Date: Wed, 10 Mar 2021 14:28:48 -0800 Subject: [PATCH 14/27] Move to main branch - clean up for 1.0 RC --- .github/workflows/build-aarch64.yml | 2 +- .github/workflows/build-test.yaml | 2 +- .github/workflows/build-wheels.yml | 2 +- .github/workflows/relic-nightly.yml | 4 +- .gitmodules | 3 - README.md | 63 ++++++----- python-bindings/README.md | 18 ++- python-bindings/test.py | 14 ++- python-impl/README.md | 6 +- python-impl/ec.py | 6 +- python-impl/fields.py | 1 + python-impl/hd_keys.py | 2 +- python-impl/hkdf.py | 4 +- python-impl/impl-test.py | 26 ++--- python-impl/op_swu_g2.py | 4 +- python-impl/pairing.py | 9 +- python-impl/private_key.py | 3 +- python-impl/schemes.py | 16 +-- setup.py | 170 +++++++++++++++------------- 19 files changed, 188 insertions(+), 167 deletions(-) delete mode 100644 .gitmodules diff --git a/.github/workflows/build-aarch64.yml b/.github/workflows/build-aarch64.yml index d31005c398543d..91ee2612eb4064 100644 --- a/.github/workflows/build-aarch64.yml +++ b/.github/workflows/build-aarch64.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Cancel previous runs on the same branch - if: ${{ github.ref != 'refs/heads/master' }} + if: ${{ github.ref != 'refs/heads/main' }} uses: styfle/cancel-workflow-action@0.7.0 with: access_token: ${{ github.token }} diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 6cc379489750c7..e27cdde961542b 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -13,7 +13,7 @@ jobs: steps: - name: Cancel previous runs on the same branch - if: ${{ github.ref != 'refs/heads/master' }} + if: ${{ github.ref != 'refs/heads/main' }} uses: styfle/cancel-workflow-action@0.7.0 with: access_token: ${{ github.token }} diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 27dd2c1a397e67..7abf5ca7fb09a6 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -13,7 +13,7 @@ jobs: steps: - name: Cancel previous runs on the same branch - if: ${{ github.ref != 'refs/heads/master' }} + if: ${{ github.ref != 'refs/heads/main' }} uses: styfle/cancel-workflow-action@0.7.0 with: access_token: ${{ github.token }} diff --git a/.github/workflows/relic-nightly.yml b/.github/workflows/relic-nightly.yml index 7286cdfc4eb556..854436e2c767c4 100644 --- a/.github/workflows/relic-nightly.yml +++ b/.github/workflows/relic-nightly.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Cancel previous runs on the same branch - if: ${{ github.ref != 'refs/heads/master' }} + if: ${{ github.ref != 'refs/heads/main' }} uses: styfle/cancel-workflow-action@0.7.0 with: access_token: ${{ github.token }} @@ -30,7 +30,7 @@ jobs: echo "Relic origin/master commit:" curl -H "application/vnd.github.v3.sha" \ https://api.github.com/repos/relic-toolkit/relic/commits/master | \ - head -10 + head -10 sudo apt-get update sudo apt-get install snap -y sudo apt-get remove --purge cmake -y diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index a00504bd4f7268..00000000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "contrib/pybind11"] - path = contrib/pybind11 - url = https://github.com/pybind/pybind11.git diff --git a/README.md b/README.md index 910598c022a998..03f5031f757127 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,15 @@ [![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/Chia-Network/bls-signatures.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/bls-signatures/context:python) [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/Chia-Network/bls-signatures.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Chia-Network/bls-signatures/context:cpp) -NOTE: THIS LIBRARY IS A DRAFT AND NOT YET REVIEWED FOR SECURITY +NOTE: THIS LIBRARY IS NOT YET FORMALLY REVIEWED FOR SECURITY NOTE: THIS LIBRARY WAS SHIFTED TO THE IETF BLS SPECIFICATION ON 7/16/20 Implements BLS signatures with aggregation using [relic toolkit](https://github.com/relic-toolkit/relic) -for cryptographic primitives (pairings, EC, hashing) according to the [IETF BLS RFC](https://datatracker.ietf.org/doc/draft-irtf-cfrg-bls-signature/) with [these curve parameters](https://datatracker.ietf.org/doc/draft-irtf-cfrg-pairing-friendly-curves/) for BLS12-381. +for cryptographic primitives (pairings, EC, hashing) according to the +[IETF BLS RFC](https://datatracker.ietf.org/doc/draft-irtf-cfrg-bls-signature/) +with [these curve parameters](https://datatracker.ietf.org/doc/draft-irtf-cfrg-pairing-friendly-curves/) +for BLS12-381. Features: @@ -23,14 +26,15 @@ Features: * Works on Windows, Mac, Linux, BSD * Efficient verification using Proof of Posssesion (only one pairing per distinct message) * Aggregate public keys and private keys -* EIP-2333 key derivation (including unhardened BIP-32-like keys) +* [EIP-2333](https://eips.ethereum.org/EIPS/eip-2333) key derivation (including unhardened BIP-32-like keys) * Key and signature serialization * Batch verification -* [Python bindings](https://github.com/Chia-Network/bls-signatures/tree/master/python-bindings) -* [Pure python bls12-381 and signatures](https://github.com/Chia-Network/bls-signatures/tree/master/python-impl) -* [JavaScript bindings](https://github.com/Chia-Network/bls-signatures/tree/master/js-bindings) (currently out of date) +* [Python bindings](https://github.com/Chia-Network/bls-signatures/tree/main/python-bindings) +* [Pure python bls12-381 and signatures](https://github.com/Chia-Network/bls-signatures/tree/main/python-impl) +* [JavaScript bindings](https://github.com/Chia-Network/bls-signatures/tree/main/js-bindings) (currently out of date - a great first issue!) ## Before you start + This library uses minimum public key sizes (MPL). A G2Element is a signature (96 bytes), and a G1Element is a public key (48 bytes). A private key is a 32 byte integer. There are three schemes: Basic, Augmented, and ProofOfPossession. Augmented should be enough for most use cases, and ProofOfPossession can be used where verification must be fast. ## Import the library @@ -194,6 +198,7 @@ cmake --build . -- -j 6 ```bash ./build/src/runbench ``` + On a 3.5 GHz i7 Mac, verification takes about 1.1ms per signature, and signing takes 1.3ms. ### Link the library to use it @@ -205,12 +210,13 @@ g++ -Wl,-no_pie -std=c++11 -Ibls-signatures/build/_deps/relic-src/include -Ibls ## Notes on dependencies Libsodium and GMP are optional dependencies: libsodium gives secure memory -allocation, and GMP speeds up the library by ~ 3x. To install them, either -download them from github and follow the instructions for each repo, or use -a package manager like APT or brew. You can follow the recipe used to build -python wheels for multiple platforms in `.github/workflows/`. libsodium is -dynamically linked unless the environment variable $CIBUILDWHEEL is set which -will then cause libsodium to statically link. +allocation, and GMP speeds up the library by ~ 3x. MPIR is used on Windows via +GitHub Actions instead. To install them, either download them from github and +follow the instructions for each repo, or use a package manager like APT or +brew. You can follow the recipe used to build python wheels for multiple +platforms in `.github/workflows/`. libsodium is dynamically linked unless +the environment variable $CIBUILDWHEEL is set which will then cause +libsodium to statically link. ## Discussion @@ -228,39 +234,39 @@ channel of Chia's [public Keybase channels](https://keybase.io/team/chia_network * Use cpplint with default rules * Use SecAlloc and SecFree when handling secrets - ## ci Building The primary build process for this repository is to use GitHub Actions to build binary wheels for MacOS, Linux (x64 and aarch64), and Windows and publish -them with a source wheel on PyPi. See `.github/workflows/build.yml`. CMake uses +them with a source wheel on PyPi. MacOS ARM64 is supported but not automated +due to a lack of M1 CI runners. See `.github/workflows/build.yml`. CMake uses [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) to download [pybind11](https://github.com/pybind/pybind11) for the Python -bindings and relic from a chia relic forked repository. Building is then -managed by [cibuildwheel](https://github.com/joerick/cibuildwheel). +bindings and relic from a chia relic forked repository for Windows. Building +is then managed by [cibuildwheel](https://github.com/joerick/cibuildwheel). Further installation is then available via `pip install blspy` e.g. The ci builds include GMP and a statically linked libsodium. ## Contributing and workflow Contributions are welcome and more details are available in chia-blockchain's -[CONTRIBUTING.md](https://github.com/Chia-Network/chia-blockchain/blob/master/CONTRIBUTING.md). +[CONTRIBUTING.md](https://github.com/Chia-Network/chia-blockchain/blob/main/CONTRIBUTING.md). -The master branch is usually the currently released latest version on PyPI. +The main branch is usually the currently released latest version on PyPI. Note that at times bls-signatures/blspy will be ahead of the release version -that chia-blockchain requires in it's master/release version in preparation -for a new chia-blockchain release. Please branch or fork master and then create -a pull request to the master branch. Linear merging is enforced on master and -merging requires a completed review. PRs will kick off a GitHub actions ci build -and analysis of bls-signatures at +that chia-blockchain requires in it's main/release version in preparation +for a new chia-blockchain release. Please branch or fork main and then create +a pull request to the main branch. Linear merging is enforced on main and +merging requires a completed review. PRs will kick off a GitHub actions ci +build and analysis of bls-signatures at [lgtm.com](https://lgtm.com/projects/g/Chia-Network/bls-signatures/?mode=list). Please make sure your build is passing and that it does not increase alerts at lgtm. ## Specification and test vectors -The [IETF bls draft](https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/) is followed. -Test vectors can also be seen in the python and cpp test files. +The [IETF bls draft](https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/) +is followed. Test vectors can also be seen in the python and cpp test files. ## Libsodium license @@ -286,7 +292,10 @@ the following copyright notice. ## GMP license -GMP is distributed under the [GNU LGPL v3 license](https://www.gnu.org/licenses/lgpl-3.0.html) +GMP is distributed under the +[GNU LGPL v3 license](https://www.gnu.org/licenses/lgpl-3.0.html) ## Relic license -Relic is used with the [Apache 2.0 license](https://github.com/relic-toolkit/relic/blob/master/LICENSE.Apache-2.0) + +Relic is used with the +[Apache 2.0 license](https://github.com/relic-toolkit/relic/blob/master/LICENSE.Apache-2.0) diff --git a/python-bindings/README.md b/python-bindings/README.md index 01f5a815163db2..d653fa1e7da7b2 100644 --- a/python-bindings/README.md +++ b/python-bindings/README.md @@ -1,23 +1,28 @@ -## Python bindings +# Python bindings + Use the full power and efficiency of the C++ bls library, but in a few lines of python! ## Install + ```bash pip3 install blspy + ``` + Alternatively, to install from source, run the following, in the project root directory: ```bash pip3 install . ``` + Cmake, a c++ compiler, and a recent version of pip3 (v18) are required for source install. GMP(speed) and libsodium(secure memory alloc) are optional dependencies. Public keys are G1Elements, and signatures are G2Elements. - Then, to use: ## Import the library + ```python from blspy import (PrivateKey, Util, AugSchemeMPL, PopSchemeMPL, G1Element, G2Element) @@ -41,7 +46,9 @@ signature: G2Element = AugSchemeMPL.sign(sk, message) ok: bool = AugSchemeMPL.verify(pk, message, signature) assert ok ``` + ## Serializing keys and signatures to bytes + ```python sk_bytes: bytes = bytes(sk) # 32 bytes pk_bytes: bytes = bytes(pk) # 48 bytes @@ -51,6 +58,7 @@ print(sk_bytes.hex(), pk_bytes.hex(), signature_bytes.hex()) ``` ## Loading keys and signatures from bytes + ```python sk = PrivateKey.from_bytes(sk_bytes) pk = G1Element.from_bytes(pk_bytes) @@ -58,6 +66,7 @@ signature = G2Element.from_bytes(signature_bytes) ``` ## Create aggregate signatures + ```python # Generate some more private keys seed = bytes([1]) + seed[1:] @@ -81,6 +90,7 @@ ok = AugSchemeMPL.aggregate_verify([pk1, pk2], [message, message2], agg_sig) ``` ## Arbitrary trees of aggregates + ```python seed = bytes([3]) + seed[1:] sk3: PrivateKey = AugSchemeMPL.key_gen(seed) @@ -93,6 +103,7 @@ ok = AugSchemeMPL.aggregate_verify([pk1, pk2, pk3], [message, message2, message3 ``` ## Very fast verification with Proof of Possession scheme + ```python # If the same message is signed, you can use Proof of Posession (PopScheme) for efficiency # A proof of possession MUST be passed around with the PK to ensure security. @@ -121,6 +132,7 @@ ok = PopSchemeMPL.sign(pop_agg_sk, message) == pop_sig_agg ``` ## HD keys using [EIP-2333](https://github.com/ethereum/EIPs/pull/2333) + ```python master_sk: PrivateKey = AugSchemeMPL.key_gen(seed) child: PrivateKey = AugSchemeMPL.derive_child_sk(master_sk, 152) @@ -134,4 +146,4 @@ child_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(master_pk, 22) grandchild_u_pk: G1Element = AugSchemeMPL.derive_child_pk_unhardened(child_u_pk, 0) ok = (grandchild_u_pk == grandchild_u.get_g1()) -``` \ No newline at end of file +``` diff --git a/python-bindings/test.py b/python-bindings/test.py index e3d03a5db8dc80..45c820ef97e508 100644 --- a/python-bindings/test.py +++ b/python-bindings/test.py @@ -1,15 +1,16 @@ # flake8: noqa: E501 +import binascii +from copy import deepcopy + from blspy import ( - PrivateKey, - Util, - BasicSchemeMPL, AugSchemeMPL, - PopSchemeMPL, + BasicSchemeMPL, G1Element, G2Element, + PopSchemeMPL, + PrivateKey, + Util, ) -from copy import deepcopy -import binascii def test_schemes(): @@ -69,6 +70,7 @@ def test_schemes(): sigU_child = Scheme.sign(childU, msg) assert Scheme.verify(childUPk, msg, sigU_child) + def test_vectors_invalid(): # Invalid inputs from https://github.com/algorand/bls_sigs_ref/blob/master/python-impl/serdesZ.py invalid_inputs_1 = [ diff --git a/python-impl/README.md b/python-impl/README.md index dcb5b1cf6b5e2f..861cfd38d6d4b0 100644 --- a/python-impl/README.md +++ b/python-impl/README.md @@ -1,12 +1,12 @@ -### BLS12-381 and Signatures in python +# BLS12-381 and Signatures in python Implements the BLS12 curve and optimal ate pairing, as well as BLS signatures and aggregation. Use for reference / educational purposes only. -For an optimized implementation, use the [Python bindings](https://github.com/Chia-Network/bls-signatures/tree/master/python-bindings). +For an optimized implementation, use the [Python bindings](https://github.com/Chia-Network/bls-signatures/tree/main/python-bindings). For a good introduction to pairings, read [Pairings for Beginners](http://www.craigcostello.com.au/pairings/PairingsForBeginners.pdf) by Craig Costello. -Map to curve implementation from https://github.com/algorand/bls_sigs_ref/. +Map to curve implementation from [Algorand](https://github.com/algorand/bls_sigs_ref/). Run the tests with `python impl-test.py`. diff --git a/python-impl/ec.py b/python-impl/ec.py index 30e6fdea2b5a5e..a733d3c52331d7 100644 --- a/python-impl/ec.py +++ b/python-impl/ec.py @@ -1,8 +1,10 @@ from __future__ import annotations -from typing import List, Optional -import bls12381 + from collections import namedtuple from copy import deepcopy +from typing import List, Optional + +import bls12381 from fields import FieldExtBase, Fq, Fq2, Fq6, Fq12 from util import hash256 diff --git a/python-impl/fields.py b/python-impl/fields.py index 84a48141a4568d..418ce50732c8d7 100644 --- a/python-impl/fields.py +++ b/python-impl/fields.py @@ -1,4 +1,5 @@ from __future__ import annotations + from copy import deepcopy from typing import Any diff --git a/python-impl/hd_keys.py b/python-impl/hd_keys.py index 92655f39dabb41..1acdb311e00a81 100644 --- a/python-impl/hd_keys.py +++ b/python-impl/hd_keys.py @@ -1,7 +1,7 @@ +from ec import G1Generator, G2Generator, JacobianPoint, default_ec from hkdf import extract_expand from private_key import PrivateKey from util import hash256 -from ec import JacobianPoint, default_ec, G1Generator, G2Generator def key_gen(seed: bytes) -> PrivateKey: diff --git a/python-impl/hkdf.py b/python-impl/hkdf.py index 4db72dedb3c63f..02c21bb4f74ea0 100644 --- a/python-impl/hkdf.py +++ b/python-impl/hkdf.py @@ -1,6 +1,6 @@ -from math import ceil -import hmac import hashlib +import hmac +from math import ceil BLOCK_SIZE = 32 diff --git a/python-impl/impl-test.py b/python-impl/impl-test.py index 39341654c7b34e..b4266f15ff299b 100644 --- a/python-impl/impl-test.py +++ b/python-impl/impl-test.py @@ -1,29 +1,17 @@ +import hashlib from copy import deepcopy from secrets import token_bytes -import hashlib +from ec import (G1FromBytes, G1Generator, G1Infinity, G2FromBytes, G2Generator, + G2Infinity, JacobianPoint, default_ec, default_ec_twist, + sign_Fq2, twist, untwist, y_for_x) from fields import Fq, Fq2, Fq6, Fq12 -from ec import ( - JacobianPoint, - G1Generator, - G2Generator, - G1Infinity, - G2Infinity, - G1FromBytes, - G2FromBytes, - default_ec, - default_ec_twist, - sign_Fq2, - twist, - untwist, - y_for_x, -) -from pairing import ate_pairing from hash_to_field import expand_message_xmd +from hkdf import expand, extract from op_swu_g2 import g2_map -from schemes import AugSchemeMPL, PopSchemeMPL, BasicSchemeMPL +from pairing import ate_pairing from private_key import PrivateKey -from hkdf import extract, expand +from schemes import AugSchemeMPL, BasicSchemeMPL, PopSchemeMPL G1Element = JacobianPoint G2Element = JacobianPoint diff --git a/python-impl/op_swu_g2.py b/python-impl/op_swu_g2.py index 7e30c725ae2863..28726112151251 100644 --- a/python-impl/op_swu_g2.py +++ b/python-impl/op_swu_g2.py @@ -17,8 +17,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from bls12381 import q, h_eff -from ec import JacobianPoint, eval_iso, default_ec_twist +from bls12381 import h_eff, q +from ec import JacobianPoint, default_ec_twist, eval_iso from fields import Fq, Fq2, roots_of_unity from hash_to_field import Hp2 diff --git a/python-impl/pairing.py b/python-impl/pairing.py index f3862ceed545cf..1780e0300cbd48 100644 --- a/python-impl/pairing.py +++ b/python-impl/pairing.py @@ -1,8 +1,9 @@ -import bls12381 -from typing import List from collections import namedtuple -from ec import untwist, AffinePoint, JacobianPoint -from fields import Fq12, Fq +from typing import List + +import bls12381 +from ec import AffinePoint, JacobianPoint, untwist +from fields import Fq, Fq12 # Struct for elliptic curve parameters EC = namedtuple("EC", "q a b gx gy g2x g2y n h x k sqrt_n3 sqrt_n3m1o2") diff --git a/python-impl/private_key.py b/python-impl/private_key.py index 3aa6ddf64b32c9..8ad377ef000bdf 100644 --- a/python-impl/private_key.py +++ b/python-impl/private_key.py @@ -1,5 +1,6 @@ from __future__ import annotations -from ec import default_ec, G1Generator + +from ec import G1Generator, default_ec from hkdf import extract_expand diff --git a/python-impl/schemes.py b/python-impl/schemes.py index 6cab03ff38dfd2..7b7a1d9730f1c8 100644 --- a/python-impl/schemes.py +++ b/python-impl/schemes.py @@ -1,16 +1,12 @@ from typing import List -from private_key import PrivateKey -from ec import JacobianPoint, G1Generator, default_ec -from hd_keys import ( - key_gen, - derive_child_sk, - derive_child_sk_unhardened, - derive_child_g1_unhardened, -) + +from ec import G1Generator, JacobianPoint, default_ec +from fields import Fq12 +from hd_keys import (derive_child_g1_unhardened, derive_child_sk, + derive_child_sk_unhardened, key_gen) from op_swu_g2 import g2_map from pairing import ate_pairing_multi -from fields import Fq12 - +from private_key import PrivateKey basic_scheme_dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_" aug_scheme_dst = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_AUG_" diff --git a/setup.py b/setup.py index a251c9a67b5483..1b0d7b2b13b591 100644 --- a/setup.py +++ b/setup.py @@ -1,69 +1,75 @@ #!/usr/bin/python3 import os -import re -import sys import platform +import re import subprocess +import sys +from distutils.version import LooseVersion -from setuptools import setup, setuptools, Extension +from setuptools import Extension, setup, setuptools from setuptools.command.build_ext import build_ext -from distutils.version import LooseVersion class CMakeExtension(Extension): - def __init__(self, name, sourcedir=''): - Extension.__init__(self, name, sources=['./']) + def __init__(self, name, sourcedir=""): + Extension.__init__(self, name, sources=["./"]) self.sourcedir = os.path.abspath(sourcedir) class CMakeBuild(build_ext): def run(self): try: - out = subprocess.check_output(['cmake', '--version']) + out = subprocess.check_output(["cmake", "--version"]) except OSError: - raise RuntimeError("CMake must be installed to build" - + " the following extensions: " - + ", ".join(e.name for e in self.extensions)) + raise RuntimeError( + "CMake must be installed to build" + + " the following extensions: " + + ", ".join(e.name for e in self.extensions) + ) if platform.system() == "Windows": cmake_version = LooseVersion( - re.search(r'version\s*([\d.]+)', out.decode()).group(1)) - if cmake_version < '3.1.0': + re.search(r"version\s*([\d.]+)", out.decode()).group(1) + ) + if cmake_version < "3.1.0": raise RuntimeError("CMake >= 3.1.0 is required on Windows") for ext in self.extensions: self.build_extension(ext) def build_extension(self, ext): - extdir = os.path.abspath(os.path.dirname( - self.get_ext_fullpath(ext.name)) - ) - cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, - '-DPYTHON_EXECUTABLE=' + sys.executable] + extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) + cmake_args = [ + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir, + "-DPYTHON_EXECUTABLE=" + sys.executable, + ] - cfg = 'Debug' if self.debug else 'Release' - build_args = ['--config', cfg] + cfg = "Debug" if self.debug else "Release" + build_args = ["--config", cfg] if platform.system() == "Windows": - cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}' - .format(cfg.upper(), extdir)] - if sys.maxsize > 2**32: - cmake_args += ['-A', 'x64'] - build_args += ['--', '/m'] + cmake_args += [ + "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir) + ] + if sys.maxsize > 2 ** 32: + cmake_args += ["-A", "x64"] + build_args += ["--", "/m"] else: - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] - build_args += ['--', '-j', '6'] + cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] + build_args += ["--", "-j", "6"] env = os.environ.copy() - env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format( - env.get('CXXFLAGS', ''), - self.distribution.get_version()) + env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format( + env.get("CXXFLAGS", ""), self.distribution.get_version() + ) if not os.path.exists(self.build_temp): os.makedirs(self.build_temp) - subprocess.check_call(['cmake', ext.sourcedir] - + cmake_args, cwd=self.build_temp, env=env) - subprocess.check_call(['cmake', '--build', '.'] - + build_args, cwd=self.build_temp) + subprocess.check_call( + ["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env + ) + subprocess.check_call( + ["cmake", "--build", "."] + build_args, cwd=self.build_temp + ) class get_pybind_include(object): @@ -71,37 +77,42 @@ class get_pybind_include(object): The purpose of this class is to postpone importing pybind11 until it is actually installed, so that the ``get_include()`` - method can be invoked. """ + method can be invoked.""" def __init__(self, user=False): self.user = user def __str__(self): import pybind11 + return pybind11.get_include(self.user) ext_modules = [ Extension( - 'blspy', + "blspy", [ - 'src/elements.cpp', - 'src/schemes.cpp', - 'src/privatekey.cpp', - 'src/bls.cpp', - 'python-bindings/pythonbindings.cpp', + "src/elements.cpp", + "src/schemes.cpp", + "src/privatekey.cpp", + "src/bls.cpp", + "python-bindings/pythonbindings.cpp", ], include_dirs=[ # Path to pybind11 headers get_pybind_include(), get_pybind_include(user=True), - 'relic_ietf_64/include', - 'mpir_gc_x64', - 'libsodium/include', + "relic_ietf_64/include", + "mpir_gc_x64", + "libsodium/include", ], - library_dirs=['relic_ietf_64', 'mpir_gc_x64', 'libsodium/x64/Release/v142/static'], - libraries=['relic_s', 'Advapi32', 'mpir', 'libsodium'], - language='c++' + library_dirs=[ + "relic_ietf_64", + "mpir_gc_x64", + "libsodium/x64/Release/v142/static", + ], + libraries=["relic_s", "Advapi32", "mpir", "libsodium"], + language="c++", ), ] @@ -113,8 +124,9 @@ def has_flag(compiler, flagname): the specified compiler. """ import tempfile - with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f: - f.write('int main (int argc, char **argv) { return 0; }') + + with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f: + f.write("int main (int argc, char **argv) { return 0; }") try: compiler.compile([f.name], extra_postargs=[flagname]) except setuptools.distutils.errors.CompileError: @@ -127,42 +139,42 @@ def cpp_flag(compiler): The newer version is prefered over c++11 (when it is available). """ - flags = ['-std=c++17', '-std=c++14', '-std=c++11'] + flags = ["-std=c++17", "-std=c++14", "-std=c++11"] for flag in flags: if has_flag(compiler, flag): return flag - raise RuntimeError('Unsupported compiler -- at least C++11 support ' - 'is needed!') + raise RuntimeError("Unsupported compiler -- at least C++11 support " "is needed!") class BuildExt(build_ext): """A custom build extension for adding compiler-specific options.""" + c_opts = { - 'msvc': ['/EHsc', '/std:c++17', '/DBLSALLOC_SODIUM=1', '/DSODIUM_STATIC'], - 'unix': [], + "msvc": ["/EHsc", "/std:c++17", "/DBLSALLOC_SODIUM=1", "/DSODIUM_STATIC"], + "unix": [], } l_opts = { - 'msvc': [], - 'unix': [], + "msvc": [], + "unix": [], } - if sys.platform == 'darwin': - darwin_opts = ['-stdlib=libc++', '-mmacosx-version-min=10.14'] - c_opts['unix'] += darwin_opts - l_opts['unix'] += darwin_opts + if sys.platform == "darwin": + darwin_opts = ["-stdlib=libc++", "-mmacosx-version-min=10.14"] + c_opts["unix"] += darwin_opts + l_opts["unix"] += darwin_opts def build_extensions(self): ct = self.compiler.compiler_type opts = self.c_opts.get(ct, []) link_opts = self.l_opts.get(ct, []) - if ct == 'unix': + if ct == "unix": opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) opts.append(cpp_flag(self.compiler)) - if has_flag(self.compiler, '-fvisibility=hidden'): - opts.append('-fvisibility=hidden') - elif ct == 'msvc': + if has_flag(self.compiler, "-fvisibility=hidden"): + opts.append("-fvisibility=hidden") + elif ct == "msvc": if sys.version_info < (3, 9): ver_flag = '/DVERSION_INFO=\\"%s\\"' else: @@ -176,32 +188,32 @@ def build_extensions(self): if platform.system() == "Windows": setup( - name='blspy', - author='Mariano Sorgente', - author_email='mariano@chia.net', - description='BLS signatures in c++ (with python bindings)', - long_description=open('README.md').read(), + name="blspy", + author="Mariano Sorgente", + author_email="mariano@chia.net", + description="BLS signatures in c++ (with python bindings)", + long_description=open("README.md").read(), long_description_content_type="text/markdown", url="https://github.com/Chia-Network/bls-signatures", - python_requires='>=3.7', - setup_requires=['pybind11>=2.5.0'], - install_requires=['pybind11>=2.5.0'], + python_requires=">=3.7", + setup_requires=["pybind11>=2.5.0"], + install_requires=["pybind11>=2.5.0"], ext_modules=ext_modules, - cmdclass={'build_ext': BuildExt}, + cmdclass={"build_ext": BuildExt}, zip_safe=False, ) else: setup( - name='blspy', - author='Mariano Sorgente', - author_email='mariano@chia.net', - description='BLS signatures in c++ (python bindings)', - python_requires='>=3.7', + name="blspy", + author="Mariano Sorgente", + author_email="mariano@chia.net", + description="BLS signatures in c++ (python bindings)", + python_requires=">=3.7", install_requires=["wheel"], - long_description=open('README.md').read(), + long_description=open("README.md").read(), long_description_content_type="text/markdown", url="https://github.com/Chia-Network/bls-signatures", - ext_modules=[CMakeExtension('blspy', '.')], + ext_modules=[CMakeExtension("blspy", ".")], cmdclass=dict(build_ext=CMakeBuild), zip_safe=False, ) From 53791a231adeb6fe56c843e0a8eb82de9df7a33a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 17 Mar 2021 17:40:15 +0100 Subject: [PATCH 15/27] fix typo in test-bench --- src/test-bench.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test-bench.cpp b/src/test-bench.cpp index 54f53b9f8cda0d..17cb0f86585454 100644 --- a/src/test-bench.cpp +++ b/src/test-bench.cpp @@ -29,7 +29,7 @@ using namespace bls; void benchSigs() { - string testName = "Sigining"; + string testName = "Signing"; double numIters = 5000; PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed()); vector message1 = sk.GetG1Element().Serialize(); From b07afe559554c7b28f6cdd3fe4026b00e46e4f3e Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Tue, 23 Mar 2021 19:12:46 -0700 Subject: [PATCH 16/27] Fix lingering pybind module issues on ARM64 runners (#192) * Use git rm to remove pybind11 * test 2nd run on ARM64 * revert for 3rd run --- contrib/pybind11 | 1 - 1 file changed, 1 deletion(-) delete mode 160000 contrib/pybind11 diff --git a/contrib/pybind11 b/contrib/pybind11 deleted file mode 160000 index 3b1dbebabc801c..00000000000000 --- a/contrib/pybind11 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3b1dbebabc801c9cf6f0953a4c20b904d444f879 From 88726b83d3dd68e72ef15ab98c65a893f0e8cc23 Mon Sep 17 00:00:00 2001 From: Gene Hoffman <30377676+hoffmang9@users.noreply.github.com> Date: Tue, 23 Mar 2021 19:49:46 -0700 Subject: [PATCH 17/27] Deal with ssri 8.0.1 (#191) * Deal with ssri 8.0.1 --- js-bindings/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js-bindings/package-lock.json b/js-bindings/package-lock.json index 91b39c06a40930..7c8049d3627f5c 100644 --- a/js-bindings/package-lock.json +++ b/js-bindings/package-lock.json @@ -756,7 +756,7 @@ "move-concurrently": "^1.0.1", "promise-inflight": "^1.0.1", "rimraf": "^2.6.3", - "ssri": "^6.0.1", + "ssri": "^8.0.1", "unique-filename": "^1.1.1", "y18n": "^4.0.0" }, From f11b54d28b907651a10fb3ad050bd33431acd2df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Mar 2021 20:17:29 -0700 Subject: [PATCH 18/27] build(deps): bump ssri from 6.0.1 to 8.0.1 in /js-bindings (#193) Bumps [ssri](https://github.com/npm/ssri) from 6.0.1 to 8.0.1. - [Release notes](https://github.com/npm/ssri/releases) - [Changelog](https://github.com/npm/ssri/blob/latest/CHANGELOG.md) - [Commits](https://github.com/npm/ssri/compare/v6.0.1...v8.0.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- js-bindings/package-lock.json | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/js-bindings/package-lock.json b/js-bindings/package-lock.json index 7c8049d3627f5c..eefe3feadaa61d 100644 --- a/js-bindings/package-lock.json +++ b/js-bindings/package-lock.json @@ -3063,6 +3063,15 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", "dev": true }, + "minipass": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", + "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, "mississippi": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/mississippi/-/mississippi-3.0.0.tgz", @@ -4354,12 +4363,12 @@ "dev": true }, "ssri": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz", - "integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==", + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", + "integrity": "sha512-97qShzy1AiyxvPNIkLWoGua7xoQzzPjQ0HAH4B0rWKo7SZ6USuPcrUiAFrws0UH8RrbWmgq3LMTObhPIHbbBeQ==", "dev": true, "requires": { - "figgy-pudding": "^3.5.1" + "minipass": "^3.1.1" } }, "static-extend": { @@ -5308,6 +5317,12 @@ "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", "dev": true }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true + }, "yargs": { "version": "13.3.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.2.tgz", From 65a17a3a3af82355d31a5e495a4d06a3ff78df11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 30 Mar 2021 10:58:21 -0700 Subject: [PATCH 19/27] build(deps): bump y18n from 4.0.0 to 4.0.1 in /js-bindings (#195) Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/yargs/y18n/releases) - [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md) - [Commits](https://github.com/yargs/y18n/commits) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- js-bindings/package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js-bindings/package-lock.json b/js-bindings/package-lock.json index eefe3feadaa61d..6de4419d069553 100644 --- a/js-bindings/package-lock.json +++ b/js-bindings/package-lock.json @@ -5312,9 +5312,9 @@ "dev": true }, "y18n": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", - "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.1.tgz", + "integrity": "sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ==", "dev": true }, "yallist": { From e420770785227d6571de74c0509265fdffac468d Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 31 Mar 2021 10:29:20 +0200 Subject: [PATCH 20/27] benchmark G1 and G2 subgroup validation --- src/test-bench.cpp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/test-bench.cpp b/src/test-bench.cpp index 17cb0f86585454..96dfc085d52bc6 100644 --- a/src/test-bench.cpp +++ b/src/test-bench.cpp @@ -71,8 +71,8 @@ void benchVerification() { void benchBatchVerification() { double numIters = 100000; - vector sigs; - vector pks; + vector> sig_bytes; + vector> pk_bytes; vector> ms; for (size_t i = 0; i < numIters; i++) { @@ -81,12 +81,30 @@ void benchBatchVerification() { vector messageBytes(message, message + 4); PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed()); G1Element pk = sk.GetG1Element(); - sigs.push_back(AugSchemeMPL().Sign(sk, messageBytes)); - pks.push_back(pk); + sig_bytes.push_back(AugSchemeMPL().Sign(sk, messageBytes).Serialize()); + pk_bytes.push_back(pk.Serialize()); ms.push_back(messageBytes); } + vector pks; + pks.reserve(numIters); + auto start = startStopwatch(); + for (auto const& pk : pk_bytes) { + pks.emplace_back(G1Element::FromBytes(Bytes(pk))); + } + endStopwatch("Public key validation", start, numIters); + + vector sigs; + sigs.reserve(numIters); + + start = startStopwatch(); + for (auto const& sig : sig_bytes) { + sigs.emplace_back(G2Element::FromBytes(Bytes(sig))); + } + endStopwatch("Signature validation", start, numIters); + + start = startStopwatch(); G2Element aggSig = AugSchemeMPL().Aggregate(sigs); endStopwatch("Aggregation", start, numIters); From 8149a18819f97e96df519c224b81adee209b1ee1 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 22 Mar 2021 16:12:24 +0100 Subject: [PATCH 21/27] use int instead of double for counting test iterations --- src/test-bench.cpp | 20 ++++++++++---------- src/test-utils.hpp | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test-bench.cpp b/src/test-bench.cpp index 96dfc085d52bc6..af351821e5e37a 100644 --- a/src/test-bench.cpp +++ b/src/test-bench.cpp @@ -30,13 +30,13 @@ using namespace bls; void benchSigs() { string testName = "Signing"; - double numIters = 5000; + const int numIters = 5000; PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed()); vector message1 = sk.GetG1Element().Serialize(); auto start = startStopwatch(); - for (size_t i = 0; i < numIters; i++) { + for (int i = 0; i < numIters; i++) { AugSchemeMPL().Sign(sk, message1); } endStopwatch(testName, start, numIters); @@ -44,13 +44,13 @@ void benchSigs() { void benchVerification() { string testName = "Verification"; - double numIters = 10000; + const int numIters = 10000; PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed()); G1Element pk = sk.GetG1Element(); std::vector sigs; - for (size_t i = 0; i < numIters; i++) { + for (int i = 0; i < numIters; i++) { uint8_t message[4]; Util::IntToFourBytes(message, i); vector messageBytes(message, message + 4); @@ -58,7 +58,7 @@ void benchVerification() { } auto start = startStopwatch(); - for (size_t i = 0; i < numIters; i++) { + for (int i = 0; i < numIters; i++) { uint8_t message[4]; Util::IntToFourBytes(message, i); vector messageBytes(message, message + 4); @@ -69,13 +69,13 @@ void benchVerification() { } void benchBatchVerification() { - double numIters = 100000; + const int numIters = 100000; vector> sig_bytes; vector> pk_bytes; vector> ms; - for (size_t i = 0; i < numIters; i++) { + for (int i = 0; i < numIters; i++) { uint8_t message[4]; Util::IntToFourBytes(message, i); vector messageBytes(message, message + 4); @@ -115,14 +115,14 @@ void benchBatchVerification() { } void benchFastAggregateVerification() { - double numIters = 5000; + const int numIters = 5000; vector sigs; vector pks; vector message = {1, 2, 3, 4, 5, 6, 7, 8}; vector pops; - for (size_t i = 0; i < numIters; i++) { + for (int i = 0; i < numIters; i++) { PrivateKey sk = PopSchemeMPL().KeyGen(getRandomSeed()); G1Element pk = sk.GetG1Element(); sigs.push_back(PopSchemeMPL().Sign(sk, message)); @@ -136,7 +136,7 @@ void benchFastAggregateVerification() { start = startStopwatch(); - for (size_t i = 0; i < numIters; i++) { + for (int i = 0; i < numIters; i++) { bool ok = PopSchemeMPL().PopVerify(pks[i], pops[i]); ASSERT(ok); } diff --git a/src/test-utils.hpp b/src/test-utils.hpp index f78c082663217b..ab17d0ce7c655b 100644 --- a/src/test-utils.hpp +++ b/src/test-utils.hpp @@ -30,7 +30,7 @@ std::chrono::time_point startStopwatch() { void endStopwatch(string testName, std::chrono::time_point start, - double numIters) { + int numIters) { auto end = std::chrono::steady_clock::now(); auto now_ms = std::chrono::duration_cast( end - start); @@ -38,7 +38,7 @@ void endStopwatch(string testName, cout << endl << testName << endl; cout << "Total: " << numIters << " runs in " << now_ms.count() << " ms" << endl; - cout << "Avg: " << now_ms.count() / numIters + cout << "Avg: " << now_ms.count() / static_cast(numIters) << " ms" << endl; } From addabd8b1763671c1a797f868780f651f1d91faf Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 31 Mar 2021 14:28:41 +0200 Subject: [PATCH 22/27] relic's main branch is now called main, not master --- .github/workflows/relic-nightly.yml | 8 ++++---- src/CMakeLists.txt | 4 ++-- src/test.cpp | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/relic-nightly.yml b/.github/workflows/relic-nightly.yml index 854436e2c767c4..f991cd14aa4d26 100644 --- a/.github/workflows/relic-nightly.yml +++ b/.github/workflows/relic-nightly.yml @@ -24,12 +24,12 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Ubuntu build C++ and test Relic at origin/master + - name: Ubuntu build C++ and test Relic at origin/main if: startsWith(matrix.os, 'ubuntu') run: | - echo "Relic origin/master commit:" + echo "Relic origin/main commit:" curl -H "application/vnd.github.v3.sha" \ - https://api.github.com/repos/relic-toolkit/relic/commits/master | \ + https://api.github.com/repos/relic-toolkit/relic/commits/main | \ head -10 sudo apt-get update sudo apt-get install snap -y @@ -48,7 +48,7 @@ jobs: cd .. echo "Setting libsodium to static compile." export CIBUILDWHEEL=1 - export RELIC_MASTER=1 + export RELIC_MAIN=1 mkdir -p build cd build cmake ../ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c9e1056ec8cdb4..7151751684ec50 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,8 +4,8 @@ set (CMAKE_CXX_STANDARD 17) # CMake 3.14+ include(FetchContent) -if (DEFINED ENV{RELIC_MASTER}) - set(RELIC_GIT_TAG "origin/master") +if (DEFINED ENV{RELIC_MAIN}) + set(RELIC_GIT_TAG "origin/main") else () set(RELIC_GIT_TAG "03a7c3b7fa43c0da6f3720e341f7d4f6a6d6f21e") endif () diff --git a/src/test.cpp b/src/test.cpp index afbfafca022abf..e53b0cbf451a7c 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -21,7 +21,6 @@ extern "C" { #include "relic.h" } -#include "relic_test.h" #include "test-utils.hpp" using std::cout; using std::endl; From b071fff7346872eb4d745c3dc4e7a8320fe282ee Mon Sep 17 00:00:00 2001 From: xdustinface Date: Mon, 8 Mar 2021 10:34:53 +0530 Subject: [PATCH 23/27] Ensure relic_core_initializer call is thread-aware Co-authored-by: Kittywhiskers Van Gogh <6098974-kittywhiskers@users.noreply.gitlab.com> --- src/bls.cpp | 5 +++++ src/test.cpp | 25 ++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/bls.cpp b/src/bls.cpp index 06c1c79c8ad04d..7586e549bbd35d 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -52,7 +52,12 @@ bool BLS::Init() SetSecureAllocator(malloc, free); #endif +#if MULTI != RELIC_NONE core_set_thread_initializer(relic_core_initializer, nullptr); +#else + relic_core_initializer(nullptr); +#endif + return true; } diff --git a/src/test.cpp b/src/test.cpp index e53b0cbf451a7c..ec6450e89cd5ec 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -489,25 +489,24 @@ TEST_CASE("Error handling") REQUIRE(core_get()->code == 10); ctx_t* ctx1 = core_get(); - bool ctxError = false; - // spawn a thread and make sure it uses a different context + // spawn a thread and make sure it uses a different/same context depending on relic's multithreading setup std::thread([&]() { - if (ctx1 == core_get()) { - ctxError = true; - } - if (core_get()->code != RLC_OK) { - ctxError = true; - } - // this should not modify the code of the main thread +#if MULTI != RELIC_NONE + REQUIRE(ctx1 != core_get()); + REQUIRE(core_get()->code == RLC_OK); +#else + REQUIRE(ctx1 == core_get()); + REQUIRE(core_get()->code != RLC_OK); +#endif core_get()->code = 1; }).join(); - REQUIRE(!ctxError); - - // other thread should not modify code +#if MULTI != RELIC_NONE REQUIRE(core_get()->code == 10); - +#else + REQUIRE(core_get()->code == 1); +#endif // reset so that future test cases don't fail core_get()->code = RLC_OK; } From 52f18c40e6e2dd43c2b3ab609daa342da36758ef Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 30 Mar 2021 23:21:27 +0200 Subject: [PATCH 24/27] remove redundant validation checks ep_map_dst() and ep2_map_dst() ought to return valid points, the validation of their output is redundant (and expensive) --- src/elements.cpp | 36 +++++++++++++++++++++--------------- src/elements.hpp | 2 ++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/elements.cpp b/src/elements.cpp index 1e2b7fb0ec6870..0f1c98ae0962d3 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -88,7 +88,7 @@ G1Element G1Element::FromMessage(const Bytes& message, { G1Element ans; ep_map_dst(ans.p, message.begin(), (int)message.size(), dst, dst_len); - ans.CheckValid(); + assert(ans.IsValid()); return ans; } @@ -100,24 +100,27 @@ G1Element G1Element::Generator() return ele; } -void G1Element::CheckValid() const { +bool G1Element::IsValid() const { // Infinity no longer valid in Relic // https://github.com/relic-toolkit/relic/commit/f3be2babb955cf9f82743e0ae5ef265d3da6c02b if (g1_is_infty((g1_st*)p) == 1) - return; + return true; if (g1_is_valid((g1_st*)p) == 0) - throw std::invalid_argument( - "Given G1 element failed g1_is_valid check"); + return false; // check if inside subgroup bn_t order; bn_new(order); g1_get_ord(order); - G1Element point = *this * order; - if (point != G1Element()) - throw std::invalid_argument("Given G1 element failed in_subgroup check"); + const G1Element point = *this * order; bn_free(order); + return point == G1Element(); +} + +void G1Element::CheckValid() const { + if (!IsValid()) + throw std::invalid_argument("G1 element is invalid"); BLS::CheckRelicErrors(); } @@ -276,7 +279,7 @@ G2Element G2Element::FromMessage(const Bytes& message, { G2Element ans; ep2_map_dst(ans.q, message.begin(), (int)message.size(), dst, dst_len); - ans.CheckValid(); + assert(ans.IsValid()); return ans; } @@ -288,14 +291,13 @@ G2Element G2Element::Generator() return ele; } -void G2Element::CheckValid() const { +bool G2Element::IsValid() const { // Infinity no longer valid in Relic // https://github.com/relic-toolkit/relic/commit/f3be2babb955cf9f82743e0ae5ef265d3da6c02b if (g2_is_infty((g2_st*)q) == 1) - return; + return true; if (g2_is_valid((g2_st*)q) == 0) - throw std::invalid_argument( - "Given G2 element failed g2_is_valid check"); + return false; // check if inside subgroup bn_t order; @@ -303,9 +305,13 @@ void G2Element::CheckValid() const { g2_get_ord(order); G2Element point = *this * order; - if (point != G2Element()) - throw std::invalid_argument("Given G2 element failed in_subgroup check"); bn_free(order); + return point == G2Element(); +} + +void G2Element::CheckValid() const { + if (!IsValid()) + throw std::invalid_argument("G2 element is invalid"); BLS::CheckRelicErrors(); } diff --git a/src/elements.hpp b/src/elements.hpp index 997d5f86274dcc..728b39ce7f9397 100644 --- a/src/elements.hpp +++ b/src/elements.hpp @@ -50,6 +50,7 @@ class G1Element { int dst_len); static G1Element Generator(); + bool IsValid() const; void CheckValid() const; void ToNative(g1_t output) const; G1Element Negate() const; @@ -87,6 +88,7 @@ class G2Element { int dst_len); static G2Element Generator(); + bool IsValid() const; void CheckValid() const; void ToNative(g2_t output) const; G2Element Negate() const; From dbc13f35ddb533ab0df8d480563b55410e24e86c Mon Sep 17 00:00:00 2001 From: arvidn Date: Thu, 1 Apr 2021 09:48:55 +0200 Subject: [PATCH 25/27] still check BLS errors after ep_map_dst() and ep2_map_dst() --- src/elements.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/elements.cpp b/src/elements.cpp index 0f1c98ae0962d3..50a60c2b0ebbdf 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -88,6 +88,7 @@ G1Element G1Element::FromMessage(const Bytes& message, { G1Element ans; ep_map_dst(ans.p, message.begin(), (int)message.size(), dst, dst_len); + BLS::CheckRelicErrors(); assert(ans.IsValid()); return ans; } @@ -279,6 +280,7 @@ G2Element G2Element::FromMessage(const Bytes& message, { G2Element ans; ep2_map_dst(ans.q, message.begin(), (int)message.size(), dst, dst_len); + BLS::CheckRelicErrors(); assert(ans.IsValid()); return ans; } From 219a6de6a5f86e99f59edb160cfab754afb0ae34 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 31 Mar 2021 15:03:01 +0200 Subject: [PATCH 26/27] just rely on g1_is_valid() and g2_is_valid() those functions already contain subgroup checks for points in G1 and G2, we don't need to duplicate that work --- src/elements.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/elements.cpp b/src/elements.cpp index 50a60c2b0ebbdf..39c0ff3a45db7e 100644 --- a/src/elements.cpp +++ b/src/elements.cpp @@ -106,17 +106,8 @@ bool G1Element::IsValid() const { // https://github.com/relic-toolkit/relic/commit/f3be2babb955cf9f82743e0ae5ef265d3da6c02b if (g1_is_infty((g1_st*)p) == 1) return true; - if (g1_is_valid((g1_st*)p) == 0) - return false; - // check if inside subgroup - bn_t order; - bn_new(order); - g1_get_ord(order); - - const G1Element point = *this * order; - bn_free(order); - return point == G1Element(); + return g1_is_valid((g1_st*)p); } void G1Element::CheckValid() const { @@ -298,17 +289,8 @@ bool G2Element::IsValid() const { // https://github.com/relic-toolkit/relic/commit/f3be2babb955cf9f82743e0ae5ef265d3da6c02b if (g2_is_infty((g2_st*)q) == 1) return true; - if (g2_is_valid((g2_st*)q) == 0) - return false; - - // check if inside subgroup - bn_t order; - bn_new(order); - g2_get_ord(order); - G2Element point = *this * order; - bn_free(order); - return point == G2Element(); + return g2_is_valid((g2_st*)q); } void G2Element::CheckValid() const { From 8fcf3f4823602066c68b0e8ff55ec6485c8b2ff4 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 31 Mar 2021 22:20:23 +0200 Subject: [PATCH 27/27] bump relic version to include improved g1_is_valid() and g2_is_valid() --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7151751684ec50..faecc6133a55dd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ include(FetchContent) if (DEFINED ENV{RELIC_MAIN}) set(RELIC_GIT_TAG "origin/main") else () - set(RELIC_GIT_TAG "03a7c3b7fa43c0da6f3720e341f7d4f6a6d6f21e") + set(RELIC_GIT_TAG "1885ae3b681c423c72b65ce1fe70910142cf941c") endif () message(STATUS "Relic will be built from: ${RELIC_GIT_TAG}")