Bootstrap: reject inputs with fewer limbs than their NoiseLevel needs instead of returning garbage - #37
Open
seyfal wants to merge 1 commit into
Open
Bootstrap: reject inputs with fewer limbs than their NoiseLevel needs instead of returning garbage#37seyfal wants to merge 1 commit into
seyfal wants to merge 1 commit into
Conversation
… instead of returning garbage ModRaise checked `getLevel() - NoiseLevel + 1 >= 1` only with assert(), which is compiled out in Release builds. A ciphertext at level 1 with NoiseLevel 2, or at level 0 with NoiseLevel 1, then goes through the raise: the pending rescale (and the raise's own multScalar + rescale) run on a single-limb polynomial, the level drops to -1 and the bootstrap completes normally but returns noise (OpenFHE's Decrypt reports "approximation error is too high"). Throw std::invalid_argument naming the level, the NoiseLevel and the required minimum (level >= NoiseLevel; for prescaled inputs level == NoiseLevel - 1), and document the precondition on Bootstrap() in Bootstrap.cuh. Valid inputs are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Bootstrap()on a ciphertext at level 1 with NoiseLevel 2, or at level 0 with NoiseLevel 1, runs to completion without any error and returns a ciphertext at the normal post-bootstrap level, but the content is noise (OpenFHE'sDecryptreports "the approximation error is too high"). Level 2 / NoiseLevel 2 and level 1 / NoiseLevel 1 bootstrap correctly.Cause:
ModRaise(src/CKKS/Bootstrap.cu) checksgetLevel() - NoiseLevel + 1 >= 1only withassert(), which is compiled out in Release builds. The raise then consumes the pending rescale of a NoiseLevel-2 input and one more limb (multScalar+rescalebeforedropToLevel(0)), so an input with fewer limbs than that rescales a single-limb polynomial (LimbPartition::rescale's ownassert(limbsize > 1)is compiled out too) and the raise works on a level -1 ciphertext.This PR turns the check into a real one:
std::invalid_argumentnaming the level, the NoiseLevel and the required minimum (level >= NoiseLevel; forprescaled == true, level == NoiseLevel - 1), and documents the precondition onBootstrap()inBootstrap.cuh. Valid inputs are unchanged.Tested on v2.1.3 (786c760), CUDA 13.0, H200 with N=2^16 / depth 25 / scaleModSize 52 / firstModSize 56 / 3 digits / FLEXIBLEAUTO / UNIFORM_TERNARY / 16384 slots, with the
examples/bootstrapparameters (N=2^12, full slots) and with the UNIFORM bootstrap configuration: the two bad cases (level 1 / NoiseLevel 2, level 0 / NoiseLevel 1) went from silent garbage to the exception; the three good cases are unchanged (max error 2.0e-3 to 2.2e-3 at our parameters, 3e-5 at the example parameters).The commit also applies cleanly on
OpenFHECompatTests.Fable 5.1 on behalf of Seyfal