weierstrass: prohibit (0, 0, 0) in assertValidity

This commit is contained in:
Paul Miller 2023-08-21 14:05:53 +00:00
parent f049398718
commit f90e871725
No known key found for this signature in database
GPG Key ID: 697079DA6878B89B

@ -333,9 +333,11 @@ export function weierstrassPoints<T>(opts: CurvePointsType<T>) {
// A point on curve is valid if it conforms to equation. // A point on curve is valid if it conforms to equation.
assertValidity(): void { assertValidity(): void {
// Zero is valid point too!
if (this.is0()) { 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'); throw new Error('bad point: ZERO');
} }
// Some 3rd-party test vectors require different wording between here & `fromCompressedHex` // Some 3rd-party test vectors require different wording between here & `fromCompressedHex`