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.

73 lines
1.6 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #ifndef CIRCOM_CALCWIT_H
  2. #define CIRCOM_CALCWIT_H
  3. #include "circom.h"
  4. #include "fr.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. FrElement *signalValues;
  21. void triggerComponent(int newCIdx);
  22. void calculateWitness(void *input, void *output);
  23. void syncPrintf(const char *format, ...);
  24. public:
  25. Circom_Circuit *circuit;
  26. // Functions called by the circuit
  27. Circom_CalcWit(Circom_Circuit *aCircuit);
  28. ~Circom_CalcWit();
  29. int getSubComponentOffset(int cIdx, u64 hash);
  30. Circom_Sizes getSubComponentSizes(int cIdx, u64 hash);
  31. int getSignalOffset(int cIdx, u64 hash);
  32. Circom_Sizes getSignalSizes(int cIdx, u64 hash);
  33. void getSignal(int currentComponentIdx, int cIdx, int sIdx, PFrElement value);
  34. void setSignal(int currentComponentIdx, int cIdx, int sIdx, PFrElement value);
  35. void checkConstraint(int currentComponentIdx, PFrElement value1, PFrElement value2, char const *err);
  36. void log(PFrElement value);
  37. void finished(int cIdx);
  38. void join();
  39. // Public functions
  40. inline void setInput(int idx, PFrElement val) {
  41. setSignal(0, 0, circuit->wit2sig[idx], val);
  42. }
  43. inline void getWitness(int idx, PFrElement val) {
  44. Fr_copy(val, &signalValues[circuit->wit2sig[idx]]);
  45. }
  46. void reset();
  47. };
  48. #endif // CIRCOM_CALCWIT_H