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.

76 lines
1.7 KiB

5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
  1. #ifndef CIRCOM_CALCWIT_H
  2. #define CIRCOM_CALCWIT_H
  3. #include "circom.h"
  4. #include "zqfield.h"
  5. #include <mutex>
  6. #include <condition_variable>
  7. #define NMUTEXES 128
  8. class Circom_CalcWit {
  9. #ifdef SANITY_CHECK
  10. bool *signalAssigned;
  11. #endif
  12. // componentStatus -> For each component
  13. // >0 Signals required to trigger
  14. // == 0 Component triggered
  15. // == -1 Component finished
  16. int *inputSignalsToTrigger;
  17. std::mutex *mutexes;
  18. std::condition_variable *cvs;
  19. std::mutex printf_mutex;
  20. BigInt *signalValues;
  21. Circom_Circuit *circuit;
  22. void triggerComponent(int newCIdx);
  23. void calculateWitness(void *input, void *output);
  24. void syncPrintf(const char *format, ...);
  25. public:
  26. ZqField *field;
  27. // Functions called by the circuit
  28. Circom_CalcWit(Circom_Circuit *aCircuit);
  29. ~Circom_CalcWit();
  30. int getSubComponentOffset(int cIdx, u64 hash);
  31. Circom_Sizes getSubComponentSizes(int cIdx, u64 hash);
  32. int getSignalOffset(int cIdx, u64 hash);
  33. Circom_Sizes getSignalSizes(int cIdx, u64 hash);
  34. PBigInt allocBigInts(int n);
  35. void freeBigInts(PBigInt bi, int n);
  36. void getSignal(int currentComponentIdx, int cIdx, int sIdx, PBigInt value);
  37. void setSignal(int currentComponentIdx, int cIdx, int sIdx, PBigInt value);
  38. void checkConstraint(int currentComponentIdx, PBigInt value1, PBigInt value2, char const *err);
  39. void log(PBigInt value);
  40. void finished(int cIdx);
  41. void join();
  42. // Public functions
  43. inline void setInput(int idx, PBigInt val) {
  44. setSignal(0, 0, circuit->wit2sig[idx], val);
  45. }
  46. inline void getWitness(int idx, PBigInt val) {
  47. mpz_set(*val, signalValues[circuit->wit2sig[idx]]);
  48. }
  49. void reset();
  50. };
  51. #endif // CIRCOM_CALCWIT_H