Fundamentals ·

secp256k1 vs ed25519: Elliptic Curves ใน Crypto


ทุก cryptocurrency transaction ต้องการ digital signature --- mathematical proof ว่าคนที่ส่ง funds ควบคุม account จริง Signature นั้นถูกสร้างโดย algorithm ที่อาศัย properties ของ elliptic curve สอง curves ที่ dominate ใน blockchain world คือ secp256k1 และ ed25519 ทำหน้าที่เดียวกันแต่ designs, performance characteristics และ adoption histories แตกต่างกันมาก

คู่มือนี้อธิบายว่า elliptic curves ทำอะไรใน cryptography, secp256k1 กับ ed25519 ต่างกันอย่างไร และ differences เหล่านั้นหมายความว่าอะไรสำหรับ key generation, wallet security และ blockchains ที่คุณใช้

Elliptic Curves คืออะไร?

ใน cryptography context elliptic curve คือ mathematical structure ที่ define ด้วยสมการรูปแบบ y^2 = x^3 + ax + b Security อยู่บน Elliptic Curve Discrete Logarithm Problem (ECDLP): ให้ point P บน curve และ point Q = k * P, การหา k จาก P และ Q computationally infeasible

ในมุม cryptocurrency:

  • k คือ private key --- secret number
  • P คือ generator point --- fixed, publicly known point
  • Q คือ public key --- derive จาก private key

ECC ให้ security เท่ากับ RSA ด้วย key sizes ที่เล็กกว่ามาก 256-bit elliptic curve key ให้ security ราวๆ 3,072-bit RSA key

secp256k1: Curve ของ Bitcoin และ Ethereum

secp256k1 คือ elliptic curve ที่ Bitcoin, Ethereum และ blockchains ส่วนใหญ่ใน ecosystem ใช้

สมการ curve: y^2 = x^3 + 7

Satoshi Nakamoto เลือก secp256k1 สำหรับ Bitcoin ในปี 2009 ในขณะนั้นเป็น unusual choice เพราะส่วนใหญ่ใช้ NIST P-256 curve cryptographers บางคน worried ว่า NIST curves อาจมี parameters ที่ influenced โดย NSA Secp256k1 หลีกเลี่ยง suspicion นี้เพราะ parameters simple และ transparent: a = 0, b = 7

Signatures: ECDSA

Signature algorithm ที่ paired กับ secp256k1 คือ ECDSA ECDSA signatures 64 bytes (two 32-byte values, commonly เรียก r และ s) plus recovery byte

ECDSA quirk คือ signature malleability: valid signature (r, s) ให้, pair (r, -s mod n) ก็ valid เช่นกัน Bitcoin แก้ด้วย BIP66 และ SegWit

ed25519: ทางเลือกสมัยใหม่ของ Solana

ed25519 เป็น elliptic curve ที่ Daniel J. Bernstein และ collaborators ออกแบบ ตีพิมพ์ปี 2011 เป็น newer generation curve design ที่ prioritize ทั้ง security และ performance

Solana เลือก ed25519 เป็น signature curve เช่นเดียวกับ modern blockchains อื่นๆ

Signatures: EdDSA

Signature algorithm ที่ paired กับ ed25519 คือ EdDSA ออกแบบมาเพื่อหลีกเลี่ยง pitfalls ของ ECDSA:

  • ไม่ต้องการ randomness ระหว่าง signing EdDSA signatures inherently deterministic
  • ไม่มี signature malleability
  • Faster batch verification
  • Simpler implementation --- surface area สำหรับ side-channel attacks น้อยลง

Performance

Ed25519 consistently เร็วกว่า ECDSA-secp256k1 ใน benchmarks Signing ประมาณ 2-3 เท่า เร็วกว่า และ batch verification คือจุดที่ Ed25519 shine จริงๆ

ECDSA vs EdDSA: เปรียบเทียบตรง

Property ECDSA (secp256k1) EdDSA (ed25519)
Curve type Short Weierstrass Twisted Edwards
Key size 256 bits 256 bits
Signature size 64-65 bytes 64 bytes
Security level ~128 bits ~128 bits
Signing speed เร็ว เร็วกว่า (2-3x)
Verification speed เร็ว เทียบเท่า (single), เร็วกว่า (batch)
Deterministic signing Optional (RFC 6979) Built-in
Signature malleability เป็นไปได้ (mitigated) ไม่มี
Nonce vulnerability ใช่ (bad RNG leak key) ไม่
Adoption Bitcoin, Ethereum, BNB Chain, Tron, Dogecoin, Litecoin Solana, XRP (partial), Cardano, Polkadot

ทั้งสอง algorithms ให้ security ประมาณ 128 bits ดู Private Key Security Best Practices

Chains ไหนใช้ Curve ไหน?

secp256k1 Chains

ed25519 Chains

  • Solana --- ใช้ Ed25519 exclusively
  • XRP --- Support ทั้ง secp256k1 และ ed25519
  • Cardano --- Ed25519 (Ed25519-BIP32, extended variant)
  • Polkadot --- Primarily Sr25519

การแบ่งเป็น generational เป็นส่วนใหญ่ Blockchains ที่ออกแบบก่อนปี 2015 tend ใช้ secp256k1 หลังปี 2017 increasingly favor ed25519

ผลต่อ Key Generation

secp256k1 Key Generation

  1. Generate random 256-bit number (private key)
  2. Compute public key: multiply private key กับ generator point G บน secp256k1
  3. Hash public key เพื่อ produce address (Bitcoin: SHA-256 + RIPEMD-160; Ethereum: Keccak-256)

Generate ด้วย Bitcoin Private Key Generator หรือ Ethereum Private Key Generator

ed25519 Key Generation

  1. Generate random 32-byte seed
  2. Hash ด้วย SHA-512 ได้ 64 bytes 32 bytes แรก (bits clamped) เป็น signing scalar
  3. Multiply scalar กับ base point B ได้ 32-byte compressed public key
  4. บน Solana public key (Base58-encoded) ก็คือ address

Generate ด้วย Solana Private Key Generator

Cross-Curve Implications

secp256k1 กับ ed25519 mathematically incompatible private key ที่ valid บน curve หนึ่งไม่มี meaningful relationship กับ key บนอีก curve เมื่อ restore seed phrase ใน wallet ที่ support ทั้ง Bitcoin และ Solana wallet จะรัน derivation processes แยกกันสอง process จาก master seed เดียวกัน

Derivation path รวม coin type: Bitcoin (m/44'/0'/0'/0/0) และ Solana (m/44'/501'/0'/0') branch ที่ coin-type level อ่าน HD Wallets and Derivation Paths Explained

เกี่ยวกับ Quantum Computing

ทั้ง secp256k1 และ ed25519 equally vulnerable ต่อ quantum computer ที่ทรงพลังเพียงพอที่รัน Shor's algorithm ไม่มี curve ที่ "more quantum-resistant" กว่า ดู Quantum Computing and the Crypto Threat

เลือก Tool ที่ถูกต้อง

ในฐานะ user คุณไม่ได้เลือกระหว่าง secp256k1 กับ ed25519 โดยตรง Blockchain เลือกให้คุณ SafeSeed generators จัดการ automatically Bitcoin Seed Phrase Generator derive secp256k1 keys Solana Seed Phrase Generator derive ed25519 keys ทั้งหมดรัน client-side ด้วย Web Crypto API ไม่มี private key material ออกจาก device