Skip to content

Commit

Permalink
Detect zero challenges in schnorr
Browse files Browse the repository at this point in the history
  • Loading branch information
levonpetrosyan93 committed Nov 17, 2023
1 parent 5da3235 commit d2d27eb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/libspark/schnorr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void Schnorr::prove(const std::vector<Scalar>& y, const std::vector<GroupElement

proof.t = r;
for (std::size_t i = 0; i < n; i++) {
if (c_power.isZero()) {
throw std::invalid_argument("Unexpected challenge!");
}

proof.t += y[i].negate()*c_power;
c_power *= c;
}
Expand All @@ -73,6 +77,10 @@ bool Schnorr::verify(const std::vector<GroupElement>& Y, const SchnorrProof& pro
const Scalar c = challenge(Y, proof.A);
Scalar c_power(c);
for (std::size_t i = 0; i < n; i++) {
if (c_power.isZero()) {
throw std::invalid_argument("Unexpected challenge!");
}

points.emplace_back(Y[i]);
scalars.emplace_back(c_power);
c_power *= c;
Expand Down

0 comments on commit d2d27eb

Please sign in to comment.