Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on negative witness inputs #6

Open
ZenGround0 opened this issue Jun 14, 2019 · 3 comments
Open

Error on negative witness inputs #6

ZenGround0 opened this issue Jun 14, 2019 · 3 comments

Comments

@ZenGround0
Copy link

Using snarkjs to prove a circuit I set -1 as an input and generated a witness.json using snarkjs calculatewitness. I then tried to use websnark's buildwitness.json on this input.
This led to the following error:

buildwitness.js:38
        const v = bi.shiftRight(i*32).and(0xFFFFFFFF).toJSNumber();
                     ^

TypeError: bi.shiftRight is not a function
    at writeBigInt (/Users/zenground0/Ground/IC3/websnark/tools/buildwitness.js:38:22)
    at Object.<anonymous> (/Users/zenground0/Ground/IC3/websnark/tools/buildwitness.js:68:5)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:282:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

Apologies if having negative inputs in a witness.json is invalid for other reasons and should not be supported.

@HarryR
Copy link

HarryR commented Jul 4, 2019

.shr seems to work, after changing it to:

const u = bi.shr(i*32);
const v = u.and(0xFFFFFFFFn).toJSNumber();

However, I then get the following error:

TypeError: u.and(...).toJSNumber is not a function

Changing it to the following seems to work:

const u = bi.shr(i*32);
const v = Number(u.and(0xFFFFFFFFn));

But then I get:

     TypeError: Found invalid object in transferList
      at Worker.postMessage (internal/worker.js:223:23)
      at Groth16.postAction (node_modules/websnark/src/groth16.js:271:32)
      at Groth16.processWorks (node_modules/websnark/src/groth16.js:280:22)
      at Groth16.queueAction (node_modules/websnark/src/groth16.js:292:14)
      at Groth16.g1_multiexp (node_modules/websnark/src/groth16.js:359:22)
      at Groth16.proof (node_modules/websnark/src/groth16.js:504:25)
      at Context.<anonymous> (test/poseidoncircuit.js:121:33)

But, if I display the list of transfers, by adding:

        console.log(transfers);
        console.log(actionData);

I get:

[
  <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 35214 more bytes>,
  <Buffer 4a 04 00>,
  <Buffer >
]
{
  command: 'CALC_H',
  signals: <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 35214 more bytes>,
  polsA: <Buffer 4a 04 00>,
  polsB: <Buffer >,
  nSignals: 74,
  domainSize: 0
}
[
  <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 4334 more bytes>,
  <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 4686 more bytes>
]
{
  command: 'G1_MULTIEXP',
  scalars: <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 4334 more bytes>,
  points: <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 4686 more bytes>,
  n: 137
}
[
  <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 4334 more bytes>,
  <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 4686 more bytes>
]
{
  command: 'G1_MULTIEXP',
  scalars: <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 4334 more bytes>,
  points: <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 4686 more bytes>,
  n: 137
}
[
  <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 4334 more bytes>,
  <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 9422 more bytes>
]
{
  command: 'G2_MULTIEXP',
  scalars: <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 89 06 72 4e fb 6a 80 65 d7 cb 99 82 92 ef e3 b0 e9 18 ... 4334 more bytes>,
  points: <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 9422 more bytes>,
  n: 137
}
[
  <Buffer de b9 1b 64 da c6 cf 7b b8 2b 46 b5 e9 fd e0 44 95 d9 7b 85 68 94 03 96 fb fa ed de e8 59 fe 02 dc b9 1b 64 da c6 cf 7b b8 2b 46 b5 e9 fd e0 44 95 d9 ... 4334 more bytes>,
  <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 4366 more bytes>
]
{
  command: 'G1_MULTIEXP',
  scalars: <Buffer de b9 1b 64 da c6 cf 7b b8 2b 46 b5 e9 fd e0 44 95 d9 7b 85 68 94 03 96 fb fa ed de e8 59 fe 02 dc b9 1b 64 da c6 cf 7b b8 2b 46 b5 e9 fd e0 44 95 d9 ... 4334 more bytes>,
  points: <Buffer 4a 04 00 00 03 00 00 00 00 02 00 00 e8 01 00 00 34 9f 01 00 e8 9c 04 00 68 af 05 00 e8 c1 06 00 e8 e6 08 00 68 f8 09 00 97 c1 cb 04 d3 d6 83 13 36 12 ... 4366 more bytes>,
  n: 137
}

Am using Node v12.4.0

It seems NodeJS can't transfer Strings or Integers to web workers via postMessage, only ArrayBuffers and MessagePorts.

I solved this in NodeJS by making sure that in I use .buffer to convert Buffer to ArrayBuffer.

@udibr
Copy link

udibr commented Jan 25, 2020

@HarryR where did you put the .buffer?
Thanks!

@harold
Copy link

harold commented Jan 26, 2020

@udibr - that's a different Harold, it seems. I am not familiar with this project. Good luck w/ your proofs though - it's good to be certain.

Take care.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants