From f90e8717253b615d58d665f5fba058049e6e76c6 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Mon, 21 Aug 2023 14:05:53 +0000 Subject: [PATCH] weierstrass: prohibit (0, 0, 0) in assertValidity --- src/abstract/weierstrass.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/abstract/weierstrass.ts b/src/abstract/weierstrass.ts index 492e35e..2f8cd24 100644 --- a/src/abstract/weierstrass.ts +++ b/src/abstract/weierstrass.ts @@ -333,9 +333,11 @@ export function weierstrassPoints(opts: CurvePointsType) { // A point on curve is valid if it conforms to equation. assertValidity(): void { - // Zero is valid point too! if (this.is0()) { - if (CURVE.allowInfinityPoint) return; + // (0, 1, 0) aka ZERO is invalid in most contexts. + // In BLS, ZERO can be serialized, so we allow it. + // (0, 0, 0) is wrong representation of ZERO and is always invalid. + if (CURVE.allowInfinityPoint && !Fp.is0(this.py)) return; throw new Error('bad point: ZERO'); } // Some 3rd-party test vectors require different wording between here & `fromCompressedHex`