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
- About 27 times from the C++ draft to Rust with a SIMD library. See what changed in the rewrite.
- 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
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
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]
- GuessA phrase plus a counter:
gensys:60237861. - 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…. - SpellBase64 is a way to spell bytes with letters, digits,
+and/. It uses 6 bits per character:gensyT8AF4HH…. - 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.
-
NO
gensys:60237860→CavohN5mTw51SHkP+fQpSRLWfJbB87B0razFJM55G3Y= -
YES
gensys: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
Pick a phrase and a prefix of 1 to 3 characters. Letters, digits, + and / work, and case matters. Your browser hashes phrase:0, phrase:1 and so on until the Base64 text starts with your prefix. It stops after 1,000,000 guesses, or when you press Stop. The 3-character cap keeps the browser search short.
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]
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.
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.
- Put one guess in each lane,
gensys:0togensys:7. SHA-256 reads 32-bit words. The second word of each guess isys:plus the counter digit. - 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. - 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.
| Lane / guess | Word “ys:k” | + constant | = sum |
|---|---|---|---|
| 0 · gensys:0 | 79733a30 | 71374491 | eaaa7ec1 |
| 1 · gensys:1 | 79733a31 | 71374491 | eaaa7ec2 |
| 2 · gensys:2 | 79733a32 | 71374491 | eaaa7ec3 |
| 3 · gensys:3 | 79733a33 | 71374491 | eaaa7ec4 |
| 4 · gensys:4 | 79733a34 | 71374491 | eaaa7ec5 |
| 5 · gensys:5 | 79733a35 | 71374491 | eaaa7ec6 |
| 6 · gensys:6 | 79733a36 | 71374491 | eaaa7ec7 |
| 7 · gensys:7 | 79733a37 | 71374491 | eaaa7ec8 |
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:
- AVX-512. AMD Zen 4 chips with SHA-NI skip this and fall through. Zen 5 uses a double-width variant.
- SHA-NI.
- AVX2, eight lanes.
- Plain portable code.
Our change targets the AVX2 choice. It applies to a processor with AVX2 and neither SHA-NI nor AVX-512.[8]
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.
| Characters | Prefix bits | Filter compares | Left for the full check | Guesses on average | Bits, drawn |
|---|---|---|---|---|---|
| 1 | 6 | 6 bits | none | 64 | |
5 (gensy) | 30 | 30 bits | none | 1,073,741,824 | |
6 (gensys) | 36 | 32 bits | 4 bits | 68,719,476,736 | |
| 10 | 60 | 32 bits | 28 bits | 1,152,921,504,606,846,976 |
“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]
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]
| Run | MH/s | Load | MHz | °C | MH/s, drawn |
|---|---|---|---|---|---|
| 1a C++ | 2.63 | 3.38 | 3717 | 66 | |
| 1b Rust | 109.61 | 3.86 | 4379 | 67 | |
| 2a Rust | 108.37 | 4.34 | 1879 | 58 | |
| 2b C++ | 2.61 | 4.68 | 2984 | 63 | |
| 3a C++ | 2.52 | 4.88 | 4344 | 65 | |
| 3b Rust | 109.58 | 5.05 | 4328 | 67 | |
| 4a Rust | 108.65 | 5.33 | 2611 | 63 | |
| 4b C++ | 2.63 | 5.66 | 2854 | 64 |
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]
| Run | MH/s | Load | MHz | °C | MH/s, drawn |
|---|---|---|---|---|---|
| 1a stock | 82.20 | 2.70 | 3900 | 77 | |
| 1b patched | 109.12 | 3.36 | 3868 | 76 | |
| 2a patched | 108.61 | 3.92 | 3800 | 76 | |
| 2b stock | 71.55 | 4.71 | 3800 | 76 | |
| 3a stock | 69.27 | 5.29 | 3800 | 78 | |
| 3b patched | 106.90 | 5.63 | 3900 | 77 |
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]
| Run set | Stock library | Custom AVX2 | Patched library |
|---|---|---|---|
| Earlier means, 6 threads, unpinned, 3–4 runs of 5 s, load 4–7 | 63 | 79 | 97 (runs 105.2, 90.1, 95.4) |
| Earlier means, 11 threads, same setup | n/a | 97 | 109 (runs 108.8, 109.7, 107.9) |
| Paired medians, 6 threads, 3 runs of 8 s, load 5.4–9.7 | n/a | 70.0 | 87.6 |
| Pinned pilot, lib against custom AVX2, 3 pairs of 10 s (separate from the headline run) | n/a | 76.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.
gensy with ignore-case was found at nonce 60,237,861 (v2/README.md).Guesses per character
Work out the time for your own prefix
Six letters with ignore-case take about 10 seconds. Ten exact characters take centuries.
Why memory stays small
Memory stays small because the miner keeps only finished ranges.
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.
- 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. - 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. - 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.
- 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. - 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
sha256sumand Python recount. - Intel Intrinsics Guide: a 256-bit AVX2 register, and
_mm256_add_epi32as eight 32-bit additions in one instruction. - 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.
- The kernel order is from the library’s public source at commit 391432a: the
select()function and the SHA-NI check. - The new call,
hash_short_heads, returns each digest’s first 32-bit word. See pull request #4. - From the miner’s source,
head_filter(): the mask covers the top min(prefix bits, 32) bits, and every survivor is checked in full. - 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. - 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.
- 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.
- 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.
- 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. - 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.