Compare commits
2 Commits
671762fab7
...
1ab309ae3e
Author | SHA1 | Date | |
---|---|---|---|
1ab309ae3e | |||
815ea7c4e5 |
1
.npmignore
Normal file
1
.npmignore
Normal file
@ -0,0 +1 @@
|
||||
test
|
1
.npmrc
Normal file
1
.npmrc
Normal file
@ -0,0 +1 @@
|
||||
@tornado:registry=https://git.tornado.ws/api/packages/tornado-packages/npm/
|
3497
build/websnark.js
3497
build/websnark.js
File diff suppressed because it is too large
Load Diff
3497
example/websnark.js
3497
example/websnark.js
File diff suppressed because it is too large
Load Diff
467
package-lock.json
generated
467
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "websnark",
|
||||
"name": "@tornado/websnark",
|
||||
"version": "0.0.4",
|
||||
"description": "big integer library to work in Zq",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "mocha --experimental-worker",
|
||||
"buildwasm": "node tools/buildwasm.js",
|
||||
"build": "node tools/buildwasm.js; browserify main.js -o build/websnark.js --exclude worker_threads --exclude crypto; cp build/websnark.js example/websnark.js"
|
||||
"build": "node tools/buildwasm.js && browserify main.js -o build/websnark.js --exclude worker_threads --exclude crypto && cp build/websnark.js example/websnark.js"
|
||||
},
|
||||
"keywords": [
|
||||
"bigint",
|
||||
@ -22,7 +22,7 @@
|
||||
"license": "GPL-3.0",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/iden3/websnark.git"
|
||||
"url": "https://git.tornado.ws/tornado-packages/websnark"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
@ -31,10 +31,10 @@
|
||||
"eslint-plugin-webassembly": "^1.8.4",
|
||||
"mocha": "^6.1.4",
|
||||
"package": "^1.0.1",
|
||||
"snarkjs": "git+https://development.tornadocash.community/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
|
||||
"wasmbuilder": "0.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tornado/snarkjs": "^0.1.20",
|
||||
"big-integer": "1.6.42"
|
||||
}
|
||||
}
|
||||
|
30
src/utils.js
30
src/utils.js
@ -18,20 +18,20 @@
|
||||
*/
|
||||
|
||||
const bigInt = require("big-integer");
|
||||
const Circuit = require("snarkjs/src/circuit");
|
||||
const bigInt2 = require("snarkjs/src/bigint");
|
||||
const Circuit = require("@tornado/snarkjs/src/circuit");
|
||||
const bigInt2 = require("@tornado/snarkjs/src/bigint");
|
||||
const hexifyBigInts = require("../tools/stringifybigint").hexifyBigInts;
|
||||
const unhexifyBigInts = require("../tools/stringifybigint").unhexifyBigInts;
|
||||
const stringifyBigInts = require("../tools/stringifybigint").stringifyBigInts;
|
||||
const unstringifyBigInts = require("../tools/stringifybigint").unstringifyBigInts;
|
||||
const stringifyBigInts2 = require("snarkjs/src/stringifybigint").stringifyBigInts;
|
||||
const unstringifyBigInts2 = require("snarkjs/src/stringifybigint").unstringifyBigInts;
|
||||
const stringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").stringifyBigInts;
|
||||
const unstringifyBigInts2 = require("@tornado/snarkjs/src/stringifybigint").unstringifyBigInts;
|
||||
|
||||
function bigInt2BytesLE(_a, len) {
|
||||
const b = Array(len);
|
||||
let v = bigInt(_a);
|
||||
for (let i = 0; i < len; i++) {
|
||||
b[i] = v.and(0xFF).toJSNumber();
|
||||
b[i] = v.and(0xff).toJSNumber();
|
||||
v = v.shiftRight(8);
|
||||
}
|
||||
return b;
|
||||
@ -41,7 +41,7 @@ function bigInt2U32LE(_a, len) {
|
||||
const b = Array(len);
|
||||
let v = bigInt(_a);
|
||||
for (let i = 0; i < len; i++) {
|
||||
b[i] = v.and(0xFFFFFFFF).toJSNumber();
|
||||
b[i] = v.and(0xffffffff).toJSNumber();
|
||||
v = v.shiftRight(32);
|
||||
}
|
||||
return b;
|
||||
@ -52,9 +52,9 @@ function convertWitness(witness) {
|
||||
const buff = new ArrayBuffer(buffLen);
|
||||
const h = {
|
||||
dataView: new DataView(buff),
|
||||
offset: 0
|
||||
offset: 0,
|
||||
};
|
||||
const mask = bigInt2(0xFFFFFFFF);
|
||||
const mask = bigInt2(0xffffffff);
|
||||
for (let i = 0; i < witness.length; i++) {
|
||||
for (let j = 0; j < 8; j++) {
|
||||
const v = Number(witness[i].shr(j * 32).and(mask));
|
||||
@ -73,13 +73,17 @@ function toHex32(number) {
|
||||
|
||||
function toSolidityInput(proof) {
|
||||
const flatProof = unstringifyBigInts([
|
||||
proof.pi_a[0], proof.pi_a[1],
|
||||
proof.pi_b[0][1], proof.pi_b[0][0],
|
||||
proof.pi_b[1][1], proof.pi_b[1][0],
|
||||
proof.pi_c[0], proof.pi_c[1],
|
||||
proof.pi_a[0],
|
||||
proof.pi_a[1],
|
||||
proof.pi_b[0][1],
|
||||
proof.pi_b[0][0],
|
||||
proof.pi_b[1][1],
|
||||
proof.pi_b[1][0],
|
||||
proof.pi_c[0],
|
||||
proof.pi_c[1],
|
||||
]);
|
||||
const result = {
|
||||
proof: "0x" + flatProof.map(x => toHex32(x)).join("")
|
||||
proof: "0x" + flatProof.map((x) => toHex32(x)).join(""),
|
||||
};
|
||||
if (proof.publicSignals) {
|
||||
result.publicSignals = hexifyBigInts(unstringifyBigInts(proof.publicSignals));
|
||||
|
@ -1,6 +1,6 @@
|
||||
const assert = require("assert");
|
||||
const refBn128 = require("snarkjs").bn128;
|
||||
const refBigInt = require("snarkjs").bigInt;
|
||||
const refBn128 = require("@tornado/snarkjs").bn128;
|
||||
const refBigInt = require("@tornado/snarkjs").bigInt;
|
||||
|
||||
const buildBn128 = require("../index.js").buildBn128;
|
||||
|
||||
@ -39,7 +39,6 @@ describe("Basic tests for g1 in bn128", () => {
|
||||
d[1] = refBigInt(d[1].toString());
|
||||
d[2] = refBigInt(d[2].toString());
|
||||
|
||||
|
||||
assert(d[0].equals(refD[0]));
|
||||
assert(d[1].equals(refD[1]));
|
||||
assert(d[2].equals(1));
|
||||
@ -101,7 +100,6 @@ describe("Basic tests for g1 in bn128", () => {
|
||||
}
|
||||
|
||||
assert(refBn128.G1.equals(d, refD));
|
||||
|
||||
}).timeout(10000000);
|
||||
it("It should do a basic point doubling in G2", async () => {
|
||||
const bn128 = await buildBn128();
|
||||
|
10
test/fft.js
10
test/fft.js
@ -1,6 +1,6 @@
|
||||
const assert = require("assert");
|
||||
const refBn128 = require("snarkjs").bn128;
|
||||
const refBigInt = require("snarkjs").bigInt;
|
||||
const refBn128 = require("@tornado/snarkjs").bn128;
|
||||
const refBigInt = require("@tornado/snarkjs").bigInt;
|
||||
|
||||
const buildBn128 = require("../index.js").buildBn128;
|
||||
|
||||
@ -53,7 +53,7 @@ describe("FFT tests", () => {
|
||||
|
||||
const p = bn128.alloc(32 * N);
|
||||
for (let i = 0; i < N; i++) {
|
||||
bn128.putInt(p+i*32, (i%2 == 0)? 0 : 1);
|
||||
bn128.putInt(p + i * 32, i % 2 == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
bn128.fft_toMontgomeryN(p, p, N);
|
||||
@ -63,7 +63,7 @@ describe("FFT tests", () => {
|
||||
|
||||
for (let i = 0; i < N; i++) {
|
||||
const a = bn128.getInt(p + i * 32);
|
||||
assert.equal(a,(i%2 == 0)? 0 : 1);
|
||||
assert.equal(a, i % 2 == 0 ? 0 : 1);
|
||||
}
|
||||
});
|
||||
it("test interleaved", async () => {
|
||||
@ -117,7 +117,5 @@ describe("FFT tests", () => {
|
||||
const a = bn128.getInt(pr1 + i * 32, 1);
|
||||
assert.equal(a, 0);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -1,8 +1,7 @@
|
||||
|
||||
const assert = require("assert");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const snarkjs = require("snarkjs");
|
||||
const snarkjs = require("@tornado/snarkjs");
|
||||
|
||||
const buildGroth16 = require("../index.js").buildGroth16;
|
||||
|
||||
@ -46,7 +45,6 @@ describe("Basic tests for groth16 proof generator", () => {
|
||||
assert.equal(r1[1], r2[1]);
|
||||
|
||||
groth16.terminate();
|
||||
|
||||
});
|
||||
|
||||
it("It should do a basic point doubling G1", async () => {
|
||||
@ -57,12 +55,13 @@ describe("Basic tests for groth16 proof generator", () => {
|
||||
const proofS = await groth16.proof(signals.buffer, provingKey.buffer);
|
||||
|
||||
const proof = snarkjs.unstringifyBigInts(proofS);
|
||||
const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")));
|
||||
const verifierKey = snarkjs.unstringifyBigInts(
|
||||
JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8"))
|
||||
);
|
||||
const pub = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "public.json"), "utf8")));
|
||||
|
||||
assert(snarkjs.groth.isValid(verifierKey, proof, pub));
|
||||
|
||||
groth16.terminate();
|
||||
}).timeout(10000000);
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user