Skip to content
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
18 changes: 18 additions & 0 deletions node/test_utxo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ def test_fee_exceeds_conservation(self):

self.assertFalse(ok)

def test_negative_fee_rejected(self):
"""Negative fee should fail — allows minting via weakened conservation."""
self._apply_coinbase('alice', 100 * UNIT)
alice_boxes = self.db.get_unspent_for_address('alice')

ok = self.db.apply_transaction({
'tx_type': 'transfer',
'inputs': [{'box_id': alice_boxes[0]['box_id'],
'spending_proof': 'sig'}],
'outputs': [{'address': 'bob', 'value_nrtc': 1100 * UNIT}],
'fee_nrtc': -1000 * UNIT, # negative fee bypasses conservation
}, block_height=10)

self.assertFalse(ok)
# Balances unchanged
self.assertEqual(self.db.get_balance('alice'), 100 * UNIT)
self.assertEqual(self.db.get_balance('bob'), 0)

# -- double-spend --------------------------------------------------------

def test_double_spend_rejected(self):
Expand Down
3 changes: 3 additions & 0 deletions node/utxo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ def apply_transaction(self, tx: dict, block_height: int,

# -- conservation check (skip for coinbase) ----------------------
output_total = sum(o['value_nrtc'] for o in outputs)
if fee < 0:
conn.execute("ROLLBACK")
return False
if inputs and (output_total + fee) > input_total:
conn.execute("ROLLBACK")
return False
Expand Down
Loading