iden3 / circom_old

Circuit compiler for zkSNARKs
GNU General Public License v3.0
471 stars 82 forks source link

circom takes forever to compile a circuit #12

Closed hellwolf closed 5 years ago

hellwolf commented 5 years ago

Following your example at: https://iden3.io/blog/circom-and-snarkjs-tutorial.html

Version: circom@0.0.17 Nodejs: v8.12.0 Machine: ubuntu 18.04

$ cat multiplier.circom 
template Multiplier() {
    signal private input a;
    signal private input b;
    signal output c;

    c <== a*b;
}

component main = Multiplier();

$ npx circom multiplier.circom -o multiplier.circom 

The compilation didn't finish in 5 minutes...

hellwolf commented 5 years ago

1 #!/usr/bin/env node --max_old_space_size=4000

from ./node_modules/.bin/circom seems the culprit, why the max_old_space_size flag anyways?

hellwolf commented 5 years ago

Removing the --max_old_space_size=4000 flag made it work for me.

weijiekoh commented 5 years ago

max_old_space_size was added earlier today because I reported that circom would not compile the sha256_2 circuit without it. Otherwise, there would be an out-of-memory error.

However, I see that you're using Node 8. I believe that the compilation can be much faster if you use Node 10, as it has native bigint support.

hellwolf commented 5 years ago

I started to use nodejs 10, but I had to remove that flag still otherwise simple examples wouldn't run.

weijiekoh commented 5 years ago

Sorry to hear that. One way to get around this quickly is to not use the circom CLI, but write a separate JS script that imports circom, compiles the circuit, and saves the json output. That'll let you compile it without having to modify cli.js. Hope that helps as a quick workaround.

jbaylina commented 5 years ago

Ok, this depends probably too much in the memory you have in your device. I just updated to remove the --max_old_space_size=4000 flag from cli.js.

I'll take a look if I can optimize a little the memory usage....

hellwolf commented 5 years ago

Thanks!