Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip change output amount verification during melt #393

Merged
merged 2 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ async def melt(

# 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, (
Expand Down
10 changes: 8 additions & 2 deletions cashu/mint/verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ async def verify_inputs_and_outputs(
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
Expand All @@ -108,7 +110,11 @@ async def _verify_outputs(self, outputs: List[BlindedMessage]):
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):
Expand Down
Loading