Skip to content

ECDSA Signatures in Bitcoin

Published: at 02:27 PM

Bitcoin’s security is built on a fundamental cryptographic mechanism: the ECDSA digital signature.

Every transaction relies on it. Without ECDSA, users would have no way to prove they own the coins they want to spend, nodes couldn’t validate transactions, and the entire protocol would collapse.

This article explains ECDSA in a clear and developer-friendly way, introduces the mathematical concepts behind it.

What Is a Digital Signature?

A digital signature allows someone to prove three things:

  1. They know a private key without revealing it.
  2. The message has not been modified after it was signed.
  3. Only the correct key owner could have produced the signature.

In Bitcoin, the signed message is part of a transaction. The signature proves that the spender truly owns the private key linked to the Bitcoin address.

Why Bitcoin Uses ECDSA

Bitcoin uses Elliptic Curve Digital Signature Algorithm (ECDSA) instead of older algorithms like RSA or classical DSA, because elliptic curves provide:

Bitcoin uses a specific curve: secp256k1, chosen for its mathematical simplicity and excellent performance.

The Math Behind secp256k1 (Explained Simply)

The curve Bitcoin uses is defined by the equation:

y² = x³ + 7

but not on regular real numbers.

Everything happens modulo a huge prime number p, forming what is called a finite field.

A finite field (very simply):

Points on the elliptic curve

A point is simply a pair (x, y) that satisfies:

y² mod p = x³ + 7 mod p

Private and public keys

A private key is just a random 256-bit number:

privkey = k

The public key is computed as:

pubkey = k × G

Where:

Scalar multiplication is easy to compute, but impossible to reverse.

This is why you can reveal your public key without exposing your private key.

How an ECDSA Signature Works (Simple Explanation)

To sign a message hash z, the wallet:

  1. Picks a random number k (must be unique and secret)
  2. Computes the point: R = k × G
  3. Takes: r = Rₓ mod n
  4. Computes: s = k⁻¹(z + r · privkey) mod n

The signature is: (r, s)

Verification only needs:

No private key is ever exposed.

Why k Must Be Unique (Critical Security Rule)

If a wallet reuses the same k twice, even once, then:

any attacker can compute the private key.

This happened in early Android wallets due to a weak random number generator.

To avoid this, many modern Bitcoin libraries use deterministic k generation (RFC 6979), based on SHA-256 and the private key itself.

ECDSA in Bitcoin Transactions

When you spend Bitcoin:

Nodes verify:

  1. The signature matches the public key
  2. The public key corresponds to the address
  3. The signature follows Bitcoin rules (low-S, DER encoding, etc.)

This ensures only the legitimate owner of the coins can spend them.

Future Direction: Schnorr, But ECDSA Remains Essential

Since Taproot (2021), Bitcoin also supports Schnorr signatures, which are more flexible and unlock features like MuSig2.

But:

ECDSA remains one of the backbone components of the protocol.

Rust Implementation: Key Generation, Signing, Verification

Here is a complete minimal Rust implementation using the k256 crate.

use k256::ecdsa::{
    signature::{Signer, Verifier},
    SigningKey, VerifyingKey, Signature,
};
use sha2::{Sha256, Digest};
use k256::elliptic_curve::rand_core::OsRng;

fn main() {
    // 1. Generate private key
    let signing_key = SigningKey::random(&mut OsRng);
    let verify_key: &VerifyingKey = &signing_key.verifying_key();

    println!("Private key: {:?}", signing_key.to_bytes());
    println!("Public key: {:?}", verify_key.to_sec1_bytes());

    // 2. Message to sign
    let message = b"Bitcoin ECDSA!";
    let message_hash = Sha256::digest(message);

    // 3. Sign the message hash
    let signature: Signature = signing_key.sign(message_hash.as_ref());
    println!("Signature: {:?}", signature);

    // 4. Verify the signature
    let is_valid = verify_key.verify(message_hash.as_ref(), &signature).is_ok();
    println!("Valid signature? {}", is_valid);
}

Final Thoughts

Understanding ECDSA is essential if you want to:

ECDSA is not just math, it’s one of the pillars that makes Bitcoin secure, decentralized, and trustless.

Code, Peace and Love