Explainer · · 19 min read

We made our SHA-256 miner about 42 times faster

The miner went from about 2.6 million guesses a second in C++ to about 109 million in Rust with our patch.

Which step gave what

  • C++2.62
  • Rust71.55
  • Rust + patch109.1
  1. About 27 times from the C++ draft to Rust with a SIMD library. See what changed in the rewrite.
  2. About 1.5 times from our patch, which returns only the start of each hash. See pull request #4 for the paired result.

41.6 times in the direct test, from 2.62 to 109.1 MH/s (millions of hashes per second). The 71.55 stock result came from a separate test the day before, so the 27 × 1.5 split is approximate.

Axis 0 to 120 MH/s. Six pinned threads on one shared i7-8700. See step 5 for every run.

Eight guesses per operation

01234567
One AVX2 operation across eight 32-bit lanes

Each square is one guess, gensys:0 to gensys:7. The library we started from already did this. See step 3.

Keep 32 bits: a cheap filter

See step 4 for what the filter checks.

Our patch alone: about 1.5 times faster

  • Stock71.55
  • Patched108.61

1.52 times in three paired 10 s runs. The patched rate is the median on the same build as above, measured in a separate test. Axis 0 to 120 MH/s. See step 5.

These were short tests on one busy, shared AVX2 computer without SHA-NI, not a controlled benchmark. The C++ miner uses OpenSSL, which can use SHA-NI on other chips and may narrow the gap. The patch gives no gain when the library selects SHA-NI or AVX-512.

The miner takes 1 to 10 Base64 characters or 1 to 16 hex characters. Our phrase is “gensys” and our prefix is “gensy”, five characters. See the filter ruler and search cost.

Step 1 of 5 · 3 min

The miner is a loop of guesses

It makes a guess, hashes it, and checks the start of the result. It repeats until one matches. This finds a real hash that happens to start that way. It never edits a hash, and it is not Bitcoin mining.[1]

  1. GuessA phrase plus a counter: gensys:60237861.
  2. HashSHA-256 turns it into a 256-bit digest, a fingerprint of 32 bytes. It is a fixed recipe with no key. In hex it begins 81e9ecc9….
  3. SpellBase64 is a way to spell bytes with letters, digits, + and /. It uses 6 bits per character: gensyT8AF4HH….
  4. CompareDoes the text start with the prefix, the first characters we want, here gensy? Yes: stop and print it. No: add 1 to the counter and go back to 1.
  • NOgensys:60237860 → CavohN5mTw51SHkP+fQpSRLWfJbB87B0razFJM55G3Y=
  • YESgensys:60237861 → gensyT8AF4HHhEQvm/ieh0R05yWqjtlAd3ONa/xPjdk=
Verify the example

We checked both guesses with Python and OpenSSL.

printf %s 'gensys:60237861' | openssl dgst -sha256 -binary | base64

The search ignored case and found this hit at counter 60,237,861. Five letters take about 34 million guesses on average that way, and about a billion in exact case.[2]

Try it: search yourself

The live search needs JavaScript.

Go deeper: work, proof and ignore-case

Each extra exact-case Base64 character makes the search 64 times longer on average. One character is 6 bits, and 26 = 64. A 2-character prefix needs about 4,096 guesses. A 3-character one needs about 262,144.

Luck varies. About 2 runs in 100 need more than 1,000,000 guesses for 3 characters. That is why the search above has a cap.

The real miner re-checks every hit with a separate reference SHA-256 before it prints it.[3]

The miner also has an ignore-case mode. Upper and lower case both match, so a letter is 1 in 32 instead of 1 in 64. Digits, + and / stay 1 in 64. The odds depend on which characters the prefix has. The search box above uses exact case. The prefix gensy is lowercase, so both modes accept the example.[4]

Next: step 2, why the miner can only guess →

Step 2 of 5 · 2 min

SHA-256 gives no shortcut, so the miner guesses

SHA-256 turns any input into a 256-bit digest. A bit is a 0 or a 1, so that is 32 bytes.[5] Change one character of the input and about half the bits flip. They flip in no pattern you can work backwards. Nobody knows a way from “a digest that starts like this” to an input. So the miner can only try inputs.

In this made-up eight-bit example, the filled squares show which bits flipped.

Filled squares in row B differ from row A: 4 of 8.

Edit A or B to see which of the 256 bits change.

Example (JavaScript is off)

SHA-256 of hello world:

b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

SHA-256 of hello worle:

0fc30e735a0228a31cbbb969988b4f50e02e737f979f091d7d224b765443f5d4

These two digests differ in 140 of their 256 bits.

Go deeper: why 140, and what “avalanche” means

If each bit flipped like a fair coin, you would expect 128 flips. 140 is an ordinary result for 256 tosses. Other one-character changes land near 128 too. “Half the bits change after a tiny change” is the avalanche effect.

A prefix of N bits is hit by about one guess in 2N. That is where the 64-fold rule in step 1 comes from. SHA-256 is a public standard, not something we wrote.

Next: step 3, what “eight lanes” means →

Step 3 of 5 · 3 min

One AVX2 register holds eight 32-bit words

So one instruction works on eight guesses at once. A processor keeps values in registers, small fast slots. An AVX2 register is 256 bits wide. SHA-256 uses 32-bit words, and 256 ÷ 32 = 8. Each 32-bit slice is a lane.[6] The lanes stay separate here. AVX2 can shuffle values between lanes, but this layout does not need that.

The same eight additions, counted both ways. The squares are instructions.

  1. Put one guess in each lane, gensys:0 to gensys:7. SHA-256 reads 32-bit words. The second word of each guess is ys: plus the counter digit.
  2. Add the second SHA-256 round constant, 0x71374491, to every lane. One instruction does it: _mm256_add_epi32. One value at a time would take eight.
  3. That is one tiny step of one round. A whole hash keeps 8 working values and a message schedule for each guess. Each is its own register, with one lane per guess. So eight lanes hold eight words of eight guesses. They are not eight finished hashes.

Eight lanes: 1 instruction does all 8 additions.

Measured Real 32-bit values in hex.
Lane / guessWord “ys:k”+ constant= sum
0 · gensys:079733a3071374491eaaa7ec1
1 · gensys:179733a3171374491eaaa7ec2
2 · gensys:279733a3271374491eaaa7ec3
3 · gensys:379733a3371374491eaaa7ec4
4 · gensys:479733a3471374491eaaa7ec5
5 · gensys:579733a3571374491eaaa7ec6
6 · gensys:679733a3671374491eaaa7ec7
7 · gensys:779733a3771374491eaaa7ec8

Working registers

In this schematic, each row is one register and each square is one guess’s value.

Rows a to h are SHA-256’s eight working values. w… stands for the message words it mixes in. A hash repeats many such steps, for all eight guesses together. Some steps cannot run across lanes. Eight lanes do not imply an eightfold speedup.[7]

Go deeper: AVX-512 and SHA-NI

Some processors have wider AVX-512 registers, with 16 lanes. Some have dedicated SHA instructions, called SHA-NI. The library checks the processor at start-up and picks the first of these that fits:

  1. AVX-512. AMD Zen 4 chips with SHA-NI skip this and fall through. Zen 5 uses a double-width variant.
  2. SHA-NI.
  3. AVX2, eight lanes.
  4. Plain portable code.

Our change targets the AVX2 choice. It applies to a processor with AVX2 and neither SHA-NI nor AVX-512.[8]

Next: step 4, what we changed →

Step 4 of 5 · 4 min

The 32-bit filter

The patch returns the first 32 bits of each digest. The stock call returns all 32 bytes, and the miner reads the first 4. Both run the same 64 rounds across eight guesses at a time.[9]

The filter rejects most guesses. The miner re-hashes each survivor and checks the whole prefix before reporting a hit.

Filter code
// head_filter(), lines 147, 149 and 150: keep at most the top 32 bits
let m = bits.min(32);
let mask = u32::MAX << (32 - m);
let expected = ((exact_target >> (bits - m)) as u32) << (32 - m);

// mine_range(), lines 324 to 325: the filter first, then the full check
if head & mask == expected && sp.matches(n + i as u64).is_some() {
    return ChunkResult::Found(n + i as u64);
}

How wide is the filter?

It compares the top min(prefix bits, 32) bits of the first word.[10] A Base64 character is 6 bits, so a prefix of N characters is 6N bits. Short prefixes fit inside the filter. Long ones need the full check for the rest.

Exact-case Base64 prefixes. Each bar spans 60 bits, the longest prefix. The line marks 32 bits.
CharactersPrefix bitsFilter comparesLeft for the full checkGuesses on averageBits, drawn
166 bitsnone64
5 (gensy)3030 bitsnone1,073,741,824
6 (gensys)3632 bits4 bits68,719,476,736
106032 bits28 bits1,152,921,504,606,846,976
checked by the filterchecked only by the full check

“Guesses on average” is 2bits, worked out from the prefix size. It is not a measured figure.

Hex prefixes work the same way. A hex character is 4 bits, so each extra one makes the search 16 times longer. The miner takes 1 to 16 of them, in lowercase, and the filter stops at 8. Ignore-case works for Base64 only.[15] In ignore-case mode the filter treats upper and lower case as equal, again over the first 32 bits. Survivors are still checked in full.

When the new path runs. Only when the library picked its AVX2 kernel. The whole message, phrase plus colon plus counter, must also fit one 64-byte block. That means 55 bytes at most: 64, minus 1 padding byte and 8 length bytes. Anywhere else the stock path runs, and the answers are identical.[11]

Proposed, not merged At the time of these tests, the miner used a fork carrying the patch proposed in spool-labs/sha256 pull request #4.

Hand-written AVX2 kernel

The miner also has an opt-in 8-lane kernel of its own. In every comparison we have, the patched library’s median or mean was higher. These are different comparisons on the same shared computer. None is part of the 1.52 figure. They are in the table of other runs in step 5.[12]

Next: step 5, the measured tests →

Step 5 of 5 · 4 min

Paired tests

Test 1: C++ and Rust

Build, timing and individual runs

Measured We built the C++ miner as it is in the repo (g++ -O2, linked to OpenSSL) and the Rust miner with our patch, on the same computer. We ran four pairs, alternating which went first, each pinned to six cores. The C++ program has no time limit and no choice of prefix, so we let each run last 11 seconds and read its own progress line at 10 seconds. The Rust miner ran for 10 seconds on a prefix that can never match.[16]

Every run as recorded, with load, clock and temperature sampled just before it. Pair ratios: 41.68, 41.52, 43.48, 41.31. Medians: C++ 2.62, Rust 109.1. Bars run from 0 to 120 MH/s.
RunMH/sLoadMHz°CMH/s, drawn
1a C++2.633.38371766
1b Rust109.613.86437967
2a Rust108.374.34187958
2b C++2.614.68298463
3a C++2.524.88434465
3b Rust109.585.05432867
4a Rust108.655.33261163
4b C++2.635.66285464

The earlier README reported 2.66 MH/s for C++ from a separate run. The pair ratios agree within about 5%. The C++ average includes thread start-up, slightly favouring Rust. Rust uses its own rate line.

The raw log of test 1, as recorded
start 2026-11-15T02:13:17+01:00  02:13:17 up 23 days,  2:42,  4 users,  load average: 1.27, 0.98, 1.43
warmup cpp: 2.61 (workers=6, v1 PROGRESS at 10 s)
warmup rust: 114.90
pair1 pos1 cpp MH/s=2.63 (workers=6, v1 PROGRESS at 10 s) | before: load1=3.38 running=3 MHz0-5=3717 pkgC=66 | after: load1=3.86 running=2 MHz0-5=4376 pkgC=66
pair1 pos2 rust MH/s=109.61 | before: load1=3.86 running=1 MHz0-5=4379 pkgC=67 | after: load1=4.34 running=1 MHz0-5=2131 pkgC=58
pair2 pos1 rust MH/s=108.37 | before: load1=4.34 running=1 MHz0-5=1879 pkgC=58 | after: load1=4.68 running=1 MHz0-5=3131 pkgC=63
pair2 pos2 cpp MH/s=2.61 (workers=6, v1 PROGRESS at 10 s) | before: load1=4.68 running=1 MHz0-5=2984 pkgC=63 | after: load1=4.88 running=1 MHz0-5=4324 pkgC=67
pair3 pos1 cpp MH/s=2.52 (workers=6, v1 PROGRESS at 10 s) | before: load1=4.88 running=1 MHz0-5=4344 pkgC=65 | after: load1=5.05 running=2 MHz0-5=4365 pkgC=71
pair3 pos2 rust MH/s=109.58 | before: load1=5.05 running=3 MHz0-5=4328 pkgC=67 | after: load1=5.33 running=1 MHz0-5=2051 pkgC=64
pair4 pos1 rust MH/s=108.65 | before: load1=5.33 running=2 MHz0-5=2611 pkgC=63 | after: load1=5.66 running=2 MHz0-5=3004 pkgC=65
pair4 pos2 cpp MH/s=2.63 (workers=6, v1 PROGRESS at 10 s) | before: load1=5.66 running=1 MHz0-5=2854 pkgC=64 | after: load1=5.72 running=1 MHz0-5=4127 pkgC=71
end 2026-11-15T02:15:05+01:00

Test 2: the patch alone

Timing and individual runs

Measured Same source, same build. Only the hash call differs. We ran three pairs of 10-second runs, with six threads pinned to six cores. Each searched for a prefix that can never match, so no run stopped early.[13]

Every run as recorded, with load, clock and temperature sampled mid-run. Pair ratios: 1.33, 1.52, 1.54. Medians: stock 71.55, patched 108.61. Bars run from 0 to 120 MH/s.
RunMH/sLoadMHz°CMH/s, drawn
1a stock82.202.70390077
1b patched109.123.36386876
2a patched108.613.92380076
2b stock71.554.71380076
3a stock69.275.29380078
3b patched106.905.63390077
Other runs on the same computer

Builds, thread counts, run lengths or pinning differed, so these runs are not directly comparable with the headline tests.[14]

MH/s unless noted; one shared i7-8700 throughout
Run setStock libraryCustom AVX2Patched library
Earlier means, 6 threads, unpinned, 3–4 runs of 5 s, load 4–7637997 (runs 105.2, 90.1, 95.4)
Earlier means, 11 threads, same setupn/a97109 (runs 108.8, 109.7, 107.9)
Paired medians, 6 threads, 3 runs of 8 s, load 5.4–9.7n/a70.087.6
Pinned pilot, lib against custom AVX2, 3 pairs of 10 s (separate from the headline run)n/a76.94, 87.88, 80.16 (median 80.16)108.61, 104.57, 99.51 (median 104.57)

The 105.2 and 109.7 are single-run peaks, not typical results. The earlier unpinned stock mean of 63 is not comparable with the pinned runs above.

The raw log, as recorded
start 2026-11-14T01:10:10+01:00  01:10:10 up 22 days,  1:39,  5 users,  load average: 2.47, 3.47, 4.10
warmup stock 4s: 84.58 | mid: load1=2.35 running=2 MHz0-5=4299 pkgC=67
warmup patched 4s: 114.70 | mid: load1=2.32 running=4 MHz0-5=3716 pkgC=68
pair1 pos1 stock MH/s=82.20 | mid: load1=2.70 running=8 MHz0-5=3900 pkgC=77 | before: load1=2.32 running=2 MHz0-5=3716 pkgC=67 | after: load1=3.04 running=2 MHz0-5=2553 pkgC=71
pair1 pos2 patched MH/s=109.12 | mid: load1=3.36 running=8 MHz0-5=3868 pkgC=76 | before: load1=3.04 running=3 MHz0-5=3144 pkgC=72 | after: load1=3.65 running=2 MHz0-5=3717 pkgC=71
pair2 pos1 patched MH/s=108.61 | mid: load1=3.92 running=9 MHz0-5=3800 pkgC=76 | before: load1=3.65 running=2 MHz0-5=3719 pkgC=71 | after: load1=4.25 running=3 MHz0-5=4300 pkgC=71
pair2 pos2 stock MH/s=71.55 | mid: load1=4.71 running=11 MHz0-5=3800 pkgC=76 | before: load1=4.25 running=3 MHz0-5=4299 pkgC=71 | after: load1=4.97 running=5 MHz0-5=4299 pkgC=78
pair3 pos1 stock MH/s=69.27 | mid: load1=5.29 running=9 MHz0-5=3800 pkgC=78 | before: load1=4.97 running=4 MHz0-5=4300 pkgC=78 | after: load1=5.51 running=3 MHz0-5=4298 pkgC=73
pair3 pos2 patched MH/s=106.90 | mid: load1=5.63 running=9 MHz0-5=3900 pkgC=77 | before: load1=5.51 running=3 MHz0-5=4301 pkgC=75 | after: load1=5.74 running=3 MHz0-5=4300 pkgC=72
end 2026-11-14T01:11:24+01:00

Limits of the tests. Neither test measured sustained performance or shows what to expect on other processors. The repo gives no C++ build flags, so we chose ours. Different compiler settings could change its rate.

In the patch test, CPU frequency was not held fixed and 1-minute load rose from 2.3 to 5.7. Part of the first pair’s 1.33 is noise. The stock build includes the miner’s own running counter. We did not profile the patch, so we cannot say how much each change contributed to the measured gain.

Next: open the miner’s README and run this yourself:

vanity-miner --prefix gensy --ignore-case

After step 5 · 3 min

How hard is the search?

Time depends on guesses needed and guesses per second. These three pictures come from What it costs to find a SHA-256 prefix.

Guess, hash, compare, repeat

See step 1 for real guesses.

Four guesses, one match Four columns. Each shows a guess, gensys:0 to gensys:3, with an arrow down to its result. The first three results read no match. The fourth reads match. gensys:0 ✗ no match gensys:1 ✗ no match gensys:2 ✗ no match gensys:3 ✓ match hash each guess, compare the start, keep or drop
Made-up run: nonce 3 is not a real match. A real one: prefix gensy with ignore-case was found at nonce 60,237,861 (v2/README.md).

Guesses per character

Work added by one more prefix character One more character multiplies the expected guesses by 64 for an exact character, by 32 for a letter when case is ignored, and by 64 for a digit, plus or slash even when case is ignored. One more character in the prefix × 64exact case: any character × 32ignore case: a letter (A and a both count) × 64ignore case: a digit, + or /
Ignore-case is a Base64 option only. Hex prefixes are lowercase and cost 16 times per character.

Work out the time for your own prefix

Six letters with ignore-case take about 10 seconds. Ten exact characters take centuries.

Open the search cost calculator

Why memory stays small

Memory stays small because the miner keeps only finished ranges.

Threads, chunks and the record of finished ranges Three thread boxes, labelled thread 1, thread 2 and thread N, each take one chunk of 262,144 nonces. Misses are discarded. Only finished chunks flow down into a journal of finished ranges, with a checkpoint every 30 seconds. thread 1 thread 2 thread N one chunk each: 262,144 nonces hash, compare, drop every miss finished chunks only journal of finished ranges neighbouring ranges merge into one checkpoint every 30 s
Only the bottom box is kept, and a chunk that was cut short or holds a hit is not recorded.

The full article also has the formula, the limit on nonces, and how a stopped run resumes.

Words used on this page

Word list, 10 terms
guess
A phrase plus a counter, like gensys:60237861.
SHA-256 and digest
A fixed recipe that turns any text into a 256-bit fingerprint, called the digest. It is set out in the public standard FIPS 180-4.
bit, 256 bits
A bit is a 0 or a 1. 256 of them are 32 bytes.
Base64
A way to write bytes as letters, digits, + and /. Each character stands for 6 bits (RFC 4648).
prefix
The first characters we want the Base64 text of the digest to start with.
register and lane
A register is a wide slot inside the processor. A lane is one 32-bit slice of it. An AVX2 register has eight.
AVX2, AVX-512, SHA-NI
Processor features. AVX2 works on 256 bits at a time, and AVX-512 on 512. SHA-NI adds instructions made for SHA hashing.
filter
A cheap test that throws out almost every guess and may let a few through.
re-hash (full check)
Hashing a surviving guess again the slow, safe way and comparing the whole prefix.
MH/s
Millions of hashes per second.

Sources and notes

Everything comes from the public repo, simple-sha256-miner, and the spool-labs/sha256 library it builds on. For another explainer in this style, read what the trading bot contract does.

What changed in the rewrite

The C++ draft, a 59-line first version, uses snprintf and one OpenSSL SHA-256 call per guess.

Before the patch, Rust’s mine_range() built gensys: once per chunk (line 104), incremented the decimal counter in place (line 115) and batched 128 guesses (line 96). The spool-labs/sha256 library hashed eight at a time with AVX2 (line 139).

Eight lanes could explain up to about 8 of the 27 times. The tests did not isolate the other changes or compare equivalent C++ and Rust programs.

Miner code: target() checks the prefix length and turns the prefix into bits. head_filter() builds the 32-bit mask. prefix_matches() is the full check.

The Intel Intrinsics Guide lists the AVX2 instructions. The miner runs the filter and full check together.

  1. The miner’s documentation: a guess is phrase:number, the test is on the start of the Base64 digest, and it is not Bitcoin mining.
  2. We recomputed the hit and miss passes for this page, as step 1 says. The counter is from docs/bench-hillclimb1-20261114.txt. The v2 README shows the run used --ignore-case. The averages are 325 = 33,554,432 and 645 = 1,073,741,824.
  3. The miner’s documentation: every candidate hit is verified with a separate reference SHA-256 before it is reported. In code, that is main.rs lines 212 to 215.
  4. The miner’s documentation: 64-fold per exact-case Base64 character. In ignore-case mode a letter matches 2 of the 64 Base64 characters, which is 1 in 32. A digit, + or / still matches 1 of 64.
  5. NIST FIPS 180-4, Secure Hash Standard: 256-bit digest, 32-bit words, 64 rounds, padding. RFC 4648: 6 bits per Base64 character. The 140-of-256 count for the two example messages matches a separate sha256sum and Python recount.
  6. Intel Intrinsics Guide: a 256-bit AVX2 register, and _mm256_add_epi32 as eight 32-bit additions in one instruction.
  7. The library’s pull request describes staging one padded block per lane. We do not claim how it arranges its registers beyond that. The schematic is an illustration.
  8. The kernel order is from the library’s public source at commit 391432a: the select() function and the SHA-NI check.
  9. The new call, hash_short_heads, returns each digest’s first 32-bit word. See pull request #4.
  10. From the miner’s source, head_filter(): the mask covers the top min(prefix bits, 32) bits, and every survivor is checked in full.
  11. In the pull request, the AVX2 fast path runs when the selected kernel is AVX2 and the message fits one block (ONE_BLOCK_MAX = 64 − 9 = 55 bytes), in groups of eight. Otherwise the general path hashes fully and truncates.
  12. The miner’s pilot log for the custom kernel against the library: docs/bench-pilot-20261114.txt. Medians: library 104.57, custom AVX2 80.16.
  13. Every number in the patch picture, the test 2 table in step 5 and its raw log comes from one file: the miner’s log for the stock-against-patched test, docs/bench-stock-vs-patched-20261114.txt. We copied it row by row. The pull request description gives the same medians and ratio.
  14. The earlier means, the 11-thread runs and the 8 s paired medians are from the miner’s v2/README.md. The pinned library-against-custom pilot is in the file named in note 12.
  15. The miner’s target() allows 1 to 10 Base64 characters at 6 bits, or 1 to 16 hex characters at 4 bits. The README says the same under “Limits”. The 16-fold step per hex character is 24, worked out from that.
  16. The miner’s log for the C++-against-Rust test, docs/bench-cpp-vs-rust-20261115.txt: method, both programs’ hashes, the script and the raw log. The Rust miner is the repo’s v2 at commit 61d8588, which builds against our fork of the library carrying the patch. The 71.55 in the card at the top is the stock median from test 2.

These short tests on one computer are not a benchmark of your machine.

Share on X