From 6eba608e6b9278e36d41f97145a07c91e820010d Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Fri, 1 Apr 2022 12:04:37 +0200 Subject: [PATCH] Fix sqrt --- .vscode/launch.json | 12 ++++++++++++ build/main.cjs | 6 +++--- src/fft.js | 6 +++--- test/bn128.js | 1 + 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index ccc0a7e..11cfc0c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,6 +15,18 @@ "args": [ "${workspaceFolder}/test/bn128.js" ] + }, + { + "type": "pwa-node", + "request": "launch", + "name": "Test Algebra", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "args": [ + "${workspaceFolder}/test/algebra.js" + ] } ] } \ No newline at end of file diff --git a/build/main.cjs b/build/main.cjs index 04bd6f8..f67a419 100644 --- a/build/main.cjs +++ b/build/main.cjs @@ -1661,8 +1661,8 @@ class FFT { this.G = G; this.opMulGF = opMulGF; - let rem = F.sqrt_t; - let s = F.sqrt_s; + let rem = F.sqrt_t || F.t; + let s = F.sqrt_s || F.s; let nqr = F.one; while (F.eq(F.pow(nqr, F.half), F.one)) nqr = F.add(nqr, F.one); @@ -1694,7 +1694,7 @@ class FFT { this.roots.push(rootsi); } */ - this._setRoots(15); + this._setRoots(Math.min(s, 15)); } _setRoots(n) { diff --git a/src/fft.js b/src/fft.js index 7e9f8af..5c34ecf 100644 --- a/src/fft.js +++ b/src/fft.js @@ -30,8 +30,8 @@ export default class FFT { this.G = G; this.opMulGF = opMulGF; - let rem = F.sqrt_t; - let s = F.sqrt_s; + let rem = F.sqrt_t || F.t; + let s = F.sqrt_s || F.s; let nqr = F.one; while (F.eq(F.pow(nqr, F.half), F.one)) nqr = F.add(nqr, F.one); @@ -63,7 +63,7 @@ export default class FFT { this.roots.push(rootsi); } */ - this._setRoots(15); + this._setRoots(Math.min(s, 15)); } _setRoots(n) { diff --git a/test/bn128.js b/test/bn128.js index 79d0a74..5a7b4ad 100644 --- a/test/bn128.js +++ b/test/bn128.js @@ -16,6 +16,7 @@ describe("bn128", async function () { let bn128; before( async() => { bn128 = await buildBn128(); + console.log(bn128.Fr.toString(bn128.Fr.w[28])); }); after( async() => { bn128.terminate();