Bitcoin (BTC) Technical Reference
This document provides a comprehensive technical reference for Bitcoin implementation in the go-crypto-wallet system. It covers specifications, protocol details, and links to official documentation to help AI agents and developers understand Bitcoin's architecture and implement features correctly.
Documentation Structure
This directory is organized into the following categories:
| File / Directory | Description | Audience |
|---|---|---|
| architecture.md | Wallet architecture — wallet roles, use case boundary map, Keygen vs Sign signing | Developers |
| overview/ | Fundamental technical references and Bitcoin basics | All |
| operations/ | Wallet operation guides and transaction flows | Operators |
| keygen/ | Key generation design and improvements | Developers |
| psbt/ | PSBT implementation and usage guides | All |
| descriptor/ | Output Descriptor implementation | Developers |
| taproot/ | Taproot (BIP341/BIP86) guides | All |
| musig2/ | MuSig2 multisignature implementation | All |
| testing/ | Test procedures and verification | Developers |
| archive/ | Outdated documentation (reference only) | - |
Quick Start
For Operators
- Start with operations/wallet-flow.md for wallet setup and transaction flows
- Review operations/e2e-transaction-patterns.md for transaction types
- See psbt/user-guide.md for offline signing workflows
For Developers
- Read architecture.md for the wallet boundary map and use case assignments
- Read overview/technical-reference.md for Bitcoin protocol fundamentals
- Review feature-specific architecture docs: descriptor/architecture.md, musig2/architecture.md
- Check psbt/developer-guide.md for PSBT implementation details
Table of Contents
- Overview
- Core Specifications
- Address Types & Key Derivation
- Transaction Architecture
- Signing Mechanisms
- Multisig & MuSig2
- PSBT (Partially Signed Bitcoin Transactions)
- Network & Consensus
- Fee Management
- Wallet Implementation
- RPC & API Reference
- Security Considerations
- Testing Resources
- Official References
- Project Documentation
Overview
What is Bitcoin?
Bitcoin is a decentralized digital currency that operates on a peer-to-peer network without central authority. It uses a UTXO (Unspent Transaction Output) model for tracking ownership and proof-of-work consensus for block validation.
Key Characteristics (2026)
| Property | Value |
|---|---|
| Launch Date | January 3, 2009 |
| Block Time | ~10 minutes |
| Block Size | 1-4 MB (with SegWit) |
| Total Supply | 21,000,000 BTC |
| Current Block Reward | 3.125 BTC (post-2024 halving) |
| Next Halving | ~2028 (Block 1,050,000) |
| Consensus Algorithm | SHA-256 Proof of Work |
| Cryptographic Curve | secp256k1 |
| Signature Algorithms | ECDSA (legacy), Schnorr (Taproot) |
Protocol Upgrades Timeline
| Year | Upgrade | Key Features |
|---|---|---|
| 2017 | SegWit (BIP141) | Transaction malleability fix, increased capacity |
| 2021 | Taproot (BIP340/341) | Schnorr signatures, MAST, privacy improvements |
| 2023 | BIP327 MuSig2 | Standardized multi-signature aggregation |
| 2024+ | OP_CAT (Proposed) | Enhanced scripting capabilities |
Core Specifications
Cryptographic Primitives
Elliptic Curve (secp256k1)
Bitcoin uses the secp256k1 elliptic curve for all cryptographic operations:
Curve Parameters:
- p = 2^256 - 2^32 - 977
- a = 0
- b = 7
- G = (0x79BE667E..., 0x483ADA77...)
- n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFE BAAEDCE6AF48A03BBFD25E8CD0364141Reference:
Hash Functions
| Function | Usage |
|---|---|
| SHA-256 | Block hashing, TXID calculation, PoW |
| RIPEMD-160 | Address generation (hash160 = RIPEMD160(SHA256(x))) |
| HASH160 | SHA256 + RIPEMD160 for pubkey hashing |
| HASH256 | Double SHA256 for transaction/block hashing |
| Tagged Hashes | BIP340 Schnorr signatures (SHA256 with tag) |
Data Encoding
| Format | Usage | Reference |
|---|---|---|
| Base58Check | Legacy addresses (P2PKH, P2SH) | Base58Check |
| Bech32 | Native SegWit addresses (P2WPKH, P2WSH) | BIP173 |
| Bech32m | Taproot addresses (P2TR) | BIP350 |
| WIF | Private key encoding | Wallet Import Format |
| Hex | Raw transaction data | Standard hexadecimal |
Address Types & Key Derivation
Address Types Supported
| Type | BIP | Prefix (Mainnet) | Prefix (Testnet) | Description |
|---|---|---|---|---|
| P2PKH | BIP44 | 1 | m/n | Legacy Pay-to-Public-Key-Hash |
| P2SH | BIP16 | 3 | 2 | Pay-to-Script-Hash |
| P2SH-P2WPKH | BIP49 | 3 | 2 | SegWit wrapped in P2SH |
| P2WPKH | BIP84 | bc1q | tb1q | Native SegWit |
| P2WSH | BIP141 | bc1q | tb1q | SegWit Script Hash |
| P2TR | BIP86 | bc1p | tb1p | Taproot (recommended) |
See overview/address-types.md for detailed comparison.
HD Wallet Derivation Paths
| Standard | Path | Address Type |
|---|---|---|
| BIP44 | m/44'/0'/account'/change/index | P2PKH (Legacy) |
| BIP49 | m/49'/0'/account'/change/index | P2SH-P2WPKH |
| BIP84 | m/84'/0'/account'/change/index | P2WPKH (Native SegWit) |
| BIP86 | m/86'/0'/account'/change/index | P2TR (Taproot) |
Coin Types:
0'= Bitcoin Mainnet1'= Bitcoin Testnet/Signet
References:
ScriptPubKey Formats
P2PKH: OP_DUP OP_HASH160 <20-byte pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
P2SH: OP_HASH160 <20-byte scriptHash> OP_EQUAL
P2WPKH: 0x00 <20-byte pubKeyHash>
P2WSH: 0x00 <32-byte witnessScriptHash>
P2TR: 0x51 <32-byte x-only pubKey>Transaction Architecture
UTXO Model
Bitcoin uses the Unspent Transaction Output (UTXO) model:
UTXO = {
txid: 32-byte transaction hash
vout: output index (uint32)
value: satoshi amount (int64)
scriptPubKey: locking script
}Key Concepts:
- Each transaction consumes UTXOs (inputs) and creates new UTXOs (outputs)
- Total inputs must equal outputs + transaction fee
- UTXOs can only be spent once (double-spend protection)
Transaction Weight & Virtual Size
SegWit introduced weight units for fee calculation:
Weight = (Non-witness data × 4) + Witness data
Virtual Size (vBytes) = Weight ÷ 4
Fee = Virtual Size × Fee Rate (sat/vB)Typical Sizes:
| Transaction Type | Weight | vBytes | Fee @ 10 sat/vB |
|---|---|---|---|
| P2PKH (1-in, 2-out) | ~680 | ~170 | ~1,700 sats |
| P2WPKH (1-in, 2-out) | ~440 | ~110 | ~1,100 sats |
| P2TR (1-in, 2-out) | ~396 | ~99 | ~990 sats |
| 2-of-3 Multisig (P2WSH) | ~1,100 | ~275 | ~2,750 sats |
| 2-of-3 MuSig2 (P2TR) | ~560 | ~140 | ~1,400 sats |
Reference:
Signing Mechanisms
ECDSA Signatures (Legacy/SegWit)
Used for P2PKH, P2SH, P2WPKH, and P2WSH transactions.
Sighash Types:
| Type | Value | Description |
|---|---|---|
| SIGHASH_ALL | 0x01 | Sign all inputs and outputs (default) |
| SIGHASH_NONE | 0x02 | Sign all inputs, no outputs |
| SIGHASH_SINGLE | 0x03 | Sign all inputs, matching output only |
| SIGHASH_ANYONECANPAY | 0x80 | Modifier: sign only current input |
Schnorr Signatures (Taproot)
Used for P2TR transactions. Introduced with Taproot (BIP340).
Advantages:
- Fixed 64-byte size (vs variable ECDSA)
- Linear: enables signature aggregation (MuSig2)
- Provably secure under standard assumptions
- Batch verification is faster
See taproot/user-guide.md for details.
Multisig & MuSig2
Traditional Multisig (P2SH/P2WSH)
M-of-N Redeem Script:
<M> <PubKey1> <PubKey2> ... <PubKeyN> <N> OP_CHECKMULTISIGMuSig2 (Schnorr Signature Aggregation)
MuSig2 enables N-of-N multisig that appears as single-sig on-chain.
Benefits:
- 30-50% smaller transactions
- Maximum privacy (looks like single-sig)
- Lower fees
- No on-chain multisig indicator
Critical Security: NONCE MANAGEMENT
- NEVER reuse nonces - reusing leaks private key
- Generate fresh nonces for every transaction
- Delete nonces after signing
See musig2/ for detailed documentation.
PSBT (Partially Signed Bitcoin Transactions)
PSBT (BIP174) is the standard format for offline/multi-party signing workflows.
PSBT Workflow
1. Creator (Watch Wallet - Online)
└── Create unsigned PSBT with UTXO data
2. Updater (Optional)
└── Add metadata (derivation paths, etc.)
3. Signer(s) (Offline Wallets)
└── Add partial signatures
4. Combiner (Optional)
└── Combine multiple PSBTs
5. Finalizer (Watch Wallet)
└── Create final scriptSig/witness
6. Extractor
└── Extract broadcastable transactionSee psbt/ for detailed documentation.
Network & Consensus
Networks
| Network | Purpose | Port | RPC Port | Magic Bytes |
|---|---|---|---|---|
| Mainnet | Production | 8333 | 8332 | 0xF9BEB4D9 |
| Testnet3 | Public testing | 18333 | 18332 | 0x0B110907 |
| Signet | Controlled testing | 38333 | 38332 | 0x0A03CF40 |
| Regtest | Local development | 18444 | 18443 | 0xFABFB5DA |
Confirmation Guidelines
| Confirmations | Risk Level | Typical Use Case |
|---|---|---|
| 0 (unconfirmed) | High | Very small amounts, trusted parties |
| 1 | Medium | Small retail transactions |
| 3 | Low | Most commerce |
| 6 | Very Low | Large transactions |
| 100+ | None | Coinbase maturity |
Fee Management
Fee Estimation
Bitcoin Core provides fee estimation via RPC:
# Estimate fee for confirmation in N blocks
bitcoin-cli estimatesmartfee <conf_target> [estimate_mode]
# Modes: UNSET, ECONOMICAL, CONSERVATIVEFee Rate Sources
| Source | Endpoint/Method |
|---|---|
| Bitcoin Core | estimatesmartfee RPC |
| Mempool.space | https://mempool.space/api/v1/fees/recommended |
| Blockstream | https://blockstream.info/api/fee-estimates |
Fee Optimization Strategies
- SegWit/Taproot - Use native SegWit or Taproot for smaller transactions
- UTXO Consolidation - Consolidate UTXOs during low-fee periods
- Batching - Combine multiple payments in single transaction
- RBF - Use Replace-by-Fee for fee bumping if needed
Wallet Implementation
Wallet Types in This System
| Wallet | Role | Network |
|---|---|---|
| Watch | Create transactions, broadcast, monitor | Online |
| Keygen | Generate keys, first signature | Offline (air-gapped) |
| Sign | Additional signatures (multisig) | Offline (air-gapped) |
Account Types
| Account | Purpose | Multisig |
|---|---|---|
| client | Customer deposit addresses | No |
| deposit | Aggregate client funds | No |
| payment | Outgoing payments | Yes (2-of-3 or 3-of-3) |
| stored | Cold storage | Yes |
For the common 3-wallet transaction flow (chain-agnostic), see docs/transaction-flow.md. For BTC-specific procedures and Mermaid diagrams, see operations/wallet-flow.md.
RPC & API Reference
Bitcoin Core RPC
Essential Commands:
| Command | Description |
|---|---|
getblockchaininfo | Network and sync status |
getbalance | Wallet balance |
listunspent | List UTXOs |
createrawtransaction | Create raw transaction |
signrawtransactionwithkey | Sign with provided keys |
sendrawtransaction | Broadcast transaction |
gettransaction | Get transaction details |
walletprocesspsbt | Process PSBT |
finalizepsbt | Finalize PSBT |
decodepsbt | Decode/analyze PSBT |
Reference:
Go Libraries
| Library | Purpose | Repository |
|---|---|---|
| btcd | Full node implementation | github.com/btcsuite/btcd |
| btcutil | Address/transaction utilities | github.com/btcsuite/btcd/btcutil |
| btcec | secp256k1 cryptography | github.com/btcsuite/btcd/btcec |
| psbt | PSBT implementation | github.com/btcsuite/btcd/btcutil/psbt |
| txscript | Script parsing/building | github.com/btcsuite/btcd/txscript |
Security Considerations
Private Key Security
- NEVER log or expose private keys
- Use air-gapped systems for key generation and signing
- Implement proper entropy for key generation
- Use hardware security modules (HSMs) for production
Transaction Security
- Verify all transaction details before signing
- Implement multi-signature for high-value accounts
- Use PSBT for offline signing workflows
- Validate change addresses
Nonce Security (MuSig2)
- CRITICAL: Never reuse nonces in MuSig2
- Generate cryptographically secure random nonces
- Delete nonces immediately after signing
See musig2/security.md for details.
Testing Resources
Testnet Faucets
| Network | Faucet URL |
|---|---|
| Testnet3 | testnet-faucet.com |
| Signet | signetfaucet.com |
| Signet (Alt) | alt.signetfaucet.com |
Block Explorers
| Network | Explorer |
|---|---|
| Mainnet | mempool.space |
| Mainnet | blockstream.info |
| Testnet3 | mempool.space/testnet |
| Signet | mempool.space/signet |
| Signet | explorer.bc-2.jp |
Development Tools
| Tool | Purpose |
|---|---|
| Bitcoin Core | Full node reference implementation |
| btcdeb | Bitcoin script debugger |
| Sparrow Wallet | Desktop wallet with PSBT support |
| Electrum | Lightweight wallet |
Official References
Bitcoin Improvement Proposals (BIPs)
Key Management & Addresses
| BIP | Title | Status |
|---|---|---|
| BIP32 | HD Wallets | Final |
| BIP39 | Mnemonic Seed | Final |
| BIP44 | Multi-Account HD | Final |
| BIP49 | P2SH-P2WPKH Derivation | Final |
| BIP84 | Native SegWit Derivation | Final |
| BIP86 | Taproot Derivation | Final |
SegWit & Taproot
| BIP | Title | Status |
|---|---|---|
| BIP141 | SegWit Consensus | Final |
| BIP143 | SegWit Signature Verification | Final |
| BIP173 | Bech32 Addresses | Final |
| BIP340 | Schnorr Signatures | Final |
| BIP341 | Taproot | Final |
| BIP342 | Tapscript | Final |
| BIP350 | Bech32m Addresses | Final |
PSBT & Transactions
| BIP | Title | Status |
|---|---|---|
| BIP174 | PSBT | Final |
| BIP370 | PSBT Version 2 | Draft |
| BIP371 | Taproot PSBT Fields | Draft |
| BIP125 | Replace-by-Fee | Final |
Multisig
| BIP | Title | Status |
|---|---|---|
| BIP11 | M-of-N Standard | Final |
| BIP16 | P2SH | Final |
| BIP327 | MuSig2 | Draft |
Official Documentation
- Bitcoin Developer Documentation
- Bitcoin Core Documentation
- Bitcoin Wiki
- Learn Me a Bitcoin
- Bitcoin Optech
Academic Papers
- Bitcoin Whitepaper - Satoshi Nakamoto (2008)
- MuSig2 Paper - Nick, Ruffing, Seurin, Wuille (2020)
- Schnorr Signatures for secp256k1
Project Documentation
By Category
| Category | Documents |
|---|---|
| Overview | technical-reference.md, address-types.md |
| Operations | wallet-flow.md, e2e-transaction-patterns.md, wallet-flow-improvements-2025.md |
| Key Generation | improvements-2025.md, interface-design.md |
| PSBT | user-guide.md, developer-guide.md, implementation.md |
| Descriptor | user-guide.md, architecture.md, api.md |
| Taproot | user-guide.md, testing.md |
| MuSig2 | user-guide.md, architecture.md, security.md |
| Testing | pattern3-verification.md |
Related Resources
| Resource | Location |
|---|---|
| E2E Test Scripts | scripts/operation/btc/e2e/ |
| Project Testing Standards | docs/guidelines/testing.md |
| Security Standards | docs/guidelines/security.md |
Version Information
| Component | Minimum Version | Recommended |
|---|---|---|
| Bitcoin Core | v22.0 (Taproot) | v26.0+ |
| btcd | v0.24.0 | Latest |
| Go | 1.25 | 1.25+ |
Document Version: 3.0 Last Updated: 2026-01-16 Maintainer: go-crypto-wallet team