算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
bitcoin-mining-pow【设计与创意】Bitcoin Proof of Work: SHA256d on block header, target, nonce iteration, hashrate, mining math. USE WHEN: explaining mining mechanics, debugging mining software, designing mining-related apps.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Bitcoin's consensus security: miners compete to find a nonce such
that SHA256d(block_header) ≤ target. The first to find one
broadcasts the block, claiming the subsidy + fees.
[4 bytes] version
[32 bytes] prev_block hash
[32 bytes] merkle_root (of all txs)
[4 bytes] timestamp (unix seconds)
[4 bytes] bits (compact target encoding)
[4 bytes] nonce
Hash function: SHA256(SHA256(header)) (SHA256d).
bits encodes the target in compact form:
bits = 0xMM_NNNNNN where MM is exponent (3 bytes) and NNNNNN
is mantissa.target = mantissa × 2^(8*(MM-3)).difficulty = max_target / current_target. Higher difficulty =
harder.
Difficulty adjusts every 2016 blocks (~2 weeks):
Number of header hashes per second. Per-block expected time: 10 minutes (protocol target, held by the retarget).
The figures below are a dated snapshot - they age fast, re-check a live source before quoting them.
As of 15 September 2026 (mempool.space mining API):
Live sources: getdifficulty / getnetworkhashps RPC, or
https://mempool.space/api/v1/mining/hashrate/1m.
def mine_block(header, target):
while True:
for nonce in range(2**32):
header[76:80] = pack('<I', nonce)
h = sha256(sha256(header))
if h < target:
return header
# Exhausted nonce space; bump extra-nonce in coinbase, redo merkle
bump_extra_nonce()
recompute_merkle_root()
extranonce lives in the coinbase tx scriptSig, allowing many
2^32 nonce-space sweeps per block template.
2^32 is only ~4.3 billion hashes; a 200 TH/s ASIC sweeps the whole
nonce field in ~21 microseconds. Miners therefore roll four fields,
cheapest first:
nonce - 32 bits, header-only.nVersion reserved bits - 16 bits (BIP 320) or 24 bits (BIP 323),
header-only.timestamp - one increment per second, and must stay inside the
consensus bounds (> median-time-past of the last 11 blocks,
<= network-adjusted time + 2h).extranonce in the coinbase scriptSig - unbounded, but every bump
rebuilds the coinbase and the merkle root, so the controller and not
the hash core does the work.Only the first three are headers-only mining: the device mutates the 80-byte header without touching transactions or merkle trees.
Standardization of the nVersion slice:
mining.configure negotiation and with it the
version-rolling extension, through which a pool advertises the
version mask a miner may roll.0xe0001fff, 16 bits)
for general use and removes them from BIP8/BIP9 signaling.0xe000001f, 24 bits). 16 bits proved too few; some devices had
started taking ~7 bits out of nTime instead, which distorts block
timestamps. Future soft forks SHOULD NOT signal on bits 5-28.Core support, as of September 2026:
Block reward = subsidy + fees. Subsidy halves every 210,000 blocks (~4 years):
Total supply asymptote: 21 million BTC.
ASIC manufacturers: Bitmain (Antminer), MicroBT (Whatsminer), Canaan (AvalonMiner), Bitfury, others.
Theoretical attack where a miner with > 25% hashrate withholds blocks to gain disproportionate share. Mitigated by random network delays in practice.