Repository navigation
Open
Conversation
ConvertRLWEToCKKS created its template plaintext without a slot count and then called SetLength(slots), which only resizes the vector of values. The returned ciphertext therefore carried the batch size of the crypto context (N/2 if none was set) instead of the requested number of slots, and EvalFBT selects its precomputation by the slot count of the ciphertext.
DecryptCoeff reads the message coefficients at a stride of N/(2*numSlots), length times, and used both arguments unchecked: - numSlots above N/2 gave a stride of 0, so every returned value was coefficient 0. EncryptCoeff accepts N values, and passing the same count as numSlots (instead of numSlots = N/2, length = N) returned N copies of the first value. - A length with (length - 1) * stride >= N read past the end of the polynomial; numSlots = 8, length = 64 at N = 1024 ended in a segmentation fault. - numSlots = 0 divided by zero (SIGFPE). DecryptCoeff now throws in these cases, before any decryption work. Arguments that were valid before are handled as before. UTRLWEMP.DecryptCoeffRejectsInvalidSlotsAndLength covers the three cases and the largest valid length of the sparse layout.
andreea-alexandru
approved these changes
Nov 18, 2026
andreea-alexandru
left a comment
Collaborator
There was a problem hiding this comment.
Look good. There were some previous bugs regarding bit reversal for a length different than the number of slots. So I added a commit doing:
- ConvertRLWEToCKKS sets the ciphertext to the requested number of slots instead of the context's batch size.
- DecryptCoeff checks numSlots and length before decrypting. With bitReverse, it requires numSlots to be a power of two and undoes the bit reversal over the whole numSlots or 2*numSlots block before trimming to length.
- EncryptCoeff rejects an empty input. With bitReverse, the input size must be a power of two and at most the ring dimension.
- Tests cover the slot count after conversion, invalid arguments, and bit reversal with any valid length.
This branch has not been deployed
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.
fix for #1399