Skip to content
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

Fix logQ(P) estimation used for finding the minimum ring dimension #796

Merged
merged 8 commits into from
Jun 11, 2024

Conversation

yspolyakov
Copy link
Contributor

@yspolyakov yspolyakov commented Jun 10, 2024

  1. Added EstimateLogP and EstimateMultipartyFloodingLogQ
  2. Updated the logic for BGV, BFV, and CKKS to use these methods prior to checking (finding) the ring dimension based on the LWE security tables

@yspolyakov yspolyakov added the bug Something isn't working label Jun 10, 2024
@yspolyakov yspolyakov added this to the Release 1.2.0 milestone Jun 10, 2024
@yspolyakov yspolyakov changed the base branch from main to dev June 10, 2024 19:30
@yspolyakov yspolyakov changed the title Fix logQ(p) estimation used for finding the minimum ring dimension Fix logQ(P) estimation used for finding the minimum ring dimension Jun 10, 2024

while (nRLWE(logqCeil) > n) {
n = 2 * n;
logq = logqBFV(n);
k = static_cast<int32_t>(std::ceil((std::ceil(logq / std::log(2)) + 1.0) / dcrtBits));
logqCeil = k * dcrtBits * std::log(2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not adding the +1 anymore? The same comment for the occurrences below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see why + 1 is needed in the current version of OpenFHE. Maybe in an old version (of PALISADE), we sometimes had larger moduli (NextPrime might have been used). So in my mind, ceil(logq/dcrtBits) is sufficient and guarantees that that logq<=k*dcrtBits. Moreover, adding + 1 would cause problems in the new estimation logic (getting an extra RNS limb when it is not needed).

Copy link
Collaborator

@andreea-alexandru andreea-alexandru left a comment

Choose a reason for hiding this comment

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

Only minor comments.

Copy link
Collaborator

@andreea-alexandru andreea-alexandru left a comment

Choose a reason for hiding this comment

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

The logic looks good to me.

@dsuponitskiy dsuponitskiy force-pushed the issue-774 branch 2 times, most recently from 705bc25 to 78b6cd4 Compare June 11, 2024 17:35
Copy link
Collaborator

@dsuponitskiy dsuponitskiy left a comment

Choose a reason for hiding this comment

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

Looks good to me

// Find number and size of individual special primes.
uint32_t maxBits = moduliPartQ[0].GetLengthForBase(2);
for (usint j = 1; j < m_numPartQ; j++) {
for (uint32_t j = 1; j < m_numPartQ; j++) {
uint32_t bits = moduliPartQ[j].GetLengthForBase(2);
if (bits > maxBits)
maxBits = bits;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

    uint32_t bits = 0, maxBits = 0;
    for (auto&& m : moduliPartQ) {
        if ((bits = m.GetLengthForBase(2)) > maxBits)
            maxBits = bits;
    }

@dsuponitskiy dsuponitskiy merged commit 4eed808 into dev Jun 11, 2024
26 checks passed
@dsuponitskiy dsuponitskiy deleted the issue-774 branch June 26, 2024 17:39
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.

Inaccurate log Q(P) used for the initial estimation when checking compliance with LWE security tables
5 participants