Skip to content

Convert pow tests to property-based tests#359

Merged
tlepoint merged 2 commits into
mainfrom
pow-proptest-1370136989131292015
Jan 31, 2026
Merged

Convert pow tests to property-based tests#359
tlepoint merged 2 commits into
mainfrom
pow-proptest-1370136989131292015

Conversation

@tlepoint

Copy link
Copy Markdown
Owner

Converted the pow unit test in crates/fhe-math/src/zq/mod.rs to use proptest. 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

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread crates/fhe-math/src/zq/mod.rs Outdated
Comment on lines +1139 to +1141
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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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>
@tlepoint tlepoint merged commit 89d4411 into main Jan 31, 2026
6 checks passed
@tlepoint tlepoint deleted the pow-proptest-1370136989131292015 branch January 31, 2026 23:11
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.

1 participant