arnaucube
arnaucube/grapevine-sonobePublic Self-hosted repository
grapevine-sonobe/circom/node_modules/circomlib/circuits/pedersen_old.circom
circom/node_modules/circomlib/circuits/pedersen_old.circomRaw
 1/*
 2    Copyright 2018 0KIMS association.
 3
 4    This file is part of circom (Zero Knowledge Circuit Compiler).
 5
 6    circom is a free software: you can redistribute it and/or modify it
 7    under the terms of the GNU General Public License as published by
 8    the Free Software Foundation, either version 3 of the License, or
 9    (at your option) any later version.
10
11    circom is distributed in the hope that it will be useful, but WITHOUT
12    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13    or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14    License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with circom. If not, see <https://www.gnu.org/licenses/>.
18*/
19pragma circom 2.0.0;
20
21include "escalarmul.circom";
22
23template Pedersen(n) {
24    signal input in[n];
25    signal output out[2];
26
27    var nexps = ((n-1) \ 250) + 1;
28    var nlastbits = n - (nexps-1)*250;
29
30    component escalarMuls[nexps];
31
32    var PBASE[10][2] = [
33        [10457101036533406547632367118273992217979173478358440826365724437999023779287,19824078218392094440610104313265183977899662750282163392862422243483260492317],
34        [2671756056509184035029146175565761955751135805354291559563293617232983272177,2663205510731142763556352975002641716101654201788071096152948830924149045094],
35        [5802099305472655231388284418920769829666717045250560929368476121199858275951,5980429700218124965372158798884772646841287887664001482443826541541529227896],
36        [7107336197374528537877327281242680114152313102022415488494307685842428166594,2857869773864086953506483169737724679646433914307247183624878062391496185654],
37        [20265828622013100949498132415626198973119240347465898028410217039057588424236,1160461593266035632937973507065134938065359936056410650153315956301179689506],
38        [1487999857809287756929114517587739322941449154962237464737694709326309567994,14017256862867289575056460215526364897734808720610101650676790868051368668003],
39        [14618644331049802168996997831720384953259095788558646464435263343433563860015,13115243279999696210147231297848654998887864576952244320558158620692603342236],
40        [6814338563135591367010655964669793483652536871717891893032616415581401894627,13660303521961041205824633772157003587453809761793065294055279768121314853695],
41        [3571615583211663069428808372184817973703476260057504149923239576077102575715,11981351099832644138306422070127357074117642951423551606012551622164230222506],
42        [18597552580465440374022635246985743886550544261632147935254624835147509493269,6753322320275422086923032033899357299485124665258735666995435957890214041481]
43
44    ];
45
46    var i;
47    var j;
48    var nexpbits;
49    for (i=0; i<nexps; i++) {
50        nexpbits = (i == nexps-1) ? nlastbits : 250;
51        escalarMuls[i] = EscalarMul(nexpbits, PBASE[i]);
52
53        for (j=0; j<nexpbits; j++) {
54            escalarMuls[i].in[j] <== in[250*i + j];
55        }
56
57        if (i==0) {
58            escalarMuls[i].inp[0] <== 0;
59            escalarMuls[i].inp[1] <== 1;
60        } else {
61            escalarMuls[i].inp[0] <== escalarMuls[i-1].out[0];
62            escalarMuls[i].inp[1] <== escalarMuls[i-1].out[1];
63        }
64    }
65
66    escalarMuls[nexps-1].out[0] ==> out[0];
67    escalarMuls[nexps-1].out[1] ==> out[1];
68}