arnaucube
arnaucube/circomlib-testvectorsPublic Self-hosted repository
Uniformize testvector prints

Also updated babyjubjub testvector for signature as there have been
changes at Poseidon implementation.
arnaucube root@arnaucube.com
Mon, 08 Mar 2021 14:42:47 +0100
commit

1348a5f5551a6a45f48e0745c97179cdc7f3c28d

parent

f5eda98c64882ec6e913b5b01dcd6faf2d9a7f12

3 files changed, 25 insertions(+), 32 deletions(-)

jump to
M test/babyjubjub.test.js → test/babyjubjub.test.js

@@ -10,7 +10,6 @@

const assert = chai.assert; describe("BabyJubJub EDDSA javascript testvectors", function () { - it("BabyJubJub Keys test", async () => { let sk = Buffer.from("0001020304050607080900010203040506070809000102030405060708090001", "hex"); let pk = eddsa.prv2pub(sk);

@@ -29,7 +28,7 @@ "11384336176656855268977457483345535180380036354188103142384839473266348197733");

assert.equal(signature.R8[1].toString(), "15383486972088797283337779941324724402501462225528836549661220478783371668959"); assert.equal(signature.S.toString(), - "1398758333392199195742243841591064350253744445503462896781493968760929513778"); + "1672775540645840396591609181675628451599263765380031905495115170613215233181"); const pkPacked = babyjub.packPoint(pk); assert.equal(pkPacked.toString("hex"), "c433f7a696b7aa3a5224efb3993baf0ccd9e92eecee0c29a3f6c8208a9e81d9e");
M test/mimc.test.js → test/mimc.test.js

@@ -2,12 +2,18 @@ const chai = require("chai");

const Scalar = require("ffjavascript").Scalar; -const mimc = require("../../iden3/circomlib/src/mimc7.js"); +const mimc = require("circomlib").mimc7; const assert = chai.assert; const SEED = "mimc"; +function testvector(method, x, k) { + console.log(method); + console.log("input:", x, k); + console.log("output:", method(x, k)); +} + describe("MiMC7 javascript testvectors", function () { this.timeout(100000); before( async () => {

@@ -17,14 +23,9 @@ let cts = mimc.getConstants(SEED, 91);

console.log(cts[1]); }); it("MiMC7", async () => { - let res = mimc.hash(1, 2, 91); - console.log("mimc.hash(1,2,91)", res); - - res = mimc.multiHash([Scalar.e(1), Scalar.e(2), Scalar.e(3)], Scalar.e(0)); - console.log("mimc.multiHash([1,2,3], 0)", res); - - res = mimc.hash(12, 45, 91); - console.log("mimc.hash(12,45,91)", res); + testvector(mimc.hash, 1, 2); + testvector(mimc.multiHash,[Scalar.e(1), Scalar.e(2), Scalar.e(3)], Scalar.e(0)); + testvector(mimc.hash, 12, 45); }); });
M test/poseidon.test.js → test/poseidon.test.js

@@ -1,34 +1,27 @@

const chai = require("chai"); -const poseidon = require("../../iden3/circomlib/src/poseidon.js"); +const poseidon = require("circomlib").poseidon; const assert = chai.assert; +function testvector(method, inputs) { + console.log(method); + console.log("input:", inputs); + console.log("output:", method(inputs)); +} + describe("Poseidon javascript testvectors", function () { this.timeout(100000); before( async () => { }); it("Poseidon t=6", async () => { - let res = poseidon([1]); - console.log(res); - - res = poseidon([1,2]); - console.log(res); - - res = poseidon([1,2, 0, 0, 0]); - console.log(res); - - res = poseidon([1,2, 0, 0, 0, 0]); - console.log(res); - - res = poseidon([3,4, 0, 0, 0]); - console.log(res); - res = poseidon([3,4, 0, 0, 0, 0]); - console.log(res); - - res = poseidon([1,2,3,4,5,6]); - console.log(res); - + testvector(poseidon, [1]); + testvector(poseidon, [1,2]); + testvector(poseidon, [1,2,0,0,0]); + testvector(poseidon, [1,2,0,0,0,0]); + testvector(poseidon, [3,4,0,0,0,]); + testvector(poseidon, [3,4,0,0,0,0]); + testvector(poseidon, [1,2,3,4,5,6]); }); });