/ circuit / test_wrapper.circom
test_wrapper.circom
  1  
  2  // wrappers around the Goldilocks templates, so that input and output are classic
  3  // signals, not Bus-es. The testing framework does not handle Bus inputs/outputs yet
  4  
  5  pragma circom 2.2.0;
  6  
  7  include "goldilocks.circom";
  8  
  9  //------------------------------------------------------------------------------
 10  
 11  template ToGoldilocksWrapper() {
 12    signal input  inp;
 13    signal output out;
 14  
 15    Goldilocks() goldi <== ToGoldilocks()(inp);
 16    goldi.val ==> out;
 17  }
 18  
 19  template ReduceWrapper(k) {
 20    signal input  inp;
 21    signal output out;
 22  
 23    Goldilocks() goldi <== ReduceModP(k);
 24    goldi.val ==> out;
 25  }
 26  
 27  //------------------------------------------------------------------------------
 28  
 29  template NegWrapper() {
 30    signal input  A;
 31    signal output C;
 32  
 33    Goldilocks() A1; A1.val <== A;
 34    Goldilocks() C1; 
 35  
 36    C1 <== Neg()( A1 );
 37    C1.val ==> C;
 38  }
 39  
 40  template AddWrapper() {
 41    signal input  A,B;
 42    signal output C;
 43  
 44    Goldilocks() A1; A1.val <== A;
 45    Goldilocks() B1; B1.val <== B;
 46    Goldilocks() C1; 
 47  
 48    C1 <== Add()( A1 , B1 );
 49    C1.val ==> C;
 50  
 51  //  log("A = ",A, " | B = ",B, " | C = ",C, " | expected = ", goldilocks_add(A,B));
 52  }
 53  
 54  template SubWrapper() {
 55    signal input  A,B;
 56    signal output C;
 57  
 58    Goldilocks() A1; A1.val <== A;
 59    Goldilocks() B1; B1.val <== B;
 60    Goldilocks() C1; 
 61  
 62    C1 <== Sub()( A1 , B1 );
 63    C1.val ==> C;
 64  }
 65  
 66  //------------------------------------------------------------------------------
 67  
 68  template SqrWrapper() {
 69    signal input  A;
 70    signal output C;
 71  
 72    Goldilocks() A1; A1.val <== A;
 73    Goldilocks() C1; 
 74  
 75    C1 <== Sqr()( A1 );
 76    C1.val ==> C;
 77  }
 78  
 79  template MulWrapper() {
 80    signal input  A,B;
 81    signal output C;
 82  
 83    Goldilocks() A1; A1.val <== A;
 84    Goldilocks() B1; B1.val <== B;
 85    Goldilocks() C1; 
 86  
 87    C1 <== Mul()( A1 , B1 );
 88    C1.val ==> C;
 89  }
 90  
 91  //------------------------------------------------------------------------------
 92  
 93  template InvWrapper() {
 94    signal input  A;
 95    signal output C;
 96  
 97    Goldilocks() A1; A1.val <== A;
 98    Goldilocks() C1; 
 99  
100    C1 <== Inv()( A1 );
101    C1.val ==> C;
102  
103    log("A = ",A, " | C = ",C, " | expected = ", goldilocks_inv(A));
104  }
105  
106  template DivWrapper() {
107    signal input  A,B;
108    signal output C;
109  
110    Goldilocks() A1; A1.val <== A;
111    Goldilocks() B1; B1.val <== B;
112    Goldilocks() C1; 
113  
114    C1 <== Div()( A1 , B1 );
115    C1.val ==> C;
116  }
117  
118  //------------------------------------------------------------------------------