ffjavascript
Advanced tools
Comparing version 0.2.16 to 0.2.17
{ | ||
"name": "ffjavascript", | ||
"type": "module", | ||
"version": "0.2.16", | ||
"version": "0.2.17", | ||
"description": "Finite Field Library in Javascript", | ||
@@ -36,3 +36,3 @@ "main": "./build/main.cjs", | ||
"big-integer": "^1.6.48", | ||
"wasmcurves": "0.0.8", | ||
"wasmcurves": "0.0.9", | ||
"worker-threads": "^1.0.0" | ||
@@ -39,0 +39,0 @@ }, |
@@ -14,3 +14,3 @@ import {log2, buffReverseBits} from "./utils.js"; | ||
let sIn, sMid, sOut, fnIn2Mid, fnMid2Out, fnName, fnFFTMix, fnFFTJoin, fnFFTFinal; | ||
let sIn, sMid, sOut, fnIn2Mid, fnMid2Out, fnFFTMix, fnFFTJoin, fnFFTFinal; | ||
if (groupName == "G1") { | ||
@@ -25,6 +25,3 @@ if (inType == "affine") { | ||
if (inverse) { | ||
fnName = "g1m_ifft"; | ||
fnFFTFinal = "g1m_fftFinal"; | ||
} else { | ||
fnName = "g1m_fft"; | ||
} | ||
@@ -50,6 +47,3 @@ fnFFTJoin = "g1m_fftJoin"; | ||
if (inverse) { | ||
fnName = "g2m_ifft"; | ||
fnFFTFinal = "g2m_fftFinal"; | ||
} else { | ||
fnName = "g2m_fft"; | ||
} | ||
@@ -69,6 +63,3 @@ fnFFTJoin = "g2m_fftJoin"; | ||
if (inverse) { | ||
fnName = "frm_ifft"; | ||
fnFFTFinal = "frm_fftFinal"; | ||
} else { | ||
fnName = "frm_fft"; | ||
} | ||
@@ -131,2 +122,3 @@ fnFFTMix = "frm_fftMix"; | ||
for (let i = 0; i< nChunks; i++) { | ||
if (logger) logger.debug(`${loggerTxt}: fft ${bits} mix start: ${i}/${nChunks}`); | ||
const task = []; | ||
@@ -160,3 +152,3 @@ task.push({cmd: "ALLOC", var: 0, len: sMid*pointsInChunk}); | ||
promises.push(tm.queueAction(task).then( (r) => { | ||
if (logger) logger.debug(`${loggerTxt}: fft ${bits} mix: ${i}/${nChunks}`); | ||
if (logger) logger.debug(`${loggerTxt}: fft ${bits} mix end: ${i}/${nChunks}`); | ||
return r; | ||
@@ -217,3 +209,6 @@ })); | ||
} | ||
opPromises.push(tm.queueAction(task)); | ||
opPromises.push(tm.queueAction(task).then( (r) => { | ||
if (logger) logger.debug(`${loggerTxt}: fft ${bits} join ${i}/${bits} ${j+1}/${nGroups} ${k}/${nChunksPerGroup/2 + 1}`); | ||
return r; | ||
})); | ||
} | ||
@@ -375,3 +370,3 @@ } | ||
for (let i=0; i<nPoints; i += MAX_CHUNK_SIZE) { | ||
if (logger) logger.debug(`${loggerTxt}: fftJoinExt: ${i}/${nPoints}`); | ||
if (logger) logger.debug(`${loggerTxt}: fftJoinExt Start: ${i}/${nPoints}`); | ||
const n= Math.min(nPoints - i, MAX_CHUNK_SIZE); | ||
@@ -410,3 +405,6 @@ | ||
opPromises.push( | ||
tm.queueAction(task) | ||
tm.queueAction(task).then( (r) => { | ||
if (logger) logger.debug(`${loggerTxt}: fftJoinExt End: ${i}/${nPoints}`); | ||
return r; | ||
}) | ||
); | ||
@@ -413,0 +411,0 @@ } |
@@ -120,7 +120,10 @@ import { log2 } from "./utils.js"; | ||
for (let i=0; i<nPoints; i += chunkSize) { | ||
if (logger) logger.debug(`Multiexp: ${logText}: ${i}/${nPoints}`); | ||
if (logger) logger.debug(`Multiexp start: ${logText}: ${i}/${nPoints}`); | ||
const n= Math.min(nPoints - i, chunkSize); | ||
const buffBasesChunk = await buffBases.slice(i*sGIn, (i+n)*sGIn); | ||
const buffScalarsChunk = await buffScalars.slice(i*sScalar, (i+n)*sScalar); | ||
opPromises.push(_multiExpChunk(buffBasesChunk, buffScalarsChunk, inType)); | ||
const buffBasesChunk = buffBases.slice(i*sGIn, (i+n)*sGIn); | ||
const buffScalarsChunk = buffScalars.slice(i*sScalar, (i+n)*sScalar); | ||
opPromises.push(_multiExpChunk(buffBasesChunk, buffScalarsChunk, inType).then( (r) => { | ||
if (logger) logger.debug(`Multiexp end: ${logText}: ${i}/${nPoints}`); | ||
return r; | ||
})); | ||
} | ||
@@ -127,0 +130,0 @@ |
import assert from "assert"; | ||
import buildBn128 from "../src/bn128.js"; | ||
import {log2} from "../src/utils.js"; | ||
import BigBuffer from "../src/bigbuffer.js"; | ||
describe("FFT", async function () { | ||
describe("bn128", async function () { | ||
this.timeout(10000000); | ||
const logger = { | ||
error: (msg) => { console.log("ERROR: "+msg); }, | ||
warning: (msg) => { console.log("WARNING: "+msg); }, | ||
info: (msg) => { console.log("INFO: "+msg); }, | ||
debug: (msg) => { console.log("DEBUG: "+msg); }, | ||
}; | ||
let bn128; | ||
@@ -43,2 +51,29 @@ before( async() => { | ||
const Fr = bn128.Fr; | ||
const N = 1<<10; | ||
const a = new BigBuffer(N*bn128.Fr.n8); | ||
for (let i=0; i<N; i++) { | ||
if (i%100000 == 0) logger.debug(`setup ${i}/${N}`); | ||
const num = Fr.e(i+1); | ||
a.set(num, i*bn128.Fr.n8); | ||
} | ||
const A = await bn128.Fr.fft(a, "", "", logger, "fft"); | ||
const Ainv = await bn128.Fr.ifft(A, "", "", logger, "ifft"); | ||
for (let i=0; i<N; i++) { | ||
if (i%100000 == 0) logger.debug(`checking ${i}/${N}`); | ||
// console.log(Fr.toString(Ainv[i])); | ||
const num1 = Ainv.slice(i*Fr.n8, i*Fr.n8+Fr.n8); | ||
const num2 = a.slice(i*Fr.n8, i*Fr.n8+Fr.n8); | ||
assert(num1, num2); | ||
} | ||
}); | ||
it("It shoud do a big FFT/IFFT in Fr", async () => { | ||
const Fr = bn128.Fr; | ||
const N = 8192*16; | ||
@@ -124,3 +159,28 @@ | ||
it("It shoud do Multiexp", async () => { | ||
const Fr = bn128.Fr; | ||
const G1 = bn128.G1; | ||
const N = 1 << 10; | ||
const scalars = new BigBuffer(N*bn128.Fr.n8); | ||
const bases = new BigBuffer(N*G1.F.n8*2); | ||
let acc = Fr.zero; | ||
for (let i=0; i<N; i++) { | ||
if (i%100000 == 0) logger.debug(`setup ${i}/${N}`); | ||
const num = Fr.e(i+1); | ||
scalars.set(Fr.fromMontgomery(num), i*bn128.Fr.n8); | ||
bases.set(G1.toAffine(G1.timesFr(G1.g, num)), i*G1.F.n8*2); | ||
acc = Fr.add(acc, Fr.square(num)); | ||
} | ||
const accG = G1.timesFr(G1.g, acc); | ||
const accG2 = await G1.multiExpAffine(bases, scalars); | ||
assert(G1.eq(accG, accG2 )); | ||
}); | ||
}); | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
739452
13890
+ Addedwasmcurves@0.0.9(transitive)
- Removedwasmcurves@0.0.8(transitive)
Updatedwasmcurves@0.0.9