Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23,914 changes: 12,118 additions & 11,796 deletions build/browser.esm.js

Large diffs are not rendered by default.

548 changes: 411 additions & 137 deletions build/main.cjs

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"homepage": "https://github.com/iden3/ffjavascript",
"dependencies": {
"wasmbuilder": "0.0.16",
"wasmcurves": "0.2.2",
"wasmcurves": "file:../wasmcurves",
"web-worker": "1.5.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions rollup.browser.esm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default [
{
format: "es",
file: "build/browser.esm.js",
inlineDynamicImports: true,
},
],
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion src/bigbuffer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const PAGE_SIZE = 1<<30;
const PAGE_SIZE = ( typeof Buffer !== "undefined" && Buffer.constants && Buffer.constants.MAX_LENGTH ) ? Buffer.constants.MAX_LENGTH : (1 << 30);

export default class BigBuffer {

Expand Down
5 changes: 3 additions & 2 deletions src/bls12381.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { buildBls12381 as buildBls12381wasm } from "wasmcurves";
import buildEngine from "./engine.js";
import * as Scalar from "./scalar.js";
import { ModuleBuilder } from "wasmbuilder";

globalThis.curve_bls12381 = null;

export default async function buildBls12381(singleThread, plugins) {
if ((!singleThread) && (globalThis.curve_bls12381)) return globalThis.curve_bls12381;

const { ModuleBuilder } = await import("wasmbuilder");
const { buildBls12381: buildBls12381wasm } = await import("wasmcurves");

const moduleBuilder = new ModuleBuilder();
moduleBuilder.setMemory(25);
buildBls12381wasm(moduleBuilder);
Expand Down
93 changes: 67 additions & 26 deletions src/bn128.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,78 @@
import { buildBn128 as buildBn128wasm } from "wasmcurves";
//import { bn128_wasm_gzip as bn128wasmPrebuilt } from "wasmcurves";
import buildEngine from "./engine.js";
import * as Scalar from "./scalar.js";
import { ModuleBuilder } from "wasmbuilder";

globalThis.curve_bn128 = null;

export default async function buildBn128(singleThread, plugins) {
if ((!singleThread) && (globalThis.curve_bn128)) return globalThis.curve_bn128;

const moduleBuilder = new ModuleBuilder();
moduleBuilder.setMemory(25);
buildBn128wasm(moduleBuilder);

if (plugins) plugins(moduleBuilder);

const bn128wasm = {};

bn128wasm.code = moduleBuilder.build();
bn128wasm.pq = moduleBuilder.modules.f1m.pq;
bn128wasm.pr = moduleBuilder.modules.frm.pq;
bn128wasm.pG1gen = moduleBuilder.modules.bn128.pG1gen;
bn128wasm.pG1zero = moduleBuilder.modules.bn128.pG1zero;
bn128wasm.pG1b = moduleBuilder.modules.bn128.pG1b;
bn128wasm.pG2gen = moduleBuilder.modules.bn128.pG2gen;
bn128wasm.pG2zero = moduleBuilder.modules.bn128.pG2zero;
bn128wasm.pG2b = moduleBuilder.modules.bn128.pG2b;
bn128wasm.pOneT = moduleBuilder.modules.bn128.pOneT;
bn128wasm.prePSize = moduleBuilder.modules.bn128.prePSize;
bn128wasm.preQSize = moduleBuilder.modules.bn128.preQSize;
bn128wasm.n8q = 32;
bn128wasm.n8r = 32;
bn128wasm.q = moduleBuilder.modules.bn128.q;
bn128wasm.r = moduleBuilder.modules.bn128.r;
let bn128wasm = {};

if (!plugins) {

console.log("Using prebuilt bn128 wasm");

//import { bn128_wasm_gzip as bn128wasmPrebuilt } from "wasmcurves";
//const { bn128_wasm_gzip: bn128wasmPrebuilt } = await import("wasmcurves");
const { default: bn128wasmPrebuilt } = await import("wasmcurves/build/bn128_wasm_gzip.js");

//console.log(bn128wasmPrebuilt);
bn128wasm.pq = bn128wasmPrebuilt.pq;
bn128wasm.pr = bn128wasmPrebuilt.pq;
bn128wasm.pG1gen = bn128wasmPrebuilt.pG1gen;
bn128wasm.pG1zero = bn128wasmPrebuilt.pG1zero;
bn128wasm.pG1b = bn128wasmPrebuilt.pG1b;
bn128wasm.pG2gen = bn128wasmPrebuilt.pG2gen;
bn128wasm.pG2zero = bn128wasmPrebuilt.pG2zero;
bn128wasm.pG2b = bn128wasmPrebuilt.pG2b;
bn128wasm.pOneT = bn128wasmPrebuilt.pOneT;
bn128wasm.prePSize = bn128wasmPrebuilt.prePSize;
bn128wasm.preQSize = bn128wasmPrebuilt.preQSize;
bn128wasm.n8q = 32;
bn128wasm.n8r = 32;
bn128wasm.q = bn128wasmPrebuilt.q;
bn128wasm.r = bn128wasmPrebuilt.r;

const compressedCode = new Uint8Array(Buffer.from(bn128wasmPrebuilt.gzipCode, "base64"));
const blob = new Blob([compressedCode]);

const ds = new DecompressionStream("gzip");
const decompressedStream = blob.stream().pipeThrough(ds);

bn128wasm.code = await new Response(decompressedStream).bytes();
} else {

//import { ModuleBuilder } from "wasmbuilder";
//import { buildBn128 as buildBn128wasm } from "wasmcurves";
const { ModuleBuilder } = await import("wasmbuilder");
const { buildBn128: buildBn128wasm } = await import("wasmcurves");

const moduleBuilder = new ModuleBuilder();
moduleBuilder.setMemory(25);
buildBn128wasm(moduleBuilder);

if (plugins) plugins(moduleBuilder);

bn128wasm.code = moduleBuilder.build();
bn128wasm.pq = moduleBuilder.modules.f1m.pq;
bn128wasm.pr = moduleBuilder.modules.frm.pq;
bn128wasm.pG1gen = moduleBuilder.modules.bn128.pG1gen;
bn128wasm.pG1zero = moduleBuilder.modules.bn128.pG1zero;
bn128wasm.pG1b = moduleBuilder.modules.bn128.pG1b;
bn128wasm.pG2gen = moduleBuilder.modules.bn128.pG2gen;
bn128wasm.pG2zero = moduleBuilder.modules.bn128.pG2zero;
bn128wasm.pG2b = moduleBuilder.modules.bn128.pG2b;
bn128wasm.pOneT = moduleBuilder.modules.bn128.pOneT;
bn128wasm.prePSize = moduleBuilder.modules.bn128.prePSize;
bn128wasm.preQSize = moduleBuilder.modules.bn128.preQSize;
bn128wasm.n8q = 32;
bn128wasm.n8r = 32;
bn128wasm.q = moduleBuilder.modules.bn128.q;
bn128wasm.r = moduleBuilder.modules.bn128.r;
}

//console.log("bn128wasm:", bn128wasm);

const params = {
name: "bn128",
Expand Down
6 changes: 4 additions & 2 deletions src/engine_applykey.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ export default function buildBatchApplyKey(curve, groupName) {

const task = [];

const b = buff.slice(i*pointsPerChunk*sGin, i*pointsPerChunk*sGin + n*sGin);

task.push({
cmd: "ALLOCSET",
var: 0,
buff: buff.slice(i*pointsPerChunk*sGin, i*pointsPerChunk*sGin + n*sGin)
buff: b
});
task.push({cmd: "ALLOCSET", var: 1, buff: t});
task.push({cmd: "ALLOCSET", var: 2, buff: inc});
Expand Down Expand Up @@ -96,7 +98,7 @@ export default function buildBatchApplyKey(curve, groupName) {
}
task.push({cmd: "GET", out: 0, var: 3, len: n*sGout});

opPromises.push(tm.queueAction(task));
opPromises.push(tm.queueAction(task, [b.buffer]));
t = Fr.mul(t, Fr.exp(inc, n));
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine_batchconvert.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function buildBatchConvert(tm, fnName, sIn, sOut) {
{cmd: "GET", out: 0, var: 1, len:sOut * n},
];
opPromises.push(
tm.queueAction(task)
tm.queueAction(task, [buffChunk.buffer])
);
}

Expand Down
Loading
Loading