Skip to content

Commit b7b8310

Browse files
committed
return error if incorrect
1 parent 494d37d commit b7b8310

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

qapver.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ int main (int argc, char **argv) {
9898
qapvks[vkfile] = readfromfile<qapvk>(vkfile, true);
9999
}
100100

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

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

125125
datablock blk; prooff >> blk;
126126

127-
cerr << "Verifying glue " << fun1 << "." << blk1 << "<->" << fun2 << "." << blk2 << " ";
128-
cerr << qapblockvalid(mkey, blk) << " ";
129-
cerr << qapblockver(mkey, blk, qapvks[type1].blocks[blk1], proofs[fun1].blocks[blk1]) << " ";
130-
cerr << qapblockver(mkey, blk, qapvks[type2].blocks[blk2], proofs[fun2].blocks[blk2]) << endl;
127+
cerr << "Verifying glue " << fun1 << "." << blk1 << "<->" << fun2 << "." << blk2 << endl;
128+
if (!qapblockvalid(mkey, blk)) return 2;
129+
if (!qapblockver(mkey, blk, qapvks[type1].blocks[blk1], proofs[fun1].blocks[blk1])) return 13;
130+
if (!qapblockver(mkey, blk, qapvks[type2].blocks[blk2], proofs[fun2].blocks[blk2])) return 14;
131131
} else {
132132
cerr << "*** Unrecognized token: " << tok << endl;
133+
return 15;
133134
}
134135
}
135136

verify.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ bool qapblockvalid(const masterkey& mk, const datablock& db) {
4848
// alpha check
4949
opt_atePairing(e1, mk.g_al, db.comm);
5050
opt_atePairing(e2, db.commal, g1);
51-
if (e1!=e2) { cerr << "*** c-alpha pairing check failed" << endl; }
51+
if (e1!=e2) {
52+
cerr << "*** c-alpha pairing check failed" << endl;
53+
return false;
54+
}
5255

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

6975
// z check
7076
opt_atePairing(e1, bvk.g2beta, db.comm + block.comm);
7177
opt_atePairing(e2, g2, block.commz);
72-
if (e1!=e2) { cerr << "*** block z pairing check failed" << endl; }
78+
if (e1!=e2) {
79+
return false;
80+
cerr << "*** block z pairing check failed" << endl;
81+
}
7382

7483
return true;
7584
}
@@ -89,23 +98,35 @@ bool qapver(const qapvk& qvk, const qapproof& proof, const wirevalt& pubwires, s
8998
// alpha checks
9099
opt_atePairing(e1, proof.p_ravx, g1);
91100
opt_atePairing(e2, qvk.g2alv, proof.p_rvx);
92-
if (e1!=e2) { cerr << "*** p_ravx pairing check failed" << endl; }
101+
if (e1!=e2) {
102+
cerr << "*** p_ravx pairing check failed" << endl;
103+
return false;
104+
}
93105

94106
opt_atePairing(e1, g2, proof.p_rawx);
95107
opt_atePairing(e2, proof.p_rwx, qvk.g1alw);
96-
if (e1!=e2) { cerr << "*** p_rawx pairing check failed" << endl; }
108+
if (e1!=e2) {
109+
cerr << "*** p_rawx pairing check failed" << endl;
110+
return false;
111+
}
97112

98113
opt_atePairing(e1, proof.p_rayx, g1);
99114
opt_atePairing(e2, qvk.g2aly, proof.p_ryx);
100-
if (e1!=e2) { cerr << "*** p_rayx pairing check failed" << endl; }
115+
if (e1!=e2) {
116+
cerr << "*** p_rayx pairing check failed" << endl;
117+
return false;
118+
}
101119

102120
// s check
103121
Ec1 versum = proof.p_rvx+proof.p_ryx;
104122
for (auto const& it: proof.blocks) versum += it.second.comm;
105123
opt_atePairing(e1, g2, proof.p_z);
106124
opt_atePairing(e2, qvk.g2bet, versum);
107125
opt_atePairing(e3, proof.p_rwx, qvk.g1bet);
108-
if (e1!=(e2*e3)) { cerr << "*** beta check failed" << endl; }
126+
if (e1!=(e2*e3)) {
127+
cerr << "*** beta check failed" << endl;
128+
return false;
129+
}
109130

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

127151
return true;
128152
}

0 commit comments

Comments
 (0)