Note: This project has been moved to ZKPyC, where it is being maintained as the crate zkpyc-python
ZKPyToolkit is a comprehensive toolkit designed for creating and evaluating Zero-Knowledge Proofs (ZKPs) natively in Python. It offers a collection of tools for compiling Python functions, up to a subset of Python >=3.10, into Zero-Knowledge Proof gadgets in the Rank-1 Constraint System (R1CS). The toolkit supports direct evaluation of ZKPs through a selected list of ZKP backends.
-
Python Compatibility: ZKPyToolkit is compatible with Python 3.10.
-
Compiler Integration: The ZKPyToolkit front-end relies on the ZKPyC compiler, requiring a stable Rust compiler.
-
ZKP Backend Support: Backends receive ZKPs in the format specified by ZkInterface. The currently supported backends include:
Backend Implementation Proving System Primefield Modulus Bellman Groth16 bls12_381 Dalek Bulletproofs ristretto255
Important: This software is a proof-of-concept and has not been audited. It is highly experimental and currently deemed unstable. Use with caution.
To install ZKPyToolkit, ensure that you have at least Rust compiler version 1.63.0 installed. Then, run the following command:
pip install .ZKPyToolkit can only be used in script mode as well as through the interactive mode provided by the IPython shell or JupyterLab. To use ZKPyToolkit, instantiate a ZKP instance from zkpytoolkit.ZKP with the required parameter modulus and optionally backend for the proving system, and id for bookkeeping. Only after instantiation can you import the ZKPyToolkit types. Here's an example:
from zkpytoolkit import ZKP
zkp = ZKP(modulus="bls12_381", backend="groth16")
from zkpytoolkit.types import Private, Public, Array, field
...For a concrete example, you are refered to the /notebooks/zkpytoolkit_demo.ipynb notebook.
The standard library (stdlib), is a migration of the ZoKrates Standard Library to Python, providing a range of Python-friendly ZKP gadgets, accessible via the submodule zkpytoolkit.stdlib. These consist of:
-
Commitment Schemes:
zkpytoolkit.stdlib.commitmentScheme Implementation Pedersen zkpytoolkit.stdlib.commitment.pedersenSHA256 zkpytoolkit.stdlib.commitment.sha256 -
Hash Functions:
zkpytoolkit.stdlib.hashesHash Function Compatible Curves Implementations Pedersen bls12_381, bn256, ristretto255 zkpytoolkit.stdlib.hashes.pedersen.bls12_381,zkpytoolkit.stdlib.hashes.pedersen.bn256,zkpytoolkit.stdlib.hashes.pedersen.ristretto255SHA256 all zkpytoolkit.stdlib.hashes.sha256Poseidon bls12_381 zkpytoolkit.stdlib.hashes.poseidon -
Elliptic Curve Cryptography:
zkpytoolkit.stdlib.eccCurve Implementation Edwards zkpytoolkit.stdlib.ecc.edwards -
Utilities:
zkpytoolkit.stdlib.utilsUtility Description Implementation Casting From int to array of bool and vice versa zkpytoolkit.stdlib.utils.castsMultiplexing Used in Pedersen hash zkpytoolkit.stdlib.utils.multiplexerPacking/Unpacking Bool array to field and back zkpytoolkit.stdlib.utils.pack
To contribute, simply submit a pull request. There are currently no strict guidelines, and any support is appreciated.
This project is dual-licensed under the Apache 2.0 and MIT licenses. See the LICENSE-APACHE and LICENSE-MIT files for more details.
This work is based upon the author's master's thesis, which was written at the University of Groningen and TNO (Department of Applied Cryptography & Quantum Algorithms).
- For reporting issues, please use GitHub Issues.
- For direct inquiries, you can contact me at lorenzo.rota@hotmail.com.