diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-10 14:49:21 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-10 17:08:01 -0300 |
| commit | ccf4489dbdf9e9d691e02e867562518c92168007 (patch) | |
| tree | d9514f8708a211f9515945bc0be6b09614731479 /docs/utxo-commitment.md | |
| parent | d2679e2c09c17e4af50535c13324ba2ddb2eb4ad (diff) | |
tools: add deterministic UTXO commitment verifier
Diffstat (limited to 'docs/utxo-commitment.md')
| -rw-r--r-- | docs/utxo-commitment.md | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/docs/utxo-commitment.md b/docs/utxo-commitment.md new file mode 100644 index 0000000..ddf5450 --- /dev/null +++ b/docs/utxo-commitment.md | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | # Bitflash UTXO-set commitment | ||
| 2 | |||
| 3 | `scripts/verify-utxo-set.py` reconstructs a deterministic commitment to the | ||
| 4 | current UTXO set from local `blk*.dat` files. | ||
| 5 | |||
| 6 | This is intentionally not a consensus rule yet. It is an audit tool: independent | ||
| 7 | operators can run it against the same chain prefix and compare the resulting | ||
| 8 | root and canonical JSON hash. | ||
| 9 | |||
| 10 | ```bash | ||
| 11 | python3 scripts/verify-utxo-set.py --max-blocks 1000 --out utxo-report.json --json | ||
| 12 | ``` | ||
| 13 | |||
| 14 | Use `--max-blocks 0` or omit the option to scan every available block file: | ||
| 15 | |||
| 16 | ```bash | ||
| 17 | python3 scripts/verify-utxo-set.py --out utxo-report.json --json | ||
| 18 | ``` | ||
| 19 | |||
| 20 | ## What It Verifies | ||
| 21 | |||
| 22 | The verifier: | ||
| 23 | |||
| 24 | - parses Bitflash block files directly; | ||
| 25 | - reconstructs the best chain rooted at the Bitflash genesis block; | ||
| 26 | - ignores side blocks that may also be present in `blk*.dat`; | ||
| 27 | - verifies every scanned block merkle root; | ||
| 28 | - applies spends and creates outputs in deterministic order; | ||
| 29 | - reports current UTXO count, current supply, mined coinbase total, fees, and | ||
| 30 | historical duplicate-output overwrites; | ||
| 31 | - computes a deterministic UTXO root. | ||
| 32 | |||
| 33 | ## Commitment Algorithm | ||
| 34 | |||
| 35 | The UTXO map is keyed by: | ||
| 36 | |||
| 37 | ```text | ||
| 38 | txid:vout | ||
| 39 | ``` | ||
| 40 | |||
| 41 | Keys are sorted lexicographically. Each leaf is: | ||
| 42 | |||
| 43 | ```text | ||
| 44 | SHA256("BTFUTXO1|" || outpoint || "|" || value_satoshis || "|" || | ||
| 45 | script_pub_key_hex || "|" || created_height || "|" || created_txid) | ||
| 46 | ``` | ||
| 47 | |||
| 48 | The tree is then reduced pairwise. If a level has an odd number of hashes, the | ||
| 49 | last hash is duplicated. Each parent is: | ||
| 50 | |||
| 51 | ```text | ||
| 52 | SHA256("BTFNODE1|" || left_hash || right_hash) | ||
| 53 | ``` | ||
| 54 | |||
| 55 | The final hash is the UTXO-set root. | ||
| 56 | |||
| 57 | ## Deterministic Output | ||
| 58 | |||
| 59 | `--json` and `--out` write canonical JSON with sorted keys, fixed separators, | ||
| 60 | ASCII escaping, and one trailing newline. It contains no local path and no | ||
| 61 | generation timestamp, so two auditors scanning the same chain prefix should | ||
| 62 | produce byte-identical reports. | ||
| 63 | |||
| 64 | ```bash | ||
| 65 | python3 scripts/verify-utxo-set.py --out utxo-report.json --json | ||
| 66 | sha256sum utxo-report.json | ||
| 67 | ``` | ||
| 68 | |||
| 69 | ## OpenTimestamps | ||
| 70 | |||
| 71 | The canonical JSON can be timestamped in Bitcoin without adding any dependency | ||
| 72 | to Bitflash consensus: | ||
| 73 | |||
| 74 | ```bash | ||
| 75 | ots stamp utxo-report.json | ||
| 76 | ots verify utxo-report.json.ots | ||
| 77 | ``` | ||
| 78 | |||
| 79 | ## Historical Duplicates | ||
| 80 | |||
| 81 | Bitflash inherited early Bitcoin behavior around duplicate transaction IDs. | ||
| 82 | The verifier reports duplicate-output overwrites as warnings and uses | ||
| 83 | last-write-wins semantics for the UTXO map, matching the legacy index model. | ||
| 84 | Those warnings are part of the report so auditors can see the historical debt | ||
| 85 | instead of relying on a polished summary. | ||
| 86 | |||
| 87 | ## Future Consensus Path | ||
| 88 | |||
| 89 | This tool is the low-risk first step toward consensus commitments. A future | ||
| 90 | hard-fork design can commit this root, or a Utreexo-style accumulator root, in | ||
| 91 | coinbase or block headers after a fixed activation height. Until then this | ||
| 92 | script provides reproducible supply and state commitments without changing what | ||
| 93 | nodes accept. | ||