# BestBitcoinHash GPU miner

`bitcoin_miner.cu` searches for the string `Bitcoin<number>` whose double
SHA-256 is the smallest, scored exactly the way <https://bestbitcoinhash.com>
scores it: the 32-byte digest read as a little-endian uint256, so the leading
zero bits match what a block explorer shows.

One file, MIT, no dependencies beyond the CUDA runtime and the C++ standard
library. Compute capability 3.5 and up, so anything from roughly 2014 onward
runs it.

Not Bitcoin mining. Nothing connects to the Bitcoin network, no block is being
competed for, nothing can be earned. It is the same hash function against the
same kind of odds, run at a rate a browser cannot reach.

## Build and run

```
curl -fsSLO https://bestbitcoinhash.com/gpu/bitcoin_miner.cu
nvcc -O3 -arch=native bitcoin_miner.cu -o bitcoin_miner
./bitcoin_miner --message Bitcoin --start 4068315053529029805 --duration 3600
```

`-arch=native` needs CUDA 12 or newer. On older toolchains pin the card:
`sm_89` for RTX 40xx, `sm_86` for RTX 30xx, `sm_75` for RTX 20xx, `sm_90` for
H100, `sm_80` for A100.

**Pick your own `--start`.** It defaults to 0, and two people who both leave it
there hash exactly the same strings. Any 19-digit number is a good choice: the
odds are identical everywhere in the space, and a day of a fast GPU covers well
under 1e15 nonces, so nobody exhausts their range.

**The nonce is a `uint64`, so it stops at 18446744073709551615**, 20 digits. A
`--start` above that is silently clamped to the maximum and the search wraps
around to 0 instead of carrying on, so keep it under about 1.8e19. The
leaderboard itself accepts up to 32 digits, so the largest nonces sitting on it
are out of this program's reach. Nothing is lost by that: a hash is no more
likely to be small at 26 digits than at 19.

On rented hardware (vast.ai and friends) rent a template whose image ships the
CUDA toolkit, meaning `nvcc` is present. Anything `-devel`, the PyTorch images,
or `nvidia/cuda:*-devel-*` will do. Both of the commands above in the on-start
box is enough, and because the miner logs to stdout and stderr, the instance's
log view shows it live.

## Flags

| Flag | Default | Meaning |
| --- | --- | --- |
| `--message <str>` | `Bitcoin` | Base string the nonce is appended to. Leave it alone if the result is meant for the leaderboard. |
| `--start <n>` | `0` | First nonce to try. Pass your own, and pass `resume_nonce` to continue a run. |
| `--duration <sec>` | run forever | Stop after N seconds. |
| `--out <file>` | `gpu_best.txt` | Best-result file, rewritten on every new best. |
| `--dump-range <start> <count>` | | Print `nonce score` for a range and exit, so two machines can diff the same range. |

## What the log looks like

```
self-test ok: 1048576 nonces from 0
self-test ok: 1048576 nonces from 999990
SELF-TEST PASSED - GPU matches CPU oracle. Mining "Bitcoin"...
near 1755950421 38
Bitcoin60596677305647 = 00000000000424c1532eeca3dc0e38b3173e05613108f23bfcc82425a94c286b  (45 bits)
3140.7 MH/s   frontier 60596734217728   best 45 bits
```

| Line | Meaning |
| --- | --- |
| `self-test ok` / `SELF-TEST PASSED` | the GPU hashed about 5M nonces across several digit lengths and an independent CPU SHA-256 in the same file agreed on every one. It exits instead of mining if they disagree. |
| `<string> = <hash> (N bits)` | a new all-time best for this run, re-verified on the CPU before it is printed. |
| `near <unix ts> <bits>` | any hit of 36 bits or better, so the pace stays visible between records. |
| `<rate> MH/s frontier <n> best <B> bits` | heartbeat, every 5 seconds. |

That record line is real: it is entry 2 on the board as of 2026-08-23. The hash
rate is a placeholder, the heartbeat prints what your own card does.

`gpu_best.txt` is rewritten on every new best and is the file to read for the
answer:

```
message=Bitcoin
best_input=Bitcoin60596677305647
best_hash=00000000000424c1532eeca3dc0e38b3173e05613108f23bfcc82425a94c286b
best_bits=45
resume_nonce=60596734217728
```

## Submit a result

Take the number out of `best_input`, the part after `Bitcoin`, and open

```
https://bestbitcoinhash.com/leaderboard?nonce=<number>
```

The form comes up prefilled. The server rehashes the string itself, so it
accepts nothing on trust, and only a hash that lands in the top 20 gets in. The
bar to beat is on <https://bestbitcoinhash.com/leaderboard>.

## Verifying it yourself

- The startup self-test is the cheap proof: the CPU SHA-256 in the same file
  recomputes about 5M nonces and the process exits non-zero on the first
  disagreement.
- `--dump-range <start> <count>` prints one line per nonce, so two different
  machines can diff the same range and catch anything silently skipped.
- Any single result is checkable by hand. The hash is
  `SHA256(SHA256(ascii("Bitcoin" + nonce)))`, printed byte-reversed the way
  explorers print block hashes, and every leaderboard entry links to an
  independent SHA-256 calculator.
