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

(bugfix): fix mpfr error in hybrid-dual #53

Merged
merged 1 commit into from
Oct 20, 2022
Merged

(bugfix): fix mpfr error in hybrid-dual #53

merged 1 commit into from
Oct 20, 2022

Conversation

bencrts
Copy link
Collaborator

@bencrts bencrts commented Oct 20, 2022

This PR fixes issue #38.

The problem was related to the exhaustive_search function creating an overflow in mpfr. In particular, when:

cost > 2**31 - 1

we see an mpfr error which crashes sage. To fix this quickly, we can add a condition on cost in the exhaustive search function which sends anything over 2**31 - 1 to oo. This is really slow, so we use 2**10000 instead. We might want to revisit this later, so I've left a todo in the codebase.

@bencrts bencrts linked an issue Oct 20, 2022 that may be closed by this pull request
@bencrts bencrts force-pushed the issue-38 branch 2 times, most recently from 967138d to 5ab323a Compare October 20, 2022 12:15
@bencrts
Copy link
Collaborator Author

bencrts commented Oct 20, 2022

For some reason I can't get the tests to run locally this time (via pytest or by using the old ./doctest.sh file method). Had to do it via the CI alone. Does the CI contain all of the tests we need? Everything seems to pass there.

@bencrts bencrts requested a review from malb October 20, 2022 12:28
@malb
Copy link
Owner

malb commented Oct 20, 2022

Hi Ben,

I was thinking we could make this slightly more general:

modified   estimator/cost.py
@@ -265,6 +265,8 @@ class Cost:
         """
         Perform basic checks.
         """
+        if self.get("rop", 0) > 2**10000:
+            setattr(self, "rop", oo)
         if self.get("beta", 0) > self.get("d", 0):
             raise RuntimeError(f"β = {self['beta']} > d = {self['d']}")
         if self.get("eta", 0) > self.get("d", 0):
modified   estimator/lwe_guess.py
@@ -217,7 +217,7 @@ class ExhaustiveSearch:
         cost = 2 * size * m
 
         ret = Cost(rop=cost, mem=cost / 2, m=m)
-        return ret
+        return ret.sanity_check()
 
     __name__ = "exhaustive_search"
 
@@ -428,7 +428,7 @@ class Distinguisher:
             raise InsufficientSamplesError(
                 "Not enough samples to distinguish with target advantage."
             )
-        return Cost(rop=m, mem=m, m=m)
+        return Cost(rop=m, mem=m, m=m).sanity_check()
 

with that applied I get

sage: from estimator import *
sage: LWE.estimate.rough(LWE.Parameters(n=4096, q=2^80, Xs=ND.CenteredBinomial(4), Xe=ND.CenteredBinomial(4)))
usvp                 :: rop: ≈2^147.5, red: ≈2^147.5, δ: 1.003380, β: 505, d: 7973, tag: usvp
dual_hybrid          :: rop: ≈2^148.0, mem: ≈2^133.5, m: ≈2^12.0, β: 507, d: 8207, ↻: 1, ζ: 9, tag: dual_hybrid
arora-gb             :: rop: ≈2^179.1, dreg: 9, mem: ≈2^179.1, t: 4, m: ≈2^89.5
{'usvp': rop: ≈2^147.5, red: ≈2^147.5, δ: 1.003380, β: 505, d: 7973, tag: usvp,
 'dual_hybrid': rop: ≈2^148.0, mem: ≈2^133.5, m: ≈2^12.0, β: 507, d: 8207, ↻: 1, ζ: 9, tag: dual_hybrid,
 'arora-gb': rop: ≈2^179.1, dreg: 9, mem: ≈2^179.1, t: 4, m: ≈2^89.5}

@bencrts
Copy link
Collaborator Author

bencrts commented Oct 20, 2022

Updated - thanks! I have now learned how sanity_check() works :).

@malb malb merged commit 75b9434 into main Oct 20, 2022
@malb malb deleted the issue-38 branch October 20, 2022 14:00
@malb
Copy link
Owner

malb commented Oct 20, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Estimator crashes when running on large parameters
2 participants