From 1839347459759fb3b23cc747ec4368b724fee008 Mon Sep 17 00:00:00 2001 From: Nsable-sh Date: Tue, 11 Aug 2026 14:13:26 -0300 Subject: tools: harden chain audit scripts --- scripts/verify-utxo-proof.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'scripts/verify-utxo-proof.py') diff --git a/scripts/verify-utxo-proof.py b/scripts/verify-utxo-proof.py index 31099f7..c29caa9 100644 --- a/scripts/verify-utxo-proof.py +++ b/scripts/verify-utxo-proof.py @@ -7,6 +7,7 @@ import json import sys from pathlib import Path +import bitflash_chain as chain SCHEMA = "bitflash-utxo-inclusion-proof-1" LEAF_DOMAIN = "BTFUTXO1" @@ -17,22 +18,6 @@ def canonical_bytes(obj): return (json.dumps(obj, sort_keys=True, separators=(",", ":"), ensure_ascii=True) + "\n").encode("ascii") -def sha256(data): - return hashlib.sha256(data).digest() - - -def utxo_leaf_hash(outpoint, utxo): - payload = "|".join([ - LEAF_DOMAIN, - outpoint, - str(utxo["value_satoshis"]), - utxo["script_pub_key_hex"], - str(utxo["created_height"]), - utxo["created_txid"], - ]).encode("ascii") - return sha256(payload) - - def load_proof(path): try: return json.loads(Path(path).read_text(encoding="ascii")) @@ -59,7 +44,7 @@ def verify(proof, expected_root=None): failures.append("target outpoint does not match txid:vout") try: - current = utxo_leaf_hash(outpoint, utxo) + current = chain.utxo_leaf_hash(outpoint, utxo) leaf_ok = target.get("leaf_hash") == current.hex() except Exception as e: failures.append("could not hash target leaf: %s" % e) @@ -79,9 +64,9 @@ def verify(proof, expected_root=None): failures.append("bad sibling hash length at proof level %d" % i) side = step.get("side") if side == "right": - current = sha256(NODE_DOMAIN + current + sibling) + current = chain.sha256(NODE_DOMAIN + current + sibling) elif side == "left": - current = sha256(NODE_DOMAIN + sibling + current) + current = chain.sha256(NODE_DOMAIN + sibling + current) else: failures.append("bad sibling side at proof level %d" % i) -- cgit v1.2.3