arnaucube
arnaucube/circomlibPublic Self-hosted repository
circomlib/test/pedersen.js
test/pedersen.jsRaw
 1const chai = require("chai");
 2const path = require("path");
 3
 4const bigInt = require("big-integer");
 5const tester = require("circom").tester;
 6
 7const babyJub = require("../src/babyjub.js");
 8
 9const PBASE =
10    [
11        [bigInt("10457101036533406547632367118273992217979173478358440826365724437999023779287"),bigInt("19824078218392094440610104313265183977899662750282163392862422243483260492317")],
12        [bigInt("2671756056509184035029146175565761955751135805354291559563293617232983272177"),bigInt("2663205510731142763556352975002641716101654201788071096152948830924149045094")],
13        [bigInt("5802099305472655231388284418920769829666717045250560929368476121199858275951"),bigInt("5980429700218124965372158798884772646841287887664001482443826541541529227896")],
14        [bigInt("7107336197374528537877327281242680114152313102022415488494307685842428166594"),bigInt("2857869773864086953506483169737724679646433914307247183624878062391496185654")],
15        [bigInt("20265828622013100949498132415626198973119240347465898028410217039057588424236"),bigInt("1160461593266035632937973507065134938065359936056410650153315956301179689506")]
16    ];
17
18describe("Double Pedersen test", function() {
19    let circuit;
20    this.timeout(100000);
21    before( async() => {
22
23        circuit = await tester(path.join(__dirname, "circuits", "pedersen_test.circom"));
24
25    });
26    it("Should pedersen at zero", async () => {
27
28        let w;
29
30        w = await circuit.calculateWitness({ in: ["0", "0"]});
31
32        await circuit.assertOut(w, {out: [0,1]});
33
34    });
35    it("Should pedersen at one first generator", async () => {
36        let w;
37
38        w = await circuit.calculateWitness({ in: ["1", "0"]});
39
40        await circuit.assertOut(w, {out: PBASE[0]});
41
42    });
43    it("Should pedersen at one second generator", async () => {
44        let w;
45
46        w = await circuit.calculateWitness({ in: ["0", "1"]});
47
48        await circuit.assertOut(w, {out: PBASE[1]});
49
50    });
51    it("Should pedersen at mixed generators", async () => {
52        let w;
53        w = await circuit.calculateWitness({ in: ["3", "7"]});
54
55        const r = babyJub.addPoint(
56            babyJub.mulPointEscalar(PBASE[0], 3),
57            babyJub.mulPointEscalar(PBASE[1], 7)
58        );
59
60        await circuit.assertOut(w, {out: r});
61
62    });
63    it("Should pedersen all ones", async () => {
64        let w;
65
66        const allOnes = bigInt("1").shiftLeft(250).minus(bigInt("1"));
67        w = await circuit.calculateWitness({ in: [allOnes, allOnes]});
68
69
70        const r2 = babyJub.addPoint(
71            babyJub.mulPointEscalar(PBASE[0], allOnes),
72            babyJub.mulPointEscalar(PBASE[1], allOnes)
73        );
74
75        await circuit.assertOut(w, {out: r2});
76    });
77});