From 67033674bee78fad98783ed9b071e752c41c34b1 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 22 Sep 2023 16:45:51 +0200 Subject: [PATCH] clean up --- cashu/mint/conditions.py | 6 +++--- cashu/mint/ledger.py | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cashu/mint/conditions.py b/cashu/mint/conditions.py index b3425c9e..98843950 100644 --- a/cashu/mint/conditions.py +++ b/cashu/mint/conditions.py @@ -28,7 +28,7 @@ def _verify_input_spending_conditions(self, proof: Proof) -> bool: Verify spending conditions: Condition: P2SH - Witnesses proof.p2shscript Condition: P2PK - Witness: proof.p2pksigs - + Condition: HTLC - Witness: proof.htlcpreimage, proof.htlcsignature """ # P2SH try: @@ -201,9 +201,9 @@ def _verify_output_spending_conditions( """ Verify spending conditions: Condition: P2PK - Witness: output.p2pksigs - """ - # P2SH + + # P2PK pubkeys_per_proof = [] n_sigs = [] for proof in proofs: diff --git a/cashu/mint/ledger.py b/cashu/mint/ledger.py index 0e0287a5..b991bb37 100644 --- a/cashu/mint/ledger.py +++ b/cashu/mint/ledger.py @@ -600,11 +600,7 @@ async def melt( await self._set_proofs_pending(proofs) try: - self._check_proofs_spendable(proofs) - - await self._verify_proofs_and_outputs(proofs) - logger.trace("verified proofs") - + # verify amounts total_provided = sum_proofs(proofs) invoice_obj = bolt11.decode(invoice) invoice_amount = math.ceil(invoice_obj.amount_msat / 1000) @@ -613,13 +609,18 @@ async def melt( f"Maximum melt amount is {settings.mint_max_peg_out} sat." ) fees_msat = await self.check_fees(invoice) + # verify overspending attempt assert ( total_provided >= invoice_amount + fees_msat / 1000 ), TransactionError("provided proofs not enough for Lightning payment.") + # verify that proofs have not been spent yet + self._check_proofs_spendable(proofs) + # verify spending inputs, outputs, and spending conditions + await self._verify_proofs_and_outputs(proofs, outputs) + # promises to return for overpaid fees return_promises: List[BlindedSignature] = [] - if settings.lightning: logger.trace("paying lightning invoice") status, preimage, fee_msat = await self._pay_lightning_invoice( @@ -739,13 +740,13 @@ async def split( total_amount = sum_proofs(proofs) try: - self._check_proofs_spendable(proofs) - # verify that amount is kosher self._verify_amount(total_amount) - # verify overspending attempt self._verify_equation_balanced(proofs, outputs) + # verify that proofs have not been spent yet + self._check_proofs_spendable(proofs) + # verify spending inputs, outputs, and spending conditions await self._verify_proofs_and_outputs(proofs, outputs) # Mark proofs as used and prepare new promises await self._invalidate_proofs(proofs)