← MRM/Projects/bitcoinfun
GPU / Systems Measurement harness Rust · wgpu · HIP

bitcoinfun

SHA-256 inside a fragment shader, checked against the Bitcoin genesis block.

This started as a question I couldn't answer from an armchair: is SHA-256 secretly geometric? So I built the harness that would tell me. The hash runs in the graphics pipeline, the nonce comes from the pixel coordinate, the digest is written into a render target — all headless, no window. The answer was no; it is statistically random. What was left is a GPU compute study with a hard oracle, because a mining hash either matches a known block or it is wrong.

gpu_hash — verify then bench
$ gpu_hash btc ✔ genesis block reproduced on GPU · 000000000019d6...8ce26f ✔ 4096 shader digests == sha2 · FIPS "abc" vector matches $ gpu_hash btcbench SHA256d naive 0.87 GH/s ✔ SHA256d midstate 1.41 GH/s (1.62x — the only optimization that worked)

Representative output — not a live instance.

What it is
●Hashing in the graphics pipeline — a fragment shader computes SHA-256, the nonce is the pixel coordinate, digests land in 32-bit-per-channel render targets. Offscreen and headless, so it never touches a window or the desktop compositor.
●A named oracle, not a vibe — the GPU path reproduces the Bitcoin genesis block hash; the CPU twin is checked against the sha2 crate and the FIPS test vector. Every field of the assembled block header is verified the same way before anything is measured.
●A complete solo miner — Stratum client, coinbase and merkle assembly, 80-byte header, on-GPU difficulty filter writing into an atomic hits buffer, extranonce roll, submit, plus recovery if the graphics device is lost mid-run.
●A native compute lane for comparison — the same hash rewritten as a HIP kernel for the same card: 4.35 GH/s sustained, 3.11× the shader build, roughly 80% of the card's integer-ALU ceiling against the shader's 28%.
●A second algorithm, ported bit-for-bit — a memory-hard hash ported from the reference miner's own source, with both SHA-3 variants verified against the published test vectors before a single downstream number was trusted.
Six ways to not get faster
●Midstate was the only real win — the first 64 bytes of a block header don't change while you scan nonces, so compress them once on the CPU. 0.87 → 1.41 GH/s, a 1.62× that survives every other change.
●Hand-rolled message schedule: 0% — cutting 64 words to a 16-word sliding window changed nothing. The compiler was already doing it.
●Compute pipeline instead of graphics: 1.42 vs 1.41 GH/s — so the fragment-shader framing was never costing anything. That was worth knowing precisely because it sounds like it should be.
●Occupancy sweep flat, instruction-level parallelism a wash — workgroups from 128 to 1024 all landed at ~1.4 GH/s, and interleaving two hashes per thread did nothing. Not occupancy-bound, not latency-bound: throughput-bound.
●Early-exit was correct and 10% slower — 245 hits, every one CPU-verified, and a net loss: the conditional break kills the compiler's unroll of the 64-round loop. Correct and worse is still worse, and I kept the result.
●The conclusion I could defend — on a clean fixed-shape shader kernel the compiler owns codegen, and six independent experiments say the ceiling is real. Past it needs a different language, which is where the 3.11× turned out to be hiding.
Proof
genesis
block hash reproduced on GPU — the oracle this is measured against
4.35 GH/s
sustained, native compute kernel
3.11×
native kernel over the shader build, same card
1.62×
midstate — the one optimization that measured
5 of 6
optimizations measured as nothing, or worse — and reported
~13M yr
expected time to a block at this card's rate
Rustwgpu 22.1 · WGSLHIP / ROCmheadless, no windowStratumFIPS + genesis-block oracles
ℹ
What this earns: nothing, and I'm not going to pretend otherwise. Solo mining is a lottery ticket. At this card's measured rate the expected time to a block is around 13 million years, and the gross revenue works out to roughly two hundredths of a cent per day against real electricity. It is a GPU compute showcase with a hard correctness oracle — not an income, not a strategy, and not advice. Anyone telling you a consumer GPU mines profitably is selling something.
🔒
Measured results and architecture shown. Source and kernels are private — this is a capability showcase, not a distribution.

Need a GPU number
you can trust?

I write GPU kernels and, more to the point, the harness that says whether they compute the right answer and whether a change actually helped. Most of what I find is that it didn't — which is the part that saves you weeks.

Start a project →