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
551 B

5 years ago
  1. template Add(n) {
  2. signal input in[n];
  3. signal output out;
  4. var lc = 0;
  5. for (var i=0; i<n; i++) {
  6. lc = lc + in[i];
  7. }
  8. out <== lc;
  9. }
  10. function FAdd(a,b) {
  11. return a+b;
  12. }
  13. template Main() {
  14. signal input in;
  15. signal output out;
  16. var o = FAdd(3,4);
  17. o = o + FAdd(3,4);
  18. o = o + FAdd(3,4); // o = 21
  19. component A1 = Add(2);
  20. A1.in[0] <== in;
  21. A1.in[1] <== o;
  22. component A2 = Add(2);
  23. A2.in[0] <== A1.out;
  24. A2.in[1] <== o;
  25. out <== A2.out; // in + 42
  26. }
  27. component main = Main();