From bb4ee2b50bd988326f892752574cbec94bb5a9b9 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 29 May 2024 10:12:43 +0200 Subject: [PATCH] bip21: consider amount=0 in bip21 uri invalid --- electrum/bip21.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electrum/bip21.py b/electrum/bip21.py index 6b9cdf2fc..a9085c97a 100644 --- a/electrum/bip21.py +++ b/electrum/bip21.py @@ -61,7 +61,7 @@ def parse_bip21_URI(uri: str) -> dict: amount = Decimal(m.group(1)) * pow(Decimal(10), k) else: amount = Decimal(am) * COIN - if amount > TOTAL_COIN_SUPPLY_LIMIT_IN_BTC * COIN: + if amount > TOTAL_COIN_SUPPLY_LIMIT_IN_BTC * COIN or amount <= 0: raise InvalidBitcoinURI(f"amount is out-of-bounds: {amount!r} BTC") out['amount'] = int(amount) except Exception as e: @@ -92,7 +92,7 @@ def parse_bip21_URI(uri: str) -> dict: amount_sat = out.get('amount') if amount_sat: # allow small leeway due to msat precision - if abs(amount_sat - int(lnaddr.get_amount_sat())) > 1: + if lnaddr.get_amount_msat() is None or abs(amount_sat - int(lnaddr.get_amount_sat())) > 1: raise InvalidBitcoinURI("Inconsistent lightning field in bip21: amount") address = out.get('address') ln_fallback_addr = lnaddr.get_fallback_address()