utxo_ledger (reference): failed apply_transaction leaks already-created outputs (supply inflation)

Aperta Adatta ai principianti
#8,766 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 10 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
79/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
blockchain

Direzione di ricerca

Leggi rips/rustchain-core/utxo_ledger.py, in particolare UtxoSet.apply_transaction intorno alle righe 303–330 e add_transaction. Inizia controllando il rilevamento degli output duplicati e il modo in cui le applicazioni non riuscite ripristinano gli input spesi; aggiungi un test di regressione che verifichi che l’offerta totale rimanga invariata dopo il fallimento. Il lavoro è completato quando le applicazioni non riuscite non lasciano output, gli input restano spendibili e il mempool rifiuta gli output duplicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Found while reviewing #8302. It already exists on main and is not caused by that PR.

Where: rips/rustchain-core reference ledger, utxo_ledger.py UtxoSet.apply_transaction (around lines 303–330). This is reference code; the live node ledger (node/utxo_db.py) is not affected.

Bug: if one output's box_id collides with an earlier output in the same transaction, or with an existing UTXO, add_box raises after the earlier outputs were already inserted. The rollback only restores the spent inputs. The result:

  • apply_transaction returns False;
  • the input is still spendable;
  • the outputs created before the failure stay in the set.

In other words, value is minted. A probe with a 100-unit input went from supply 100 to 150.

Suggested fix (verified with the duplicate-box_id probe: supply stays 100):

  • Before applying, reject the transaction if output ids are not unique, or if any of them already exists or was already spent.
  • Record the outputs as they are created. On failure, remove them as well as restoring the inputs.
  • Give add_transaction (the mempool) the same duplicate-output check.
+        output_ids = [out.box_id for out in tx.outputs]
+        if len(output_ids) != len(set(output_ids)):
+            return False
+        if any(oid in self._boxes or oid in self._spent for oid in output_ids):
+            return False
         spent_boxes = []
+        created_boxes = []
 ...
                 self.add_box(output, owner)
+                created_boxes.append((output.box_id, owner))
 ...
         except Exception as e:
+            for box_id, owner in created_boxes:
+                self._boxes.pop(box_id, None)
+                self._by_address.get(owner, set()).discard(box_id)

A regression test should check that total supply is unchanged after a failed apply.

Lingua principale
Python
Stelle
850
Fork
589
Merge medio
11g 7h
PR unite (30g)
29

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Scottcjn/Rustchain

Tutte le issue di Scottcjn/Rustchain

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.