Convert pow tests to property-based tests#359
Conversation
Replaced the manual unit tests for `pow` in `crates/fhe-math/src/zq/mod.rs` with a `proptest!` block. The new test verifies basic properties of modular exponentiation ($a^0 = 1$, $a^1 = a$, $a^2 = a*a$) and compares the result against a simple multiplication loop for small exponents. It also includes debug assertions for invalid inputs. This improves test coverage by checking randomized inputs across a wider range of moduli. Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3c48f33481
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| prop_assert_eq!(p.pow(a, 0), 1); | ||
| prop_assert_eq!(p.pow(a, 1), a); | ||
| prop_assert_eq!(p.pow(a, 2), p.mul(a, a)); |
There was a problem hiding this comment.
Avoid invalid exponent for modulus 2
The new property test always calls p.pow(a, 2) even though pow explicitly debug-asserts n < p. Because valid_moduli() admits p = 2, this test will panic in debug builds whenever the generator picks that modulus (since 2 >= p), making the test flaky and violating the function’s documented preconditions. Consider guarding with prop_assume!(p > 2) or reducing the exponent (e.g., p.reduce(2) / 2 % *p) so the exponent is always < p.
Useful? React with 👍 / 👎.
Replaced the manual unit tests for `pow` in `crates/fhe-math/src/zq/mod.rs` with a `proptest!` block. The new test verifies basic properties of modular exponentiation ($a^0 = 1$, $a^1 = a$, $a^2 = a*a$) and compares the result against a simple multiplication loop for small exponents. It includes debug assertions for invalid inputs and guards against `pow(a, 2)` when $p=2$ to satisfy the precondition $n < p$. This improves test coverage by checking randomized inputs across a wider range of moduli. Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
Converted the
powunit test incrates/fhe-math/src/zq/mod.rsto useproptest. The new test strategy generates valid moduli and random inputs, verifying mathematical properties and consistency with a reference implementation for small exponents. Debug assertions are also verified.PR created automatically by Jules for task 1370136989131292015 started by @tlepoint