Skip to content

Instantly share code, notes, and snippets.

View LarryRuane's full-sized avatar

Larry Ruane LarryRuane

View GitHub Profile
#include <iostream>
using namespace std;
class X {
public:
int i;
// ordinary cons X y(5):
X(int x) : i(x) { cout << "constructor " << i; }
#include <iostream>
#include <string.h>
int line;
class String {
public:
char* m_buffer;
size_t m_size;
@LarryRuane
LarryRuane / witness-bytes.py
Created March 22, 2023 17:16
calculate total amount of chain witness data
#!/usr/bin/env python3
from bitcoinrpc.authproxy import AuthServiceProxy
api = AuthServiceProxy("http://lmr:[email protected]:8332")
info = api.getblockchaininfo()
tip_height = info['blocks']
print("tip height", tip_height)
witness = 0
for i in range(0, tip_height+1):
blockhash = api.getblockhash(i)
b = api.getblock(blockhash)
@LarryRuane
LarryRuane / txo-history.py
Last active May 5, 2023 19:09
This prints one line for each tx output: 1) the output's txid, 2) its index, 3) its age in units of txos since genesis before being spent, 9999999999 means a long time or currently unspent
#!/usr/bin/env python3
import time, sys
from bitcoinrpc.authproxy import AuthServiceProxy
api = AuthServiceProxy("http://lmr:[email protected]:8332")
# infinite retry
def api_retry(*args):
global api
while True:
#!/bin/env python3
import sys
import random
if not len(sys.argv) == 4:
print("usage:", sys.argv[0], "reps points a-win-%")
sys.exit(1)
reps = int(sys.argv[1])
points = int(sys.argv[2])
@LarryRuane
LarryRuane / txo-flush-log-to-bin.py
Created May 16, 2023 23:07
temporary script to turn logging lines into binary
#!/bin/env python3
import sys
from struct import pack
if len(sys.argv) != 2:
print("usage:", sys.argv[0], "file")
sys.exit(1)
bitoffset = 0
v = 0
@LarryRuane
LarryRuane / backtrace.txt
Created May 24, 2023 16:31
gdb backtrace (bt, stack trace) of prevector dynamically allocating memory during -reindex-chainstate, master commit 3a93957a5dc97cb2fd0656d1e2451ebef57204df
prevector<28u, unsigned char, unsigned int, int>::change_capacity (this=0x555561065eb8, new_capacity=67) at ./prevector.h:191
prevector<28u, unsigned char, unsigned int, int>::resize_uninitialized (this=0x555561065eb8, new_size=67) at ./prevector.h:392
Unserialize_impl<CAutoFile, 28u, unsigned char> (is=..., v=...) at ./serialize.h:782
Unserialize<CAutoFile, 28u, unsigned char> (is=..., v=...) at ./serialize.h:797
UnserializeMany<CAutoFile, prevector<28u, unsigned char, unsigned int, int>&> (s=..., arg=...) at ./serialize.h:1059
SerReadWriteMany<CAutoFile, prevector<28u, unsigned char, unsigned int, int>&> (s=..., ser_action=...) at ./serialize.h:1072
CScript::SerializationOps<CAutoFile, CScript, CSerActionUnserialize> (obj=..., s=..., ser_action=...) at ./script/script.h:435
CScript::Unser<CAutoFile> (s=..., obj=...) at ./script/script.h:435
CScript::Unserialize<CAutoFile> (this=0x555561065eb8, s=...) at ./script/script.h:435
Unserialize<CAutoFile, CScript&> (is=..., a=...) at ./serialize.h:705
@LarryRuane
LarryRuane / block-times.py
Created December 31, 2023 20:52
print heights of blocks with out-of-order timestamps
#!/usr/bin/env python3
# When two cosecutive blocks have out of order timestamps (the higher height's time
# is less than the lower height's time), print the height of the lower-height block.
#
# prerequisite;
# $ pip3 install python-bitcoinrpc
# or see https://github.com/jgarzik/python-bitcoinrpc
from bitcoinrpc.authproxy import AuthServiceProxy
api = AuthServiceProxy("http://lmr:[email protected]:8332")
@LarryRuane
LarryRuane / specification-proposal.md
Last active July 8, 2025 14:14
proposal for bitcoin consensus protocol specification written in code

Proposal Summary

I don't have a formal protocol verification background, but I have a proposal related to specification that may aid in creating formal verification, and would be helpful in its own right.

Specifications are usually in the form of a document, but of Bitcoin it's often said that its only protocol (consensus) specification is the Bitcoin Core client software (although it's a de facto, not authoritative specification; the latter doesn't exist). But the difficulty in verifying its correctness, or for readers to understand it, is that it (appropriately) includes so much non-protocol complexity and optimization (both CPU and memory). Also, it's written in C++, which is very efficient, but is not easy to understand.

With that background, my proposal is to write a full consensus protocol specification in the form of working code in its simplest possible form. Human language is amgibuous, but code is precise; it answers all possible question