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
 7class Circom_CalcWit {
 8
 9#ifdef SANITY_CHECK
10    bool *signalAssigned;
11#endif
12
13    // componentStatus -> For each component
14    // >0 Signals required to trigger
15    // == 0 Component triggered
16    int *inputSignalsToTrigger;
17
18    BigInt *signalValues;
19
20    Circom_Circuit *circuit;
21
22    void triggerComponent(int newCIdx);
23    void calculateWitness(void *input, void *output);
24
25
26public:
27    ZqField *field;
28    int cIdx;
29// Functions called by the circuit
30    Circom_CalcWit(Circom_Circuit *aCircuit);
31    ~Circom_CalcWit();
32
33    int getSubComponentOffset(int cIdx, u64 hash);
34    Circom_Sizes getSubComponentSizes(int cIdx, u64 hash);
35    int getSignalOffset(int cIdx, u64 hash);
36    Circom_Sizes getSignalSizes(int cIdx, u64 hash);
37
38    PBigInt allocBigInts(int n);
39    void freeBigInts(PBigInt bi, int n);
40
41    void getSignal(int cIdx, int sIdx, PBigInt value);
42    void setSignal(int cIdx, int sIdx, PBigInt value);
43
44    void checkConstraint(PBigInt value1, PBigInt value2, char const *err);
45
46    void log(PBigInt value);
47
48
49// Public functions
50    inline void setInput(int idx, PBigInt val) {
51        setSignal(0, circuit->wit2sig[idx], val);
52    }
53    inline void getWitness(int idx, PBigInt val) {
54        mpz_set(*val, signalValues[circuit->wit2sig[idx]]);
55    }
56
57    void reset();
58
59};
60
61
62
63#endif // CIRCOM_CALCWIT_H