-
Notifications
You must be signed in to change notification settings - Fork 45
Support BigUint plaintext moduli in BFV #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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>
|
👋 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.
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".
crates/fhe/src/bfv/plaintext_vec.rs
Outdated
| 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()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
- 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>
dbf3e09 to
7710b5a
Compare
This PR adds support for using
BigUintas the plaintext modulus in the BFV scheme. This allows for plaintext moduli larger than 62 bits.Key changes:
BfvParametersnow stores the plaintext modulus asBigUintinternally, exposingplaintext()foru64(panics if too large) andplaintext_big()forBigUint.Plaintextstruct now holds values inPlaintextValues, which is an enumSmall(Box<[u64]>)orLarge(Box<[BigUint]>). This optimization ensures that operations with small moduli remain performant.SecretKey::try_decryptwas updated to properly reconstruct large integer coefficients from the ciphertext polynomial's RNS representation when the plaintext modulus is large.PlaintextVecand related encoders/decoders were updated to handleBigUintinputs and the newPlaintextValuesstructure.tests/biguint_support.rsverify the functionality with a 128-bit Mersenne prime modulus.PR created automatically by Jules for task 4494186955965380558 started by @tlepoint