From a2709703f514c760cd653f3469b0b25915075e18 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:45:40 +0100 Subject: [PATCH] skip change output amount verification during melt (#393) * skip change output amount verification during melt * make format --- cashu/mint/ledger.py | 2 +- cashu/mint/verification.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 7836098..7c61c45 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -625,7 +625,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions): # make sure that the outputs (for fee return) are in the same unit as the quote if outputs: - await self._verify_outputs(outputs) + await self._verify_outputs(outputs, skip_amount_check=True) assert outputs[0].id, "output id not set" outputs_unit = self.keysets[outputs[0].id].unit assert melt_quote.unit == outputs_unit.name, ( diff --git a/cashu/mint/verification.py b/cashu/mint/verification.py index 06eb8b7..f1e9387 100644 --- a/cashu/mint/verification.py +++ b/cashu/mint/verification.py @@ -96,7 +96,9 @@ class LedgerVerification(LedgerSpendingConditions, SupportsKeysets, SupportsDb): if outputs and not self._verify_output_spending_conditions(proofs, outputs): raise TransactionError("validation of output spending conditions failed.") - async def _verify_outputs(self, outputs: List[BlindedMessage]): + async def _verify_outputs( + self, outputs: List[BlindedMessage], skip_amount_check=False + ): """Verify that the outputs are valid.""" logger.trace(f"Verifying {len(outputs)} outputs.") # Verify all outputs have the same keyset id @@ -108,7 +110,11 @@ class LedgerVerification(LedgerSpendingConditions, SupportsKeysets, SupportsDb): if not self.keysets[outputs[0].id].active: raise TransactionError("keyset id inactive.") # Verify amounts of outputs - if not all([self._verify_amount(o.amount) for o in outputs]): + # we skip the amount check for NUT-8 change outputs (which can have amount 0) + if ( + not all([self._verify_amount(o.amount) for o in outputs]) + and not skip_amount_check + ): raise TransactionError("invalid amount.") # verify that only unique outputs were used if not self._verify_no_duplicate_outputs(outputs):