From e9431b8236213202a629585fa40e86e898cf5df9 Mon Sep 17 00:00:00 2001 From: xevisalle Date: Thu, 9 Nov 2023 02:50:40 +0100 Subject: [PATCH] proof to mcl --- src/gro16/prover.c | 6 +++--- src/gro16/verifier.c | 3 +-- src/zpie.c | 29 ++++++++++++----------------- src/zpie.h | 2 +- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/gro16/prover.c b/src/gro16/prover.c index 7ed8874..e62d4ac 100644 --- a/src/gro16/prover.c +++ b/src/gro16/prover.c @@ -92,7 +92,7 @@ void h_coefficients(proving_key *pk) ifft(n, pk->wMFr, AsFr); } -void mul_exp(struct mulExpResult *result, mpz_t *uwProof, proving_key *pk) +void mul_exp(struct mulExpResult *result, mclBnFr *uwProof, proving_key *pk) { int n = mpz_get_ui(pk->Ne); @@ -101,7 +101,7 @@ void mul_exp(struct mulExpResult *result, mpz_t *uwProof, proving_key *pk) for (int i = nConst; i < (nPublic + nConst); i++) { - mpz_set(uwProof[i-nConst], uw[i]); + mpz_to_fr(&uwProof[i-nConst], &uw[i]); } #pragma omp parallel for @@ -124,7 +124,7 @@ void mul_exp(struct mulExpResult *result, mpz_t *uwProof, proving_key *pk) mclBnG1_mulVecMT(&result->htdelta, pk->xt1_rand, AsFr, n, num_threads); } -void prove(int *circuit, mclBnG1 *piA, mclBnG2 *piB2, mclBnG1 *piC, mpz_t *uwProof, proving_key *pk) +void prove(int *circuit, mclBnG1 *piA, mclBnG2 *piB2, mclBnG1 *piC, mclBnFr *uwProof, proving_key *pk) { prover = 1; diff --git a/src/gro16/verifier.c b/src/gro16/verifier.c index 6f0acaf..3aec82c 100644 --- a/src/gro16/verifier.c +++ b/src/gro16/verifier.c @@ -10,8 +10,7 @@ int verify(proof *p, verifying_key *vk) for (int i = (nPublic); i--;) { // Vu = Vu + u[i] * s1.vk[i] - mpz_to_fr(&frFactor, &p->uwProof[i]); - mclBnG1_mul(&factorG1, &vk->vk1[i+nConst], &frFactor); + mclBnG1_mul(&factorG1, &vk->vk1[i+nConst], &p->uwProof[i]); mclBnG1_add(&Vu, &Vu, &factorG1); } diff --git a/src/zpie.c b/src/zpie.c index c5dc287..bf69cb2 100644 --- a/src/zpie.c +++ b/src/zpie.c @@ -382,12 +382,7 @@ proof generate_proof(void *circuit, proving_key *pk) proof p; - p.uwProof = (mpz_t*) malloc((nPublic) * sizeof(mpz_t)); - - for (int i = 0; i < (nPublic); i++) - { - mpz_init(p.uwProof[i]); - } + p.uwProof = (mclBnFr*) malloc((nPublic) * sizeof(mclBnFr)); if (bench) printf("--- Computing proof...\n"); struct timespec begin, end; @@ -427,14 +422,14 @@ void store_proof(proof *p) FILE *fproof; fproof = fopen("data/proof.params", "w"); + int size = 0; + for (int i = 0; i < (nPublic); i++) { - mpz_out_raw(fproof, p->uwProof[i]); + size += mclBnFr_serialize(buff + size, SIZE_FR, &p->uwProof[i]); } - int size = 0; - - size += mclBnG1_serialize(buff, SIZE_G1, &p->piA); + size += mclBnG1_serialize(buff + size, SIZE_G1, &p->piA); size += mclBnG2_serialize(buff + size, SIZE_G2, &p->piB2); size += mclBnG1_serialize(buff + size, SIZE_G1, &p->piC); @@ -450,18 +445,18 @@ proof read_proof() FILE *fproof; fproof = fopen("data/proof.params", "r"); - p.uwProof = (mpz_t*) malloc((nPublic) * sizeof(mpz_t)); + p.uwProof = (mclBnFr*) malloc((nPublic) * sizeof(mclBnFr)); + + int size = 0; + + fread(buff, 1, (SIZE_FR * nPublic) + SIZE_G1 + SIZE_G2 + SIZE_G1, fproof); for (int i = 0; i < (nPublic); i++) { - mpz_init(p.uwProof[i]); - mpz_inp_raw(p.uwProof[i], fproof); + size += mclBnFr_deserialize(&p.uwProof[i], buff + size, SIZE_FR); } - int size = 0; - - fread(buff, 1, SIZE_G1 + SIZE_G2 + SIZE_G1, fproof); - size += mclBnG1_deserialize(&p.piA, buff, SIZE_G1); + size += mclBnG1_deserialize(&p.piA, buff + size, SIZE_G1); size += mclBnG2_deserialize(&p.piB2, buff + size, SIZE_G2); size += mclBnG1_deserialize(&p.piC, buff + size, SIZE_G1); diff --git a/src/zpie.h b/src/zpie.h index aa5108b..f2e0a32 100644 --- a/src/zpie.h +++ b/src/zpie.h @@ -69,7 +69,7 @@ typedef struct typedef struct { - mpz_t *uwProof; + mclBnFr *uwProof; mclBnG1 piA, piC; mclBnG2 piB2; } proof;