Skip to content

Conversation

@tlepoint
Copy link
Owner

This PR adds support for using BigUint as the plaintext modulus in the BFV scheme. This allows for plaintext moduli larger than 62 bits.

Key changes:

  • BfvParameters now stores the plaintext modulus as BigUint internally, exposing plaintext() for u64 (panics if too large) and plaintext_big() for BigUint.
  • Plaintext struct now holds values in PlaintextValues, which is an enum Small(Box<[u64]>) or Large(Box<[BigUint]>). This optimization ensures that operations with small moduli remain performant.
  • SecretKey::try_decrypt was updated to properly reconstruct large integer coefficients from the ciphertext polynomial's RNS representation when the plaintext modulus is large.
  • PlaintextVec and related encoders/decoders were updated to handle BigUint inputs and the new PlaintextValues structure.
  • New tests in tests/biguint_support.rs verify the functionality with a 128-bit Mersenne prime modulus.

PR created automatically by Jules for task 4494186955965380558 started by @tlepoint

- Refactored `BfvParameters` to support arbitrary precision plaintext moduli using `BigUint`.
- Updated `Plaintext` struct to use an enum `PlaintextValues` (`Small(u64)` or `Large(BigUint)`) to maintain performance for standard `u64` moduli while enabling large moduli.
- Updated `SecretKey` decryption to correctly handle `BigUint` plaintexts by reconstructing the value from RNS representation.
- Updated `FheEncoder` and `FheDecoder` implementations to support `BigUint` values.
- Added comprehensive tests for encryption, decryption, and homomorphic addition with `BigUint` plaintext moduli.

Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
@google-labs-jules
Copy link
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.

Copy link

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

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: 30ff8d9307

ℹ️ 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 on lines 140 to 142
let value_enum = match par.plaintext {
crate::bfv::PlaintextModulus::Small(_) => PlaintextValues::Small(v.iter().map(|x| x.to_u64().unwrap_or(0)).collect::<Vec<_>>().into_boxed_slice()),
crate::bfv::PlaintextModulus::Large(_) => PlaintextValues::Large(v.iter().map(|x| BigUint::from(x.clone())).collect::<Vec<_>>().into_boxed_slice()),

Choose a reason for hiding this comment

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

P2 Badge Reject or reduce BigUint inputs that don’t fit u64

When the plaintext modulus is Small, BigUint inputs that exceed u64::MAX are silently converted to 0 via to_u64().unwrap_or(0). If callers use the BigUint encoder generically (e.g., a large literal or a value already reduced mod t but still > u64::MAX), the stored PlaintextValues::Small will not match the intended message, and Plaintext::to_poly() will encrypt the wrong value. This should return an error or explicitly reduce modulo the plaintext modulus instead of zeroing on overflow.

Useful? React with 👍 / 👎.

google-labs-jules bot and others added 5 commits January 31, 2026 23:31
- Added `PlaintextModulus` enum to `BfvParameters` to support both `Small` (u64) and `Large` (BigUint) moduli.
- Updated `Plaintext` to store values in `PlaintextValues` enum (`Small` or `Large`).
- Updated `PlaintextVec` encoders/decoders to handle both variants.
- Updated `SecretKey` decryption to correctly lift RNS residues to `BigUint` for large moduli.
- Added new tests in `crates/fhe/tests/biguint_support.rs`.
- Updated `fhe.proto` to include optional `plaintext_big` field.

Co-authored-by: tlepoint <1345502+tlepoint@users.noreply.github.com>
@tlepoint tlepoint force-pushed the biguint-plaintext-modulus-4494186955965380558 branch from dbf3e09 to 7710b5a Compare February 1, 2026 15:03
@tlepoint tlepoint merged commit be7afa8 into main Feb 1, 2026
6 checks passed
@tlepoint tlepoint deleted the biguint-plaintext-modulus-4494186955965380558 branch February 1, 2026 16:14
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