iden3 / snarkjs

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

Inputs over 16 digits are modified #49

Closed Ssophoclis closed 4 years ago

Ssophoclis commented 4 years ago

I am experimenting with the circuit.circom circuit from the circom Tutorial:

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

    c <== a*b;
}

component main = Multiplier();

If I provide inputs which are longer than 16 digits such as:

{"a": 13905001134553859943, "b": 2}

the witness.json output is:

[
 "1",
 "27810002269107720192",
 "13905001134553860096",
 "2"
]

Notice that the second to last number is the signal a which is 13905001134553860096 instead of 13905001134553859943 and the output signal is 27810002269107720192 instead of 27810002269107719886.

I am using "circom": "^0.5.11", "snarkjs": "^0.1.31"

jbaylina commented 4 years ago

This is a javascript issue. Javascript truncates integers to 56 bits. You should pass it as String or as BigInt.