Skip to content

Commit

Permalink
return error if incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
meilof committed Sep 25, 2019
1 parent 494d37d commit b7b8310
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
19 changes: 10 additions & 9 deletions qapver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ int main (int argc, char **argv) {
qapvks[vkfile] = readfromfile<qapvk>(vkfile, true);
}

cerr << "Verifying " << name << " (" << vkfile << ")" << " ";
cerr << "Verifying " << name << " (" << vkfile << ")" << endl;
prooff >> proofs[name];
cerr << qapver(qapvks[vkfile], proofs[name], wirevals, name) << endl;
if (!qapver(qapvks[vkfile], proofs[name], wirevals, name)) return 10;
} else if (tok=="[external]") {
string fun; sched >> fun;
string type = qap2type[fun];
Expand All @@ -111,9 +111,9 @@ int main (int argc, char **argv) {
cerr << "Reading input block file " << blkfile << endl;
datablock din = readfromfile<datablock>(blkfile);

cerr << "Verifying input block " << fun << " " << blk << " ";
cerr << qapblockvalid(mkey, din) << " ";
cout << qapblockver(mkey, din, qapvks[type].blocks[blk], proofs[fun].blocks[blk]) << endl;
cerr << "Verifying input block " << fun << " " << blk << endl;
if (!qapblockvalid(mkey, din)) return 11;
if (!qapblockver(mkey, din, qapvks[type].blocks[blk], proofs[fun].blocks[blk])) return 12;
} else if (tok=="[glue]") {
string fun1; sched >> fun1;
string type1 = qap2type[fun1];
Expand All @@ -124,12 +124,13 @@ int main (int argc, char **argv) {

datablock blk; prooff >> blk;

cerr << "Verifying glue " << fun1 << "." << blk1 << "<->" << fun2 << "." << blk2 << " ";
cerr << qapblockvalid(mkey, blk) << " ";
cerr << qapblockver(mkey, blk, qapvks[type1].blocks[blk1], proofs[fun1].blocks[blk1]) << " ";
cerr << qapblockver(mkey, blk, qapvks[type2].blocks[blk2], proofs[fun2].blocks[blk2]) << endl;
cerr << "Verifying glue " << fun1 << "." << blk1 << "<->" << fun2 << "." << blk2 << endl;
if (!qapblockvalid(mkey, blk)) return 2;
if (!qapblockver(mkey, blk, qapvks[type1].blocks[blk1], proofs[fun1].blocks[blk1])) return 13;
if (!qapblockver(mkey, blk, qapvks[type2].blocks[blk2], proofs[fun2].blocks[blk2])) return 14;
} else {
cerr << "*** Unrecognized token: " << tok << endl;
return 15;
}
}

Expand Down
40 changes: 32 additions & 8 deletions verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ bool qapblockvalid(const masterkey& mk, const datablock& db) {
// alpha check
opt_atePairing(e1, mk.g_al, db.comm);
opt_atePairing(e2, db.commal, g1);
if (e1!=e2) { cerr << "*** c-alpha pairing check failed" << endl; }
if (e1!=e2) {
cerr << "*** c-alpha pairing check failed" << endl;
return false;
}

return true;
}
Expand All @@ -64,12 +67,18 @@ bool qapblockver(const masterkey& mk, const datablock& db, const blockvk& bvk, c
// alpha' check
opt_atePairing(e1, bvk.g2al, block.comm);
opt_atePairing(e2, block.commal, g1);
if (e1!=e2) { cerr << "*** c'-alpha pairing check failed" << endl; }
if (e1!=e2) {
cerr << "*** c'-alpha pairing check failed" << endl;
return false;
}

// z check
opt_atePairing(e1, bvk.g2beta, db.comm + block.comm);
opt_atePairing(e2, g2, block.commz);
if (e1!=e2) { cerr << "*** block z pairing check failed" << endl; }
if (e1!=e2) {
return false;
cerr << "*** block z pairing check failed" << endl;
}

return true;
}
Expand All @@ -89,23 +98,35 @@ bool qapver(const qapvk& qvk, const qapproof& proof, const wirevalt& pubwires, s
// alpha checks
opt_atePairing(e1, proof.p_ravx, g1);
opt_atePairing(e2, qvk.g2alv, proof.p_rvx);
if (e1!=e2) { cerr << "*** p_ravx pairing check failed" << endl; }
if (e1!=e2) {
cerr << "*** p_ravx pairing check failed" << endl;
return false;
}

opt_atePairing(e1, g2, proof.p_rawx);
opt_atePairing(e2, proof.p_rwx, qvk.g1alw);
if (e1!=e2) { cerr << "*** p_rawx pairing check failed" << endl; }
if (e1!=e2) {
cerr << "*** p_rawx pairing check failed" << endl;
return false;
}

opt_atePairing(e1, proof.p_rayx, g1);
opt_atePairing(e2, qvk.g2aly, proof.p_ryx);
if (e1!=e2) { cerr << "*** p_rayx pairing check failed" << endl; }
if (e1!=e2) {
cerr << "*** p_rayx pairing check failed" << endl;
return false;
}

// s check
Ec1 versum = proof.p_rvx+proof.p_ryx;
for (auto const& it: proof.blocks) versum += it.second.comm;
opt_atePairing(e1, g2, proof.p_z);
opt_atePairing(e2, qvk.g2bet, versum);
opt_atePairing(e3, proof.p_rwx, qvk.g1bet);
if (e1!=(e2*e3)) { cerr << "*** beta check failed" << endl; }
if (e1!=(e2*e3)) {
cerr << "*** beta check failed" << endl;
return false;
}

Ec1 pub_rvx = g10;
Ec2 pub_rwx = g20;
Expand All @@ -122,7 +143,10 @@ bool qapver(const qapvk& qvk, const qapproof& proof, const wirevalt& pubwires, s
opt_atePairing(e1, pub_rwx + proof.p_rwx, pub_rvx + proof.p_rvx);
opt_atePairing(e2, qvk.g2ryt, proof.p_h);
opt_atePairing(e3, g2, pub_ryx + proof.p_ryx);
if (e1!=(e2*e3)) { cerr << "*** divisibility check failed" << endl; }
if (e1!=(e2*e3)) {
cerr << "*** divisibility check failed" << endl;
return false;
}

return true;
}

0 comments on commit b7b8310

Please sign in to comment.