Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Cibuild #6

Merged
merged 39 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e20e009
test running CI on macos-13
olomix Oct 3, 2023
b9e0f57
try to run on arm-64 worker
olomix Oct 3, 2023
a3e2561
try to run on macos-13-xlarge worker
olomix Oct 3, 2023
00db771
try to run on macos-13-xlarge worker
olomix Oct 3, 2023
8171763
find omp.h
olomix Oct 3, 2023
704e604
install libomp
olomix Oct 3, 2023
b36a10e
Fix build on macos: require installed libomp for ffiasm
olomix Oct 5, 2023
ecda275
first try to build prover for iOS on CI
olomix Oct 5, 2023
4cb7969
cache gmp build
olomix Oct 5, 2023
3d29f5c
look up for android SDK
olomix Oct 5, 2023
61e6190
Add iOS Simulator build and upload artifacts
olomix Oct 10, 2023
b833fe5
move android build to linux worker
olomix Oct 10, 2023
eab1bb2
Try to build and upload android artifacts
olomix Oct 12, 2023
306cec9
fix yaml build file
olomix Oct 12, 2023
5769ced
fix if condition
olomix Oct 12, 2023
5f99b0d
Get rid of libomp dependency for ios builds. Add libgmp to distributi…
olomix Oct 24, 2023
7213f70
add .idea dir to .gitignore
olomix Oct 24, 2023
d2b1ab6
switch build_gmp script to bash to support arrays
olomix Oct 24, 2023
905e4b3
fix path to iphone simulator libgmp
olomix Oct 24, 2023
f3289b2
Add build CI for macos
olomix Oct 31, 2023
3f978bf
verify proof generation
olomix Nov 2, 2023
55dbc30
debug snarkjs verify
olomix Nov 2, 2023
c6cbd2a
do not run linux for now
olomix Nov 2, 2023
e7bdbac
debug snarkjs verify
olomix Nov 2, 2023
cdb3378
debug snarkjs verify
olomix Nov 2, 2023
28a9345
debug snarkjs verify
olomix Nov 2, 2023
d9115bf
debug snarkjs verify
olomix Nov 2, 2023
8cad37f
build for macos x86_64
olomix Nov 2, 2023
abb713a
cache gmp
olomix Nov 2, 2023
c2f7053
cache gmp
olomix Nov 2, 2023
634f8a4
cache gmp
olomix Nov 2, 2023
f7d731f
build prover for macos x86_64
olomix Nov 2, 2023
05a1c8c
test prover on macos x86_64
olomix Nov 2, 2023
6bb09ba
test prover on macos x86_64
olomix Nov 2, 2023
8eb0111
uncomment all jobs
olomix Nov 2, 2023
92c1933
return WRT instruction to ASM for elf format
olomix Nov 3, 2023
c38b435
build prover for linux x86_64
olomix Nov 3, 2023
69828ac
Cleanup build_gmp.sh usage text
olomix Nov 6, 2023
e0f4c6b
update ffiasm submoule path to github.com/0xPolygonID/ffiasm repo
olomix Nov 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 192 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: Build

on:
push:
branches:
- main
- cibuild

jobs:
build-linux:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: install requirements
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: curl xz-utils build-essential cmake m4 nasm
version: 1.0

- name: Cache gmp build
uses: actions/cache@v3
with:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-gmp-${{ hashFiles('build_gmp.sh') }}-2

- name: build gmp android arm64
run: if [[ ! -d "depends/gmp/package_android_arm64" ]]; then ./build_gmp.sh android; fi

- name: build gmp 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
run: if [[ ! -d "depends/gmp/package" ]]; then ./build_gmp.sh host; fi

- name: Build prover Android ARM64
run: |
mkdir 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
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
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install

- name: upload Android ARM64 artifacts
uses: actions/upload-artifact@v3
with:
name: rapidsnark-Android-arm64
path: |
package_android
if-no-files-found: error

- name: upload Android x86_64 artifacts
uses: actions/upload-artifact@v3
with:
name: rapidsnark-Android-x86_64
path: |
package_android_x86_64
if-no-files-found: error

- name: upload Linux x86_64 artifacts
uses: actions/upload-artifact@v3
with:
name: rapidsnark-Linux-x86_64
path: |
package
if-no-files-found: error

build-apple-arm64:
runs-on: macos-13-xlarge
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Cache gmp build
uses: actions/cache@v3
with:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-gmp-arm64-${{ hashFiles('build_gmp.sh') }}

- name: build
run: |
if [[ ! -d "depends/gmp/package_ios_arm64" ]]; then ./build_gmp.sh ios; fi
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
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
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
cmake .. -DTARGET_PLATFORM=macos_arm64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_arm64
make -j4 && make install

- name: test prover
run: |
set -x
set -e
npm install -g snarkjs
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
uses: actions/upload-artifact@v3
with:
name: rapidsnark-iOS
path: |
build_prover_ios/src/Release-iphoneos
if-no-files-found: error

- name: upload iOS Simulator artifacts
uses: actions/upload-artifact@v3
with:
name: rapidsnark-iOS-Simulator
path: |
build_prover_ios_simulator/src/Debug-iphonesimulator
if-no-files-found: error

- name: upload macOS arm64 artifacts
uses: actions/upload-artifact@v3
with:
name: rapidsnark-macOS-arm64
path: |
package_macos_arm64
if-no-files-found: error

build-apple-x86_64:
runs-on: macos-13
steps:
- uses: actions/checkout@v4
with:
submodules: "recursive"

- name: Cache gmp build
uses: actions/cache@v3
with:
path: |
depends/gmp
depends/gmp-6.2.1.tar.xz
key: ${{ runner.os }}-gmp-x86_64-${{ hashFiles('build_gmp.sh') }}-2

- name: install dependencies
run: |
brew install nasm

- name: build
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
cmake .. -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64
make -j4 && make install

- name: test prover
run: |
set -x
set -e
npm install -g snarkjs
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
uses: actions/upload-artifact@v3
with:
name: rapidsnark-macOS-x86_64
path: |
package_macos_x86_64
if-no-files-found: error
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,5 @@ package*

build/fq_asm.o
build/fr_asm.o

.idea/
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
url = https://github.com/nlohmann/json.git
[submodule "depends/ffiasm"]
path = depends/ffiasm
url = https://github.com/nixw4/ffiasm.git
url = https://github.com/0xPolygonID/ffiasm
branch = master
[submodule "depends/circom_runtime"]
path = depends/circom_runtime
Expand Down
90 changes: 58 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,55 @@ You should have installed gcc, cmake, libsodium, and gmp (development)

In ubuntu:

````
sudo apt-get install build-essential cmake libgmp-dev libsodium-dev nasm
````
```
sudo apt-get install build-essential cmake libgmp-dev libsodium-dev nasm curl m4
```

## Compile prover in standalone mode

### Compile prover for x86_64 host machine

````sh
```sh
git submodule init
git submodule update
./build_gmp.sh host
mkdir build_prover && cd build_prover
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install
````
```

### Compile prover for macOS arm64 host machine

````sh
```sh
git submodule init
git submodule update
./build_gmp.sh host_noasm
mkdir build_prover && cd build_prover
cmake .. -DTARGET_PLATFORM=arm64_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
./build_gmp.sh macos_arm64
mkdir 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
````
```

### Compile prover for linux arm64 host machine

````sh
```sh
git submodule init
git submodule update
./build_gmp.sh host
mkdir build_prover && cd build_prover
cmake .. -DTARGET_PLATFORM=arm64_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install
````
```

### Compile prover for linux arm64 machine

````sh
```sh
git submodule init
git submodule update
./build_gmp.sh host
mkdir build_prover && cd build_prover
cmake .. -DTARGET_PLATFORM=aarch64 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_aarch64
make -j4 && make install
````
```

### Compile prover for Android

Expand All @@ -66,73 +66,99 @@ Set the value of ANDROID_NDK environment variable to the absolute path of Androi

Examples:

````sh
```sh
export ANDROID_NDK=/home/test/Android/Sdk/ndk/23.1.7779620 # NDK is installed by "SDK Manager" in Android Studio.
export ANDROID_NDK=/home/test/android-ndk-r23b # NDK is installed as a stand-alone package.
````
```

Prerequisites if build on Ubuntu:

```sh
apt-get install curl xz-utils build-essential cmake m4 nasm
```

Compilation:

````sh
```sh
git submodule init
git submodule update
./build_gmp.sh android
mkdir build_prover_android && cd build_prover_android
cmake .. -DTARGET_PLATFORM=ANDROID -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_android
make -j4 && make install
````
```

### Compile prover for iOS

Install Xcode.
Install Xcode

````sh
```sh
git submodule init
git submodule update
./build_gmp.sh ios
mkdir build_prover_ios && cd build_prover_ios
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package_ios
````
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios
xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj -configuration Release
```
Open generated Xcode project and compile prover.

## Build for iOS emulator

Install Xcode

```sh
git submodule init
git submodule update
./build_gmp.sh ios_simulator
mkdir 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
```

Files that you need to copy to your XCode project to link against Rapidsnark:
* build_prover_ios_simulator/src/Debug-iphonesimulator/librapidsnark.a
* build_prover_ios_simulator/src/Debug-iphonesimulator/libfq.a
* build_prover_ios_simulator/src/Debug-iphonesimulator/libfr.a
* depends/gmp/package_iphone_simulator/lib/libgmp.a

## Building proof

You have a full prover compiled in the build directory.

So you can replace snarkjs command:

````sh
```sh
snarkjs groth16 prove <circuit.zkey> <witness.wtns> <proof.json> <public.json>
````
```

by this one
````sh
```sh
./package/bin/prover <circuit.zkey> <witness.wtns> <proof.json> <public.json>
````
```

## Compile prover in server mode

````sh
```sh
npm install
git submodule init
git submodule update
npx task createFieldSources
npx task buildPistache
npx task buildProverServer
````
```

## Launch prover in server mode
````sh
```sh
./build/proverServer <port> <circuit1_zkey> <circuit2_zkey> ... <circuitN_zkey>
````
```

For every `circuit.circom` you have to generate with circom with --c option the `circuit_cpp` and after compilation you have to copy the executable into the `build` folder so the server can generate the witness and then the proof based on this witness.
You have an example of the usage calling the server endpoints to generate the proof with Nodejs in `/tools/request.js`.

To test a request you should pass an `input.json` as a parameter to the request call.
````sh
```sh
node tools/request.js <input.json> <circuit>
````
```

## Benchmark

Expand Down
Loading