Skip to content

Commit

Permalink
proof to mcl
Browse files Browse the repository at this point in the history
  • Loading branch information
xevisalle committed Nov 9, 2023
1 parent 8656ae7 commit e9431b8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/gro16/prover.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand All @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions src/gro16/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
29 changes: 12 additions & 17 deletions src/zpie.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/zpie.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ typedef struct

typedef struct
{
mpz_t *uwProof;
mclBnFr *uwProof;
mclBnG1 piA, piC;
mclBnG2 piB2;
} proof;
Expand Down

0 comments on commit e9431b8

Please sign in to comment.