Skip to content

fix: replace GMP primality check with Baillie-PSW via num-bigint-dig#1

Open
lucasfernandes wants to merge 8 commits into
masterfrom
fix/primality-check-baillie-psw
Open

fix: replace GMP primality check with Baillie-PSW via num-bigint-dig#1
lucasfernandes wants to merge 8 commits into
masterfrom
fix/primality-check-baillie-psw

Conversation

@lucasfernandes
Copy link
Copy Markdown

@lucasfernandes lucasfernandes commented May 22, 2026

Summary

  • Increasing reps in probab_prime(2) does not solve the issue. More Miller-Rabin rounds only add computation time — they do not fix the adversarial input problem. Here we used 20 to follow the lib pattern probably_prime(&n, iterations.max(20) as usize). Since more iterations doesn't help anyways.

IMPORTANT: on file vdf/src/proof_wesolowski.rs an if must've removed because of compiler version updated.

References

The primality check in hash_prime was delegating to GMP's
mpz_probab_prime_p, which used Miller-Rabin only in versions <= 6.1.2.
Miller-Rabin alone is vulnerable to adversarially crafted inputs,
allowing a malicious prover to forge VDF proofs.

Changes:
- classgroup/Cargo.toml: add num-bigint-dig (Baillie-PSW, pure Rust, static)
- classgroup/build.rs: assert GMP >= 6.2.0 at compile time as a fallback guard
- classgroup/src/gmp_classgroup/mod.rs: replace __gmpz_probab_prime_p with
  probably_prime from num-bigint-dig (Miller-Rabin + Lucas test)
- vdf/src/proof_wesolowski.rs: remove dead code block that blocked compilation
- .cargo/config.toml: linker path for GMP on macOS Apple Silicon (Homebrew)

Ref: poanetwork#25
See: https://eprint.iacr.org/2018/749.pdf
Comment thread .cargo/config.toml Outdated
lucasfernandes and others added 5 commits May 22, 2026 09:12
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…rror)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants