iden3 / snarkjs

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

Invalid Unicode escape sequence on Windows #33

Closed KimiWu123 closed 4 years ago

KimiWu123 commented 4 years ago

I wrote some samples to practice. It seems some format error in my json file. It shows

C:\Users\user\code\test\circom\hellow>snarkjs info -c main.json
SyntaxError: Invalid Unicode escape sequence
    at new Circuit (C:\Users\user\AppData\Roaming\npm\node_modules\snarkjs\src\circuit.js:46:78)
    at Object.<anonymous> (C:\Users\user\AppData\Roaming\npm\node_modules\snarkjs\cli.js:279:21)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
ERROR: SyntaxError: Invalid Unicode escape sequence

Here is my circom code, (not sure it's correct or not, still learning...)

include "../circomlib/circuits/sha256/sha256.circom"
include "../circomlib/circuits/binsum.circom"
include "../circomlib/circuits/bitify.circom"

template Sha256_verifier() {
    signal private input in;
    signal output out;

    var numBits = nbits(in);
    component inBits = Num2Bits(numBits);
    inBits.in <-- in;

    component sha256 = Sha256(numBits);
    for (var i=0; i<numBits; i++) {
        sha256.in[i] <-- inBits.out[i];
    }

    component outNum = Bits2Num(256);
    for (var i=0; i<256; i++) {
        outNum.in[i] <== sha256.out[i];
    }
    out <== outNum.out;
    // sha256.out === out;
}

component main = Sha256_verifier();

It works on my Mac, but it's too slow to setup. So, I run it on my Windows, but it has the above errors.

it works on Windows with the following code.(generating proofs, setup, and verification are fine)

template Multiplier() {
    signal private input a;
    signal private input b;
    signal output c;

    c <== a*b;
}
component main = Multiplier();
zyra-zia commented 4 years ago

I had the same error on Windows. In my case, it was being caused by strings with "\\" in my file paths in the offending file. I manually changed them to forward slashes "/" and it worked.

So basically check if your circuit.js file has any strings like "C:\\Users\\Alice\\project\\..." and changing them to "C:/Users/Alice/project/..." should work

jbaylina commented 4 years ago

This shoiuld be translated to circom repo.