for loops

This commit is contained in:
Jordi Baylina
2019-11-28 15:10:59 +01:00
parent 66291a0efe
commit 93330f065b
24 changed files with 1385 additions and 81 deletions

View File

@@ -25,8 +25,12 @@ Circom_CalcWit::Circom_CalcWit(Circom_Circuit *aCircuit) {
// Initialize remaining signals
for (int i=1; i<circuit->NSignals; i++) mpz_init2(signalValues[i], 256);
reset();
BigInt p;
mpz_init_set_str(p, circuit->P, 10);
field = new ZqField(&p);
mpz_clear(p);
reset();
}
void Circom_CalcWit::reset() {
@@ -43,6 +47,8 @@ void Circom_CalcWit::reset() {
Circom_CalcWit::~Circom_CalcWit() {
delete field;
#ifdef SANITY_CHECK
delete signalAssigned;
#endif

View File

@@ -2,6 +2,7 @@
#define CIRCOM_CALCWIT_H
#include "circom.h"
#include "zqfield.h"
class Circom_CalcWit {
@@ -18,13 +19,12 @@ class Circom_CalcWit {
Circom_Circuit *circuit;
void triggerComponent(int newCIdx);
void calculateWitness(void *input, void *output);
public:
ZqField *field;
int cIdx;
// Functions called by the circuit
Circom_CalcWit(Circom_Circuit *aCircuit);

View File

@@ -48,6 +48,7 @@ public:
int *wit2sig;
Circom_Component *components;
u32 *mapIsInput;
const char *P;
};
#define BITMAP_ISSET(m, b) (m[b>>5] & (1 << (b&0x1F)))

30
c/zqfield.cpp Normal file
View File

@@ -0,0 +1,30 @@
#include "zqfield.h"
ZqField::ZqField(PBigInt ap) {
mpz_init_set(p, *ap);
mpz_init_set_ui(zero, 0);
mpz_init_set_ui(one, 1);
}
void ZqField::add(PBigInt r, PBigInt a, PBigInt b) {
mpz_add(*r,*a,*b);
mpz_fdiv_r(*r, *r, p);
}
void ZqField::lt(PBigInt r, PBigInt a, PBigInt b) {
int c = mpz_cmp(*a, *b);
if (c<0) {
mpz_set(*r, one);
} else {
mpz_set(*r, zero);
}
}
int ZqField::isTrue(PBigInt a) {
return mpz_sgn(*a);
}
void ZqField::copy(PBigInt a, PBigInt b) {
return mpz_set(*a, *b);
}

20
c/zqfield.h Normal file
View File

@@ -0,0 +1,20 @@
#ifndef ZQFIELD_H
#define ZQFIELD_H
#include "circom.h"
class ZqField {
public:
BigInt p;
BigInt one;
BigInt zero;
ZqField(PBigInt ap);
void copy(PBigInt a, PBigInt b);
void add(PBigInt r,PBigInt a, PBigInt b);
void lt(PBigInt r, PBigInt a, PBigInt b);
int isTrue(PBigInt a);
};
#endif // ZQFIELD_H