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.

56 lines
1.0 KiB

  1. include "bitify.circom";
  2. // Returns 1 if in (in binary) > ct
  3. template CompConstant(ct) {
  4. signal input in[254];
  5. signal output out;
  6. signal parts[127];
  7. signal sout;
  8. var clsb;
  9. var cmsb;
  10. var slsb;
  11. var smsb;
  12. var sum=0;
  13. var b = (1 << 128) -1;
  14. var a = 1;
  15. var e = 1;
  16. var i;
  17. for (i=0;i<127; i++) {
  18. clsb = (ct >> (i*2)) & 1;
  19. cmsb = (ct >> (i*2+1)) & 1;
  20. slsb = in[i*2];
  21. smsb = in[i*2+1];
  22. if ((cmsb==0)&(clsb==0)) {
  23. parts[i] <== -b*smsb*slsb + b*smsb + b*slsb;
  24. } else if ((cmsb==0)&(clsb==1)) {
  25. parts[i] <== a*smsb*slsb - a*slsb + b*smsb - a*smsb + a;
  26. } else if ((cmsb==1)&(clsb==0)) {
  27. parts[i] <== b*smsb*slsb - a*smsb + a;
  28. } else {
  29. parts[i] <== -a*smsb*slsb + a;
  30. }
  31. sum = sum + parts[i];
  32. b = b -e;
  33. a = a +e;
  34. e = e*2;
  35. }
  36. sout <== sum;
  37. component num2bits = Num2Bits(135);
  38. num2bits.in <== sout;
  39. out <== num2bits.out[127];
  40. }