circomlib/test/pedersen2.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

const path = require("path");
2019-12-13 21:05:20 +03:00
const bigInt = require("big-integer");
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;
2019-12-13 21:05:20 +03:00
w = await circuit.calculateWitness({ in: 0});
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;
2019-12-13 21:05:20 +03:00
const n = bigInt.one.shiftLeft(253).minus(bigInt.one);
2019-12-13 21:05:20 +03:00
w = await circuit.calculateWitness({ in: n});
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});
});
});