This project demonstrates Shor's algorithm for the Elliptic Curve Discrete Logarithm Problem (ECDLP) using Qiskit quantum simulators. It's an educational tool to understand the quantum threat to Bitcoin and other ECDSA-based systems.
Bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm) with the secp256k1 curve:
- Private key: A 256-bit number
k - Public key: A point
Q = k * Gwhere G is the generator point - The problem: Given
QandG, findk
Classically, this requires ~2^128 operations (infeasible). Shor's algorithm solves it in polynomial time on a quantum computer.
Since we can't simulate 2300+ qubits needed for real Bitcoin keys, we use toy curves:
- Tiny curve (p=5): ~15 qubits, runs in seconds
- Small curve (p=251): ~80 qubits, pushes simulator limits
- Medium curve (p=1009): ~100+ qubits, very slow to simulate
All demonstrate the same principle that would break Bitcoin given sufficient qubits.
pip install qiskit qiskit-aer numpy
pip install https://p51lee.github.io/assets/python/wheel/qiskit_ecdlp-0.1-py3-none-any.whlFor GPU acceleration (optional, recommended for larger curves):
pip install qiskit-aer-gpuquantum-attack/
├── README.md # This file
├── requirements.txt # Python dependencies
├── classical_ec.py # Classical elliptic curve operations
├── elliptic_curve_attack.py # Generic attack program (works with any curve config)
├── configs/ # Curve configuration files
│ ├── tiny_curve.json # p=5 curve (~15 qubits)
│ ├── small_curve.json # p=251 curve (~80 qubits)
│ └── medium_curve.json # p=1009 curve (~100+ qubits)
├── simplified_demo.py # Simplified quantum attack simulation
└── bitcoin_extrapolation.py # Resource estimates for real Bitcoin
Works immediately (no external dependencies beyond numpy):
# Classical EC operations demo
python classical_ec.py
# Resource estimates for real Bitcoin
python bitcoin_extrapolation.py
# Simplified quantum attack simulation
python simplified_demo.py --explainRequires full Qiskit + qiskit_ecdlp library:
# Full quantum circuit attack on tiny curve
python elliptic_curve_attack.py --config configs/tiny_curve.json --key 3 --shots 8
# Attack on small curve (slower)
python elliptic_curve_attack.py --config configs/small_curve.json --key 42 --shots 4
# Show curve information
python elliptic_curve_attack.py --config configs/tiny_curve.json --infoThe complete working implementation with real quantum circuits is available in this Google Colab notebook (runs in browser, no local setup needed):
This notebook uses the qiskit_ecdlp library to build actual quantum circuits for elliptic curve point addition and runs them on Qiskit's Aer simulator.
Curve configurations are stored as JSON files in the configs/ directory. Each file specifies:
modulus: Prime field modulus (p)a,b: Curve coefficients (y² = x³ + ax + b)generator: Generator point [x, y]order: Group order (or setcalculate_order: trueto compute automatically)name: Human-readable curve namedescription: Description of the curve
Example configuration:
{
"name": "Tiny Curve",
"modulus": 5,
"a": 3,
"b": 2,
"generator": [2, 1],
"order": 5,
"calculate_order": false,
"description": "Tiny elliptic curve with p=5..."
}The attack outputs:
- Circuit statistics: Number of qubits, gates, and depth
- Measurement results: Raw quantum measurements
- Recovered key: The private key extracted via post-processing
- Verification: Confirms
k * G = Q
Bitcoin addresses that have spent transactions have exposed public keys. A quantum computer with ~2300 logical qubits could:
- Read the public key from the blockchain
- Run Shor's algorithm
- Recover the private key
- Steal the funds
Current quantum computers have ~100-1000 physical qubits with high error rates. The timeline to 2300+ logical qubits is estimated at 10-20 years, but this is uncertain.
- Proos & Zalka (2003): "Shor's discrete logarithm quantum algorithm for elliptic curves"
- Roetteler et al. (2017): "Quantum Resource Estimates for Computing Elliptic Curve Discrete Logarithms"
- BIP-360: Bitcoin's proposed quantum-resistant address format
This is educational software demonstrating a well-known vulnerability. It cannot attack real Bitcoin keys—the curves used here are millions of times smaller than secp256k1.