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

5 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[10][2] = [
  23. [7688621503272331394947188562469131124099290577812125474996268020905176040083,6637287939860384587467947982369268811366630904563077767287326262235485629411],
  24. [11549681895645637778324638856880330712650895608496649854094912415387988201330,5771732722784528537721081267383956005090479808901717812009343940574217488577],
  25. [18790245153471844934157747708238883966079935875787657036767664036124524381945,18300275459419441151064576487317481499516933849631632883767173501999997278432],
  26. [16301069151422548986850494139112207641738464387919729729324473657161689764196,8215273507373494014441104012907835625670941526105528197815397741007626226499],
  27. [12597665704678284488008395353749282149622295037737374782196049599390683534185,4072455241781501621593714139281767473040087753548015968773801065193764079468],
  28. [4729410576230735258214831208080552588881894465489299233097088872252465832672,14367731890670510422926552586486424937476635415639602730590517235570020260326],
  29. [7546420686025050869200393054526306477146836870617678274607971529534032974471,8663210466512842901413293603100781938253817808912549776944118491282484711929],
  30. [6544653022506992755201027646251976600601201151329001772892901529509137954387,5932506509962692832681604586561215780097326378431958035490245111470435106811],
  31. [12376274813795671622507230443130412169480807188767687554607910279743333852725,10116389110458158800073166533660211332390835019644001845057351607297889034557],
  32. [18268098112071835140361074835791174816144587762778386397940339415400583397725,8120955462199046866292537174552276799123029303901205157708576578886090835495]
  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. }