This code is not owned by EY and EY provides no warranty and disclaims any and all liability for use of this code. Users must conduct their own diligence with respect to use for their purposes and any and all usage is on an as-is basis and at your own risk.
- Install Docker for Mac, or Docker for Windows
- Clone this repository to your computer:
git clone [email protected]:EYBlockchain/zokrates-worker.git - Run:
cd zokrates-worker
npm installdocker-compose build --build-arg NPM_TOKEN=${NPM_TOKEN}
docker-compose up -dWhen docker is done building, the http:// API will be available at http://localhost:8080.
There is also a docker image of zokrates-worker. It can be pulled from GitHub:
docker pull docker.pkg.github.com/eyblockchain/zokrates-worker/zokrates_worker:<version>You will need a GitHub token with package read permission so that you can log in to
docker.pkg.github.com to pull the image. The instructions on how to make one of these are
here.
Once available, you can run the docker image with the following command
docker run -p 8080:80 docker.pkg.github.com/eyblockchain/zokrates-worker/zokrates_worker:<version>To test locally:
docker-compose up -d
npm testTo build and test without docker-compose:
docker build --build-arg NPM_TOKEN=${NPM_TOKEN} . (note the image id)
docker run -p 8080:80 -v $PWD/output:/app/output -v $PWD/circuits:/app/circuits <image id>
npm testTo test using the published Docker image:
docker run -p 8080:80 -v $PWD/output:/app/output -v $PWD/circuits:/app/circuits docker.pkg.github.com/eyblockchain/zokrates-worker/zokrates_worker:<version>Run the following instruction to ensure that the service is up:
docker-compose up -d
This should spin up a container called api. api contains RESTful endpoints for interacting with
the service.
The api service is a RESTful service that makes use of the @eyblockchain/zokrates-zexe.js
package, and has the following endpoints.
To be able to leverage the service, mount the .zok file(s) to /app/circuits/path/to/file.zok or
load them via the load-circuits endpoint (see below). If using the load-circuits enpoint, you
can also use a .tar archive of .zok files to quickly load several files.
This service lists on container port 80 and can be exposed via a port set in the
docker-compose.yml (http://localhost:8080 in all the example commands which follow).
This is a post instruction that takes a .zok or a .tar archive of .zok files and uploads
it/them. It/they will be stored in ./circuits/.
If a tar file was used, the unpacked files will be in a subdirectory,named after the tar file, with
the .tar extension removed.
Request body:
form-data: key = circuits, value = <file to upload>
This is a POST instruction that runs compile, setup and exportVerifier instructions.
Request body:
filepath: the path of the.zokfile (relative to/app/circuits/). E.g. for a file at/app/circuits/path/to/test.zokthe filepath ispath/to/test.zok.curve: specify one of:[bn128, bls12_381]provingScheme: specify one of:[g16, gm17, pghr13].backend: specify one of:libsnark,bellman.
Note, Nightfall currently uses [ bn128, libsnark, gm17]
Example:
curl -d '{"filepath": "path/to/test.zok", "curve": "bn128", "provingScheme": "gm17", "backend": "libsnark"}' -H "Content-Type: application/json" -X POST http://localhost:8080/generate-keys
Alternatively, the POSTMAN application can be used to run these curl requests. E.g. with body:
{
"filepath": "path/to/test.zok",
"curve": "bn128",
"provingScheme": "gm17",
"backend": "libsnark"
}Note: All the resultant files from this step are stored in a new sub-directory of the output
directory, called ${circuitName} (where, for example, if the circuitName is test, the output
files are stored in a dir app/output/test/).
This is a POST instruction that runs compute-witness and generate-proof instructions.
Request body:
folderpath: the path of the circuit folder (relative to/app/outputs/). E.g. for a folder at/app/outputs/path/to/testthe folderpath ispath/to/test. The folder contains the keys related to the circuitinputs: array of the arguments for the witness computation.
The /app/circuits/output dir has the outputs of these steps copied from within the container. When
the generate-proof instruction is run, the corresponding proof.json is stored in the
/app/circuits/output dir.
Example:
curl -d '{"folderpath": "path/to/test", "inputs": [6, 3, 2]}' -H "Content-Type: application/json" -X POST http://localhost:8080/generate-proof
Alternatively, the POSTMAN application can be used to run these curl requests. E.g. with body:
{
"folderpath": "path/to/test",
"inputs": [6, 32, 2],
"provingScheme": "gm17",
"backend": "libsnark"
}Note: All of the resultant files from this step are stored in the same sub-directory of the output
directory, called path/to/test (where, for example, if the folderpath is test/circuit, the
output files are stored in a dir app/output/test/circuit).
This is a GET request, to retrieve a vk from disk. (Note: a trusted setup will have to have taken place for the vk to exist).
query parameters:
folderpath: the path of the circuit folder (relative to/app/outputs/). E.g. for a folder at/app/outputs/path/to/testthe folderpath ispath/to/test. The folder contains the keys related to the circuit
Example:
curl -H "Content-Type: application/json" -X GET http://localhost:8080/vk?folderpath=test
Alternatively, the POSTMAN application can be used to run these curl requests. E.g. with params:
key: "folderpath", value: "test"
To test a particular .zok file manually in the terminal:
(You might need to do
docker pull docker.pkg.github.com/eyblockchain/zokrates-worker/zokrates_worker:<version> if you
haven't already).
cd path/to/parent-dir-of-zok-file/
docker run -v $PWD:/home/zokrates/code -ti docker.pkg.github.com/eyblockchain/zokrates-worker/zokrates_worker:<version> /bin/bash
(mounting to /code ensures the outputs from zokrates don't overwrite / mix with our local
machine's files).
For zokrates worker v1.2.3 and below (uses ZoKrates 0.6.1 and below):
./zokrates compile -c bn128 -i code/<circuitName>.zok
./zokrates setup -b libsnark -proving-scheme gm17
./zokrates compute-witness -a <inputs>
./zokrates generate-proof -b libsnark -proving-scheme gm17
For later versions (uses ZoKrates 0.6.4):
./zokrates/bin/zokrates compile -c bn128 -i code/<circuitName>.zok
./zokrates/bin/zokrates setup -b libsnark -proving-scheme gm17
./zokrates/bin/zokrates compute-witness -a <inputs>
./zokrates/bin/zokrates generate-proof -b libsnark -proving-scheme gm17
Tip: add the --light tag to any of the above commands and you won't see walls of compiled circuits
filling up your terminal.