Skip to content

Fix SchemeletRLWEMP: ConvertRLWEToCKKS ignores its slots argument, and DecryptCoeff does not validate numSlots/length - #1402

Open
pascoec wants to merge 3 commits into
devfrom
issue1399
Open

pascoec wants to merge 3 commits into
devfrom
issue1399

Conversation

@pascoec

@pascoec pascoec commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

fix for #1399

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.
@pascoec pascoec added this to the Release 1.6.2 milestone Nov 17, 2026
@pascoec pascoec self-assigned this Nov 17, 2026
@pascoec pascoec added the bug Something isn't working label Nov 17, 2026

@andreea-alexandru andreea-alexandru left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SchemeletRLWEMP: ConvertRLWEToCKKS ignores its slots argument, and DecryptCoeff does not validate numSlots/length

2 participants