From b1f35023b87dabab5ca2642e99abc3f4682537b8 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Wed, 7 Jun 2023 14:32:35 +0100 Subject: [PATCH 01/15] Switch from assets to exceptions --- build/fq.cpp | 3 +-- build/fq_generic.cpp | 1 - build/fr.cpp | 3 +-- build/fr_generic.cpp | 1 - 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/build/fq.cpp b/build/fq.cpp index b5977e3..46295c5 100644 --- a/build/fq.cpp +++ b/build/fq.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -165,7 +164,7 @@ void Fq_div(PFqElement r, PFqElement a, PFqElement b) { } void Fq_fail() { - assert(false); + throw std::runtime_error("Fq error"); } void Fq_longErr() diff --git a/build/fq_generic.cpp b/build/fq_generic.cpp index 9fa2071..c927e66 100644 --- a/build/fq_generic.cpp +++ b/build/fq_generic.cpp @@ -1,7 +1,6 @@ #include "fq.hpp" #include #include -#include FqElement Fq_q = {0, 0x80000000, {0x3c208c16d87cfd47,0x97816a916871ca8d,0xb85045b68181585d,0x30644e72e131a029}}; FqElement Fq_R2 = {0, 0x80000000, {0xf32cfc5b538afa89,0xb5e71911d44501fb,0x47ab1eff0a417ff6,0x06d89f71cab8351f}}; diff --git a/build/fr.cpp b/build/fr.cpp index 0e392b9..087b9f7 100644 --- a/build/fr.cpp +++ b/build/fr.cpp @@ -1,6 +1,5 @@ #include "fr.hpp" #include -#include #include #include @@ -161,7 +160,7 @@ void Fr_div(PFrElement r, PFrElement a, PFrElement b) { } void Fr_fail() { - assert(false); + throw std::runtime_error("Fr error"); } void Fr_longErr() diff --git a/build/fr_generic.cpp b/build/fr_generic.cpp index 7b68077..13a5ddc 100644 --- a/build/fr_generic.cpp +++ b/build/fr_generic.cpp @@ -1,7 +1,6 @@ #include "fr.hpp" #include #include -#include FrElement Fr_q = {0, 0x80000000, {0x43e1f593f0000001,0x2833e84879b97091,0xb85045b68181585d,0x30644e72e131a029}}; FrElement Fr_R2 = {0, 0x80000000, {0x1bb8e645ae216da7,0x53fe3ab1e35c59e3,0x8c49833d53bb8085,0x0216d0b17f4e44a5}}; From 75e216dde34b7da4a2f9c34dbfd21f25cb4c39d2 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Wed, 7 Jun 2023 18:05:54 +0100 Subject: [PATCH 02/15] Switch from assets to exceptions --- build/fq.cpp | 1 + build/fr.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build/fq.cpp b/build/fq.cpp index 46295c5..fbc33b1 100644 --- a/build/fq.cpp +++ b/build/fq.cpp @@ -5,6 +5,7 @@ #include #include #include +#include static mpz_t q; diff --git a/build/fr.cpp b/build/fr.cpp index 087b9f7..6fae289 100644 --- a/build/fr.cpp +++ b/build/fr.cpp @@ -2,7 +2,7 @@ #include #include #include - +#include static mpz_t q; static mpz_t zero; From b22232daa91f8c6e755472c5645cd17168718743 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Wed, 27 Dec 2023 17:31:09 +0000 Subject: [PATCH 03/15] minor sync with witnesscalc --- build/fr.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/build/fr.cpp b/build/fr.cpp index fd5191c..415a824 100644 --- a/build/fr.cpp +++ b/build/fr.cpp @@ -5,6 +5,7 @@ #include #include + static mpz_t q; static mpz_t zero; static mpz_t one; From 68721bcd82c3cd719b8917803fa08efa0c830cbb Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 11 Jan 2024 20:22:03 +0000 Subject: [PATCH 04/15] Use mmap buffer instead of regular buffer for BinFile::openExisting --- src/binfile_utils.cpp | 75 +++++++++++++++++++++++++++++++++++++++++-- src/binfile_utils.hpp | 4 +++ 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index de6d0d7..7b1f5d1 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -1,3 +1,7 @@ +#include +#include +#include +#include #include #include #include @@ -8,6 +12,64 @@ namespace BinFileUtils { +BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { + + is_fd = true; + struct stat sb; + + fd = open(fileName.c_str(), O_RDONLY); + if (fd == -1) + throw std::system_error(errno, std::generic_category(), "open"); + + + if (fstat(fd, &sb) == -1) /* To obtain file size */ + throw std::system_error(errno, std::generic_category(), "fstat"); + + size = sb.st_size; + + addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); + if (addr == MAP_FAILED) { + close(fd); + throw std::system_error(errno, std::generic_category(), "mmap failed"); + } + + type.assign((const char *)addr, 4); + pos = 4; + + if (type != _type) { + munmap(addr, size); + close(fd); + throw new std::invalid_argument("Invalid file type. It should be " + _type + " and it is " + type + " filename: " + fileName); + } + + version = readU32LE(); + if (version > maxVersion) { + munmap(addr, size); + close(fd); + throw new std::invalid_argument("Invalid version. It should be <=" + std::to_string(maxVersion) + " and it is " + std::to_string(version)); + } + + u_int32_t nSections = readU32LE(); + + + for (u_int32_t i=0; i())); + } + + sections[sType].push_back(Section( (void *)((u_int64_t)addr + pos), sSize)); + + pos += sSize; + } + + pos = 0; + readingSection = NULL; +} + + BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint32_t maxVersion) { size = fileSize; @@ -49,7 +111,12 @@ BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint3 } BinFile::~BinFile() { - free(addr); + if (is_fd) { + munmap(addr, size); + close(fd); + } else { + free(addr); + } } void BinFile::startReadSection(u_int32_t sectionId, u_int32_t sectionPos) { @@ -126,9 +193,11 @@ void *BinFile::read(u_int64_t len) { std::unique_ptr openExisting(std::string filename, std::string type, uint32_t maxVersion) { - FileLoader fileLoader(filename); + // FileLoader fileLoader(filename); + // + // return std::unique_ptr(new BinFile(fileLoader.dataBuffer(), fileLoader.dataSize(), type, maxVersion)); - return std::unique_ptr(new BinFile(fileLoader.dataBuffer(), fileLoader.dataSize(), type, maxVersion)); + return std::unique_ptr(new BinFile(filename, type, maxVersion)); } } // Namespace diff --git a/src/binfile_utils.hpp b/src/binfile_utils.hpp index 44b74d3..87fa00b 100644 --- a/src/binfile_utils.hpp +++ b/src/binfile_utils.hpp @@ -9,6 +9,9 @@ namespace BinFileUtils { class BinFile { + bool is_fd; + int fd; + void *addr; u_int64_t size; u_int64_t pos; @@ -33,6 +36,7 @@ namespace BinFileUtils { public: BinFile(const void *fileData, size_t fileSize, std::string _type, uint32_t maxVersion); + BinFile(std::string fileName, std::string _type, uint32_t maxVersion); ~BinFile(); void *getSetcionData(u_int32_t sectionId, u_int32_t sectionPos = 0); From b1c2e9104d3211c6c022f1b1a549fdb908764389 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 11 Jan 2024 20:47:21 +0000 Subject: [PATCH 05/15] Fix build on Mac --- src/binfile_utils.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index 7b1f5d1..1044d4a 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -27,11 +27,12 @@ BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { size = sb.st_size; - addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0); + addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) { close(fd); throw std::system_error(errno, std::generic_category(), "mmap failed"); } + madvise(addr, size, MADV_SEQUENTIAL); type.assign((const char *)addr, 4); pos = 4; From 9c7555d293cc347d1acced1deacbb598a50f4ffa Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 18 Jan 2024 18:28:50 +0000 Subject: [PATCH 06/15] Added groth16_prover_zkey_file function. Small cleanup --- src/binfile_utils.cpp | 3 +++ src/binfile_utils.hpp | 2 -- src/prover.cpp | 28 +++++++++++++++++++++------- src/prover.h | 24 ++++++++++++++++++------ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index 1044d4a..3081f85 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -73,6 +73,9 @@ BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint32_t maxVersion) { + is_fd = false; + fd = -1; + size = fileSize; addr = malloc(size); memcpy(addr, fileData, size); diff --git a/src/binfile_utils.hpp b/src/binfile_utils.hpp index 87fa00b..fba2c79 100644 --- a/src/binfile_utils.hpp +++ b/src/binfile_utils.hpp @@ -39,8 +39,6 @@ namespace BinFileUtils { BinFile(std::string fileName, std::string _type, uint32_t maxVersion); ~BinFile(); - void *getSetcionData(u_int32_t sectionId, u_int32_t sectionPos = 0); - void startReadSection(u_int32_t sectionId, u_int32_t setionPos = 0); void endReadSection(bool check = true); diff --git a/src/prover.cpp b/src/prover.cpp index 4c3fee0..fea94fb 100644 --- a/src/prover.cpp +++ b/src/prover.cpp @@ -11,6 +11,7 @@ #include "wtns_utils.hpp" #include "groth16.hpp" #include "binfile_utils.hpp" +#include "fileloader.hpp" using json = nlohmann::json; @@ -65,13 +66,11 @@ unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_s return 0; } -int -groth16_prover(const void *zkey_buffer, unsigned long zkey_size, - const void *wtns_buffer, unsigned long wtns_size, - char *proof_buffer, unsigned long *proof_size, - char *public_buffer, unsigned long *public_size, - char *error_msg, unsigned long error_msg_maxsize) -{ +int groth16_prover(const void *zkey_buffer, unsigned long zkey_size, + const void *wtns_buffer, unsigned long wtns_size, + char *proof_buffer, unsigned long *proof_size, + char *public_buffer, unsigned long *public_size, + char *error_msg, unsigned long error_msg_maxsize) { try { BinFileUtils::BinFile zkey(zkey_buffer, zkey_size, "zkey", 1); auto zkeyHeader = ZKeyUtils::loadHeader(&zkey); @@ -160,3 +159,18 @@ groth16_prover(const void *zkey_buffer, unsigned long zkey_size, return PROVER_OK; } + +int groth16_prover_zkey_file(const std::string& zkey_filename, + const void *wtns_buffer, unsigned long wtns_size, + char *proof_buffer, unsigned long *proof_size, + char *public_buffer, unsigned long *public_size, + char *error_msg, unsigned long error_msg_maxsize) { + + BinFileUtils::FileLoader fileLoader(zkey_filename); + + return groth16_prover(fileLoader.dataBuffer(), fileLoader.dataSize(), + wtns_buffer, wtns_size, + proof_buffer, proof_size, + public_buffer, public_size, + error_msg, error_msg_maxsize); +} diff --git a/src/prover.h b/src/prover.h index 79d55f0..e46fe12 100644 --- a/src/prover.h +++ b/src/prover.h @@ -24,12 +24,24 @@ unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_s * PPOVER_ERROR - in case of an error * PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess */ -int -groth16_prover(const void *zkey_buffer, unsigned long zkey_size, - const void *wtns_buffer, unsigned long wtns_size, - char *proof_buffer, unsigned long *proof_size, - char *public_buffer, unsigned long *public_size, - char *error_msg, unsigned long error_msg_maxsize); +int groth16_prover(const void *zkey_buffer, unsigned long zkey_size, + const void *wtns_buffer, unsigned long wtns_size, + char *proof_buffer, unsigned long *proof_size, + char *public_buffer, unsigned long *public_size, + char *error_msg, unsigned long error_msg_maxsize); + +/** + * groth16_prover + * @return error code: + * PROVER_OK - in case of success + * PPOVER_ERROR - in case of an error + * PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess + */ +int groth16_prover_zkey_file(const std::string &zkey_filename, + const void *wtns_buffer, unsigned long wtns_size, + char *proof_buffer, unsigned long *proof_size, + char *public_buffer, unsigned long *public_size, + char *error_msg, unsigned long error_msg_maxsize); #ifdef __cplusplus } From c55de63e1db6c7e421f0747df8af9524df6258fb Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Mon, 22 Jan 2024 19:55:19 +0000 Subject: [PATCH 07/15] Switch from std::string to char* for zkey filename --- src/prover.cpp | 4 +++- src/prover.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/prover.cpp b/src/prover.cpp index fea94fb..d443d66 100644 --- a/src/prover.cpp +++ b/src/prover.cpp @@ -160,12 +160,14 @@ int groth16_prover(const void *zkey_buffer, unsigned long zkey_size, return PROVER_OK; } -int groth16_prover_zkey_file(const std::string& zkey_filename, +int groth16_prover_zkey_file(const char *zkey_file_path, const void *wtns_buffer, unsigned long wtns_size, char *proof_buffer, unsigned long *proof_size, char *public_buffer, unsigned long *public_size, char *error_msg, unsigned long error_msg_maxsize) { + std::string zkey_filename(zkey_file_path); + BinFileUtils::FileLoader fileLoader(zkey_filename); return groth16_prover(fileLoader.dataBuffer(), fileLoader.dataSize(), diff --git a/src/prover.h b/src/prover.h index e46fe12..7afb5ff 100644 --- a/src/prover.h +++ b/src/prover.h @@ -37,7 +37,7 @@ int groth16_prover(const void *zkey_buffer, unsigned long zkey_size, * PPOVER_ERROR - in case of an error * PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess */ -int groth16_prover_zkey_file(const std::string &zkey_filename, +int groth16_prover_zkey_file(const char *zkey_file_path, const void *wtns_buffer, unsigned long wtns_size, char *proof_buffer, unsigned long *proof_size, char *public_buffer, unsigned long *public_size, From ca2e25d72f866ced7612ef2d7d76bd37a5005cd5 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 25 Jan 2024 10:13:56 +0000 Subject: [PATCH 08/15] Always upload artifacts --- .github/workflows/build.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a4a26a4..3635661 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: snarkjs groth16 verify testdata/verification_key.json public.json proof.json - name: upload Android ARM64 artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -77,7 +77,7 @@ jobs: gh release upload ${{ github.event.release.tag_name }} rapidsnark-android-arm64-${{ github.ref_name }}.zip - name: upload Android x86_64 artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -88,7 +88,7 @@ jobs: gh release upload ${{ github.event.release.tag_name }} rapidsnark-android-x86_64-${{ github.ref_name }}.zip - name: upload Linux x86_64 artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -144,7 +144,7 @@ jobs: snarkjs groth16 verify testdata/verification_key.json public.json proof.json - name: upload iOS artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -155,7 +155,7 @@ jobs: gh release upload ${{ github.event.release.tag_name }} rapidsnark-iOS-${{ github.ref_name }}.zip - name: upload iOS Simulator artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -166,7 +166,7 @@ jobs: gh release upload ${{ github.event.release.tag_name }} rapidsnark-iOS-Simulator-${{ github.ref_name }}.zip - name: upload macOS arm64 artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -212,7 +212,7 @@ jobs: snarkjs groth16 verify testdata/verification_key.json public.json proof.json - name: upload macOS x86_64 artifacts - if: github.event_name == 'release' + #if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | From 20607a7fe1c9cf9022643f9228420cfa857fb843 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 25 Jan 2024 10:19:08 +0000 Subject: [PATCH 09/15] Fix GHA --- .github/workflows/build.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3635661..e0af6e4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,19 +41,19 @@ jobs: - name: Build prover Android ARM64 run: | - mkdir build_prover_android && cd build_prover_android + mkdir -p build_prover_android && cd build_prover_android cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android make -j4 && make install - name: Build prover Android x86_64 run: | - mkdir build_prover_android_x86_64 && cd build_prover_android_x86_64 + mkdir -p build_prover_android_x86_64 && cd build_prover_android_x86_64 cmake .. -DTARGET_PLATFORM=ANDROID_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android_x86_64 make -j4 && make install - name: Build prover Linux run: | - mkdir build_prover && cd build_prover + mkdir -p build_prover && cd build_prover cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package make -j4 && make install @@ -71,7 +71,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-android-arm64-${{ github.ref_name }} + mkdir -p rapidsnark-android-arm64-${{ github.ref_name }} cp -r package_android/* rapidsnark-android-arm64-${{ github.ref_name }}/ zip -r rapidsnark-android-arm64-${{ github.ref_name }}.zip rapidsnark-android-arm64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-android-arm64-${{ github.ref_name }}.zip @@ -82,7 +82,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-android-x86_64-${{ github.ref_name }} + mkdir -p rapidsnark-android-x86_64-${{ github.ref_name }} cp -r package_android_x86_64/* rapidsnark-android-x86_64-${{ github.ref_name }}/ zip -r rapidsnark-android-x86_64-${{ github.ref_name }}.zip rapidsnark-android-x86_64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-android-x86_64-${{ github.ref_name }}.zip @@ -93,7 +93,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-linux-x86_64-${{ github.ref_name }} + mkdir -p rapidsnark-linux-x86_64-${{ github.ref_name }} cp -r package/* rapidsnark-linux-x86_64-${{ github.ref_name }}/ zip -r rapidsnark-linux-x86_64-${{ github.ref_name }}.zip rapidsnark-linux-x86_64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-linux-x86_64-${{ github.ref_name }}.zip @@ -119,19 +119,19 @@ jobs: if [[ ! -d "depends/gmp/package_iphone_simulator" ]]; then ./build_gmp.sh ios_simulator; fi if [[ ! -d "depends/gmp/package_macos_arm64" ]]; then ./build_gmp.sh macos_arm64; fi - mkdir build_prover_ios && cd build_prover_ios + mkdir -p build_prover_ios && cd build_prover_ios cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj -configuration Release cp ../depends/gmp/package_ios_arm64/lib/libgmp.a src/Release-iphoneos cd ../ - mkdir build_prover_ios_simulator && cd build_prover_ios_simulator + mkdir -p build_prover_ios_simulator && cd build_prover_ios_simulator cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios_simulator -DUSE_ASM=NO xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj cp ../depends/gmp/package_iphone_simulator/lib/libgmp.a src/Debug-iphonesimulator cd ../ - mkdir build_prover_macos_arm64 && cd build_prover_macos_arm64 + mkdir -p build_prover_macos_arm64 && cd build_prover_macos_arm64 cmake .. -DTARGET_PLATFORM=macos_arm64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_arm64 make -j4 && make install @@ -149,7 +149,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-iOS-${{ github.ref_name }} + mkdir -p rapidsnark-iOS-${{ github.ref_name }} cp -r build_prover_ios/src/Release-iphoneos/* rapidsnark-iOS-${{ github.ref_name }}/ zip -r rapidsnark-iOS-${{ github.ref_name }}.zip rapidsnark-iOS-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-iOS-${{ github.ref_name }}.zip @@ -160,7 +160,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-iOS-Simulator-${{ github.ref_name }} + mkdir -p rapidsnark-iOS-Simulator-${{ github.ref_name }} cp -r build_prover_ios_simulator/src/Debug-iphonesimulator/* rapidsnark-iOS-Simulator-${{ github.ref_name }}/ zip -r rapidsnark-iOS-Simulator-${{ github.ref_name }}.zip rapidsnark-iOS-Simulator-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-iOS-Simulator-${{ github.ref_name }}.zip @@ -171,7 +171,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-macOS-arm64-${{ github.ref_name }} + mkdir -p rapidsnark-macOS-arm64-${{ github.ref_name }} cp -r package_macos_arm64/* rapidsnark-macOS-arm64-${{ github.ref_name }}/ zip -r rapidsnark-macOS-arm64-${{ github.ref_name }}.zip rapidsnark-macOS-arm64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-macOS-arm64-${{ github.ref_name }}.zip @@ -199,7 +199,7 @@ jobs: run: | if [[ ! -d "depends/gmp/package_macos_x86_64" ]]; then ./build_gmp.sh macos_x86_64; fi - mkdir build_prover_macos_x86_64 && cd build_prover_macos_x86_64 + mkdir -p build_prover_macos_x86_64 && cd build_prover_macos_x86_64 cmake .. -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64 make -j4 && make install @@ -217,7 +217,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir rapidsnark-macOS-x86_64-${{ github.ref_name }} + mkdir -p rapidsnark-macOS-x86_64-${{ github.ref_name }} cp -r package_macos_x86_64/* rapidsnark-macOS-x86_64-${{ github.ref_name }}/ zip -r rapidsnark-macOS-x86_64-${{ github.ref_name }}.zip rapidsnark-macOS-x86_64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-macOS-x86_64-${{ github.ref_name }}.zip From f6936de3df1a0836d096af227c1224958adb8bd9 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 25 Jan 2024 10:40:17 +0000 Subject: [PATCH 10/15] Upload dev artifacts --- .github/workflows/build.yml | 91 +++++++++++++++++++++++++++++++------ 1 file changed, 77 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e0af6e4..4b8c2a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,8 +65,35 @@ jobs: package/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json snarkjs groth16 verify testdata/verification_key.json public.json proof.json - - name: upload Android ARM64 artifacts - #if: github.event_name == 'release' + - name: upload Linux amd64 dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-linux-amd64 + path: | + package + if-no-files-found: error + + - name: upload Android dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-Android + path: | + package_android + if-no-files-found: error + + - name: upload Android x86_64 dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-Android-x86_64 + path: | + package_android_x86_64 + if-no-files-found: error + + - name: upload Android ARM64 release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -76,8 +103,8 @@ jobs: zip -r rapidsnark-android-arm64-${{ github.ref_name }}.zip rapidsnark-android-arm64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-android-arm64-${{ github.ref_name }}.zip - - name: upload Android x86_64 artifacts - #if: github.event_name == 'release' + - name: upload Android x86_64 release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -87,8 +114,8 @@ jobs: zip -r rapidsnark-android-x86_64-${{ github.ref_name }}.zip rapidsnark-android-x86_64-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-android-x86_64-${{ github.ref_name }}.zip - - name: upload Linux x86_64 artifacts - #if: github.event_name == 'release' + - name: upload Linux x86_64 release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -143,8 +170,35 @@ jobs: package_macos_arm64/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json snarkjs groth16 verify testdata/verification_key.json public.json proof.json - - name: upload iOS artifacts - #if: github.event_name == 'release' + - name: upload macOS arm64 dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-macOS-arm64 + path: | + package + if-no-files-found: error + + - name: upload iOS dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-iOS + path: | + package_ios + if-no-files-found: error + + - name: upload iOS Simulator dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-iOS-Simulator + path: | + package_ios_simulator + if-no-files-found: error + + - name: upload iOS release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -154,8 +208,8 @@ jobs: zip -r rapidsnark-iOS-${{ github.ref_name }}.zip rapidsnark-iOS-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-iOS-${{ github.ref_name }}.zip - - name: upload iOS Simulator artifacts - #if: github.event_name == 'release' + - name: upload iOS Simulator release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -165,8 +219,8 @@ jobs: zip -r rapidsnark-iOS-Simulator-${{ github.ref_name }}.zip rapidsnark-iOS-Simulator-${{ github.ref_name }} gh release upload ${{ github.event.release.tag_name }} rapidsnark-iOS-Simulator-${{ github.ref_name }}.zip - - name: upload macOS arm64 artifacts - #if: github.event_name == 'release' + - name: upload macOS arm64 release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | @@ -211,8 +265,17 @@ jobs: package_macos_x86_64/bin/prover testdata/circuit_final.zkey testdata/witness.wtns proof.json public.json snarkjs groth16 verify testdata/verification_key.json public.json proof.json - - name: upload macOS x86_64 artifacts - #if: github.event_name == 'release' + - name: upload macOS x86_64 dev artifacts + if: github.event_name != 'release' + uses: actions/upload-artifact@v3 + with: + name: rapidsnark-macOS-x86_64 + path: | + package_macos_x86_64 + if-no-files-found: error + + - name: upload macOS x86_64 release artifacts + if: github.event_name == 'release' env: GH_TOKEN: ${{ github.token }} run: | From 7dae8548c721293ed4fee75254fb111831bd2442 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 25 Jan 2024 10:51:59 +0000 Subject: [PATCH 11/15] fix artifact build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b8c2a8..2786f36 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -176,7 +176,7 @@ jobs: with: name: rapidsnark-macOS-arm64 path: | - package + package_macos_arm64 if-no-files-found: error - name: upload iOS dev artifacts From 1148f0dd4b3c4dbd0ec7e23c8cf6677c636e27a6 Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Thu, 25 Jan 2024 11:09:31 +0000 Subject: [PATCH 12/15] fix artefact build --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2786f36..3f60650 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -185,7 +185,7 @@ jobs: with: name: rapidsnark-iOS path: | - package_ios + build_prover_ios/src/Release-iphoneos if-no-files-found: error - name: upload iOS Simulator dev artifacts @@ -194,7 +194,7 @@ jobs: with: name: rapidsnark-iOS-Simulator path: | - package_ios_simulator + build_prover_ios_simulator/src/Debug-iphonesimulator if-no-files-found: error - name: upload iOS release artifacts From 4c6f5d7e225ee96c2eb7f3e948d6ddbfa410428c Mon Sep 17 00:00:00 2001 From: Oleksandr Brezhniev Date: Tue, 6 Feb 2024 10:29:47 +0000 Subject: [PATCH 13/15] Fix review comments --- src/binfile_utils.cpp | 33 ++++++++++++++------------------- src/fileloader.cpp | 2 +- src/prover.h | 6 ++++-- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index 3081f85..d1f2e6e 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -27,7 +27,7 @@ BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { size = sb.st_size; - addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + addr = mmap(nullptr, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (addr == MAP_FAILED) { close(fd); throw std::system_error(errno, std::generic_category(), "mmap failed"); @@ -40,14 +40,14 @@ BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { if (type != _type) { munmap(addr, size); close(fd); - throw new std::invalid_argument("Invalid file type. It should be " + _type + " and it is " + type + " filename: " + fileName); + throw std::invalid_argument("Invalid file type. It should be " + _type + " and it is " + type + " filename: " + fileName); } version = readU32LE(); if (version > maxVersion) { munmap(addr, size); close(fd); - throw new std::invalid_argument("Invalid version. It should be <=" + std::to_string(maxVersion) + " and it is " + std::to_string(version)); + throw std::invalid_argument("Invalid version. It should be <=" + std::to_string(maxVersion) + " and it is " + std::to_string(version)); } u_int32_t nSections = readU32LE(); @@ -67,7 +67,7 @@ BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { } pos = 0; - readingSection = NULL; + readingSection = nullptr; } @@ -85,13 +85,13 @@ BinFile::BinFile(const void *fileData, size_t fileSize, std::string _type, uint3 if (type != _type) { free(addr); - throw new std::invalid_argument("Invalid file type. It should be " + _type + " and it is " + type); + throw std::invalid_argument("Invalid file type. It should be " + _type + " and it is " + type); } version = readU32LE(); if (version > maxVersion) { free(addr); - throw new std::invalid_argument("Invalid version. It should be <=" + std::to_string(maxVersion) + " and it is " + std::to_string(version)); + throw std::invalid_argument("Invalid version. It should be <=" + std::to_string(maxVersion) + " and it is " + std::to_string(version)); } u_int32_t nSections = readU32LE(); @@ -126,15 +126,15 @@ BinFile::~BinFile() { void BinFile::startReadSection(u_int32_t sectionId, u_int32_t sectionPos) { if (sections.find(sectionId) == sections.end()) { - throw new std::range_error("Section does not exist: " + std::to_string(sectionId)); + throw std::range_error("Section does not exist: " + std::to_string(sectionId)); } if (sectionPos >= sections[sectionId].size()) { - throw new std::range_error("Section pos too big. There are " + std::to_string(sections[sectionId].size()) + " and it's trying to access section: " + std::to_string(sectionPos)); + throw std::range_error("Section pos too big. There are " + std::to_string(sections[sectionId].size()) + " and it's trying to access section: " + std::to_string(sectionPos)); } if (readingSection != NULL) { - throw new std::range_error("Already reading a section"); + throw std::range_error("Already reading a section"); } pos = (u_int64_t)(sections[sectionId][sectionPos].start) - (u_int64_t)addr; @@ -145,7 +145,7 @@ void BinFile::startReadSection(u_int32_t sectionId, u_int32_t sectionPos) { void BinFile::endReadSection(bool check) { if (check) { if ((u_int64_t)addr + pos - (u_int64_t)(readingSection->start) != readingSection->size) { - throw new std::range_error("Invalid section size"); + throw std::range_error("Invalid section size"); } } readingSection = NULL; @@ -154,14 +154,14 @@ void BinFile::endReadSection(bool check) { void *BinFile::getSectionData(u_int32_t sectionId, u_int32_t sectionPos) { if (sections.find(sectionId) == sections.end()) { - throw new std::range_error("Section does not exist: " + std::to_string(sectionId)); + throw std::range_error("Section does not exist: " + std::to_string(sectionId)); } if (sectionPos >= sections[sectionId].size()) { - throw new std::range_error("Section pos too big. There are " + std::to_string(sections[sectionId].size()) + " and it's trying to access section: " + std::to_string(sectionPos)); + throw std::range_error("Section pos too big. There are " + std::to_string(sections[sectionId].size()) + " and it's trying to access section: " + std::to_string(sectionPos)); } - return sections[sectionId][sectionPos].start; + return sections[sectionId][sectionPos].start; } u_int64_t BinFile::getSectionSize(u_int32_t sectionId, u_int32_t sectionPos) { @@ -174,7 +174,7 @@ u_int64_t BinFile::getSectionSize(u_int32_t sectionId, u_int32_t sectionPos) { throw new std::range_error("Section pos too big. There are " + std::to_string(sections[sectionId].size()) + " and it's trying to access section: " + std::to_string(sectionPos)); } - return sections[sectionId][sectionPos].size; + return sections[sectionId][sectionPos].size; } u_int32_t BinFile::readU32LE() { @@ -196,11 +196,6 @@ void *BinFile::read(u_int64_t len) { } std::unique_ptr openExisting(std::string filename, std::string type, uint32_t maxVersion) { - - // FileLoader fileLoader(filename); - // - // return std::unique_ptr(new BinFile(fileLoader.dataBuffer(), fileLoader.dataSize(), type, maxVersion)); - return std::unique_ptr(new BinFile(filename, type, maxVersion)); } diff --git a/src/fileloader.cpp b/src/fileloader.cpp index 48381a0..efc1b6c 100644 --- a/src/fileloader.cpp +++ b/src/fileloader.cpp @@ -25,7 +25,7 @@ FileLoader::FileLoader(const std::string& fileName) size = sb.st_size; - addr = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + addr = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0); } FileLoader::~FileLoader() diff --git a/src/prover.h b/src/prover.h index 7afb5ff..a250bb1 100644 --- a/src/prover.h +++ b/src/prover.h @@ -24,7 +24,8 @@ unsigned long CalcPublicBufferSize(const void *zkey_buffer, unsigned long zkey_s * PPOVER_ERROR - in case of an error * PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess */ -int groth16_prover(const void *zkey_buffer, unsigned long zkey_size, +int +groth16_prover(const void *zkey_buffer, unsigned long zkey_size, const void *wtns_buffer, unsigned long wtns_size, char *proof_buffer, unsigned long *proof_size, char *public_buffer, unsigned long *public_size, @@ -37,7 +38,8 @@ int groth16_prover(const void *zkey_buffer, unsigned long zkey_size, * PPOVER_ERROR - in case of an error * PROVER_ERROR_SHORT_BUFFER - in case of a short buffer error, also updates proof_size and public_size with actual proof and public sizess */ -int groth16_prover_zkey_file(const char *zkey_file_path, +int +groth16_prover_zkey_file(const char *zkey_file_path, const void *wtns_buffer, unsigned long wtns_size, char *proof_buffer, unsigned long *proof_size, char *public_buffer, unsigned long *public_size, From dd8e75c05e4987be440edacc6016949c2850d98f Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Tue, 6 Feb 2024 05:45:18 -0500 Subject: [PATCH 14/15] Make unmodified string arguments const references --- src/binfile_utils.cpp | 4 ++-- src/binfile_utils.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index d1f2e6e..4ca5dab 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -12,7 +12,7 @@ namespace BinFileUtils { -BinFile::BinFile(std::string fileName, std::string _type, uint32_t maxVersion) { +BinFile::BinFile(const std::string& fileName, const std::string& _type, uint32_t maxVersion) { is_fd = true; struct stat sb; @@ -195,7 +195,7 @@ void *BinFile::read(u_int64_t len) { return res; } -std::unique_ptr openExisting(std::string filename, std::string type, uint32_t maxVersion) { +std::unique_ptr openExisting(const std::string& filename, const std::string& type, uint32_t maxVersion) { return std::unique_ptr(new BinFile(filename, type, maxVersion)); } diff --git a/src/binfile_utils.hpp b/src/binfile_utils.hpp index fba2c79..4e342ef 100644 --- a/src/binfile_utils.hpp +++ b/src/binfile_utils.hpp @@ -36,7 +36,7 @@ namespace BinFileUtils { public: BinFile(const void *fileData, size_t fileSize, std::string _type, uint32_t maxVersion); - BinFile(std::string fileName, std::string _type, uint32_t maxVersion); + BinFile(const std::string& fileName, const std::string& _type, uint32_t maxVersion); ~BinFile(); void startReadSection(u_int32_t sectionId, u_int32_t setionPos = 0); @@ -51,7 +51,7 @@ namespace BinFileUtils { void *read(uint64_t l); }; - std::unique_ptr openExisting(std::string filename, std::string type, uint32_t maxVersion); + std::unique_ptr openExisting(const std::string& filename, const std::string& type, uint32_t maxVersion); } #endif // BINFILE_UTILS_H From 01518a8ce6aaf98d94bb4664d51eadc9f3823a07 Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Tue, 6 Feb 2024 06:05:41 -0500 Subject: [PATCH 15/15] Remove inplicit copy/assignment constructors as those are not safe in default implementation. --- src/binfile_utils.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/binfile_utils.hpp b/src/binfile_utils.hpp index 4e342ef..69c2201 100644 --- a/src/binfile_utils.hpp +++ b/src/binfile_utils.hpp @@ -37,6 +37,8 @@ namespace BinFileUtils { BinFile(const void *fileData, size_t fileSize, std::string _type, uint32_t maxVersion); BinFile(const std::string& fileName, const std::string& _type, uint32_t maxVersion); + BinFile(const BinFile&) = delete; + BinFile& operator=(const BinFile&) = delete; ~BinFile(); void startReadSection(u_int32_t sectionId, u_int32_t setionPos = 0);