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.

39 lines
672 B

3 years ago
  1. template CheckBits(n) {
  2. signal input in;
  3. signal bits[n];
  4. var lc1=0;
  5. var e2=1;
  6. for (var i = 0; i<n; i++) {
  7. bits[i] <-- (in >> i) & 1;
  8. bits[i] * (bits[i] -1 ) === 0;
  9. lc1 += bits[i] * e2;
  10. e2 = e2+e2;
  11. }
  12. lc1 === in;
  13. }
  14. template Multiplier(n) {
  15. signal private input a;
  16. signal private input b;
  17. signal output c;
  18. signal inva;
  19. signal invb;
  20. component chackA = CheckBits(n);
  21. component chackB = CheckBits(n);
  22. chackA.in <== a;
  23. chackB.in <== b;
  24. inva <-- 1/(a-1);
  25. (a-1)*inva === 1;
  26. invb <-- 1/(b-1);
  27. (b-1)*invb === 1;
  28. c <== a*b;
  29. }
  30. component main = Multiplier(64);