You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
3.2 KiB

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