Private key finder based on the (Bitcoin) secp256k1 elliptic curve.

Overview

keyripper

keyripper is a powerful tool developed in Rust to assist in the recovery of Bitcoin private keys by leveraging the Baby-Step Giant-Step (BSGS) algorithm to solve the discrete logarithm problem on the secp256k1 elliptic curve. This project underscores the importance of robust cryptographic practices and provides insights into the mathematical foundations that secure blockchain technologies.


Mathematical Background Summary:

  • Elliptic Curves: Key structures in cryptography, defined by the equation y² = x³ + ax + b with conditions to avoid singularities.

  • secp256k1: A specific elliptic curve used in Bitcoin, defined by y² = x³ + 7 over a 256-bit prime field.

  • Key Points:

    • Generator Point (G): Starting point for key generation.
    • Order (n): Number of distinct points generated from G, a large prime.
  • Discrete Logarithm Problem (DLP): Challenge of finding the integer k such that Q = k * G. Security of systems like Bitcoin relies on the difficulty of solving DLP.

  • Baby-Step Giant-Step (BSGS) Algorithm: Efficient method for solving DLP, reducing complexity from O(n) to O(sqrt(n)).

    • Baby Steps: Compute and store points G, 2G, 3G, ..., mG.
    • Giant Steps: Compute Q - j * mG and check against the baby steps table for matches.
  • Steps:

    • Initialization: Choose m = ceiling(n) and create a hash table.
    • Baby Steps Phase: Store points in the hash table.
    • Giant Steps Phase: Check for matches and calculate k.
  • Advantages of BSGS: Efficient and deterministic.

  • Limitations: High memory usage and scalability issues for large n.

  • Optimization Strategies: Use hash tables, parallelization, and subrange splitting to improve performance.


Features

  • Efficient DLP Solver: Implements the Baby-Step Giant-Step algorithm optimized for the secp256k1 curve.
  • Multithreading Support: Leverages multiple CPU cores to accelerate the search process.
  • User-Friendly Configuration: Allows customization of search ranges and subrange sizes.
  • Integration with Google Colab: Facilitates running the tool in cloud environments.
  • Secure Key Handling: Ensures safe management of sensitive cryptographic materials.

Installation

Prerequisites

  • Rust Programming Language: Ensure Rust is installed on your system. If not, follow the Installing Rust section.
  • Git: Required for cloning the repository.
  • Internet Connection: Necessary for downloading dependencies.

Installing Rust

Rust is the primary language used for developing keyripper. Follow these steps to install Rust on your system:

On Windows

  1. Download Rust Installer:

    Visit rustup.rs and click on the Windows button to download the installer.

  2. Run the Installer:

    Execute the downloaded .exe file and follow the on-screen instructions.

  3. Configure Your Current Shell:

    After installation, open a new Command Prompt or PowerShell window to ensure that the Rust binaries are in your PATH.

  4. Verify the Installation:

    rustc --version

    You should see output similar to:

    rustc 1.XX.X (commit hash)
    

On Linux

  1. Install Rust via rustup:

    Open your terminal and execute:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  2. Follow the On-Screen Instructions:

    The script will guide you through the installation process. By default, it installs the latest stable version of Rust.

  3. Configure Your Current Shell:

    After installation, configure your shell environment by running:

    source $HOME/.cargo/env
  4. Verify the Installation:

    rustc --version

    You should see output similar to:

    rustc 1.XX.X (commit hash)
    

Cloning the Repository

Clone the keyripper repository from GitHub:

git clone https://github.com/yourusername/keyripper.git

Navigate to the project directory:

cd keyripper

Setting Up Configuration

keyripper uses a .env file to configure essential variables. Create a .env file in the root directory of the project with the following content:

NUM_THREADS=4
SUBRANGE_SIZE=1000000000
SERVER_URL=https://yourserver.com/api
API_AUTH_TOKEN=your_auth_token
  • NUM_THREADS: Number of threads to utilize for the search process.
  • SUBRANGE_SIZE: Size of each subrange for the search.
  • SERVER_URL: URL of the server to send the found key.
  • API_AUTH_TOKEN: Authentication token for the server.

Building and Running the Project

Build the project using Cargo, Rust's package manager and build system:

On Windows and Linux

cargo build --release
cargo run

This command compiles the project in release mode, optimizing for performance. The compiled binary will be located in the target/release/ directory.


Example Output:

Start scalar: 780778204189001025463454792048743977763, Maximum steps: 10001
[+] ThreadId(15) is processing the range: 780778204189001025463454792048743977763 - 780778204189001025463454792048743987763
[-] ThreadId(18) is processing the range: 680564733841876926926749214863536422911 - 680564733841876926926749214863536422911
...
Private Key Found! <1a2b3c4d5e6f...>
Data successfully sent to the server.
Elapsed time: 2m 35s
Total steps attempted: 20002

Running in Google Colab

Google Colab provides a cloud-based environment to run keyripper without local setup. Follow these steps to execute keyripper in Google Colab:

  1. Open the Code in Google Colab

    Click the badge below to open the project in Google Colab:

  2. Run the Kernel Installation Cell

    Execute the first cell to install the Rust compiler and necessary dependencies:

    !curl https://sh.rustup.rs -sSf | sh -s -- -y
    !source $HOME/.cargo/env
  3. Wait for the Runtime to Restart

    After the installation, the runtime will automatically restart. Wait until the process completes.

  4. Clone the Repository

    Once the runtime has restarted, run the following cell to clone the keyripper repository:

    !git clone https://github.com/yourusername/keyripper.git
    %cd keyripper

Target Address Structure

keyripper requires target addresses to be defined in a specific JSON format. Below is an example of the expected structure:

{
    "Address": 130,
    "BitRange": "2^129...2^130-1",
    "PrivateKeyRange": "200000000000000000000000000000000...3ffffffffffffffffffffffffffffffff",
    "PrivateKeyRangeStart": "200000000000000000000000000000000",
    "PrivateKeyRangeEnd": "3ffffffffffffffffffffffffffffffff",
    "PrivateKey(HEX)": "Unknown",
    "PublicKey(HEX)": "03633cbe3ec02b9401c5effa144c5b4d22f87940259634858fc7e59b1c09937852",
    "BitcoinAddress": "1Fo65aKq8s8iquMt6weF1rku1moWVEd5Ua",
    "PercentOfRange": 0.0,
    "ResolutionDate": "Unknown",
    "Solver": "Unknown",
    "Solved": false
}

Field Descriptions:

  • Address: Identifier for the puzzle (e.g., 130).
  • BitRange: The range of bits for the private key search.
  • PrivateKeyRange: The hexadecimal range of private keys to search within.
  • PrivateKeyRangeStart: Starting point of the private key search range (hexadecimal).
  • PrivateKeyRangeEnd: Ending point of the private key search range (hexadecimal).
  • PrivateKey(HEX): The discovered private key in hexadecimal format (initially "Unknown").
  • PublicKey(HEX): The public key corresponding to the target Bitcoin address.
  • BitcoinAddress: The target Bitcoin address.
  • PercentOfRange: Percentage of the range that has been searched.
  • ResolutionDate: Date when the puzzle was solved (initially "Unknown").
  • Solver: Entity that solved the puzzle (initially "Unknown").
  • Solved: Boolean indicating whether the puzzle has been solved.

Puzzle Context

keyripper is designed to assist in solving cryptographic puzzles such as those found on PrivateKeys.pw. These puzzles involve finding specific private keys within defined ranges that control significant amounts of Bitcoin.

~1000 BTC Bitcoin Challenge Transaction

  • Status: PARTIALLY SOLVED
  • Prize: 988.498 BTC (total), 51.598 BTC (won), 936.9 BTC (remaining)
  • Creator: Unknown
  • Start Date: 2015-01-15
  • Address: 1BY8GQbnueYofwSuFAT3USAhGjPrkxDdW9

Description

In 2015, to demonstrate the vastness of the private key space (or perhaps for entertainment), someone created a "puzzle" where private keys within a specific, smaller space were chosen, and increasing amounts of Bitcoin were sent to each of those keys as follows:

History:

  • 2015-01-15: A transaction was created containing transfers to 256 different Bitcoin addresses.
  • 2017-07-11: Funds from addresses #161–256 were moved to corresponding lower-range addresses, increasing their balances.
  • 2019-05-31: Outgoing transactions with 1000 satoshi were created for specific addresses to compare the difficulty of finding private keys.
  • 2023-04-16: Puzzle #66 was solved, but the prize was split between two addresses.

Solution

To solve these puzzles, one must iterate over the specific private key space and check each private key for a balance. The narrower the key space, the higher the chance of success. Utilizing algorithms like Baby-Step Giant-Step or Pollard's kangaroo can optimize this search process.


Contributing

Contributions are welcome! Follow these steps to contribute to keyripper:

  1. Fork the Repository

    Click the "Fork" button at the top-right corner of the repository page.

  2. Clone Your Fork

    git clone https://github.com/yourusername/keyripper.git
    cd keyripper
  3. Create a New Branch

    git checkout -b feature/your-feature-name
  4. Make Your Changes

    Implement your feature or bug fix.

  5. Commit Your Changes

    git commit -m "Add feature: your feature description"
  6. Push to Your Fork

    git push origin feature/your-feature-name
  7. Create a Pull Request

    Navigate to your fork on GitHub and click "New pull request".


License

This project is licensed under the Apache License 2.0.


Contact

For any questions or support, please open an issue on the GitHub repository or contact the maintainer at [email protected].


Disclaimer: This tool is intended for educational and authorized security testing purposes only. Unauthorized use of this tool to compromise private keys is illegal and unethical. The authors are not responsible for any misuse of this software.

You might also like...
ZKP fork for rust-secp256k1, adds wrappers for range proofs, pedersen commitments, etc

rust-secp256k1 rust-secp256k1 is a wrapper around libsecp256k1, a C library by Peter Wuille for producing ECDSA signatures using the SECG curve secp25

stealth addresses library implementing ERC-5564 over secp256k1 in rust

eth-stealth-addresses rust library implementing ERC-5564 stealth addresses using canonical ECC over the secp256k1 curve. let's make privacy on evm cha

Radix Babylon vanity address finder allowing easy import into Radix mobile Wallet.
Radix Babylon vanity address finder allowing easy import into Radix mobile Wallet.

Rad Vanity address finder for Radix Babylon which you can import directly into your Radix Wallet using QR scanner using Import from a Legacy Wallet fe

Bulletproofs and Bulletproofs+ Rust implementation for Aggregated Range Proofs over multiple elliptic curves

Bulletproofs This library implements Bulletproofs+ and Bulletproofs aggregated range proofs with multi-exponent verification. The library supports mul

Rust implementation of multi-party Schnorr signatures over elliptic curves.

Multi Party Schnorr Signatures This library contains several Rust implementations of multi-signature Schnorr schemes. Generally speaking, these scheme

L2 validity rollup combined with blind signatures over elliptic curves inside zkSNARK, to provide offchain anonymous voting with onchain binding execution on Ethereum

blind-ovote Blind-OVOTE is a L2 voting solution which combines the validity rollup ideas with blind signatures over elliptic curves inside zkSNARK, to

Fast Hilbert space-filling curve transformation using a LUT
Fast Hilbert space-filling curve transformation using a LUT

Fast Hilbert Fast Hilbert 2D curve computation using an efficient Lookup Table (LUT). Convert from discrete 2D space to 1D hilbert space and reverse V

Implementation of the Grumpkin curve in Rust.

Grumpkin curve implementation in Rust This repository implements the Grumpkin curve for use in Rust, by building off of the code provided by ZCash and

Implements ERC-5564 for the bn254 curve using arkworks-rs

erc-5564-bn254 Uses the arkworks-rs suite of libraries, and utilities from rln Usage Note: this scheme should be used with the fork of circom-rln. use

Owner
Denzy
For the Glory of Humanity
Denzy
Multi Party Key Management System (KMS) for Secp256k1 Elliptic curve based digital signatures.

Key Management System (KMS) for curve Secp256k1 Multi Party Key Management System (KMS) for Secp256k1 Elliptic curve based digital signatures. Introdu

[ZenGo X] 61 Dec 28, 2022
X25519 elliptic curve Diffie-Hellman key exchange in pure-Rust, using curve25519-dalek.

x25519-dalek A pure-Rust implementation of x25519 elliptic curve Diffie-Hellman key exchange, with curve operations provided by curve25519-dalek. This

dalek cryptography 252 Dec 26, 2022
Flexible secp256k1 curve math library.

secp A flexible and secure secp256k1 elliptic curve math library, with constant-time support, and superb ergonomics. secp takes full advantage of Rust

null 7 Nov 1, 2023
Implementation of the BLS12-381 pairing-friendly elliptic curve group

bls12_381 This crate provides an implementation of the BLS12-381 pairing-friendly elliptic curve construction. This implementation has not been review

Zero-knowledge Cryptography in Rust 183 Dec 27, 2022
Rust implementation of {t,n}-threshold ECDSA (elliptic curve digital signature algorithm).

Multi-party ECDSA This project is a Rust implementation of {t,n}-threshold ECDSA (elliptic curve digital signature algorithm). Threshold ECDSA include

[ZenGo X] 706 Jan 5, 2023
Elliptic curve cryptography on Soroban.

Elliptic Curve Cryptography on Soroban Contract examples and reusable primitives. Groth 16 verifier. This crate provides a SorobanGroth16Verifier obje

Xycloo Labs 5 Feb 10, 2023
Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transactions of your non-custodial wallets on a provider of your choice, all while respecting your privacy

Bitcoin Push Notification Service (BPNS) Description Bitcoin Push Notification Service (BPNS) allows you to receive notifications of Bitcoin transacti

BPNS 1 May 2, 2022
Minimal Bitcoin wallet intended for teaching rust-bitcoin

Insanely minimal Bitcoin wallet intended for demonstration of Rust Bitcoin ecosystem Absolutely DO NOT use with mainnet funds!!! No privacy - address

Martin Habovštiak 4 May 5, 2023
Modern, lightweight & standard-compliant bitcoin wallet runtime & cli without rust-bitcoin dependencies

Bitcoin protocol command-line wallet & tools Modern, minimalistic & standard-compliant cold wallet from LNP/BP Standards Association. Contributing Con

BP: Bitcoin protocol 3 Jul 31, 2023
a Solana program for granting friends permissions on your account without revealing your private key.

Delegatooooor Granting Permission: An account holder (the delegator) decides to grant permission to a delegate. They create and sign a transaction tha

0xGhostMac 3 Apr 3, 2024