Skip to content

Commit

Permalink
vdf fix (#142)
Browse files Browse the repository at this point in the history
* Division by 0 catching.

* Use mpz_sgn.

Co-authored-by: Florin Chirica <[email protected]>
  • Loading branch information
arvidn and fchirica authored Jun 27, 2023
1 parent 3097201 commit c75ec14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bqfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ int bqfc_decompr(mpz_t out_a, mpz_t out_b, const mpz_t D, const struct qfb_c *c)
mpz_set(t, c->t);
}

if (mpz_sgn(c->a) == 0) {
ret = -1;
goto out;
}
mpz_gcdext(tmp, t_inv, NULL, t, c->a);
if (mpz_cmp_ui(tmp, 1)) {
ret = -1;
Expand Down
3 changes: 3 additions & 0 deletions src/proof_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ form DeserializeForm(const integer &D, const uint8_t *bytes, size_t size)

integer FastPow(uint64_t a, uint64_t b, integer& c) {
integer res, a1 = integer(a);
if (mpz_sgn(c.impl) == 0) {
throw std::runtime_error("Division by 0");
}
mpz_powm_ui(res.impl, a1.impl, b, c.impl);
return res;
}
Expand Down

0 comments on commit c75ec14

Please sign in to comment.