upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/utxo-commitment.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/utxo-commitment.md')
-rw-r--r--docs/utxo-commitment.md93
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
4current UTXO set from local `blk*.dat` files.
5
6This is intentionally not a consensus rule yet. It is an audit tool: independent
7operators can run it against the same chain prefix and compare the resulting
8root and canonical JSON hash.
9
10```bash
11python3 scripts/verify-utxo-set.py --max-blocks 1000 --out utxo-report.json --json
12```
13
14Use `--max-blocks 0` or omit the option to scan every available block file:
15
16```bash
17python3 scripts/verify-utxo-set.py --out utxo-report.json --json
18```
19
20## What It Verifies
21
22The 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
35The UTXO map is keyed by:
36
37```text
38txid:vout
39```
40
41Keys are sorted lexicographically. Each leaf is:
42
43```text
44SHA256("BTFUTXO1|" || outpoint || "|" || value_satoshis || "|" ||
45 script_pub_key_hex || "|" || created_height || "|" || created_txid)
46```
47
48The tree is then reduced pairwise. If a level has an odd number of hashes, the
49last hash is duplicated. Each parent is:
50
51```text
52SHA256("BTFNODE1|" || left_hash || right_hash)
53```
54
55The final hash is the UTXO-set root.
56
57## Deterministic Output
58
59`--json` and `--out` write canonical JSON with sorted keys, fixed separators,
60ASCII escaping, and one trailing newline. It contains no local path and no
61generation timestamp, so two auditors scanning the same chain prefix should
62produce byte-identical reports.
63
64```bash
65python3 scripts/verify-utxo-set.py --out utxo-report.json --json
66sha256sum utxo-report.json
67```
68
69## OpenTimestamps
70
71The canonical JSON can be timestamped in Bitcoin without adding any dependency
72to Bitflash consensus:
73
74```bash
75ots stamp utxo-report.json
76ots verify utxo-report.json.ots
77```
78
79## Historical Duplicates
80
81Bitflash inherited early Bitcoin behavior around duplicate transaction IDs.
82The verifier reports duplicate-output overwrites as warnings and uses
83last-write-wins semantics for the UTXO map, matching the legacy index model.
84Those warnings are part of the report so auditors can see the historical debt
85instead of relying on a polished summary.
86
87## Future Consensus Path
88
89This tool is the low-risk first step toward consensus commitments. A future
90hard-fork design can commit this root, or a Utreexo-style accumulator root, in
91coinbase or block headers after a fixed activation height. Until then this
92script provides reproducible supply and state commitments without changing what
93nodes accept.