iden3 / circom

zkSnark circuit compiler
GNU General Public License v3.0
1.3k stars 252 forks source link

Circom Public Inputs Example not working, Snarkjs 0.7.4, Circom 2.1.9 #293

Open jonas089 opened 3 weeks ago

jonas089 commented 3 weeks ago
[ERROR] snarkJS: Error: Scalar size does not match
    at _multiExp (/opt/homebrew/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:4978:19)
    at WasmCurve.multiExpAffine (/opt/homebrew/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:5015:22)
    at groth16Prove$1 (/opt/homebrew/lib/node_modules/snarkjs/build/cli.cjs:5768:33)
    at async Object.groth16Prove [as action] (/opt/homebrew/lib/node_modules/snarkjs/build/cli.cjs:12975:36)
    at async clProcessor (/opt/homebrew/lib/node_modules/snarkjs/build/cli.cjs:481:27)

for circuit:

pragma circom 2.0.0;

template Multiplier2(){
   //Declaration of signals
   signal input in1;
   signal input in2;
   signal output out;
   out <== in1 * in2;
}

component main {public [in1,in2]} = Multiplier2();

with inputs:

{"in1": "3", "in2": "11"}

Is this a known issue? I followed the tutorial exactly yet it does not generate a proof. If I make either of the inputs private it works e.g. component main {public [in1]} = Multiplier2(); is ok.

Screenshot 2024-09-09 at 22 45 55

See example for reference: https://docs.circom.io/circom-language/signals/

I suspect this might be due to the two inputs forming a quadratic constraint. When I introduce a third input and make it public it works again.

Arvolear commented 1 day ago

Sad to see this mistake in the official circom docs. This is a common issue though. When a circuit has 0 constraints, snarkjs throws this exact error.

In the example, all the signals (both outputs and inputs) are public and ZK proof results into hiding nothing, becoming meaningless. Sometimes this error may also occur due to weird circom optimizations that "remove" constraints.