-
Notifications
You must be signed in to change notification settings - Fork 13
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
Python code for map2curve is incorrect #6
Comments
Was wrestling with this myself today as it happens... It's because this repo doesn't yet implement the updated Implementing this makes the output match the test vectors in the draft 07 spec. Note to the maintainers: it would be really helpful to have an indication somewhere in here of which draft version the code implements. It appears to be draft 06 at the moment, but I can't find that info stated anywhere findable. |
@benjaminion I implemented it in def sgn0(x):
sign = 0
zero = 1
for xi in x:
sign_i = xi % 2
zero_i = xi == Fq.zero
sign = sign or (zero and sign_i)
zero = zero and zero_i
if not sign:
sign = 0
return sign |
I ended up doing the following (Warnings: (a) I don't Python, (b) this breaks constant time): In fields.py:
In opt_swu_g2.py:
and
This gets me to the answer, but there may remain other things to update. Best would be to wait until this repo is updated for draft 07. Or use py_ecc linked below. You can check the |
Thanks.
This ain't an issue for Python, JS, or any other GC language. GC breaks constant time, as you know. "Algorithmic" constant timeness is nice, but not too nice, and not everywhere. |
@benjaminion actually py_ecc produces invalid output as well. See: ethereum/py_ecc#98 |
Oh no! All I can tell you is that my Java implementation is working flawlessly against the spec test vectors 😂 |
Due to this, there's also one more problem with the draft says:
consider following two implementations def opt_swu2_map(t, t2=None):
Pp = osswu2_help(t)
if t2 is not None:
Pp2 = osswu2_help(t2)
Pp = point_add(Pp, Pp2)
P = iso3(Pp)
return P # NOTE: deliberately returning without clearing cofactor def opt_swu2_map2(t, t2=None):
Pp = iso3(osswu2_help(t))
if t2 is not None:
Pp2 = iso3(osswu2_help(t2))
Pp = point_add(Pp, Pp2)
return Pp # NOTE: deliberately returning without clearing cofactor both implementations should give same results, they do not. More importantly, this means that g2 signing test vectors in this repo are incorrect. edit, dumb me, I now see, there's #7 waiting to be merged |
Using this code produces correct P.x, but incorrect P.y.
See this test vector from spec:
The text was updated successfully, but these errors were encountered: