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.

41 lines
678 B

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