circomlib/test/pedersen2.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

const path = require("path");
const Fr = require("ffjavascript").bn128.Fr;
2019-12-13 21:05:20 +03:00
const tester = require("circom").tester;
const babyJub = require("../src/babyjub.js");
const pedersen = require("../src/pedersenHash.js");
describe("Pedersen test", function() {
let circuit;
this.timeout(100000);
before( async() => {
2019-12-13 21:05:20 +03:00
circuit = await tester(path.join(__dirname, "circuits", "pedersen2_test.circom"));
});
it("Should pedersen at zero", async () => {
2019-12-13 21:05:20 +03:00
let w;
2020-03-26 21:24:20 +03:00
w = await circuit.calculateWitness({ in: 0}, true);
const b = Buffer.alloc(32);
const h = pedersen.hash(b);
const hP = babyJub.unpackPoint(h);
2019-12-13 21:05:20 +03:00
await circuit.assertOut(w, {out: hP});
});
it("Should pedersen with 253 ones", async () => {
2019-12-13 21:05:20 +03:00
let w;
const n = Fr.sub(Fr.shl(Fr.one, Fr.e(253)), Fr.one);
2020-03-26 21:24:20 +03:00
w = await circuit.calculateWitness({ in: n}, true);
const b = Buffer.alloc(32);
for (let i=0; i<31; i++) b[i] = 0xFF;
b[31] = 0x1F;
const h = pedersen.hash(b);
const hP = babyJub.unpackPoint(h);
2019-12-13 21:05:20 +03:00
await circuit.assertOut(w, {out: hP});
});
});