24

"snarkJS: Error: Scalar size does not match" on Num2Bits · Issue #252...

 9 months ago
source link: https://github.com/iden3/snarkjs/issues/252
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Comments

Hi, i'm new to zksnark and i'v installed circom2.0 and snarkjs.

Now I'm testing tutorials from https://docs.circom.io/circom-language/basic-operators/:

pragma circom 2.0.0;

template Num2Bits(n) {
    signal input in;
    signal output out[n];
    var lc1=0;
    var e2=1;
    for (var i = 0; i<n; i++) {
        out[i] <-- (in >> i) & 1;
        out[i] * (out[i] -1 ) === 0;
        lc1 += out[i] * e2;
        e2 = e2+e2;
    }
    lc1 === in;
}

component main {public [in]}= Num2Bits(3);

I set the input.json as:

{
    "in": 1
}

Then I compile the circom, calculate the witness, and do the trusted setup:

circom circuit.circom --r1cs --wasm --sym

node circuit_js/generate_witness.js circuit_js/circuit.wasm input.json witness.wtns

snarkjs powersoftau new bn128 12 pot12_0000.ptau -v 
snarkjs powersoftau contribute pot12_0000.ptau pot12_0001.ptau --name="First contribution" -v 
snarkjs powersoftau prepare phase2 pot12_0001.ptau pot12_final.ptau -v 
snarkjs groth16 setup circuit.r1cs pot12_final.ptau circuit_0000.zkey 
snarkjs zkey contribute circuit_0000.zkey circuit_0001.zkey --name="First contribution" -v
snarkjs zkey export verificationkey circuit_0001.zkey verification_key.json

But when I generate the proof, the error happens:

snarkjs groth16 prove circuit_0001.zkey witness.wtns proof.json public.json
[ERROR] snarkJS: Error: Scalar size does not match
    at _multiExp (/Users/chubingnan/.nvm/versions/node/v16.14.0/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:4975:19)
    at WasmCurve.multiExpAffine (/Users/chubingnan/.nvm/versions/node/v16.14.0/lib/node_modules/snarkjs/node_modules/ffjavascript/build/main.cjs:5012:22)
    at groth16Prove$1 (/Users/chubingnan/.nvm/versions/node/v16.14.0/lib/node_modules/snarkjs/build/cli.cjs:5550:33)
    at async Object.groth16Prove [as action] (/Users/chubingnan/.nvm/versions/node/v16.14.0/lib/node_modules/snarkjs/build/cli.cjs:8459:36)
    at async clProcessor (/Users/chubingnan/.nvm/versions/node/v16.14.0/lib/node_modules/snarkjs/build/cli.cjs:454:27)

Any insights are greatly appreciated!

bytetang, socathie, and adamiak reacted with thumbs up emoji

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK