Skip to content

Commit

Permalink
rsigma to mcl
Browse files Browse the repository at this point in the history
  • Loading branch information
xevisalle committed Nov 9, 2023
1 parent 2e6f7dc commit 82a2035
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/common/fourier.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ void ifft_t(size_t arr, mclBnFr domain[], mclBnFr *o)
out[i] = o[i];
}

mclBnFr_mul(&o[0], &out[0], &rsigmaFr[0]);
mclBnFr_mul(&o[0], &out[0], &rsigma[0]);

for (int i = 1; i < arr; i++)
{
mclBnFr_mul(&o[i], &out[arr-i], &rsigmaFr[i]);
mclBnFr_mul(&o[i], &out[arr-i], &rsigma[i]);
}

fft(arr, domain, o);
Expand Down
57 changes: 24 additions & 33 deletions src/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,55 +72,46 @@ void init_prover(void *circuit, proving_key pk)
mpz_set_str(pPrime, PRIMESTR, 10);
if (bench) printf(" |--- FFT domain size : %d\n", n);

rsigma = (mpz_t*) malloc((n) * sizeof(mpz_t));
rsigmaFr = (mclBnFr*) malloc((n) * sizeof(mclBnFr));
rsigmaInv = (mpz_t*) malloc((n) * sizeof(mpz_t));

mpz_t randNum;
mpz_init(randNum);
mpz_t factor, shift_fft_mpz;
mpz_init_set_ui(factor, n);
mpz_invert(factor, factor, pPrime);
rsigma = (mclBnFr*) malloc((n) * sizeof(mclBnFr));
rsigmaInv = (mclBnFr*) malloc((n) * sizeof(mclBnFr));

mpz_t shift_fft_mpz;
mpz_init(shift);
mpz_init(shift_fft_mpz);

mclBnFr rand;
generate_random_scalar(&rand);
fr_to_mpz(&randNum, &rand);
mpz_set(shift, randNum);
fr_to_mpz(&shift, &rand);

mpz_powm(shift_fft_mpz, shift, pk.Ne, pPrime);
mpz_sub_ui(shift_fft_mpz, shift_fft_mpz, 1);
mpz_invert(shift_fft_mpz, shift_fft_mpz, pPrime);

mpz_to_fr(&shift_fft, &shift_fft_mpz);

mpz_init2(rsigma[0], BITS);
mpz_init2(rsigmaInv[0], BITS);
mpz_set_ui(rsigma[0], 1);
mpz_invert(rsigmaInv[0], rsigma[0], pPrime);
mclBnFr_setInt(&rsigma[0], 1);
mclBnFr_inv(&rsigmaInv[0], &rsigma[0]);

mclBnFr frFactor;
mpz_to_fr(&frFactor, &rsigmaInv[0]);
mclBnG1_mul(&pk.xt1_rand[0], &pk.xt1[0], &frFactor);
mpz_mul(rsigma[0], rsigma[0], factor);
mpz_mod(rsigma[0], rsigma[0], pPrime);
mpz_to_fr(&rsigmaFr[0], &rsigma[0]);
mclBnG1_mul(&pk.xt1_rand[0], &pk.xt1[0], &rsigmaInv[0]);

mclBnFr n_inverted;
mclBnFr_setInt(&n_inverted, n);
mclBnFr_inv(&n_inverted, &n_inverted);

mclBnFr_mul(&rsigma[0], &rsigma[0], &n_inverted);

for (int i = 1; i < n; i++)
{
mclBnFr frFactorMulti;
mpz_init2(rsigma[i], BITS);
mpz_init2(rsigmaInv[i], BITS);
mpz_powm_ui(rsigma[i], shift, i, pPrime);
mpz_invert(rsigmaInv[i], rsigma[i], pPrime);

mpz_to_fr(&frFactorMulti, &rsigmaInv[i]);
mclBnG1_mul(&pk.xt1_rand[i], &pk.xt1[i], &frFactorMulti);

mpz_mul(rsigma[i], rsigma[i], factor);
mpz_mod(rsigma[i], rsigma[i], pPrime);
mpz_to_fr(&rsigmaFr[i], &rsigma[i]);
mpz_t factor;
mpz_init(factor);
mpz_powm_ui(factor, shift, i, pPrime);

mpz_to_fr(&rsigma[i], &factor);

mclBnFr_inv(&rsigmaInv[i], &rsigma[i]);
mclBnG1_mul(&pk.xt1_rand[i], &pk.xt1[i], &rsigmaInv[i]);

mclBnFr_mul(&rsigma[i], &rsigma[i], &n_inverted);
}

clock_gettime(CLOCK_MONOTONIC, &end);
Expand Down
6 changes: 3 additions & 3 deletions src/gro16/gro16.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ static mclBnFr *AsFr;
static mclBnFr *BsFr;
static mclBnFr *CsFr;

static mpz_t *rsigma;
static mclBnFr *rsigmaFr;
static mpz_t *rsigmaInv;
static mclBnFr *rsigma;
static mclBnFr *rsigmaInv;

static mpz_t shift;
static mclBnFr shift_fft;

Expand Down
4 changes: 2 additions & 2 deletions src/zpie.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ proof generate_proof(void *circuit, proving_key pk)
mclBnFr_clear(&BsFr[i]);
mclBnFr_clear(&CsFr[i]);

mpz_clear(rsigma[i]);
mpz_clear(rsigmaInv[i]);
mclBnFr_clear(&rsigma[i]);
mclBnFr_clear(&rsigmaInv[i]);
}

for (int i = 0; i < M; i++)
Expand Down

0 comments on commit 82a2035

Please sign in to comment.