From 2c5e12d5f893c6af9b97fec17d572268de3bd899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Tue, 2 Feb 2021 12:53:36 +0100 Subject: [PATCH] Workaround aliasing in Fp12[BLS12-377] inversion, fix #147 --- constantine.nimble | 12 ++++++------ .../tower_field_extensions/cubic_extensions.nim | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/constantine.nimble b/constantine.nimble index 99eb565..bc42e14 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -48,11 +48,11 @@ const testDesc: seq[tuple[path: string, useGMP: bool]] = @[ ("tests/t_finite_fields_double_width.nim", false), # Towers of extension fields # ---------------------------------------------------------- - # ("tests/t_fp2.nim", false), + ("tests/t_fp2.nim", false), ("tests/t_fp2_sqrt.nim", false), - # ("tests/t_fp6_bn254_snarks.nim", false), - # ("tests/t_fp6_bls12_377.nim", false), - # ("tests/t_fp6_bls12_381.nim", false), + ("tests/t_fp6_bn254_snarks.nim", false), + ("tests/t_fp6_bls12_377.nim", false), + ("tests/t_fp6_bls12_381.nim", false), ("tests/t_fp6_bw6_761.nim", false), ("tests/t_fp12_bn254_snarks.nim", false), ("tests/t_fp12_bls12_377.nim", false), @@ -60,8 +60,8 @@ const testDesc: seq[tuple[path: string, useGMP: bool]] = @[ ("tests/t_fp12_exponentiation.nim", false), ("tests/t_fp12_anti_regression.nim", false), - # ("tests/t_fp4_frobenius.nim", false), - # ("tests/t_fp6_frobenius.nim", false), + ("tests/t_fp4_frobenius.nim", false), + ("tests/t_fp6_frobenius.nim", false), ("tests/t_fp12_frobenius.nim", false), # Elliptic curve arithmetic G1 # ---------------------------------------------------------- diff --git a/constantine/tower_field_extensions/cubic_extensions.nim b/constantine/tower_field_extensions/cubic_extensions.nim index 5796260..091fa5b 100644 --- a/constantine/tower_field_extensions/cubic_extensions.nim +++ b/constantine/tower_field_extensions/cubic_extensions.nim @@ -183,7 +183,8 @@ func inv*(r: var CubicExt, a: CubicExt) = v3 += r.c1 v3 += r.c2 - v3.inv(v3) + let t = v3 # TODO, support aliasing in all primitives + v3.inv(t) # (a0 + a1 v + a2 v²)^-1 = (A + B v + C v²) / F r.c0 *= v3