Understanding Ethereum Keys and Addresses: A Comprehensive Guide

ยท

The Basics: What Many People Get Wrong

Ethereum Private Key

A standard Ethereum private key looks like this:

fad9c8855b740a0b7ed4c221dbad0f33a83a49cad6b3fe8d5817ac83d38b6a19

Key characteristics:

Ethereum Public Address

Example public address:

0x20F8D42FB0F667F2E53930fed426f225752453b3

Key characteristics:

Are Public Keys and Ethereum Addresses the Same Thing?

In short: No. An Ethereum address is actually derived from the public key through a specific cryptographic process:

  1. The public key undergoes Keccak-256 hashing
  2. The last 160 bits of this hash become the address
  3. This address is then converted to hexadecimal format

Ethereum Address Case Sensitivity: Does It Matter?

You might notice wallet applications display mixed-case addresses while blockchain explorers accept both uppercase and lowercase. This stems from Ethereum's EIP-55 proposal which introduced checksum validation.

How EIP-55 Works

The JavaScript implementation:

function toChecksumAddress(address) {
  address = address.toLowerCase().replace('0x', '')
  var hash = createKeccakHash('keccak256').update(address).digest('hex')
  var ret = '0x'
  for (var i = 0; i < address.length; i++) {
    if (parseInt(hash[i], 16) >= 8) {
      ret += address[i].toUpperCase()
    } else {
      ret += address[i]
    }
  }
  return ret
}

Example addresses:

Benefits of EIP-55

BIP39 Mnemonic Phrases and Private Keys: The Conversion Process

Most wallets use 12-word mnemonic phrases, though 15, 18, and 24-word variants exist. These phrases enable:

  1. Easier private key backup and recovery
  2. Hierarchical deterministic (HD) wallet functionality
  3. Generation of multiple accounts from single seed

๐Ÿ‘‰ Learn more about HD wallets

From Private Key to Public Key: The Technical Process

Here's how Ethereum generates keys programmatically (Go implementation):

package main
import (
  "crypto/ecdsa"
  "fmt"
  "log"
  "github.com/ethereum/go-ethereum/common/hexutil"
  "github.com/ethereum/go-ethereum/crypto"
  "golang.org/x/crypto/sha3"
)

func main() {
  privateKey, err := crypto.GenerateKey()
  if err != nil {
    log.Fatal(err)
  }
  privateKeyBytes := crypto.FromECDSA(privateKey)
  fmt.Println(hexutil.Encode(privateKeyBytes)[2:]) // Private key
  
  publicKey := privateKey.Public()
  publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
  if !ok {
    log.Fatal("type assertion failed")
  }
  
  publicKeyBytes := crypto.FromECDSAPub(publicKeyECDSA)
  fmt.Println(hexutil.Encode(publicKeyBytes)[4:]) // Public key
  
  address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()
  fmt.Println(address) // Ethereum address
}

Key steps:

  1. Generate random private key (256-bit)
  2. Derive public key from private key
  3. Convert public key to Ethereum address via Keccak-256 hashing
  4. Take last 20 bytes as final address

ECDSA: The Signature Algorithm Behind Ethereum

What is ECDSA?

Elliptic Curve Digital Signature Algorithm combines:

Core functions:

  1. Generates key pairs (public/private keys)
  2. Creates cryptographic signatures with private key
  3. Verifies signatures with public key

๐Ÿ‘‰ Deep dive into ECDSA security

ECDSA Signature Process

  1. Select elliptic curve parameters (Ep(a,b)) and base point G
  2. Choose private key k (where k < n, n being the curve's order)
  3. Calculate public key Q = k * G
  4. For signing:

    • Generate random number r
    • Calculate (x,y) = r * G
    • Signature components: (r, s)
  5. For verification:

    • Confirm signature matches public key

FAQ Section

Q: Can I recover my private key from my Ethereum address?
A: No. Ethereum addresses are one-way hashes of public keys, which themselves are derived from private keys. The process cannot be reversed.

Q: Why does my wallet show a different address case than blockchain explorers?
A: Wallets typically display EIP-55 checksum addresses while explorers accept any case format but internally convert to checksum for validation.

Q: How secure are 12-word mnemonic phrases?
A: Extremely secure. A 12-word phrase has 128 bits of entropy, making brute-force attacks practically impossible with current technology.

Q: What happens if I lose my private key but have my public key?
A: Without the private key, you cannot sign transactions or access funds. Always backup your private key or mnemonic phrase securely.

Q: Why does Ethereum use Keccak-256 instead of standard SHA-256?
A: Keccak-256 (used in Ethereum) has different padding rules than SHA-256, making it more resistant to certain types of cryptographic attacks.

Q: Can two different private keys generate the same public address?
A: Theoretically possible but astronomically unlikely due to the enormous size of Ethereum's key space (2^256 possible private keys).