Test fixes

This commit is contained in:
Jordi Baylina
2020-07-11 09:35:40 +02:00
parent a557d21bdb
commit 0e154f7e70
7 changed files with 23 additions and 16 deletions

View File

@@ -33,7 +33,7 @@
"homepage": "https://github.com/iden3/ffjs#readme",
"dependencies": {
"big-integer": "^1.6.48",
"wasmcurves": "0.0.3",
"wasmcurves": "0.0.4",
"worker-threads": "^1.0.0"
},
"devDependencies": {

View File

@@ -21,9 +21,9 @@ export default async function buildBls12381() {
curve = await buildEngine(params);
curve.terminate = function() {
this.tm.terminate();
curve.terminate = async function() {
curve = null;
await this.tm.terminate();
};
return curve;
}

View File

@@ -19,9 +19,9 @@ export default async function buildBn128() {
};
curve = await buildEngine(params);
curve.terminate = function() {
this.tm.terminate();
curve.terminate = async function() {
curve = null;
await this.tm.terminate();
};
return curve;

View File

@@ -4,7 +4,7 @@ export default function buildFFT(curve, groupName) {
const G = curve[groupName];
const Fr = curve.Fr;
const tm = G.tm;
async function _fft(buff, inverse, inType, outType, log) {
async function _fft(buff, inverse, inType, outType, logger) {
inType = inType || "affine";
outType = outType || "affine";
@@ -131,7 +131,7 @@ export default function buildFFT(curve, groupName) {
}
task.push({cmd: "GET", out:0, var: 0, len: sMid*pointsInChunk});
promises.push(tm.queueAction(task).then( (r) => {
if (log) log(`fft: ${i}/${nChunks}`);
if (logger) logger.debug(`fft: ${i}/${nChunks}`);
return r;
}));
}
@@ -140,7 +140,7 @@ export default function buildFFT(curve, groupName) {
for (let i = 0; i< nChunks; i++) chunks[i] = chunks[i][0];
for (let i = MAX_BITS_THREAD+1; i<=bits; i++) {
if (log) log(`${i}/${bits}`);
if (logger) logger.debug(`fft join ${i}/${bits}`);
const nGroups = 1 << (bits - i);
const nChunksPerGroup = nChunks / nGroups;
const opPromises = [];
@@ -230,12 +230,12 @@ export default function buildFFT(curve, groupName) {
}
}
G.fft = async function(buff, inType, outType, log) {
return await _fft(buff, false, inType, outType, log);
G.fft = async function(buff, inType, outType, logger) {
return await _fft(buff, false, inType, outType, logger);
};
G.ifft = async function(buff, inType, outType, log) {
return await _fft(buff, true, inType, outType, log);
G.ifft = async function(buff, inType, outType, logger) {
return await _fft(buff, true, inType, outType, logger);
};
G.fftMix = async function fftMix(buff) {
@@ -422,7 +422,7 @@ export default function buildFFT(curve, groupName) {
}
const nPoints = Math.floor(buff.byteLength / sG);
if (nPoints == 1 << log2(nPoints)) {
if (nPoints != 1 << log2(nPoints)) {
throw new Error("Invalid number of points");
}

View File

@@ -302,5 +302,5 @@ export default class ZqField {
return v;
}
};
}

View File

@@ -40,6 +40,10 @@ class Deferred {
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function base64ToArrayBuffer(base64) {
if (process.browser) {
var binary_string = window.atob(base64);
@@ -240,10 +244,11 @@ class ThreadManager {
return res;
}
terminate() {
async terminate() {
for (let i=0; i<this.workers.length; i++) {
this.workers[i].postMessage([{cmd: "TERMINATE"}]);
}
await sleep(200);
}
}

View File

@@ -193,6 +193,7 @@ export default class WasmField1 {
fromRng(rng) {
let v;
const buff = new Uint8Array(this.n8);
do {
v = Scalar.zero;
for (let i=0; i<this.n64; i++) {
@@ -200,7 +201,8 @@ export default class WasmField1 {
}
v = Scalar.band(v, this.mask);
} while (Scalar.geq(v, this.p));
return this.e(v);
Scalar.toRprLE(buff, 0, v, this.n8);
return buff;
}
random() {