Go Back > Fun Stuff > Puzzles

Thread Tools
Old 2005-08-31, 22:41   #1
akruppa's Avatar
Aug 2002

25×7×11 Posts
Default ECM puzzle (hard)

Note: do not attempt to solve this if you are unfamiliar with the internal workings of ECM and its implementations.

This is an oddity I stumbled upon while making a few more test cases for 2^n+-1 numbers for GMP-ECM with the GWNUM stage 1. It caused a bit of puzzlement between Dave and me on the developers mailing list, until Paul Zimmermann completely solved the mystery.

echo 33554520197234177 | ./ecm -sigma 2046841451 372 1

does not find the prime, but

echo 33554520197234177 | ./ecm -sigma 2046841451 373 1

does. However,

echo 33554520197234177 | ./ecm -sigma 2046841451 -go 373 372 1

does not. Why?

akruppa is offline   Reply With Quote
Old 2005-09-08, 19:08   #2
akruppa's Avatar
Aug 2002

46408 Posts

I admit that this puzzle was a bit unfair, but I think the answer is interesting enough to post it anyways.

GMP-ECM (and Prime95 as well) use Montgomery's PRAC algorithm to multiply a point on the curve by a small integer, i.e. by the successive stage 1 primes. The PRAC algorithm ensures that at any time, when two multiples a*X and b*X of a point X are to be added to (a+b)*X during the addition chain, the difference (a-b)*X is already known. This is required for doing arithmetic using the Montgomery parameterisation of elliptic curves.

Since the group order of the curve with sigma=2046841451 is 2^2*3^5*5^2*13*23^2*59*83*131*313 and 23^2=529, the factor should be found if B1>=529, or if an extra factor of 23 "magically" appears somewhere...

We suspected that maybe some way though the PRAC algorithm the residues (mod p) "go zero", i.e. we get the point at infinity on the curve, and get stuck there. That would explain why supplying the prime 373 via -go does not find the factor - the -go code uses a simple binary additon ladder, not PRAC.

Paul Zimmermann was able to confirm this suspicion:

Originally Posted by Paul Zimmermann
I've investigated further and I guess that you are both correct :-)
Indeed as conjectured by Alex the "prac" algorithm goes through the
computation of 23P. More precisely to compute 373P it computes at some
point A=63P B=29P C=|A-B|=34P. The next step is to replace B by A+B,
which gives B=92P. But since 92=4*23, we get B=(5461051122294227 : 0),
thus B is the point at infinity. The next step computes 155P = 63P + 92P
knowing the difference 29P, and this is still correct since the "add3" function
works if one of (x1:z1) or (x2:z2) is the point at infinity. The problem comes
from the next step, where we compute 155P + 63P knowing the difference 92P.
More precisely 155P is represented by (352101332154742 : 1209249988666152)
[with -mpzmod to avoid Montgomery representation which complicates things]
and 63P by (15889330945101281 : 12525994685524041). You can check that both
ratios x/z mod p=33554520197234177 are the same, so David was right too.

Here it is the *difference* (x:z) that is the point at infinity in add3,
and in that case add3 returns (0:0). Thus a value of z=0 that appears during
the prac computation will survive until the end.

In summary:
(a) the add3 code is incorrect. When z=0 it should call duplicate() instead
(but this would need to pass the 'b' parameter to add3 too...)
(b) we should not change anything, since this solving this 'bug' should
reduce the number of factors found...

What is interesting about this is that it is a genuine bug we found - the PRAC algorithm as currently implemented in GMP-ECM (and possibly in Prime95) is incorrect. We are using a function to add distinct points when they are identical, and the function to double the point would have to be used. But so far as we can tell, the only effect of this bug is that it (very rarely) helps find factors that would otherwise be missed - a genuine bug that genuinely makes the program better!


Last fiddled with by akruppa on 2005-09-10 at 16:09
akruppa is offline   Reply With Quote

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hard Drive Failure? In 3... 2... 1... TheMawn Lounge 32 2013-10-12 06:06
Hard reboot dans Hardware 5 2009-12-30 08:22
Any puzzle I can't solve in 15 minutes is to be considered HARD JuanTutors Puzzles 14 2005-05-27 21:27
Learning About RAM the Hard Way Longshot Hardware 5 2005-05-21 16:40
wow...1 Tb hard drive ixfd64 Hardware 8 2004-06-03 20:37

All times are UTC. The time now is 01:45.

Tue Oct 27 01:45:31 UTC 2020 up 46 days, 22:56, 0 users, load averages: 2.11, 1.80, 1.77

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.