Browse Source

Uniformize testvector prints

Also updated babyjubjub testvector for signature as there have been
changes at Poseidon implementation.
master
arnaucube 3 years ago
parent
commit
1348a5f555
3 changed files with 25 additions and 32 deletions
  1. +1
    -2
      test/babyjubjub.test.js
  2. +10
    -9
      test/mimc.test.js
  3. +14
    -21
      test/poseidon.test.js

+ 1
- 2
test/babyjubjub.test.js

@ -10,7 +10,6 @@ const babyjub = require("circomlib").babyJub;
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 @@ describe("BabyJubJub EDDSA javascript testvectors", function () {
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");

+ 10
- 9
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 @@ describe("MiMC7 javascript testvectors", function () {
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);
});
});

+ 14
- 21
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]);
});
});

Loading…
Cancel
Save