From 75493dfb5badbecb4ac91295d8fe979c8c8f203e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Sun, 24 Jan 2021 12:37:02 +0100 Subject: [PATCH] Fix #131, inversion tests didn't take into account that the RNG can produce a 0 input and so a.inv can be different from 1 --- tests/t_finite_fields_powinv.nim | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/t_finite_fields_powinv.nim b/tests/t_finite_fields_powinv.nim index 9271c78..e3e632e 100644 --- a/tests/t_finite_fields_powinv.nim +++ b/tests/t_finite_fields_powinv.nim @@ -257,25 +257,25 @@ proc main() = let a = rng.random_unsafe(Fp[curve]) aInv.inv(a) r.prod(a, aInv) - check: bool r.isOne() + check: bool r.isOne() or (a.isZero() and r.isZero()) r.prod(aInv, a) - check: bool r.isOne() + check: bool r.isOne() or (a.isZero() and r.isZero()) for _ in 0 ..< Iters: let a = rng.randomHighHammingWeight(Fp[curve]) aInv.inv(a) r.prod(a, aInv) - check: bool r.isOne() + check: bool r.isOne() or (a.isZero() and r.isZero()) r.prod(aInv, a) - check: bool r.isOne() + check: bool r.isOne() or (a.isZero() and r.isZero()) for _ in 0 ..< Iters: let a = rng.random_long01Seq(Fp[curve]) aInv.inv(a) r.prod(a, aInv) - check: bool r.isOne() + check: bool r.isOne() or (a.isZero() and r.isZero()) r.prod(aInv, a) - check: bool r.isOne() + check: bool r.isOne() or (a.isZero() and r.isZero()) testRandomInv P224 testRandomInv BN254_Nogami