iden3 / snarkjs

zkSNARK implementation in JavaScript & WASM
GNU General Public License v3.0
1.79k stars 424 forks source link

`Error: Variable not used` when setting up plonk #136

Closed noway closed 2 years ago

noway commented 2 years ago

What I've done

I'm using snarkjs@0.4.15

I'm running the following command:

$ snarkjs plonk setup my_circuit.r1cs powersOfTau28_hez_final_22.ptau my_circuit_final.zkey

I'm using the following ptau file:

https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_22.ptau

$ b2sum powersOfTau28_hez_final_22.ptau
0d64f63dba1a6f11139df765cb690da69d9b2f469a1ddd0de5e4aa628abb28f787f04c6a5fb84a235ec5ea7f41d0548746653ecab0559add658a83502d1cb21b  powersOfTau28_hez_final_22.ptau

What's the output

[INFO]  snarkJS: Reading r1cs
[INFO]  snarkJS: Plonk constraints: 2202182
[ERROR] snarkJS: Error: Variable not used
    at writeSigma (/opt/homebrew/lib/node_modules/snarkjs/build/cli.cjs:6309:23)
    at plonkSetup$1 (/opt/homebrew/lib/node_modules/snarkjs/build/cli.cjs:6113:11)
    at async clProcessor (/opt/homebrew/lib/node_modules/snarkjs/build/cli.cjs:301:27)

The process exits with code 1

What's expected No error.

Additional info Meanwhile groth16 phase1/phase2 setup and verification works fine

noway commented 2 years ago

I've tried making a minimal case, but I think it happens only on a big enough circuit or something? Anyway, here's an instruction on how to reproduce:

How to reproduce (tested on a Mac)

  1. Clone and build the nzcp-circom circuit:

    git clone git@github.com:noway/nzcp-circom.git
    cd nzcp-circom
    make
  2. Symlink powersOfTau28_hez_final_22.ptau from https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final_22.ptau into the working directory:

ln -s ~/Downloads/powersOfTau28_hez_final_22.ptau powersOfTau28_hez_final_22.ptau
  1. Attempt to setup plonk (this fails)
    make plonk

I've tested this on a fresh cloned repo, the commands above reproduce the bug.

Let me know if you need any more info.

Cheers.

noway commented 2 years ago

Update, I managed to reproduce this bug with the following circuit:

pragma circom 2.0.3;

template Test() {
    signal input a;
    signal output b;
    b <== 0;
}

component main = Test();

I guess "Variable not used" really means "Signal not used". Is this really a necessary limitation for plonk? Groth16 works fine with unused signals, I think.

noway commented 2 years ago

Another update: compiling the circuit with --O0 solves the issue. But then the circuit is really big which is not ideal, so still looking for a way to solve this while compiling with --O2 or at least --O1.

In fact, at --O0 the I have 6718622 plonk constraints while only 2307089 at --O2. The zkey size at --O0 ends up being 15G which is too big for browser to load using plonk.fullProve.

socathie commented 2 years ago

Encountering the same problem when trying to compile my circuit here https://github.com/socathie/zkPhoto/blob/main/circuits/zkPhoto.circom . It is bound to have unused signals which is kinda the purpose of this circuit. I am really hoping to use plonk 'cause that will save me the hassle from doing a public phase 2 ceremony. Is it really impossible to use plonk with compression during compilation with a circuit that has unused signals?

noway commented 2 years ago

Update: This is resolved for me, snarkjs no longer crashes on version 0.4.16 @socathie try 0.4.16 version, the fix was actually in master for a few weeks but only got released recently.

socathie commented 2 years ago

Update: This is resolved for me, snarkjs no longer crashes on version 0.4.16 @socathie try 0.4.16 version, the fix was actually in master for a few weeks but only got released recently.

Yes, update to latest version resolves the error. Thanks. (but now my plonkVerifier contract is way too big for deployment, but that's another issue not related to this one).

phated commented 2 years ago

Thanks for confirming this was fixed in 0.4.16!