malb / lattice-estimator

An attempt at a new LWE estimator
213 stars 49 forks source link

Crash and error for specific values of q #114

Open jdumezy opened 4 months ago

jdumezy commented 4 months ago

Description When using the rough LWE estimator for set n and distributions, there is a specific range of value of q for which either python crashes or it outputs an error.

How I encountered the problem In a fresh session of sage (after importing the estimator with from estimator import *), I can run the following estimations with no problem:

sage: params = LWE.Parameters(n=2^14, q=2^180, Xs = ND.Uniform(-1,1,n), Xe=ND.DiscreteGaussian(3.19))
sage: LWE.estimate.rough(params)
expected result
sage: params = LWE.Parameters(n=2^14, q=2^280, Xs = ND.Uniform(-1,1,n), Xe=ND.DiscreteGaussian(3.19))
sage: LWE.estimate.rough(params)
expected result

But for values between 2^180 and 2^280 there is unexpected behavior. Either an error and some results:

sage: params = LWE.Parameters(n=2^14, q=2^240, Xs = ND.Uniform(-1,1,n), Xe=ND.DiscreteGaussian(3.19))
sage: LWE.estimate.rough(params)
Algorithm functools.partial(<estimator.lwe_dual.MATZOV object at 0x743d85bb9e80>, red_cost_model=<estimator.reduction.ADPS16 object at 0x743d860cb830>) on LWEParameters(n=16384, q=1766847064778384329583297500742918515827483896875618958121606201292619776, Xs=D(σ=0.82), Xe=D(σ=3.19), m=+Infinity, tag=None) failed with Calling ceil() on infinity or NaN
usvp                 :: rop: ≈2^218.4, red: ≈2^218.4, δ: 1.002540, β: 748, d: 31817, tag: usvp
{'usvp': rop: ≈2^218.4, red: ≈2^218.4, δ: 1.002540, β: 748, d: 31817, tag: usvp}

Or a crash for values around 260:

sage: params = LWE.Parameters(n=2^14, q=2^250, Xs = ND.Uniform(-1,1,n), Xe=ND.DiscreteGaussian(3.19))
sage: LWE.estimate.rough(params)
sig_error() without sig_on()
...
(very long crash log)
------------------------------------------------------------------------
Unhandled SIGABRT: An abort() occurred.
This probably occurred because a *compiled* module has a bug
in it and is not properly wrapped with sig_on(), sig_off().
Python will now terminate.
------------------------------------------------------------------------
[1]    23531 IOT instruction (core dumped)  sage

OS/specs I am running sage 10.3 (python 3.12.3) on linux with a 13th gen i9 and 32Gb of RAM.

Is this "expected" (wrong choice of parameters?) or isolated behavior? Thanks.

ludopulles commented 3 days ago

FYI I can't reproduce this error on SageMath 10.4, Python 3.12.5 and commit 1e58f0211dae18b36e1cf978a49be04a2f0d07a0 :

Note: you call Uniform(-1, 1, n) but n is not assigned any value in the example you give.

sage: from estimator import *
sage: params = LWE.Parameters(n=2^14, q=2^240, Xs = ND.Uniform(-1,1), Xe=ND.DiscreteGaussian(3.19))
sage: LWE.estimate.rough(params)
usvp                 :: rop: ≈2^218.4, red: ≈2^218.4, δ: 1.002540, β: 748, d: 31817, tag: usvp
dual_hybrid          :: rop: ≈2^217.5, red: ≈2^217.5, guess: ≈2^164.1, β: 745, p: 3, ζ: 0, t: 90, β': 745, N: ≈2^153.6, m: ≈2^14.0
{'usvp': rop: ≈2^218.4, red: ≈2^218.4, δ: 1.002540, β: 748, d: 31817, tag: usvp,
 'dual_hybrid': rop: ≈2^217.5, red: ≈2^217.5, guess: ≈2^164.1, β: 745, p: 3, ζ: 0, t: 90, β': 745, N: ≈2^153.6, m: ≈2^14.0}
sage: params = LWE.Parameters(n=2^14, q=2^250, Xs = ND.Uniform(-1,1), Xe=ND.DiscreteGaussian(3.19))
sage: LWE.estimate.rough(params)
usvp                 :: rop: ≈2^206.7, red: ≈2^206.7, δ: 1.002645, β: 708, d: 31862, tag: usvp
dual_hybrid          :: rop: ≈2^205.7, red: ≈2^205.6, guess: ≈2^202.3, β: 704, p: 3, ζ: 20, t: 90, β': 704, N: ≈2^146.0, m: ≈2^14.0
{'usvp': rop: ≈2^206.7, red: ≈2^206.7, δ: 1.002645, β: 708, d: 31862, tag: usvp,
 'dual_hybrid': rop: ≈2^205.7, red: ≈2^205.6, guess: ≈2^202.3, β: 704, p: 3, ζ: 20, t: 90, β': 704, N: ≈2^146.0, m: ≈2^14.0}