Skip to content

Commit 6208460

Browse files
committed
updates
1 parent eb97f7c commit 6208460

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# PySNARK
22

3+
Recent news:
4+
5+
*03.11.2020*: updated to latest snarkjs
6+
37
*(This is a re-write of the original version of PySNARK, still available [here](https://github.com/Charterhouse/pysnark).)*
48

59
PySNARK lets you program zk-SNARKs (aka verifiable computations) directly in Python 3. For example, the following code runs a SNARK program to compute a cube of a number, generates key material, generates a proof, and verifies it:
@@ -21,6 +25,7 @@ PySNARK can use [qaptools](https://github.com/Charterhouse/qaptools) or [libsnar
2125
Features:
2226

2327
* Pure Python 3.*; libsnark and qaptools backends supported on Windows/Linux/Mac OS
28+
* Can be used in combination with snarkjs as a drop-in replacement for circom
2429
* Automatically produce Solidity smart contracts
2530
* Automatically produce snarkjs circuit+witness or verification key+proof+public values
2631
* Automatically produce [zkinterface](https://github.com/QED-it/zkinterface) file for computation
@@ -80,8 +85,6 @@ PYSNARK_BACKEND=libsnarkgg python3 cube.py 3
8085

8186
### Combining with snarkjs
8287

83-
**Note: this feature has been recently updated, please use the latest Git version**
84-
8588
PySNARK with the libsnarkgg backend can automatically produce snarkjs `public.json`, `proof.json` and `verification_key.json` files for the performed verifiable computation:
8689

8790
```
@@ -98,8 +101,6 @@ meilofs-air:examples meilof$ snarkjs groth16 verify verification_key.json public
98101

99102
## Using PySNARK (snarkjs backend)
100103

101-
**Note: this feature has been recently updated, please use the latest Git version**
102-
103104
PySNARK can be used in combination with snarkjs as a drop-in replacement of programming circuits using circom. PySNARK generates the `circuit.r1cs` file corresponding to the computation constraints and the `witness.wtns` file containing the values for the current computation:
104105

105106
```

dist.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
rm -rf PySNARK.egg-info/
44
python3 setup.py sdist
55
rm -rf PySNARK.egg-info/
6-
python3 setup.py --disable-libsnark --qaptools-bin=qaptools/ sdist --formats=zip
6+
python3 setup.py sdist --formats=zip
7+

docs/README.md

+56-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# PySNARK
22

3+
Recent news:
4+
5+
*03.11.2020*: updated to latest snarkjs
6+
37
*(This is a re-write of the original version of PySNARK, still available [here](https://github.com/Charterhouse/pysnark).)*
48

59
PySNARK lets you program zk-SNARKs (aka verifiable computations) directly in Python 3. For example, the following code runs a SNARK program to compute a cube of a number, generates key material, generates a proof, and verifies it:
@@ -20,9 +24,11 @@ PySNARK can use [qaptools](https://github.com/Charterhouse/qaptools) or [libsnar
2024

2125
Features:
2226

23-
* Support Unix platforms (Linux, Mac OS X, ...) and Windows
27+
* Pure Python 3.*; libsnark and qaptools backends supported on Windows/Linux/Mac OS
28+
* Can be used in combination with snarkjs as a drop-in replacement for circom
2429
* Automatically produce Solidity smart contracts
2530
* Automatically produce snarkjs circuit+witness or verification key+proof+public values
31+
* Automatically produce [zkinterface](https://github.com/QED-it/zkinterface) file for computation
2632
* Support for [integer arithmetic](https://github.com/meilof/pysnark/blob/master/pysnark/runtime.py#L179), [linear algebra](https://github.com/meilof/pysnark/blob/master/pysnark/linalg.py#L3), [arrays with conditional indexing](https://github.com/meilof/pysnark/blob/master/pysnark/array.py#L36), [if statements](https://github.com/meilof/pysnark/blob/master/pysnark/branching.py#L10) and [branching](https://github.com/meilof/pysnark/blob/master/pysnark/branching.py#L132), and [hashing](https://github.com/meilof/pysnark/blob/master/pysnark/hash.py#L61); see provided [examples](https://github.com/meilof/pysnark/tree/master/examples)
2733

2834
PySNARK may be used for non-commercial, experimental and research purposes; see `LICENSE.md` for details.
@@ -69,41 +75,72 @@ By default, if available, the libsnark backend will be used. In this case, the f
6975
* `pysnark_vk`: key material to verify proofs for this computation
7076
* `pysnark_log`: computation log that can be verified with the `pysnark_vk` key: number of inputs/outputs, followed by the inputs/outputs themselves, followed by a proof that the input/outputs were correctly computed
7177

78+
PySNARK with libsnark can use the more recent Groth16 proof system instead of traditional Pinocchio proofs by using the libsnarkgg backend:
79+
80+
```
81+
cd examples
82+
rm pysnark_*
83+
PYSNARK_BACKEND=libsnarkgg python3 cube.py 3
84+
```
7285

7386
### Combining with snarkjs
7487

75-
PySNARK with the libsnark backend can automatically produce snarkjs `public.json`, `proof.json` and `verification_key.json` files for the performed verifiable computation:
88+
PySNARK with the libsnarkgg backend can automatically produce snarkjs `public.json`, `proof.json` and `verification_key.json` files for the performed verifiable computation:
7689

7790
```
78-
meilofs-air:examples meilof$ python3 cube.py 33
91+
meilofs-air:examples meilof$ PYSNARK_BACKEND=libsnarkgg python3 cube.py 33
7992
The cube of 33 is 35937
8093
*** Trying to read pysnark_ek
8194
*** PySNARK: generating proof pysnark_log (sat=True, #io=2, #witness=2, #constraint=3)
8295
*** Public inputs: 33 35937
8396
*** Verification status: True
84-
meilofs-air:examples meilof$ python3 -m pysnark.libsnark.tosnarkjs
85-
meilofs-air:examples meilof$ snarkjs verify
86-
OK
87-
$ snarkjs generateverifier
88-
$ snarkjs generatecall
97+
meilofs-air:examples meilof$ python3 -m pysnark.libsnark.tosnarkjsgg
98+
meilofs-air:examples meilof$ snarkjs groth16 verify verification_key.json public.json proof.json
99+
[INFO] snarkJS: OK!
89100
```
90101

91102
## Using PySNARK (snarkjs backend)
92103

104+
PySNARK can be used in combination with snarkjs as a drop-in replacement of programming circuits using circom. PySNARK generates the `circuit.r1cs` file corresponding to the computation constraints and the `witness.wtns` file containing the values for the current computation:
105+
93106
```
94-
$ cd examples
95107
$ PYSNARK_BACKEND=snarkjs python3 cube.py 33
96108
The cube of 33 is 35937
97-
witness.json and circuit.json written; use 'snarkjs setup', 'snarkjs proof', and 'snarkjs verify'
98-
$ snarkjs setup
99-
$ snarkjs proof
100-
$ snarkjs verify
101-
OK
102-
$ snarkjs generateverifier
103-
$ snarkjs generatecall
109+
snarkjs witness.wtns and circuit.r1cs written; see readme
110+
$ snarkjs powersoftau new bn128 12 pot.ptau -v
111+
...
112+
$ snarkjs powersoftau prepare phase2 pot.ptau pott.ptau -v
104113
...
114+
$ snarkjs zkey new circuit.r1cs pott.ptau circuit.zkey
115+
...
116+
$ snarkjs zkey export verificationkey circuit.zkey verification_key.json
117+
$ snarkjs groth16 prove circuit.zkey witness.wtns proof.json public.json
118+
$ snarkjs groth16 verify verification_key.json public.json proof.json
119+
[INFO] snarkJS: OK!
120+
$ snarkjs zkey export solidityverifier circuit.zkey verifier.sol
121+
$ snarkjs zkey export soliditycalldata public.json proof.json
105122
```
106123

124+
## Using PySNARK (zkinterface backend)
125+
126+
PySNARK with the `zkinterface` backend automatically produces a file `computation.zkif` containing the circuit, witness, and constraint system for the computation.
127+
128+
```
129+
$ cd examples
130+
$ PYSNARK_BACKEND=zkinterface python3 cube.py 33
131+
The cube of 33 is 35937
132+
*** zkinterface: writing circuit
133+
*** zkinterface: writing witness
134+
*** zkinterface: writing constraints
135+
*** zkinterface circuit, witness, constraints written to 'computation.zkif', size 656
136+
```
137+
138+
The contents of the file can be printed with the `print` example program provided with zkinterface:
139+
140+
```
141+
$ cargo run --bin print < /path/to/computation.zkif
142+
...
143+
```
107144

108145
## Using PySNARK (qaptools backend)
109146

@@ -132,6 +169,7 @@ PySNARK produces the following files:
132169
* `pysnark_ek_main`: zk-SNARK evaluation
133170
key for the main function of the computation
134171
* `pysnark_eqs_main`: equations for the main function of the computation
172+
* `pysnark_masterpk`: master public key
135173
* Files that the trusted party should distribute to verifiers:
136174
* `pysnark_schedule`: schedule of functions called in the computation
137175
* `pysnark_masterpk`: master public key
@@ -219,6 +257,8 @@ When a particular functon is used multiple times in a verifiable computation, us
219257

220258
The `qaptools` backand of PySNARK supports the automatic generation of Solidity smart contracts that verify the correctness of the given zk-SNARK.
221259

260+
(Smart contracts can also be implemented using snarkjs with the snarkjs backend, see above.)
261+
222262
First, run a verifiable computation using the `qaptools` backend:
223263

224264
```

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup
44

55
setup(name='PySNARK',
6-
version='0.3',
6+
version='0.3.1',
77
description='Python zk-SNARK execution environment',
88
author='Meilof Veeningen',
99
author_email='[email protected]',

0 commit comments

Comments
 (0)