From 66c13b155a808073c240a612743ed7cb45ffb4cf Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Thu, 21 Dec 2023 07:47:08 -0500 Subject: [PATCH 1/2] Handle invalid witness length --- .github/workflows/build.yml | 14 +++++++------- .gitmodules | 2 +- depends/ffiasm | 2 +- src/binfile_utils.cpp | 4 ++-- src/main_prover.cpp | 2 +- src/prover.cpp | 7 +++++++ src/prover.h | 7 ++++--- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bc12007..19579a4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,13 +30,13 @@ jobs: depends/gmp-6.2.1.tar.xz key: ${{ runner.os }}-gmp-${{ hashFiles('build_gmp.sh') }}-2 - - name: build gmp android arm64 + - name: build gmp for Android arm64 run: if [[ ! -d "depends/gmp/package_android_arm64" ]]; then ./build_gmp.sh android; fi - - name: build gmp android x86_64 + - name: build gmp for Android x86_64 run: if [[ ! -d "depends/gmp/package_android_x86_64" ]]; then ./build_gmp.sh android_x86_64; fi - - name: build gmp android x86_64 + - name: build gmp for Linux x86_64 run: if [[ ! -d "depends/gmp/package" ]]; then ./build_gmp.sh host; fi - name: Build prover Android ARM64 @@ -209,7 +209,7 @@ jobs: GH_TOKEN: ${{ github.token }} run: | set -x - mkdir 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 + mkdir 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 diff --git a/.gitmodules b/.gitmodules index 59a3def..9a647c3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/nlohmann/json.git [submodule "depends/ffiasm"] path = depends/ffiasm - url = https://github.com/0xPolygonID/ffiasm + url = https://github.com/iden3/ffiasm branch = master [submodule "depends/circom_runtime"] path = depends/circom_runtime diff --git a/depends/ffiasm b/depends/ffiasm index 23429cd..f47c1cd 160000 --- a/depends/ffiasm +++ b/depends/ffiasm @@ -1 +1 @@ -Subproject commit 23429cd1fe343a4f6af6e1fdfa4e9bb1c3ee983a +Subproject commit f47c1cd603b97cfe5c4a38720cf0b01f4120b0d6 diff --git a/src/binfile_utils.cpp b/src/binfile_utils.cpp index 64359e3..de6d0d7 100644 --- a/src/binfile_utils.cpp +++ b/src/binfile_utils.cpp @@ -19,13 +19,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 us " + type); + throw new 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 us " + std::to_string(version)); + 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(); diff --git a/src/main_prover.cpp b/src/main_prover.cpp index cc4c8ca..30eafbc 100644 --- a/src/main_prover.cpp +++ b/src/main_prover.cpp @@ -9,7 +9,7 @@ do { perror(msg); exit(EXIT_FAILURE); } while (0) -const size_t BufferSize = 16384; +const size_t BufferSize = 32768; int main(int argc, char **argv) diff --git a/src/prover.cpp b/src/prover.cpp index 7968d54..6cf97f5 100644 --- a/src/prover.cpp +++ b/src/prover.cpp @@ -68,6 +68,13 @@ groth16_prover(const void *zkey_buffer, unsigned long zkey_size, BinFileUtils::BinFile wtns(wtns_buffer, wtns_size, "wtns", 2); auto wtnsHeader = WtnsUtils::loadHeader(&wtns); + if (zkeyHeader->nVars != wtnsHeader->nVars) { + snprintf(error_msg, error_msg_maxsize, + "Invalid witness length. Circuit: %u, witness: %u", + zkeyHeader->nVars, wtnsHeader->nVars); + return PPROVER_INVALID_WITNESS_LENGTH; + } + size_t proofMinSize = ProofBufferMinSize(); size_t publicMinSize = PublicBufferMinSize(zkeyHeader->nPublic); diff --git a/src/prover.h b/src/prover.h index 4dfad8e..970584f 100644 --- a/src/prover.h +++ b/src/prover.h @@ -6,9 +6,10 @@ extern "C" { #endif //Error codes returned by the functions. -#define PRPOVER_OK 0x0 -#define PPROVER_ERROR 0x1 -#define PPROVER_ERROR_SHORT_BUFFER 0x2 +#define PRPOVER_OK 0x0 +#define PPROVER_ERROR 0x1 +#define PPROVER_ERROR_SHORT_BUFFER 0x2 +#define PPROVER_INVALID_WITNESS_LENGTH 0x3 /** From bdfef206807eb7167ee17282bda183c3573f8a42 Mon Sep 17 00:00:00 2001 From: Oleg Lomaka Date: Wed, 3 Jan 2024 04:18:57 -0500 Subject: [PATCH 2/2] replace tabs with spaces --- src/prover.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/prover.cpp b/src/prover.cpp index 6cf97f5..50919d3 100644 --- a/src/prover.cpp +++ b/src/prover.cpp @@ -68,12 +68,12 @@ groth16_prover(const void *zkey_buffer, unsigned long zkey_size, BinFileUtils::BinFile wtns(wtns_buffer, wtns_size, "wtns", 2); auto wtnsHeader = WtnsUtils::loadHeader(&wtns); - if (zkeyHeader->nVars != wtnsHeader->nVars) { - snprintf(error_msg, error_msg_maxsize, - "Invalid witness length. Circuit: %u, witness: %u", - zkeyHeader->nVars, wtnsHeader->nVars); - return PPROVER_INVALID_WITNESS_LENGTH; - } + if (zkeyHeader->nVars != wtnsHeader->nVars) { + snprintf(error_msg, error_msg_maxsize, + "Invalid witness length. Circuit: %u, witness: %u", + zkeyHeader->nVars, wtnsHeader->nVars); + return PPROVER_INVALID_WITNESS_LENGTH; + } size_t proofMinSize = ProofBufferMinSize(); size_t publicMinSize = PublicBufferMinSize(zkeyHeader->nPublic);