The ZoKrates core library wrap around an API
Report Bug
·
Request Feature
ZoKrates-API is a JSON API wrapper around the Zokrates commands involved in the generation of zk-SNARKs proofs. Being able to perform Zokrates operations through http facilitates the automation of processes in which the calculation of zk-SNARKs is required. Furthermore, ZoKrates-API was developed to be easily deployed as micro-service on the cloud, to avoid running into memory problems so common when developing zk-SNARKs. With ZoKrates-API, you can have multiple instances running in parallel on a Kubernetes cluster.
ZoKrates-API aims to tackle the following problems:
- Once you figure out how zk-SNARKs can solve your specific problem, Don't waste your time how to embed it on your system. Pull the image and communicate with the service through standard http requests.
- Though to be used as a micro-service, ZoKrates-API can be scaled horizontally and vertically with ease.
- ZoKrates-API is written in rust and provides a performance boost and memory granularity compare to ZoKrates-js
$ docker run -p 8000:8000 --env ROCKET_LOG_LEVEL=normal alvaround/zokrates-api:latest
$ docker-compose up
$ RUST_MIN_STACK=1000000 cargo +nightly run
Or with hot-loading:
$ RUST_MIN_STACK=1000000 cargo +nightly watch -x run
Once you have the image running locally, open the OpenAPI interface on http://0.0.0.0:8000/docs/index.html in your browser. In the url you can access all the methods support, endpoints, body schemas, and response tes supported by the API.
The API is able to generate proofs for multiple .zok
at once. However, for each new .zok
the Proof Setup process has to be done once.
- Add your
.zok
file in thePOST /compile
endpoint and click execute. Zokrates will compile the program on the server. This can take some time. If the program compiles successfully, the response constains theprogram_hash
and the abi.json structure. You will need both information on later steps. - Call the
POST /<PROGRAM_HASH>/proving-key
with theprogram_hash
from previous step and the proving key of the program attached in the response.
Once the proof Setup step is done, you can create zk-SNARKs by providing a valid witness in the .json format specified in abi
field in the response of the POST /compile
.
You have two ways to get a proof from a valid witness:
- Calling the endpoint
POST /<PROGRAM_HASH>/compute-generate-proof
. This is the preferred and simplest option. This endpoint takes the proof arguments as inputs and delivers the final proof in the response under thepayload
field. - Calling the endpoints
POST /<PROGRAM_HASH>/compute-witness
andPOST /<PROGRAM_HASH>/generate-proof
. These two endpoints replicate the functionality of the ZoKrates CLI.POST /<PROGRAM_HASH>/compute-witness
takes the proof arguments and generates the witness. The witness is the used by<PROGRAM_HASH>/generate-proof
to generate the zk-SNARK.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Open an Issue to discuss the problem at hand and possible solutions
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Run tests:
$ cargo test
Rust format:
$ cargo fmt
Rust lint:
$ cargo clippy
Distributed under the GNU LGPL 3.0. See LICENSE
for more information.