ZKPyC is a compiler for a subset of Python 3.10 to a Rank-1 Constraint System (R1CS) description, used by modern zero-knowledge (ZK) proof systems such as zk-SNARKs. The ZKPyC compiler leverages the CirC circuit compiler infrastructure to produce optimized and secure R1CS constraints.
- Compile Python 3.10 code (subset defined in
zkpyc.asdl
) to R1CS. - Export R1CS in two formats:
- CirC-IR serialization: Compatible with ZK proof system backends directly supported by CirC, such as Groth16, Mirage, and Spartan.
- zkInterface format: Compatible with ZK proof system backends that support R1CS constraints in the zkInterface format.
- Generate valid witnesses for the R1CS constraints.
Note: This software is a proof-of-concept and has not been audited. Use with caution
To install ZKPyC, you need a stable Rust compiler. Install directly from GitHub using the following command:
cargo install --git https://github.com/zkpyc/zkpyc.git zkpyc-core
To compile a Python file into an instance of R1CS:
zkpyc <file_name> r1cs --action setup --proof-impl <groth16 | zkinterface>
To generate the witness for the corresponding R1CS instance:
zk --inputs <prover_inputs_file_name> --action prove --proof-impl <groth16 | zkinterface>
To verify the witness or generate the verifier's zkInterface file:
zk --inputs <verifier_inputs_file_name> --action verify --proof-impl <groth16 | zkinterface>
# Compile the program into an R1CS instance
zkpyc examples/mm.py r1cs --action setup --proof-impl groth16
# Generate the zero-knowledge proof
zk --inputs examples/mm.py.pin --action prove --proof-impl groth16
# Verify the witness in zero-knowledge
zk --inputs examples/mm.py.vin --action verify --proof-impl groth16
# Compile the program into an R1CS instance
zkpyc --field-custom-modulus 7237005577332262213973186563042994240857116359379907606001950938285454250989 examples/zkinterface.py --action setup --proof-impl zkinterface
# Generate the zero-knowledge proof
zk --field-custom-modulus 7237005577332262213973186563042994240857116359379907606001950938285454250989 examples/zkinterface.py.pin --action prove --proof-impl zkinterface
# Verify the witness in zero-knowledge
zk --field-custom-modulus 7237005577332262213973186563042994240857116359379907606001950938285454250989 examples/zkinterface.py.vin --action verify --proof-impl zkinterface
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. See NOTICE
for information on software derivations and their respective licenses.
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).
The logo used in this repository, zkpyc-logo.svg
, is a derivative of the official Python logo. Usage of the derived logo has been approved by the Python Software Foundation (PSF) under the terms of their trademark usage policy.
- For reporting issues, please use GitHub Issues.
- For direct inquiries, you can contact me at [email protected].