# Workstream 29 — Review CPU SIMD optimization opportunities (Bitcoin Puzzle #71) ## 1. Question and assumptions **Question.** For the brute-force search required by Puzzle #71, what speedup is available on a general CPU from SIMD vectorization of the inner loop, and where is the bottleneck? Concretely: is the hot path the hash160 (SHA-256 + RIPEMD-160) of candidate public keys, or the secp256k1 field arithmetic that generates those keys? I measured both, scalar vs. AVX2, on this machine, and validated a small-puzzle search end-to-end. **Assumptions, verified below.** - Puzzle #71 is an address-only target (`1PWo3JeB9jrGwfHDNpdGK54CRas7fsVzXU`): the public key is **not** exposed, so Pollard-kangaroo/BSGS do not apply and the only generic attack is sequential scan of the 2^70 keys in `[2^70, 2^71-1]`, deriving each address and comparing hash160. SIMD therefore acts on the hash + EC step, not on a shortcut. Confirmed: the funding tx spends nothing from this address (0 spent outputs), so no signature/pubkey is on chain (§2). - This machine has AVX2 + BMI2 but **no** SHA-NI, AVX-512, or GPU (verified `/proc/cpuinfo`), and 2 vCPUs. All numbers are single-threaded unless stated. This is representative of the "no GPU, bounded CPU" worker the goal describes. - No vendor crypto binary was installed; I wrote and compiled my own reference kernels (zig/clang 22) and cross-checked them against Python `hashlib`. This keeps the experiment self-contained and auditable. ## 2. Verified target facts (UTC 2026-11-23 07:33–07:42) - **Address** `1PWo3JeB9jrGwfHDNpdGK54CRas7fsVzXU`, hash160 `f6f5431d25bbf7b12e8add9af5e3475c44a0a5b8`. It is output #70 (value 0.071 BTC) of the original 2015 puzzle funding tx `08389f34…5fa6cd15`, confirmed in **block 339085** (2015-01-15). Blockstream API. - **Unsolved.** `chain_stats.spent_txo_count = 0`: not one of the 73 funded outputs has ever been spent, so no key is revealed and no pubkey is on chain. Current balance ≈ 7.10196696 BTC (reward + accumulated tips). Chain tip at query time: **block 977165**. - **Range.** `0x400000000000000000 … 0x7fffffffffffffffff` = `2^70 … 2^71−1`, exactly 2^70 keys (computed: `hi−lo+1 = 0x400000000000000000`). Matches the public convention "Puzzle #N has a key between 2^(N-1) and 2^N" and the creator's note that keys are "consecutive keys from a deterministic wallet (masked with leading 000...0001)". Puzzle #71 has no exposed public key — brute-force only. - **Recipient** `bc1pg6luxm9s4qq65lge4l6ual7xwdw5v85eh675cmrl5we0ht3vpfhswxu0cx` decodes as a valid **bech32m / witness-v1 / 32-byte P2TR** output (checksum constant `0x2bc830a3`, witver 1, program len 32). Used only as the designated reward recipient; not a search input. No transaction was built or broadcast. **A solution was NOT found** and none was attempted at full scale (infeasible — see §6). ## 3. Method and reproducible code All code is in `test/scratch/` (scratch, not submitted). Core files: `hash_tmpl.h` (a macro template instantiated once for scalar `uint32_t` and once for a GCC/clang 8-lane `uint32_t` vector) and `bench.c`. Build (zig cc bundles clang+musl, no system toolchain needed): ``` python3 -m ziglang cc -O3 -march=haswell -o u_avx2 bench_u.c # AVX2 target python3 -m ziglang cc -O3 -march=x86_64 -o u_sse2 bench_u.c # SSE2 baseline ``` The hash160 kernel is a straight SHA-256→RIPEMD-160 over the 33-byte compressed pubkey, written once with portable operators so the compiler maps the 8-wide version to `vpsrld/vpslld/vpand/vpaddd` (AVX2) or to SSE2 when AVX2 is disabled — i.e. the *same source* auto-vectorizes across 8 independent keys. Field arithmetic has two implementations: a scalar 4×64 Montgomery-free reduction using the secp256k1 fast prime (`p = 2^256−2^32−977`, folding with `c = 0x1000003D1`), and an AVX2 `fev_mul` packing **4 keys × 10 limbs of 26 bits** multiplied with `vpmuludq` (PMULUDQ: "Multiply packed unsigned doubleword integers in ymm2 by … ymm3/m256, and store the quadword results in ymm1"). The search kernel walks a run of consecutive keys with **batched-inverse point addition** (one modular inverse amortized over 1024 additions via a Montgomery product tree), the standard Kangaroo/VanitySearch-style trick, then hash160s the whole batch. **Correctness gates (all passed):** - hash160 of compressed G = `751e76e8199196d454941c45d1b3a323f1433bd6`, identical for scalar, vector lane, and Python `hashlib` — exact match. - 8000 random inputs: **0** scalar-vs-vector hash mismatches. - AVX2 `fev_mul` vs scalar after 1000 chained multiplies: **0/8** lanes mismatch. - End-to-end: on three independent locally-generated **24-bit** puzzles and one **28-bit** puzzle, the search recovered the exact planted offset (e.g. 129727493 of 134217728) in both scalar and AVX2 modes — the vectorization does not change the answer, only the speed. ## 4. Actual tests, hardware and results **Hardware.** QEMU/KVM guest, Intel "Haswell" model, flags include `avx2 bmi2 aes`; **no** sha_ni, no avx512, 2 vCPU @ ~2.39 GHz, 3 GB RAM. clang 22.1.8 via ziglang 0.17.1. Single thread. **hash160 throughput** (2^21 hashes/run, best of 2): | build | scalar | 8-lane SIMD | SIMD speedup | |--------------|--------------|--------------|--------------| | AVX2 (`-march=haswell`), unrolled | 1.27 Mhash/s | **7.32 Mhash/s** | **5.8×** | | SSE2 (`-march=x86_64`), unrolled | 1.14 Mhash/s | 3.28 Mhash/s | 2.9× | | AVX2, not unrolled | 0.92 | 6.06 | 6.6× | Full loop unrolling of the SHA/RIPEMD rounds helped scalar most (≈+40%) and lifted AVX2 to 7.3 Mhash/s. AVX2 over SSE2 for the vector kernel is ~2.2× (256- vs 128-bit lanes), as expected. **secp256k1 field multiply** (ns per multiply, 8 independent chains): | kernel | ns/mul | |--------|--------| | scalar 4×64 (128-bit products) | **30.4** | | AVX2 4-lane 10×26 (`vpmuludq`) | 38.8 (per lane) | Here SIMD **lost**: a single 256-bit scalar multiply using native 64×64→128 (`mulx`-class) hardware beats the 10×26 limb schoolbook that AVX2 forces, because 26-bit limbs need 100 partial products per multiply vs. 16 for 4×64, and Haswell has only limited `vpmuludq` throughput. On CPUs this is the known result: scalar 5×52 (secp256k1's `field_5x52`, "5 uint64_t limbs in base 2^52") is the fast path; SIMD field mul only wins with AVX-512-IFMA (52-bit `vpmadd52`), which this CPU lacks. **End-to-end search rate** (batched-inverse, single thread): | mode | Mkeys/s | time in hash | time in EC | |------|---------|--------------|-----------| | scalar | 0.85–0.94 | ~75% | ~25% | | **AVX2** | **2.5–2.68** | ~34% | ~66% | Vectorizing only the hash moved the bottleneck: at scalar speed hashing dominates (75%), so SIMD on hash gives ~2.8× overall; past that the **unvectorized EC step becomes the limit (66%)**. The two multi-process runs (2 cores) each sustained ~2.48 Mkeys/s with no contention, i.e. ≈2× aggregate — the workload is embarrassingly parallel and memory-light, so per-core SIMD gains compound with core count. ## 5. Analysis vs. measurement — where SIMD helps - **Measured:** hash160 is the single best SIMD target on this class of CPU: **5.8× scalar→AVX2**, and it is the initial bottleneck. This is the concrete "optimization opportunity" for workstream 29. - **Measured:** naive AVX2 field multiply is *slower* than scalar 64-bit here; do not vectorize EC point math on non-IFMA CPUs. Use scalar 5×52 + batched inversion instead. - **Analysis-only (not run here):** (a) SHA-NI would roughly halve SHA-256 cost on capable CPUs but is absent here; (b) AVX-512 would ~double lane width (16-wide hash) and enable IFMA field mul — both plausibly ~2× more, but unverifiable on this hardware; (c) the RIPEMD-160 half has no hardware instruction and stays the dominant hash cost, so wide-SIMD RIPEMD is the highest-value remaining CPU kernel. ## 6. Limitations and concrete next step **Limitations.** Numbers are one CPU model, single-thread, my own kernels (correct but not micro-tuned to the level of hand-written VanitySearch/Rotor assembly, which reach ~2–3× my hash rate). I did not test AVX-512/SHA-NI (absent) or GPUs (absent). Results transfer as *ratios and bottleneck location*, not as absolute throughput for other machines. **Feasibility is decisive and independent of SIMD.** At the best measured **2.68 Mkeys/s/core**, 2^70 keys take 2^70 / 2.68e6 ≈ **1.4×10^16 core-seconds ≈ 4.4×10^8 core-years**. A 10× SIMD/asm CPU gain, times thousands of cores, still leaves astronomically more than any authorized budget. CPU SIMD meaningfully improves constant factors (the real, reproducible finding here) but does not make Puzzle #71 tractable; GPU/FPGA farms, not CPU SIMD, are where public effort concentrates, and even those are quoted in tens of thousands of GPU-years. **Best next experiment (bounded):** implement an 8/16-wide RIPEMD-160 and benchmark a combined SHA-NI+AVX2 hash path on a Zen/Ice-Lake host to quantify the two biggest un-measured levers (SHA-NI for SHA-256, IFMA for field mul), using the same correctness harness and locally-generated ≤32-bit puzzles for end-to-end validation. This stays within CPU-only, no-cost bounds while closing the main gaps in §5. No key search at scale should be attempted; it cannot finish. *No private key, seed, or signed transaction is produced or disclosed. No transaction was broadcast. If a key were ever found it would require a separate secure claiming process, not publication.*