From 2d6e34c8c289f6c8c9ab2597c20b9f5976fefd32 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 13 Feb 2023 08:54:39 +0000 Subject: [PATCH] ecc: make ECPubkey.__lt__ relation strongly-connected/total Previously we had: ``` >>> import electrum >>> from electrum.ecc import POINT_AT_INFINITY >>> G = electrum.ecc.GENERATOR >>> G <= (-1 * G) False >>> (-1 * G) <= G False ``` --- electrum/ecc.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/electrum/ecc.py b/electrum/ecc.py index d00a11f16..c8503593b 100644 --- a/electrum/ecc.py +++ b/electrum/ecc.py @@ -303,7 +303,9 @@ class ECPubkey(object): def __lt__(self, other): if not isinstance(other, ECPubkey): raise TypeError('comparison not defined for ECPubkey and {}'.format(type(other))) - return (self.x() or 0) < (other.x() or 0) + p1 = ((self.x() or 0), (self.y() or 0)) + p2 = ((other.x() or 0), (other.y() or 0)) + return p1 < p2 def verify_message_for_address(self, sig65: bytes, message: bytes, algo=lambda x: sha256d(msg_magic(x))) -> bool: assert_bytes(message)