Home/Blockchain/Elliptic Curve Playground/Blockchain Implementation

⛓️ secp256k1: Bitcoin's Chosen Curve

Explore why Bitcoin chose this specific elliptic curve for security

Previous
ECDSA Signatures

⛓️ ECC in Blockchain

Bitcoin and Ethereum both use elliptic curve cryptography, but with different implementations. Let's explore how!

🎮 Interactive: Compare Implementations

Bitcoin (secp256k1)
The original cryptocurrency
Curve Parameters:
Equation:y² = x³ + 7
Prime (p):2²⁵⁶ - 2³² - 977
Order (n):~2²⁵⁶
Key Generation:
  1. 1.Generate random 256-bit private key (d)
  2. 2.Compute public key: Q = d × G (G is generator point)
  3. 3.Compress public key (33 bytes instead of 65)
  4. 4.Create Bitcoin address from public key hash
Address Generation:
Public Key (compressed):
02a1b2c3d4e5f6...
SHA-256 hash:
7f3a8b9c2d1e...
RIPEMD-160 hash:
1a2b3c4d5e...
Bitcoin Address (Base58):
1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
Why secp256k1?
  • Performance: Chosen for computational efficiency
  • Simple: Equation y² = x³ + 7 (a=0, b=7)
  • Battle-tested: Used since 2009, never broken
  • Non-NIST: Not standardized by NIST (some prefer this)

🔐 Wallet Generation Process

Both Bitcoin and Ethereum follow this general process to create a wallet:

1
Generate Entropy

Create 256 bits (32 bytes) of random data using cryptographically secure RNG

a1b2c3d4e5f6... (256 bits)
2
Create Mnemonic (Optional)

Convert entropy to 12-24 word seed phrase (BIP39 standard)

"witch collapse practice feed shame open despair creek road again ice least"
3
Derive Private Key

Private key (d) = entropy value (must be < curve order n)

🚨 KEEP SECRET! Never share!
4
Compute Public Key

Q = d × G (scalar multiplication on secp256k1 curve)

Result: (x, y) coordinate pair on elliptic curve
5
Generate Address

Hash public key (Bitcoin: SHA-256 + RIPEMD-160, Ethereum: Keccak-256)

Bitcoin:
1A1z...DivfNa
Ethereum:
0xd8dA...A96045

📊 Quick Comparison Table

FeatureBitcoinEthereum
Curvesecp256k1secp256k1
Hash FunctionSHA-256 + RIPEMD-160Keccak-256
Public KeyCompressed (33 bytes)Uncompressed (64 bytes)
Address FormatBase58 (starts with 1 or 3)Hex (starts with 0x)
Address Length25-34 characters42 characters (40 + 0x)
Signature SchemeECDSAECDSA

⚠️ Common Security Mistakes

🚨
Using Weak Randomness

Using predictable "random" numbers (like timestamp) can expose your private key. Always use crypto.getRandomValues() or equivalent CSPRNG.

🚨
Reusing Addresses

Reduces privacy. Best practice: generate new address for each transaction (HD wallets do this automatically).

🚨
Storing Private Keys in Plaintext

Encrypt private keys at rest. Hardware wallets keep keys in secure enclaves that never expose them.