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