Skip to content

Commit

Permalink
Moving catch to upper level
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Apr 9, 2021
1 parent 86cdb95 commit 532fe71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 60 deletions.
25 changes: 11 additions & 14 deletions src/liblelantus/lelantus_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ bool LelantusVerifier::verify(

Scalar zV, zR;
unique_ptr<ChallengeGenerator> challengeGenerator;
// we are passing challengeGenerator ptr here, as after LELANTUS_TX_VERSION_4_5 we need it back, with filled data, to use in schnorr proof,
if (!(verify_sigma(vAnonymity_sets, anonymity_set_hashes, vSin, serialNumbers, ecdsaPubkeys, Cout, proof.sigma_proofs, qkSchnorrProof, x, challengeGenerator, zV, zR, fSkipVerification) &&
verify_rangeproof(Cout, proof.bulletproofs) &&
verify_schnorrproof(x, zV, zR, Vin, Vout, fee, Cout, proof, challengeGenerator)))
try {
// we are passing challengeGenerator ptr here, as after LELANTUS_TX_VERSION_4_5 we need it back, with filled data, to use in schnorr proof,
if (!(verify_sigma(vAnonymity_sets, anonymity_set_hashes, vSin, serialNumbers, ecdsaPubkeys, Cout, proof.sigma_proofs, qkSchnorrProof, x, challengeGenerator, zV, zR, fSkipVerification) &&
verify_rangeproof(Cout, proof.bulletproofs) &&
verify_schnorrproof(x, zV, zR, Vin, Vout, fee, Cout, proof, challengeGenerator)))
return false;
} catch (std::invalid_argument&) {
return false;
}

return true;
}

Expand Down Expand Up @@ -158,11 +163,7 @@ bool LelantusVerifier::verify_sigma(
for (std::size_t k = 0; k < Qk.size(); ++k)
{
Gk_sum += (Qk[k]) * qK_x_n.pow;
try {
qK_x_n.go_next();
} catch (std::invalid_argument&) {
return false;
}
qK_x_n.go_next();

Qks.emplace_back(Qk[k]);
}
Expand Down Expand Up @@ -242,11 +243,7 @@ bool LelantusVerifier::verify_schnorrproof(
for (int k = 0; k < params->get_sigma_m(); ++k)
{
x_ks.emplace_back(x_k.pow);
try {
x_k.go_next();
} catch (std::invalid_argument&) {
return false;
}
x_k.go_next();
}

GroupElement Comm;
Expand Down
31 changes: 5 additions & 26 deletions src/liblelantus/range_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,15 @@ bool RangeVerifier::verify_batch(const std::vector<GroupElement>& V, const std::
}

Scalar z_square_neg = (z.square()).negate();
Scalar delta;
try {
delta = LelantusPrimitives::delta(y, z, n, m);
} catch (std::invalid_argument&) {
return false;
}
Scalar delta = LelantusPrimitives::delta(y, z, n, m);

//check line 97
GroupElement V_z;
NthPower z_m(z);
for (std::size_t j = 0; j < m; ++j)
{
V_z += V[j] * (z_square_neg * z_m.pow);
try {
z_m.go_next();
} catch (std::invalid_argument&) {
return false;
}
z_m.go_next();
}

std::vector<Scalar> l_r;
Expand All @@ -106,11 +97,7 @@ bool RangeVerifier::verify_batch(const std::vector<GroupElement>& V, const std::
for (uint64_t k = 0; k < n; ++k)
{
two_n.emplace_back(two_n_.pow);
try {
two_n_.go_next();
} catch (std::invalid_argument&) {
return false;
}
two_n_.go_next();
}

for (uint64_t t = 0; t < m ; ++t)
Expand All @@ -133,17 +120,9 @@ bool RangeVerifier::verify_batch(const std::vector<GroupElement>& V, const std::
}
l_r[i] = x_il * innerProductProof.a_ + z;
l_r[n * m + i] = y_n_.pow * (x_ir * innerProductProof.b_ - (z_j.pow * two_n[k])) - z;
try {
y_n_.go_next();
} catch (std::invalid_argument&) {
return false;
}
}
try {
z_j.go_next();
} catch (std::invalid_argument&) {
return false;
y_n_.go_next();
}
z_j.go_next();
}

//check lines 98 and 105
Expand Down
24 changes: 4 additions & 20 deletions src/liblelantus/sigmaextended_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ bool SigmaExtendedVerifier::batchverify(
for (std::size_t i = I_[N - 1][j] + 1; i < n; i++)
fi_sum += f_[t][j*n + i];
pow += fi_sum * xj.pow * f_part_product[m - j - 1];
try {
xj.go_next();
} catch (std::invalid_argument&) {
return false;
}
xj.go_next();
}

f_i_t[N - 1] += pow * y[t];
Expand All @@ -117,11 +113,7 @@ bool SigmaExtendedVerifier::batchverify(
NthPower x_k(x);
for (uint64_t k = 0; k < m; ++k) {
x_k_neg.emplace_back(x_k.pow.negate());
try {
x_k.go_next();
} catch (std::invalid_argument&) {
return false;
}
x_k.go_next();
}

GroupElement t2;
Expand Down Expand Up @@ -224,11 +216,7 @@ bool SigmaExtendedVerifier::batchverify(
for (std::size_t i = I_[size - 1][j] + 1; i < n; i++)
fi_sum += f_[t][j*n + i];
pow += fi_sum * xj.pow * f_part_product[m - j - 1];
try {
xj.go_next();
} catch (std::invalid_argument&) {
return false;
}
xj.go_next();
}

f_i_t[N - 1] += pow * y[t];
Expand All @@ -248,11 +236,7 @@ bool SigmaExtendedVerifier::batchverify(
NthPower x_k(challenges[t]);
for (uint64_t k = 0; k < m; ++k) {
x_t_k_neg[t].emplace_back(x_k.pow.negate());
try {
x_k.go_next();
} catch (std::invalid_argument&) {
return false;
}
x_k.go_next();
}
}
GroupElement t2;
Expand Down

0 comments on commit 532fe71

Please sign in to comment.