"""Independent checks of the published experiment and signed transaction bytes. python verify-results.py.txt . Does not validate signatures, run Core, use accounts or contact a network. """ from decimal import Decimal from pathlib import Path import hashlib import json import sys folder = Path(sys.argv[1] if len(sys.argv) > 1 else ".") result = json.loads((folder / "results.json").read_text(encoding="utf-8")) trace = json.loads((folder / "rpc-trace.json").read_text(encoding="utf-8"))["calls"] count = 0 def check(condition, message): global count assert condition, message count += 1 def parse_transaction(hex_string): raw = bytes.fromhex(hex_string) pos = 4 witness = raw[pos] == 0 if witness: check(raw[pos + 1] == 1, "Ordinary SegWit flag only; no MWEB transaction parser") pos += 2 def read_varint(): nonlocal pos first = raw[pos]; pos += 1 if first < 253: return first size = {253: 2, 254: 4, 255: 8}[first] value = int.from_bytes(raw[pos:pos + size], "little"); pos += size return value inputs_start = pos n_inputs = read_varint() for _ in range(n_inputs): pos += 36 script_size = read_varint(); pos += script_size + 4 inputs_serialized = raw[inputs_start:pos] outputs_start = pos n_outputs = read_varint() outputs = [] for index in range(n_outputs): litoshis = int.from_bytes(raw[pos:pos + 8], "little"); pos += 8 script_size = read_varint() script_hex = raw[pos:pos + script_size].hex(); pos += script_size outputs.append({"index": index, "litoshis": litoshis, "script_hex": script_hex}) outputs_serialized = raw[outputs_start:pos] if witness: for _ in range(n_inputs): n_stack = read_varint() for _ in range(n_stack): item_size = read_varint(); pos += item_size locktime = raw[pos:pos + 4]; pos += 4 check(pos == len(raw), "Transaction consumed exactly") stripped = raw[:4] + inputs_serialized + outputs_serialized + locktime txid = hashlib.sha256(hashlib.sha256(stripped).digest()).digest()[::-1].hex() return txid, outputs check(result["network"] == "regtest", "Test network explicitly identified") check("0.21.5.8" in result["core_version"], "Pinned tested version") check(result["assertions_passed"] == len(result["assertions"]), "Assertion count agrees") check(all(a["passed"] for a in result["assertions"]), "All recorded assertions passed") states = {s["stage"]: s for s in result["snapshots"]} before, stopped, restart, after = (states[k] for k in ("before_shutdown", "sender_confirmed_recipient_stopped", "restarted_without_peers", "after_loopback_catchup")) check(before["sender_height"] == before["recipient_height"] == 101, "Initial equal heights") check(stopped["recipient_height"] is None and stopped["recipient_balance_ltc"] is None, "Stopped node has no fabricated RPC balance") check(stopped["recipient_process_exit_code"] == 0, "Actual recipient process exit") check(restart["recipient_height"] == 101 and Decimal(restart["recipient_balance_ltc"]) == 0, "Restarted stale state") check(restart["recipient_peers"] == [], "Restart remained disconnected") check(after["sender_height"] == after["recipient_height"] == 104, "Final equal heights") check(Decimal(after["recipient_balance_ltc"]) == Decimal("0.175"), "Final RPC balance") check(sum(Decimal(p["output_value_ltc"]) for p in result["payments"]) == Decimal("0.175"), "Independent Decimal sum") check(all(p["addr"].startswith("127.0.0.1:") for s in (before, after) for p in s["sender_peers"] + s["recipient_peers"]), "Only loopback peer metadata") lifecycle = result["peer_lifecycle"] stopped_time = next(x["time_utc"] for x in lifecycle if x["node"] == "recipient" and x["event"] == "stopped") recipient_starts = [x["time_utc"] for x in lifecycle if x["node"] == "recipient" and x["event"] == "started"] check(len(recipient_starts) == 2, "Recipient was restarted exactly once") restart_time = recipient_starts[1] for payment in result["payments"]: txid = payment["txid"] sending = [c for c in trace if c["node"] == "sender" and c["method"] == "sendtoaddress" and c.get("result") == txid] check(len(sending) == 1 and stopped_time < sending[0]["time_utc"] < restart_time, "Send lies inside stopped recipient interval") full = next(c["result"] for c in trace if c["node"] == "sender" and c["method"] == "gettransaction" and c["params"] == [txid]) recomputed, outputs = parse_transaction(full["hex"]) check(recomputed == txid, "TXID independently reconstructed from signed transaction") recipient_output = outputs[payment["output_n"]] check(Decimal(recipient_output["litoshis"]) / 100000000 == Decimal(payment["output_value_ltc"]), "Raw-byte recipient value matches record") check(recipient_output["script_hex"].startswith("0014") and len(recipient_output["script_hex"]) == 44, "Ordinary P2WPKH output") expected_conf = 104 - payment["sender_confirmation_height"] + 1 check(payment["sender_confirmations_at_height_104"] == payment["recipient_confirmations_after_catchup"] == expected_conf, "Confirmation depth independently calculated") for label in ("sender", "recipient"): stopped_events = [x for x in lifecycle if x["node"] == label and x["event"] == "stopped"] check(stopped_events and stopped_events[-1]["exit_code"] == 0, "Final clean process shutdown " + label) check(not any(c["method"] in ("dumpprivkey", "dumpwallet", "walletpassphrase", "importprivkey", "importwallet") for c in trace), "No secret export or user-wallet operations in trace") print(json.dumps({"export_checks_passed": count, "scope": "Recorded states, output bytes and TXID arithmetic; no independent signature or network-validation proof"}))