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
1.3 KiB

  1. template MultiMux3(n) {
  2. signal input c[n][8]; // Constants
  3. signal input s[3]; // Selector
  4. signal output out[n];
  5. signal a210[n];
  6. signal a21[n];
  7. signal a20[n];
  8. signal a2[n];
  9. signal a10[n];
  10. signal a1[n];
  11. signal a0[n];
  12. signal a[n];
  13. // 4 constrains for the intermediary variables
  14. signal s10;
  15. s10 <== s[1] * s[0];
  16. for (var i=0; i<n; i++) {
  17. a210[i] <== ( c[i][ 7]-c[i][ 6]-c[i][ 5]+c[i][ 4] - c[i][ 3]+c[i][ 2]+c[i][ 1]-c[i][ 0] ) * s10;
  18. a21[i] <== ( c[i][ 6]-c[i][ 4]-c[i][ 2]+c[i][ 0] ) * s[1];
  19. a20[i] <== ( c[i][ 5]-c[i][ 4]-c[i][ 1]+c[i][ 0] ) * s[0];
  20. a2[i] <== ( c[i][ 4]-c[i][ 0] );
  21. a10[i] <== ( c[i][ 3]-c[i][ 2]-c[i][ 1]+c[i][ 0] ) * s10;
  22. a1[i] <== ( c[i][ 2]-c[i][ 0] ) * s[1];
  23. a0[i] <== ( c[i][ 1]-c[i][ 0] ) * s[0];
  24. a[i] <== ( c[i][ 0] )
  25. out[i] <== ( a210[i] + a21[i] + a20[i] + a2[i] ) * s[2] +
  26. ( a10[i] + a1[i] + a0[i] + a[i] );
  27. }
  28. }
  29. template Mux3() {
  30. var i;
  31. signal input c[8]; // Constants
  32. signal input s[3]; // Selector
  33. signal output out;
  34. component mux = MultiMux3(1);
  35. for (i=0; i<8; i++) {
  36. mux.c[0][i] <== c[i];
  37. }
  38. for (i=0; i<3; i++) {
  39. s[i] ==> mux.s[i];
  40. }
  41. mux.out[0] ==> out;
  42. }