Skip to content

Commit eb8cb0a

Browse files
committed
Almost ready for 0.5.0
1 parent ef899e6 commit eb8cb0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1251
-15155
lines changed

.eslintrc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
module.exports = {
2-
"plugins": [
3-
"mocha"
4-
],
52
"env": {
63
"es6": true,
74
"node": true,
@@ -27,7 +24,6 @@ module.exports = {
2724
"semi": [
2825
"error",
2926
"always"
30-
],
31-
"mocha/no-exclusive-tests": "error"
27+
]
3228
}
3329
};

COPYING

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GNU GENERAL PUBLIC LICENSE
22
Version 3, 29 June 2007
33

4-
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
4+
Copyright (C) 2020 0Kims Association <https://0kims.org>
55
Everyone is permitted to copy and distribute verbatim copies
66
of this license document, but changing it is not allowed.
77

TUTORIAL.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This tutorial will guide you in creating your first Zero Knowledge zkSnark circu
66

77
### 1.1 Pre-requisites
88

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`.
1010

1111
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 (!).
1212

@@ -16,6 +16,7 @@ Run:
1616

1717
```sh
1818
npm install -g circom
19+
npm install -g circom_runtime
1920
npm install -g snarkjs
2021
```
2122

@@ -42,7 +43,7 @@ template Multiplier() {
4243
signal private input a;
4344
signal private input b;
4445
signal output c;
45-
46+
4647
c <== a*b;
4748
}
4849
@@ -62,10 +63,12 @@ Note: When compiling a circuit, a component named `main` must always exist.
6263
We are now ready to compile the circuit. Run the following command:
6364

6465
```sh
65-
circom circuit.circom -o circuit.json
66+
circom circuit.circom --r1cs --wasm --sym
6667
```
6768

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)
6972

7073

7174
## 3. Taking the compiled circuit to *snarkjs*
@@ -74,21 +77,21 @@ Now that the circuit is compiled, we will continue with `snarkjs`.
7477
Please note that you can always access the help of `snarkjs` by typing:
7578

7679
```sh
77-
snarkjs --help
80+
snarkjs --help
7881
```
7982

8083
### 3.1 View information and stats regarding a circuit
8184

8285
To show general statistics of this circuit, you can run:
8386

8487
```sh
85-
snarkjs info -c circuit.json
88+
snarkjs info -r circuit.r1cs
8689
```
8790

8891
You can also print the constraints of the circuit by running:
8992

9093
```sh
91-
snarkjs printconstraints -c circuit.json
94+
snarkjs printconstraints -r circuit.r1cs -s circuit.sym
9295
```
9396

9497

@@ -98,24 +101,24 @@ snarkjs printconstraints -c circuit.json
98101
Ok, let's run a setup for our circuit:
99102

100103
```sh
101-
snarkjs setup
104+
snarkjs setup
102105
```
103106

104-
> 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>`
105108
106109
The output of the setup will in the form of 2 files: `proving_key.json` and `verification_key.json`
107110

108111
### 3.3. Calculating a witness
109112

110113
Before creating any proof, we need to calculate all the signals of the circuit that match (all) the constrains of the circuit.
111114

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*.
113116

114117
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.
115118

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.
117120

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.
119122
120123
So you want to prove that you know 3 and 11.
121124

@@ -128,9 +131,13 @@ Let's create a file named `input.json`
128131
Now let's calculate the witness:
129132

130133
```sh
131-
snarkjs calculatewitness
134+
snarkjs --wasm circuit.wasm --input input.json --witness witness.json
132135
```
133136

137+
`calcwit` is part of the circom_runtime package and it's just a wrapper in JS to call the wasm module.
138+
139+
You can use `circom_runtime` from your own project to calulate the witness.
140+
134141
You may want to take a look at `witness.json` file with all the signals.
135142

136143
### Create the proof
@@ -214,20 +221,20 @@ template Multiplier() {
214221
signal output c;
215222
signal inva;
216223
signal invb;
217-
224+
218225
inva <-- 1/(a-1);
219226
(a-1)*inva === 1;
220-
227+
221228
invb <-- 1/(b-1);
222-
(b-1)*invb === 1;
223-
229+
(b-1)*invb === 1;
230+
224231
c <== a*b;
225232
}
226233
227234
component main = Multiplier();
228235
```
229236

230-
A nice thing of the circom language is that you can split a <== into two independent actions: <-- and ===
237+
A nice thing of the circom language is that you can split a <== into two independent actions: <-- and ===
231238

232239
The <-- and --> operators assign a value to a signal without creating any constraints.
233240

cli.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const fs = require("fs");
2525
const path = require("path");
26+
const bigInt = require("big-integer");
2627

2728
const compiler = require("./src/compiler");
2829

@@ -37,6 +38,7 @@ const argv = require("yargs")
3738
.alias("t", "wat")
3839
.alias("s", "sym")
3940
.alias("r", "r1cs")
41+
.alias("p", "prime")
4042
.alias("n", "newThreadTemplates")
4143
.help("h")
4244
.alias("h", "help")
@@ -50,10 +52,6 @@ const argv = require("yargs")
5052
type: "boolean",
5153
description: "Do not optimize constraints"
5254
})
53-
.option("sanityCheck", {
54-
type: "boolean",
55-
description: "Add sanity check code"
56-
})
5755
.epilogue(`Copyright (C) 2018 0kims association
5856
This program comes with ABSOLUTELY NO WARRANTY;
5957
This is free software, and you are welcome to redistribute it
@@ -84,6 +82,8 @@ const options = {};
8482
options.reduceConstraints = !argv.fast;
8583
options.verbose = argv.verbose || false;
8684
options.sanityCheck = argv.sanitycheck;
85+
options.prime = argv.prime || bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
86+
8787
if (argv.csource) {
8888
options.cSourceWriteStream = fs.createWriteStream(cSourceName);
8989
}

0 commit comments

Comments
 (0)