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.

55 lines
890 B

  1. include "bitify.circom";
  2. include "binsum.circom";
  3. template IsZero() {
  4. signal input in;
  5. signal output out;
  6. signal inv;
  7. inv <-- in!=0 ? 1/in : 0;
  8. out <== -in*inv +1;
  9. in*out === 0;
  10. }
  11. template IsEqual() {
  12. signal input in[2];
  13. signal output out;
  14. component isz = IsZero();
  15. in[1] - in[0] ==> isz.in;
  16. isz.out ==> out;
  17. }
  18. // N is the number of bits the input have.
  19. // The MSF is the sign bit.
  20. template LessThan(n) {
  21. signal input in[2];
  22. signal output out;
  23. component num2Bits0;
  24. component num2Bits1;
  25. component adder;
  26. adder = BinSum(n, 2);
  27. num2Bits0 = Num2Bits(n);
  28. num2Bits1 = Num2BitsNeg(n);
  29. in[0] ==> num2Bits0.in;
  30. in[1] ==> num2Bits1.in;
  31. var i;
  32. for (i=0;i<n;i++) {
  33. num2Bits0.out[i] ==> adder.in[0][i];
  34. num2Bits1.out[i] ==> adder.in[1][i];
  35. }
  36. adder.out[n-1] ==> out;
  37. }