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: TUTORIAL.md
+25-18Lines changed: 25 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ This tutorial will guide you in creating your first Zero Knowledge zkSnark circu
6
6
7
7
### 1.1 Pre-requisites
8
8
9
-
If you don't have it installed yet, you need to install `Node.js`.
9
+
If you don't have it installed yet, you need to install `Node.js`.
10
10
11
11
The last stable version of `Node.js` (or 8.12.0) works just fine, but if you install the latest current version `Node.js` (10.12.0) you will see a significant increase in performance. This is because last versions of node includes Big Integer Libraries nativelly. The `snarkjs` library makes use of this feature if available, and this improves the performance x10 (!).
12
12
@@ -16,6 +16,7 @@ Run:
16
16
17
17
```sh
18
18
npm install -g circom
19
+
npm install -g circom_runtime
19
20
npm install -g snarkjs
20
21
```
21
22
@@ -42,7 +43,7 @@ template Multiplier() {
42
43
signal private input a;
43
44
signal private input b;
44
45
signal output c;
45
-
46
+
46
47
c <== a*b;
47
48
}
48
49
@@ -62,10 +63,12 @@ Note: When compiling a circuit, a component named `main` must always exist.
62
63
We are now ready to compile the circuit. Run the following command:
63
64
64
65
```sh
65
-
circom circuit.circom -o circuit.json
66
+
circom circuit.circom --r1cs --wasm --sym
66
67
```
67
68
68
-
to compile the circuit to a file named `circuit.json`
69
+
The -r optin will generate `circuit.r1cs` ( The r1cs constraint system of the circuit in binary format)
70
+
The -w will generate `circuit.wasm` (The wasm code to generate the witness)
71
+
The -s will generate `circuit.sym` (This is the symbols file, required for debugging or if you want to print the constraint system in an annotated mode)
69
72
70
73
71
74
## 3. Taking the compiled circuit to *snarkjs*
@@ -74,21 +77,21 @@ Now that the circuit is compiled, we will continue with `snarkjs`.
74
77
Please note that you can always access the help of `snarkjs` by typing:
75
78
76
79
```sh
77
-
snarkjs --help
80
+
snarkjs --help
78
81
```
79
82
80
83
### 3.1 View information and stats regarding a circuit
81
84
82
85
To show general statistics of this circuit, you can run:
83
86
84
87
```sh
85
-
snarkjs info -c circuit.json
88
+
snarkjs info -r circuit.r1cs
86
89
```
87
90
88
91
You can also print the constraints of the circuit by running:
> By default `snarkjs` will look for and use `circuit.json`. You can always specify a different circuit file by adding `-c <circuit JSON file name>`
107
+
> By default `snarkjs` will look for and use `circuit.r1cs`. You can always specify a different circuit file by adding `-r <circuit R1CS file name>`
105
108
106
109
The output of the setup will in the form of 2 files: `proving_key.json` and `verification_key.json`
107
110
108
111
### 3.3. Calculating a witness
109
112
110
113
Before creating any proof, we need to calculate all the signals of the circuit that match (all) the constrains of the circuit.
111
114
112
-
`snarkjs` calculates those for you. You need to provide a file with the inputs and it will execute the circuit and calculate all the intermediate signals and the output. This set of signals is the *witness*.
115
+
`circom` generates a wasm module that calculates those for you. You need to provide a file with the inputs and it will execute the circuit and calculate all the intermediate signals and the output. This set of signals is the *witness*.
113
116
114
117
The zero knowledge proofs prove that you know a set of signals (witness) that match all the constraints, without revealing any of the signals except the public inputs plus the outputs.
115
118
116
-
For example, imagine you want to prove you are able to factor 33. It means that you know two numbers `a` and `b` and when you multiply them, it results in 33.
119
+
For example, imagine you want to prove you are able to factor 33. It means that you know two numbers `a` and `b` and when you multiply them, it results in 33.
117
120
118
-
> Of course you can always use one and the same number as `a`and`b`. We will deal with this problem later.
121
+
> Of course you can always use one and the same number as `a`or`b`. We will deal with this problem later.
119
122
120
123
So you want to prove that you know 3 and 11.
121
124
@@ -128,9 +131,13 @@ Let's create a file named `input.json`
0 commit comments