Introduction
In our previous discussion, we explored the fundamentals of transactions in blockchain systems. Now, we'll dive into Bitcoin addresses—the human-readable identifiers that replace arbitrary strings to designate ownership of transaction outputs.
Code Implementation Note: Significant changes have been made to the codebase. Refer to the GitHub comparison for full details.
Understanding Bitcoin Addresses
A Bitcoin address like 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa (the first-ever Bitcoin address, allegedly owned by Satoshi Nakamoto) serves as a public identifier for receiving funds. Crucially:
- Addresses are derived from public keys through cryptographic hashing.
- They contain no personal data, adhering to Bitcoin's privacy principles.
Public-Key Cryptography Essentials
Bitcoin uses ECDSA (Elliptic Curve Digital Signature Algorithm) with key pairs:
- Private Key: A secret number proving ownership (e.g., randomly generated 256-bit integer).
- Public Key: Derived from the private key using elliptic curve multiplication.
// Key pair generation in Go
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
publicKey := append(privateKey.PublicKey.X.Bytes(), privateKey.PublicKey.Y.Bytes()...)Digital Signatures
Signatures verify:
- Data Integrity: No tampering during transmission.
- Authenticity: Confirmed sender identity.
- Non-Repudiation: Sender cannot deny the transaction.
Signing workflow:
- Hash the transaction data.
- Sign the hash with the private key.
- Attach signature to the transaction input.
Technical Implementation
Address Generation Steps
- Double Hashing: Apply
RIPEMD160(SHA256(PublicKey))to the public key. - Version Prefix: Add network version byte (e.g.,
0x00for mainnet). - Checksum: Compute
SHA256(SHA256(version + hash))and take the first 4 bytes. - Base58 Encoding: Convert the final payload to human-readable Base58.
func (w Wallet) GetAddress() []byte {
pubKeyHash := HashPubKey(w.PublicKey)
versionedPayload := append([]byte{version}, pubKeyHash...)
checksum := checksum(versionedPayload)
fullPayload := append(versionedPayload, checksum...)
return Base58Encode(fullPayload)
}Transaction Signing & Verification
- Signing: Requires private key and referenced outputs.
- Verification: Checks against the public key and signature.
func (tx *Transaction) Sign(privKey ecdsa.PrivateKey, prevTXs map[string]Transaction) {
txCopy := tx.TrimmedCopy()
for i, vin := range txCopy.Vin {
prevTx := prevTXs[hex.EncodeToString(vin.Txid)]
txCopy.Vin[i].PubKey = prevTx.Vout[vin.Vout].PubKeyHash
txCopy.ID = txCopy.Hash()
r, s, _ := ecdsa.Sign(rand.Reader, &privKey, txCopy.ID)
tx.Vin[i].Signature = append(r.Bytes(), s.Bytes()...)
}
}Practical Usage
Creating Wallets and Transactions
Generate a wallet:
$ blockchain_go createwallet Your new address: 1AmVdDvvQ977oVCpUqz7zAPUEiXKrX5avRCreate a blockchain:
$ blockchain_go createblockchain -address 1AmVdDvvQ977oVCpUqz7zAPUEiXKrX5avRSend funds:
$ blockchain_go send -from 1AmVdDvvQ977oVCpUqz7zAPUEiXKrX5avR -to 1NE86r4Esjf53EL7fR86CsfTZpNN42Sfab -amount 6
👉 Explore more about secure transactions
FAQ Section
Q1: Why can't I reuse Bitcoin addresses?
A1: While technically possible, reusing addresses compromises privacy by allowing others to link all transactions to the same owner.
Q2: How secure is ECDSA?
A2: ECDSA provides robust security due to the mathematical complexity of reversing elliptic curve operations, making private key forgery computationally infeasible.
Q3: What happens if I lose my private key?
A3: Lost private keys result in permanent loss of access to associated Bitcoin funds—no recovery mechanism exists.
Q4: Why does Base58 exclude certain characters?
A4: Base58 omits visually ambiguous characters (0/O/I/l) to prevent errors in manual entry.
Q5: How are transactions validated before mining?
A5: Nodes verify signatures against public keys and ensure inputs reference unspent outputs.
👉 Learn advanced wallet security practices
This Markdown document adheres to SEO best practices with:
- Hierarchical headings for readability
- Natural keyword integration (e.g., "Bitcoin addresses," "ECDSA," "private key")
- Structured FAQs for user engagement