You just proved real computational work on your machine. Now explore the three engineering techniques that multiply hashrate without changing the odds of any single hash.
1. Midstate: cutting 33% of the work for free
A Bitcoin block header is 80 bytes. SHA-256 processes 64-byte chunks, so the first hash takes 2 compressions (bytes 0..63 and bytes 64..79 + padding), and the second hash takes 1 more — 3 compressions per nonce.
Because the nonce sits in the final 4 bytes (76..79), the first 64 bytes stay identical across all 4.29 billion nonces. Computing the intermediate state (midstate) once per work unit drops each attempt from 3 compressions to 2.
// core/src/work.rs — precompute midstate once per WorkUnit
let mut midstate = IV;
compress256(&mut midstate, &[header[..64].try_into().unwrap()]);
// Inside the hot loop, every nonce only runs:
// 1) compress(midstate, block2_with_nonce)
// 2) compress(IV, hash1_with_padding)
2. Hardware SHA Instructions (SHA-NI & ARMv8 Crypto)
Modern CPUs (Apple Silicon, ARMv8, x86 with SHA-NI) execute 4 SHA-256 rounds per hardware instruction, yielding a 6×–10× jump over pure software.
On 32-bit ARM builds running on 64-bit cores (e.g. Android TVs), the sha2 crate falls back to software. That is why sandra-core embeds core/src/sha256_arm.c with NEON crypto intrinsics (vsha256hq_u32) enabled at runtime via getauxval(AT_HWCAP2).
- Apple M1: ~6.5 MH/s per thread at 100% (~130× a physical ESP32 NerdMiner).
- True duty-cycle throttling: hashes an 8,192-nonce chunk, then sleeps proportionally to keep fans quiet.
- Fast candidate filter: full verification only runs when state word 7 meets the top-32-bit threshold.
3. GPU Compute Shaders (WGSL & OpenCL)
On the GPU, thousands of threads run sha256d.wgsl (wgpu -> Metal/Vulkan/DX12) or sha256d.cl (dynamically loaded libOpenCL for ARM Mali GPUs). Batch size self-tunes to ~30 ms per dispatch so your desktop stays smooth.
Further optimization comes from early exit: since only s2[7] is checked by the filter, rounds 61–63 of the second compression can be skipped, and rounds 0–2 of block 2 can be precomputed on the CPU.