Ask Your Question
1

Same code, (vastly) different results locally and at aleph.sagemath.org

asked 2022-02-10 13:38:18 +0100

fakub gravatar image

I have SageMath 9.4 for Ubuntu 20.04 downloaded from a french mirror (link) and I am trying to run an LWE estimator (link) by Albrecht et al (link).

Running on Aleph

Without any problem, I can paste the estimator.py code (link) into Aleph (link), followed by my parameters, e.g.:

n, stdv = 1024, 2^-30.0
set_verbose(1)
_ = estimate_lwe(n, sqrt(2*pi)*stdv, 2^32,  reduction_cost_model=BKZ.sieve, secret_distribution=(0,1))

from which I obtain

Warning: the LWE secret is assumed to have Hamming weight 512.
usvp: rop: ≈2^108.0,  red: ≈2^108.0,  δ_0: 1.005242,  β:  266,  d: 1889,  m:      864,  repeat:        1,  k:        0,  postprocess:        0
 dec: rop: ≈2^131.5,  m:     1198,  red: ≈2^131.5,  δ_0: 1.004529,  β:  332,  d: 2222,  babai: ≈2^117.5,  babai_op: ≈2^132.6,  repeat:       17,  ε: 0.250000
dual: rop: ≈2^112.1,  m:      994,  red: ≈2^112.1,  δ_0: 1.005070,  β:  280,  repeat: ≈2^60.8,  d: 1986,  c:        8,  k:       32,  postprocess:        1

which tells me that I have 108.0 bits of security (2nd line: usvp: rop: ≈2^108.0). Until here -- fine.

Running locally

Now I need to process a heap of parameters automatically, which I am trying to run locally (using the aforementioned version of SageMath). Problems arise (with 1-3 possibly irrelevant, 4 indeed relevant):

  1. With the very same code I get: ImportError: cannot import name complex_mpfr, which seems to be resolved by adding import sage.all in the very beginning.
  2. Then I get: n, stdv = 1024, 2^-30.0 .. TypeError: unsupported operand type(s) for ^: 'int' and 'float' which I fix by replacing 2^-30.0 with 9.3132257e-10.
  3. Next run: NameError: name 'set_verbose' is not defined which I solved by importing from sage.misc.verbose import verbose, set_verbose, get_verbose (still some warnings -- deprecated stuff and syntax -- which I ignore)
  4. Final run: I get the results,

but with completely different numbers:

Warning: the LWE secret is assumed to have Hamming weight 512.
usvp: rop: ≈2^44.9,  red: ≈2^44.9,  δ_0: 1.013310,  β:   40,  d: 1024,  m:       -1,  repeat:        1,  k:        0,  postprocess:        0
 dec: rop: ≈2^43.6,  m:     -614,  red: ≈2^43.6,  δ_0: 1.021759,  β:   40,  d:  410,  babai:        1,  babai_op: ≈2^15.1,  repeat:        1,  ε:        1

(and then TypeError: unable to convert '2.5275472536193645856387667200778292581e-30+2.6845375638424411831060264943943048062e9*I' to a real number which I ignore)

Compared to 108.0 from Aleph, my local result 44.9 is completely false, though running the same code. I also pasted the modified code into Aleph and it still gives 108.0.

Find my final code at Pastebin (link) (gives results both on Aleph and locally).

edit retag flag offensive close merge delete

Comments

Find the links at https://stackoverflow.com/questions/71065271 (https://stackoverflow.com/questions/7...)

fakub gravatar imagefakub ( 2022-02-10 13:40:43 +0100 )edit
1

Please check your reliance on Sage's preparser, e.g. by running preparse(""""your code here""") inside Sage. For example ^ between numbers should be replaced by ** when using Python directly without the preparser (as you seem to be doing). In Python, 2^32 is 34 (bitwise xor).

rburing gravatar imagerburing ( 2022-02-10 14:30:00 +0100 )edit

(upvote for your comment) preparse did the job, but I'd rather recommend to run $ sage --preparse estimator.sage and only then $ sage estimator.sage.py

fakub gravatar imagefakub ( 2022-02-10 16:16:13 +0100 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2022-02-10 16:20:44 +0100

fakub gravatar image

As commented by @rburing, the problem is that the code needs to be preparsed first, see the doc (I cannot insert the link for you..).

I made it work as follows:

$ sage --preparse estimator.sage

which creates an estimator.sage.py file, which can be executed with

$ sage estimator.sage.py
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-02-10 13:38:18 +0100

Seen: 290 times

Last updated: Feb 10 '22