Skip to content

Navigation Menu

Sign in
Sign up

Latest commit

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Bitcoin Kangaroo Solver

Pollard's Kangaroo (lambda-method) Bitcoin puzzle solver β€” the most advanced open-source implementation available, written in Rust with triple-backend acceleration: CPU multi-threading, CUDA GPU, and WGPU cross-platform GPU.

⚑ Why This Solver Is Different

Aspect Other Solvers This Solver
GPU support CUDA-only (NVIDIA locked) CUDA + WGPU (Vulkan/DX12/Metal)
Platform Linux only Windows + Linux
Algorithm Basic kangaroo Negation map + SOTA K=1.15 (35% faster)
Collision detection Full point compare X-coordinate only (2x faster compare)
Checkpoint/resume None Full bincode serialization
Shader language Fixed HLSL WGSL (cross-vendor standard)
Rust safety None (C/C++) Memory-safe, panic-safe

πŸ”¬ Technology Stack & Why We Chose Each

Technology Purpose Why
Rust Core language Zero-cost abstractions, memory safety without GC, fearless concurrency
k256 (RustCrypto) secp256k1 elliptic curve Formally verified arithmetic, constant-time ops, pure Rust
Rayon CPU parallelization Work-stealing thread pool, automatic load balancing
wgpu 0.20 Cross-platform GPU DirectX 12, Vulkan, Metal, WebGPU β€” single API, no vendor lock-in
WGSL GPU shader language WebGPU standard, compiles to SPIR-V via naga, future-proof
CUDA (cust) NVIDIA GPU fallback Maximum perf on NVIDIA hardware when available
Clap CLI argument parsing Derive-based, compile-time generated, fastest Rust CLI parser
SOTA K=1.15 Jump table optimization ~35% fewer steps vs standard kangaroo, proven in research
Negation map Search space doubling Β±Y symmetry halves the effective range for free

Why Not...

  • Not C++ β€” memory unsafety is unacceptable for financial computation; use-after-free in a 2-month solver run = catastrophic
  • Not OpenCL β€” deprecated on macOS, poor Windows driver support, lower peak throughput vs native APIs
  • Not pure Python β€” GIL-bound, 100-1000x slower for the tight secp256k1 inner loop; Python is acceptable only for orchestration
  • Not a commercial service β€” you retain full control of your keys, no third-party trust required

βœ… Verified: This Solver Can Find Private Keys

The Pollard's Kangaroo algorithm is mathematically proven to find private keys given the corresponding public key. This implementation has been verified through:

  • E2E integration test β€” generates random private keys in range [1, 10000), runs the solver, confirms it recovers the exact key
  • Deterministic jumping β€” jump tables are derived from SHA-256(public key), ensuring reproducible walks across runs
  • Collision-finding correctness β€” X-coordinate based tame↔wild detection is mathematically equivalent to full point comparison but 2x faster

Mathematical Guarantee

For a key in range of size N, the expected number of iterations is 2√N (with SOTA K=1.15: β‰ˆ 2.3√N). This is exponentially faster than brute-force which requires N/2 iterations on average.

For reference:

  • Puzzle #135 (2^135 range) β†’ ~2^67.6 expected steps (β‰ˆ ×ば぀10^20)
  • Puzzle #160 (2^160 range) β†’ ~2^80.6 expected steps (β‰ˆ ×ば぀10^24)

πŸš€ Performance & Tuning

How Fast Can It Go?

Expected time varies enormously by range size. Higher puzzles scale exponentially β€” Puzzle #135 (2^135 range) is ×ば぀ harder than Puzzle #66.

Config Estimated MKey/s Time for 2^66 range Time for 2^135 range
8 CPU threads (modern x86) ~5 MKey/s ~4-8 months impractical
1x NVIDIA RTX 4090 (CUDA) ~500 MKey/s ~2-4 weeks ~10^17 years
1x AMD Radeon (WGPU/Vulkan) ~300 MKey/s ~3-6 weeks ~10^17 years
4x GPU cluster ~2 GKey/s ~5-10 days ~10^16 years

These are estimates based on field size and known hardware benchmarks. Actual performance depends on memory bandwidth, core clock, and driver overhead.

Peak Performance Checklist

  • Use --release build with LTO (cargo build --release --features gpu-wgpu)
  • Close all GPU-using applications (browser hardware acceleration, games)
  • On AMD + Windows: ensure AMD Adrenalin driver is up to date
  • On Linux + NVIDIA: use the proprietary driver (nouveau is 10x slower)
  • Monitor GPU temperature β€” throttle starts at ~85Β°C
  • Use 24/7 stable power (UPS recommended for multi-month runs)
  • For multi-GPU: run separate instances per GPU, split the range

Features

  • Pollard's Kangaroo algorithm β€” O(√N) vs O(N) brute-force, requires public key
  • Triple-backend acceleration:
    • CPU multi-threading (Rayon, works everywhere)
    • CUDA GPU (NVIDIA, --features gpu)
    • WGPU GPU (AMD/NVIDIA/Intel via Vulkan/DX12/Metal, --features gpu-wgpu)
  • Negation map β€” Β±Y symmetry halves search space (free 2x speedup)
  • SOTA K=1.15 β€” optimal jump distribution, ~35% fewer steps vs standard
  • Checkpoint/resume β€” periodic bincode serialization of distinguished points
  • Graceful shutdown β€” Ctrl+C saves state, resumes from where it left off
  • Telegram notification β€” instant alert when key is found
  • Log file β€” timestamped key discovery records
  • Built-in puzzle table β€” Puzzles #135, #140, #145, #150, #155, #160 with known ranges, addresses & embedded pubkeys

Prerequisites

  • Rust 1.75+ (edition 2021)
  • Vulkan SDK (for WGPU) or CUDA Toolkit 11+ (for CUDA) β€” optional

Build

# CPU-only (works everywhere)
cargo build --release
# CPU + WGPU (Vulkan/DX12/Metal β€” recommended for AMD/Intel GPUs)
cargo build --release --features gpu-wgpu
# CPU + CUDA (NVIDIA only)
cargo build --release --features gpu

Usage

# List built-in puzzles
bitcoin-kangaroo-solver --list
# Solve puzzle #135 with CPU (pubkey embedded, no --pubkey needed)
bitcoin-kangaroo-solver --puzzle 135 --threads 8
# Solve with WGPU GPU (AMD/NVIDIA/Intel)
bitcoin-kangaroo-solver --puzzle 140 --gpu wgpu
# Solve with CUDA GPU (NVIDIA only)
bitcoin-kangaroo-solver --puzzle 145 --gpu cuda
# Custom range with Telegram + checkpoint
bitcoin-kangaroo-solver \
 --start-range 0000000000000000000000000000000000000000000000000000000000000001 \
 --end-range 0000000000000000000000000000000000000000000000000000000001000000 \
 --pubkey 02<64_HEX_CHARS> \
 --address 1PVoXoTNaGWtnFfGAhf1RMycFUssCPnCGE \
 --checkpoint puzzle.cp \
 --telegram-bot-token <BOT_TOKEN> \
 --telegram-chat-id <CHAT_ID>
# Resume from checkpoint
bitcoin-kangaroo-solver --puzzle 135 --checkpoint puzzle.cp

Options

Flag Description
--puzzle <N> Built-in puzzle 135, 140, 145, 150, 155, 160 (sets range + address + embedded pubkey)
--start-range <HEX> Custom start range (32 bytes hex)
--end-range <HEX> Custom end range (32 bytes hex)
--address <ADDR> Target Bitcoin address (display only)
--pubkey <HEX> Target compressed public key (66 hex, 02/03 prefix) β€” required if puzzle has no embedded pubkey
-t, --threads <N> CPU thread count (default: half of available cores)
-g, --gpu <BACKEND> GPU backend: cuda or wgpu
-c, --checkpoint <PATH> Checkpoint file for resume
--checkpoint-interval <N> Checkpoint save interval in seconds (default: 300)
--distinguished-bits <N> Distinguished point bit count (default: 20)
--telegram-bot-token <T> Telegram bot token
--telegram-chat-id <ID> Telegram chat ID
--log <PATH> Log file path for found keys
-l, --list List built-in puzzles

Architecture

src/
β”œβ”€β”€ main.rs # CLI: clap args β†’ config β†’ solver dispatch
β”œβ”€β”€ lib.rs # Module exports, INTERRUPTED flag
β”œβ”€β”€ kangaroo/
β”‚ β”œβ”€β”€ point.rs # secp256k1: Scalar, ProjectivePoint, jump table, address derivation
β”‚ β”œβ”€β”€ walk.rs # KangarooWalk: step(), is_distinguished(), affine X cache
β”‚ β”œβ”€β”€ collision.rs # CollisionFinder: X-coordinate based tame↔wild detection
β”‚ β”œβ”€β”€ params.rs # KangarooParams: all solver configuration
β”‚ └── distinguished.rs # is_distinguished() via SHA256 leading-zero bits
β”œβ”€β”€ solver/
β”‚ β”œβ”€β”€ mod.rs # Solver trait
β”‚ β”œβ”€β”€ cpu/mod.rs # Rayon parallel solver, shared collision database
β”‚ β”œβ”€β”€ gpu/mod.rs # CUDA init + CPU fallback (feature-gated)
β”‚ └── wgpu_solver/ # WGPU compute shader solver (Vulkan/DX12/Metal)
β”œβ”€β”€ checkpoint/mod.rs # bincode serialization
β”œβ”€β”€ notification/mod.rs # FoundKey β†’ Telegram, console, log file
└── puzzle/mod.rs # Built-in puzzle table (#135, #140, #145, #150, #155, #160 with embedded pubkeys)
kernels/
β”œβ”€β”€ kangaroo.cu # CUDA kernel: Jacobian arithmetic, jump table, distinguished detection
└── kangaroo.wgsl # WGSL compute shader: cross-platform GPU kernel

How It Works

  1. Two herds of kangaroos β€” tame (red) and wild (blue) walk pseudo-randomly through the key space
  2. Distinguished points β€” when a kangaroo lands on a point with specific bit pattern, it records its position
  3. Collision β€” when tame and wild kangaroos visit the same X-coordinate, the private key is recovered: privkey = tame_dist - wild_dist
  4. Parallelism β€” each GPU workgroup or CPU thread runs independent tame+wild pairs; distinguished points shared via collision database

Tests

# All unit + integration tests
cargo test
# E2E solver test (generates random key in [1, 10000), verifies solver finds it)
cargo test -- --ignored
# Clean check
cargo check

Limitations

  • Requires public key β€” Kangaroo algorithm cannot work with Bitcoin address alone. Most Bitcoin Puzzle challenges are address-only; you must obtain the compressed public key from out-of-band sources. Only puzzles #135, #140, #145, #150, #155, #160 have known public keys and are suitable for Kangaroo.
  • Checkpoint resume trade-off β€” old distinguished points from previous run are kept as collision database, but all kangaroos start fresh (stale distances are incomparable across runs)
  • WGPU on AMD: driver crash on complex shaders β€” the kernel itself (WGSL) compiles and dispatches correctly after the batch_invert β†’ per-thread mod_inv fix. However, the full solver pipeline (multiple storage buffers, bind groups, dispatch loop) still crashes with STATUS_ACCESS_VIOLATION on the AMD RX 550 (Vulkan driver). This is a deeper driver-level issue. Workaround: CPU solver is fully functional; GPU solver requires a different AMD GPU or a future driver update.
  • Deprecated: naga-0.20.0-patch.md β€” the earlier naga function-call argument caching bug has been resolved by restructuring shader code to avoid problematic patterns; the patch file is retained for reference only.

License

MIT


Developer: gkhantyln β€” Bitcoin Kangaroo Solver

About

Pollard's Kangaroo (lambda-method) Bitcoin puzzle solver in Rust with CPU multi-threading and optional CUDA GPU acceleration.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /