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.

79 lines
1.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
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. template BabyAdd() {
  16. signal input x1;
  17. signal input y1;
  18. signal input x2;
  19. signal input y2;
  20. signal output xout;
  21. signal output yout;
  22. signal beta;
  23. signal gamma;
  24. signal delta;
  25. signal tau;
  26. var a = 168700;
  27. var d = 168696;
  28. beta <== x1*y2;
  29. gamma <== y1*x2;
  30. delta <== (-a*x1+y1)*(x2 + y2);
  31. tau <== beta * gamma;
  32. xout <-- (beta + gamma) / (1+ d*tau);
  33. (1+ d*tau) * xout === (beta + gamma);
  34. yout <-- (delta + a*beta - gamma) / (1-d*tau);
  35. (1-d*tau)*yout === (delta + a*beta - gamma);
  36. }
  37. template BabyDbl() {
  38. signal input x;
  39. signal input y;
  40. signal output xout;
  41. signal output yout;
  42. component adder = BabyAdd();
  43. adder.x1 <== x;
  44. adder.y1 <== y;
  45. adder.x2 <== x;
  46. adder.y2 <== y;
  47. adder.xout ==> xout;
  48. adder.yout ==> yout;
  49. }
  50. template BabyCheck() {
  51. signal input x;
  52. signal input y;
  53. signal x2;
  54. signal y2;
  55. var a = 168700;
  56. var d = 168696;
  57. x2 <== x*x;
  58. y2 <== y*y;
  59. a*x2 + y2 === 1 + d*x2*y2;
  60. }