Skip to content

Commit

Permalink
READMEs (#8)
Browse files Browse the repository at this point in the history
* Added Readme for the whole project and for witness calc. Updated readme for prover

* Updated Readme for witness calc

* Update test deps

* Print CPU Info in GHA

* Disable package cache for GHA

* Rebuild of gmp with disabled asm optimizations that were causing problems. Benchmark test.
  • Loading branch information
OBrezhniev authored Nov 22, 2022
1 parent 8d7beac commit 955a65b
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 18 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test-linux-asm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ jobs:
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: false
- name: Checkout code
uses: actions/checkout@v2
- name: Print CPU Info
run: cat /proc/cpuinfo
- name: Run tests
# rapidsnark_asm build tag enables asm optimizations
run: cd tests && go test -tags rapidsnark_asm -v -covermode=count
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test-linux-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ jobs:
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: false
- name: Checkout code
uses: actions/checkout@v2
- name: Print CPU Info
run: cat /proc/cpuinfo
- name: Run tests
run: cd tests && go test -v -covermode=count

5 changes: 4 additions & 1 deletion .github/workflows/test-linux-noasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ jobs:
steps:
- name: Install Go
if: success()
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: false
- name: Checkout code
uses: actions/checkout@v2
- name: Print CPU Info
run: cat /proc/cpuinfo
- name: Run tests
# rapidsnark_noasm build tag is needed for older GitHub Action runners
run: cd tests && go test -tags rapidsnark_noasm -v -covermode=count
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# go-rapidsnark

go-rapidsnark is a collection of packages to [calculate witness](/witness), [generate zk-proof](/prover) and [verify zk-proof](/verifier).

Note: prover and witness calculator have specific build & installation instructions.
27 changes: 14 additions & 13 deletions prover/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
# go-rapidsnark
# go-rapidsnark prover

A go wrapper for the RapidSNARK C++ library.

To use this module you either need to have RapidSNARK library available on
your build host or have one of the supported architectures to use vendored
pre-built library for convenience use.
pre-built libraries for convenience.

## Build using pre-built vendored RapidSNARK library.
## Dependencies
* C/C++ compiler and standard libraries available
* glibc version >= 2.31
* OpenMP

On Ubuntu it would be enough to install `build-essential` and `libomp-dev` packages.

For few architectures, pre-built vendored libraries are included. And just use
this module without any externally built dependencies except standard C/C++
libraries.
If you build your project using `golang` Docker container, all tools are already installed.

Supported architectures are:
To run compiled project on Alpine linux you would need to install there `libstdc++`, `gcompat` and `libgomp` packages.

## Build using pre-built vendored RapidSNARK library.

For the following architectures, pre-built vendored libraries are included:
* MacOS x86_64
* MacOS ARM64 Apple Silicon
* Linux x86_64
* Linux ARM64 v8

Minimum glibc version that should be available on build host is 2.31.

Also, you need a C/C++ compiler and standard libraries available. On Ubuntu it
would be enough to install `build-essential` package. If you build your project
using `golang` Docker container, all tools are already installed.

## Performance optimization on x86_64 hardware

Rapidsnark has optimization for recent x86_64 processors that gives ~2x speed boost, but older hardware may lack support for ADX and BMI2 instruction sets used.
Expand Down
Binary file modified prover/rapidsnark_vendor/libgmp-linux-amd64.a
Binary file not shown.
5 changes: 3 additions & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/iden3/go-rapidsnark/tests
go 1.18

require (
github.com/iden3/go-rapidsnark/prover v0.0.5
github.com/iden3/go-rapidsnark/verifier v0.0.2
github.com/iden3/go-rapidsnark/prover v0.0.6
github.com/iden3/go-rapidsnark/verifier v0.0.3
github.com/stretchr/testify v1.8.0
)

Expand All @@ -21,4 +21,5 @@ require (
replace (
github.com/iden3/go-rapidsnark/prover => ../prover
github.com/iden3/go-rapidsnark/verifier => ../verifier
github.com/iden3/go-rapidsnark/types => ../types
)
4 changes: 4 additions & 0 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ github.com/ethereum/go-ethereum v1.10.26 h1:i/7d9RBBwiXCEuyduBQzJw/mKmnvzsN14jqB
github.com/ethereum/go-ethereum v1.10.26/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
github.com/iden3/go-iden3-crypto v0.0.13 h1:ixWRiaqDULNyIDdOWz2QQJG5t4PpNHkQk2P6GV94cok=
github.com/iden3/go-iden3-crypto v0.0.13/go.mod h1:swXIv0HFbJKobbQBtsB50G7IHr6PbTowutSew/iBEoo=
github.com/iden3/go-rapidsnark/prover v0.0.6 h1:AXxizQJ3ofddpqlN3cFm6Yg/0eO3hE41Gm7cLUfYT7Y=
github.com/iden3/go-rapidsnark/prover v0.0.6/go.mod h1:wgDsmKOGCuWGtgVtuW9ARWNguNr4NJAIyg2G7+uTax0=
github.com/iden3/go-rapidsnark/types v0.0.2 h1:CjJSrlbWchHzuMRdxSYrEh7n/akP+Z2PLNbwT5yBmQY=
github.com/iden3/go-rapidsnark/types v0.0.2/go.mod h1:ApgcaUxKIgSRA6fAeFxK7p+lgXXfG4oA2HN5DhFlfF4=
github.com/iden3/go-rapidsnark/verifier v0.0.3 h1:DkEe9xiwMTocOr5dH0jUt/NBk49EPujArUFvAHqpc0M=
github.com/iden3/go-rapidsnark/verifier v0.0.3/go.mod h1:A3R3qr+8QiQtFBghrx94VJrOIr+9mdgrrbmFzJyS9Sg=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
24 changes: 24 additions & 0 deletions tests/rapidsnark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,27 @@ func Test_Groth16Prover(t *testing.T) {
err = verifier.VerifyGroth16(*proof, verificationKey)
assert.NoError(t, err)
}

func Benchmark(b *testing.B) {
var provingKey, verificationKey, witness []byte
var err error

provingKey, err = os.ReadFile("./testdata/circuit_final.zkey")
assert.Nil(b, err)

witness, err = os.ReadFile("./testdata/witness.wtns")
assert.Nil(b, err)

verificationKey, err = os.ReadFile("./testdata/verification_key.json")
assert.Nil(b, err)

assert.NoError(b, err)

for i := 0; i < b.N; i++ {
proof, err := prover.Groth16Prover(provingKey, witness)
assert.NoError(b, err)

err = verifier.VerifyGroth16(*proof, verificationKey)
assert.NoError(b, err)
}
}
14 changes: 14 additions & 0 deletions witness/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# go-rapidsnark witness calculator

Calculates witness, that can be passed to a prover ([snarkjs](https://github.com/iden3/snarkjs), [go-rapidsnark/prover](/prover) or [rapidsnark](https://github.com/iden3/rapidsnark)) to generate a zero-knowledge proof.

## Installation

```
go get github.com/iden3/go-rapidsnark/witness
```

## Dependencies

This package depends on wasmer shared library, which needs to be copied from [wasmer-go](https://github.com/wasmerio/wasmer-go/tree/master/wasmer/packaged/lib) module source code.
E.g. to run compiled project on Alpine linux you would need to copy `/go/pkg/mod/github.com/wasmerio/[email protected]/wasmer/packaged/lib/linux-amd64/libwasmer.so` from the build host/container.

0 comments on commit 955a65b

Please sign in to comment.