Arrays working

This commit is contained in:
Jordi Baylina
2019-12-06 13:26:26 +01:00
parent 1e3d1235cb
commit fbcc753bc1
9 changed files with 290 additions and 145 deletions

View File

@@ -142,7 +142,7 @@ void Circom_CalcWit::checkConstraint(PBigInt value1, PBigInt value2, char const
#ifdef SANITY_CHECK
if (mpz_cmp(*value1, *value2) != 0) {
char *pcV1 = mpz_get_str(0, 10, *value1);
char *pcV2 = mpz_get_str(0, 10, *value1);
char *pcV2 = mpz_get_str(0, 10, *value2);
std::string sV1 = std::string(pcV1);
std::string sV2 = std::string(pcV2);
free(pcV1);

View File

@@ -1,14 +1,27 @@
#include "zqfield.h"
ZqField::ZqField(PBigInt ap) {
mpz_init2(tmp, 1024);
mpz_init_set(p, *ap);
mpz_init_set_ui(zero, 0);
mpz_init_set_ui(one, 1);
}
ZqField::~ZqField() {
mpz_clear(tmp);
mpz_clear(p);
mpz_clear(zero);
mpz_clear(one);
}
void ZqField::add(PBigInt r, PBigInt a, PBigInt b) {
mpz_add(*r,*a,*b);
mpz_fdiv_r(*r, *r, p);
mpz_add(tmp,*a,*b);
mpz_fdiv_r(*r, tmp, p);
}
void ZqField::mul(PBigInt r, PBigInt a, PBigInt b) {
mpz_mul(tmp,*a,*b);
mpz_fdiv_r(*r, tmp, p);
}
void ZqField::lt(PBigInt r, PBigInt a, PBigInt b) {

View File

@@ -4,15 +4,18 @@
#include "circom.h"
class ZqField {
mpz_t tmp;
public:
BigInt p;
BigInt one;
BigInt zero;
ZqField(PBigInt ap);
~ZqField();
void copyn(PBigInt a, PBigInt b, int n);
void add(PBigInt r,PBigInt a, PBigInt b);
void mul(PBigInt r,PBigInt a, PBigInt b);
void lt(PBigInt r, PBigInt a, PBigInt b);
int isTrue(PBigInt a);
};