|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## What this is |
| 6 | + |
| 7 | +Vanitygen: a command-line vanity Bitcoin (and altcoin-family) address generator, written in C. Given a desired prefix or regex pattern, it brute-force searches EC keypairs until it finds an address matching the pattern. A CPU implementation (`vanitygen`) and an OpenCL/GPU implementation (`oclvanitygen`, `oclvanityminer`) share the same pattern-matching core. |
| 8 | + |
| 9 | +## Build |
| 10 | + |
| 11 | +``` |
| 12 | +make # builds vanitygen and keyconv only (the "most" target, no OpenCL deps needed) |
| 13 | +make all # also builds oclvanitygen and oclvanityminer (requires OpenCL + libcurl) |
| 14 | +make clean |
| 15 | +``` |
| 16 | + |
| 17 | +Dependencies: OpenSSL (`libcrypto`), PCRE (`libpcre`), pthreads. OpenCL targets additionally need an OpenCL SDK/driver and `libcurl` (oclvanityminer only, for pool mining). |
| 18 | + |
| 19 | +This code targets the OpenSSL 1.0.x API (`BIGNUM` as a transparent struct) and the legacy PCRE1 API (`<pcre.h>`), not OpenSSL 1.1+ (opaque `BIGNUM`) or PCRE2. On a system that only has newer versions installed system-wide, build OpenSSL 1.0.2 and PCRE1 from source under `$HOME/development/crypto/` and point the Makefile at them, e.g.: |
| 20 | + |
| 21 | +``` |
| 22 | +make OPENSSL_PATH=$HOME/development/crypto/openssl-1.0.2u PCRE_PATH=$HOME/development/crypto/pcre-8.45 |
| 23 | +``` |
| 24 | + |
| 25 | +`OPENSSL_PATH`/`PCRE_PATH` default to those same paths under `$HOME`, so a plain `make` picks them up automatically if built there. |
| 26 | + |
| 27 | +Windows build uses `Makefile.Win32` with `nmake` (MSVC); see `INSTALL` for required SDK paths (OpenSSL, pthreads-Win32, PCRE, AMD APP SDK/CUDA). |
| 28 | + |
| 29 | +There is no test suite in this repository. |
| 30 | + |
| 31 | +## Architecture |
| 32 | + |
| 33 | +The codebase splits into a reusable pattern-matching/crypto core and multiple thin front ends: |
| 34 | + |
| 35 | +- **`pattern.c`/`pattern.h`** — the core `vg_context_t` / `vg_exec_context_t` abstraction. A `vg_context_t` holds the search parameters (address type, patterns, output callbacks) and dispatches to one of two pattern engines via function pointers (`vc_add_patterns`, `vc_test`, `vc_hash160_sort`, ...): |
| 36 | + - **Prefix matching** (`vg_prefix_context_new`): builds a trie/AVL-based structure (see `avl.h`) over base58 prefixes for O(log N) matching against many patterns simultaneously, and can compute match difficulty. |
| 37 | + - **Regex matching** (`vg_regex_context_new`): compiles PCRE patterns and matches against generated addresses. |
| 38 | + Each worker thread owns a `vg_exec_context_t` (its own OpenSSL `BN_CTX`/`EC_KEY`/scratch bignums) and calls back into `vc_test` per candidate key. Thread coordination (locking, upgrade/downgrade, stop) lives here too. |
| 39 | +- **`util.c`/`util.h`** — base58check encode/decode, address/private-key encoding, private key protection/encryption (BIP38-like PBKDF2+AES), PKCS#8 import/export, password handling, and file reading helpers. Independent of the search engine. |
| 40 | +- **`vanitygen.c`** — CPU front end: parses CLI args, builds a `vg_context_t` (prefix or regex), spawns one pthread worker per CPU (or `-t` override), and calls into `pattern.c`. |
| 41 | +- **`oclengine.c`/`oclengine.h`** — the OpenCL execution engine (`vg_ocl_context_t`): device/platform enumeration, kernel compilation and dispatch, batched EC point arithmetic on the GPU. This is what makes GPU search fast — it computes many candidate public keys per kernel invocation rather than one key at a time. |
| 42 | +- **`calc_addrs.cl`** — the actual OpenCL kernel source (EC point math, hashing) compiled/loaded at runtime by `oclengine.c`. |
| 43 | +- **`oclvanitygen.c`** — GPU front end analogous to `vanitygen.c`, but driving `vg_ocl_context_t` instead of pthread workers. |
| 44 | +- **`oclvanityminer.c`** — a pool-mining-style variant of the OpenCL front end: pulls patterns from a remote server over HTTP (via libcurl) and reports matches back, instead of taking patterns from argv. |
| 45 | +- **`keyconv.c`** — standalone small utility to convert/reformat keys and addresses between formats (base58check, hex, PEM/PKCS#8), independent of the search engines. |
| 46 | +- **`winglue.c`/`winglue.h`** — Windows compatibility shims (pthreads/time/stat equivalents) used only when building with MSVC. |
| 47 | + |
| 48 | +### Key extension points |
| 49 | + |
| 50 | +- New coin/address types are just `addrtype`/`privtype` byte values passed into `vg_prefix_context_new`/`vg_regex_context_new` — see CLI handling in `vanitygen.c`/`oclvanitygen.c` for `-t`/address-version flags (Bitcoin, Namecoin, testnet variants). |
| 51 | +- Output is fully pluggable via `vc_output_match`/`vc_output_timing`/`vc_output_error` function pointers on `vg_context_t`; default console implementations are `vg_output_match_console`/`vg_output_timing_console` in `pattern.c`. |
| 52 | +- Both CPU and GPU front ends build the same `vg_context_t` and differ only in what drives `vc_test` (pthread loop vs. OpenCL kernel batches), so pattern-matching logic changes belong in `pattern.c`, not duplicated per front end. |
0 commit comments