-
Notifications
You must be signed in to change notification settings - Fork 37
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
Fused modular square root on 32-bit - wrong "isSquare" result #43
Labels
Comments
Similar to #30 and #43 another square root bug: import
# Standard library
std/[unittest, times],
# Internals
../constantine/config/[common, curves],
../constantine/arithmetic,
../constantine/io/[io_bigints, io_fields],
../constantine/elliptic/[ec_weierstrass_affine, ec_weierstrass_projective]
proc trySetFromCoordX_debug*[F](P: var ECP_SWei_Proj[F], x: F): SecretBool =
## Try to create a point the elliptic curve
## y² = x³ + a x + b (affine coordinate)
##
## The `Z` coordinates is set to 1
##
## return true and update `P` if `x` leads to a valid point
## return false otherwise, in that case `P` is undefined.
##
## Note: Dedicated robust procedures for hashing-to-curve
## will be provided, this is intended for testing purposes.
P.y.curve_eq_rhs(x)
# TODO: supports non p ≡ 3 (mod 4) modulus like BLS12-377
echo "P.y: ", P.y.toHex()
echo "P.y.isSquare: ", bool P.y.isSquare
result = sqrt_if_square_p3mod4(P.y)
echo "P.y.wasSquare: ", bool result
P.x = x
P.z.setOne()
var a: ECP_SWei_Proj[Fp[BLS12_381]]
var x: Fp[BLS12_381]
x.fromHex("0x1494859e30da25337d020ccf8629c81df7ddab3185acee7a5712c47e2192bc71d6bf74db134d3c7f7f21e43b59242ff3")
let ok = a.trySetFromCoordX_debug(x)
echo "ok: ", bool ok
echo "a.x: ", a.x.toHex()
echo "a.y: ", a.y.toHex()
doAssert bool isOnCurve(a.x, a.y)
var r0{.noInit.}, r1{.noInit.}: ECP_SWei_Proj[Fp[BLS12_381]]
r0.double(a)
r1.sum(a, a)
doAssert bool(r0 == r1)
|
mratsim
changed the title
EC add / EC double inconsistency
Fused modular square root on 32-bit - wrong "isSquare" result
Jun 19, 2020
This was referenced Jun 20, 2020
Merged
mratsim
added a commit
that referenced
this issue
Jun 22, 2020
mratsim
added a commit
that referenced
this issue
Jun 22, 2020
mratsim
added a commit
that referenced
this issue
Jun 22, 2020
Merged
2 tasks
mratsim
added a commit
that referenced
this issue
Jun 22, 2020
* Add test case for #30 - Euler's criterion doesn't return 1 for a square * Detect #42 in the test suite * Detect #43 in the test suite * comment in sqrt tests * Add #67 to the anti-regression suite * Add #61 to the anti-regression suite * Add #62 to anti-regression suite * Add #60 to the anti-regression suite * Add #64 to the test suite * Add #65 - case 1 * Add #65 case 2 * Add #65 case 3 * Add debug check to isSquare/Euler's Criterion/Legendre Symbol * Make sure our primitives are correct * For now deactivate montySquare CIOS fix #61 #62 * Narrow down #42 and #43 to powinv on 32-bit * Detect #42 #43 at the fast squaring level * More #42, #43 tests, Use multiplication instead of squaring as a temporary workaround, see #68 * Prevent regression of #67 now that squaring is "fixed"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproduced locally in 32-bit mode (might not be related to 32-bit as the RNG will initialize differently)
constantine/tests/test_ec_weierstrass_projective_g1.nim
Lines 157 to 175 in 082edaa
The text was updated successfully, but these errors were encountered: