circomlib/test/pedersen2.js
test/pedersen2.jsRaw
1const path = require("path");
2
3const bigInt = require("big-integer");
4const tester = require("circom").tester;
5
6const babyJub = require("../src/babyjub.js");
7const pedersen = require("../src/pedersenHash.js");
8
9
10describe("Pedersen test", function() {
11 let circuit;
12 this.timeout(100000);
13 before( async() => {
14
15 circuit = await tester(path.join(__dirname, "circuits", "pedersen2_test.circom"));
16 });
17 it("Should pedersen at zero", async () => {
18
19 let w;
20
21 w = await circuit.calculateWitness({ in: 0});
22
23 const b = Buffer.alloc(32);
24
25 const h = pedersen.hash(b);
26 const hP = babyJub.unpackPoint(h);
27
28 await circuit.assertOut(w, {out: hP});
29
30 });
31 it("Should pedersen with 253 ones", async () => {
32
33 let w;
34
35 const n = bigInt.one.shiftLeft(253).minus(bigInt.one);
36
37 w = await circuit.calculateWitness({ in: n});
38
39 const b = Buffer.alloc(32);
40 for (let i=0; i<31; i++) b[i] = 0xFF;
41 b[31] = 0x1F;
42
43 const h = pedersen.hash(b);
44 const hP = babyJub.unpackPoint(h);
45
46 await circuit.assertOut(w, {out: hP});
47
48 });
49});