You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+5-4
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# PySNARK
2
2
3
+
Recent news:
4
+
5
+
*03.11.2020*: updated to latest snarkjs
6
+
3
7
*(This is a re-write of the original version of PySNARK, still available [here](https://github.com/Charterhouse/pysnark).)*
4
8
5
9
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
21
25
Features:
22
26
23
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
24
29
* Automatically produce Solidity smart contracts
25
30
* Automatically produce snarkjs circuit+witness or verification key+proof+public values
26
31
* Automatically produce [zkinterface](https://github.com/QED-it/zkinterface) file for computation
**Note: this feature has been recently updated, please use the latest Git version**
84
-
85
88
PySNARK with the libsnarkgg backend can automatically produce snarkjs `public.json`, `proof.json` and `verification_key.json` files for the performed verifiable computation:
**Note: this feature has been recently updated, please use the latest Git version**
102
-
103
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:
Copy file name to clipboardexpand all lines: docs/README.md
+56-16
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# PySNARK
2
2
3
+
Recent news:
4
+
5
+
*03.11.2020*: updated to latest snarkjs
6
+
3
7
*(This is a re-write of the original version of PySNARK, still available [here](https://github.com/Charterhouse/pysnark).)*
4
8
5
9
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
20
24
21
25
Features:
22
26
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
24
29
* Automatically produce Solidity smart contracts
25
30
* Automatically produce snarkjs circuit+witness or verification key+proof+public values
31
+
* Automatically produce [zkinterface](https://github.com/QED-it/zkinterface) file for computation
26
32
* 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)
27
33
28
34
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
69
75
*`pysnark_vk`: key material to verify proofs for this computation
70
76
*`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
71
77
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
+
```
72
85
73
86
### Combining with snarkjs
74
87
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:
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
+
93
106
```
94
-
$ cd examples
95
107
$ PYSNARK_BACKEND=snarkjs python3 cube.py 33
96
108
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
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
+
```
107
144
108
145
## Using PySNARK (qaptools backend)
109
146
@@ -132,6 +169,7 @@ PySNARK produces the following files:
132
169
*`pysnark_ek_main`: zk-SNARK evaluation
133
170
key for the main function of the computation
134
171
*`pysnark_eqs_main`: equations for the main function of the computation
172
+
*`pysnark_masterpk`: master public key
135
173
* Files that the trusted party should distribute to verifiers:
136
174
*`pysnark_schedule`: schedule of functions called in the computation
137
175
*`pysnark_masterpk`: master public key
@@ -219,6 +257,8 @@ When a particular functon is used multiple times in a verifiable computation, us
219
257
220
258
The `qaptools` backand of PySNARK supports the automatic generation of Solidity smart contracts that verify the correctness of the given zk-SNARK.
221
259
260
+
(Smart contracts can also be implemented using snarkjs with the snarkjs backend, see above.)
261
+
222
262
First, run a verifiable computation using the `qaptools` backend:
0 commit comments