fix: replace GMP primality check with Baillie-PSW via num-bigint-dig#1
Open
lucasfernandes wants to merge 8 commits into
Open
fix: replace GMP primality check with Baillie-PSW via num-bigint-dig#1lucasfernandes wants to merge 8 commits into
lucasfernandes wants to merge 8 commits into
Conversation
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
leonardotc
requested changes
May 22, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
repsinprobab_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 patternprobably_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