SimpleBTC
A complete Bitcoin implementation in ~3000 lines of Rust — full UTXO model, secp256k1 ECDSA, M-of-N multisig, BIP125 RBF, time-lock, Merkle SPV proofs, 3.8x parallel mining via Rayon, RocksDB persistence, and mdBook documentation exceeding 15,000 words. 9 of 10 Bitcoin Core features implemented.
// DESCRIPTION
The Problem: Educational Bitcoin Implementations Are Toys
Most educational Bitcoin implementations used in university courses and online tutorials share a fatal flaw: they abstract away the very things that make Bitcoin interesting and hard. They use a simple list of transactions instead of an Unspent Transaction Output (UTXO) set, substitute toy hash functions for real SHA-256, and omit the cryptographic signature scheme entirely. A student completing these tutorials can explain Bitcoin in a presentation but cannot answer basic questions like: "How does a node verify a transaction hasn't double-spent?" or "What actually happens during an SPV proof?"
SimpleBTC is built on the opposite philosophy: implement every component the way Bitcoin Core implements it, make it run, make it fast, and document every decision. The result is a complete, self-contained Bitcoin node in approximately 3,000 lines of Rust that a developer can read top-to-bottom and understand why every line exists.
问题:大多数教育性比特币实现回避了真正困难的部分——用交易列表替代UTXO集合,用玩具哈希函数替代真正的SHA-256,完全省略密码学签名方案。SimpleBTC采用完全相反的哲学:按照Bitcoin Core的方式实现每个组件,使其可运行、高效,并记录每个设计决策。结果是约3000行Rust实现的完整自包含比特币节点。
Situation & Task: Every Feature, No Shortcuts
The project targets developers with systems programming experience who want to understand Bitcoin at the implementation level, not just the conceptual level. The goal was to implement 9 of 10 Bitcoin Core features (excluding P2P network gossip, which would require a live node network) with production-quality cryptography, a persistent storage layer, and a REST API for external interaction. Cross-platform CI/CD on Linux, macOS, and Windows ensures the implementation is not environment-dependent.
任务:面向具有系统编程经验的开发者,目标是在没有捷径的情况下实现9/10个Bitcoin Core特性(仅排除需要活跃节点网络的P2P网络传播),配备生产级密码学、持久化存储层和REST API,并在Linux、macOS和Windows三平台CI/CD验证。
Technical Approach: Bitcoin by the Book
UTXO Model: The full Unspent Transaction Output model is implemented with RocksDB persistence. Every transaction input references a previous output by (txid, output_index), and the UTXO set tracks which outputs remain unspent. Double-spend detection is O(1) via RocksDB key lookup. The UTXO set survives node restarts, unlike in-memory implementations that require replaying the entire chain on startup.
Real Cryptography: secp256k1 ECDSA — the same elliptic curve Bitcoin uses — handles signature generation and verification. Private keys, public keys, and Bitcoin addresses are generated and formatted according to the actual Bitcoin address encoding scheme (Base58Check). There is no mock cryptography; every signature is mathematically valid on the actual secp256k1 curve.
SHA-256 Proof-of-Work: The mining loop implements Bitcoin's actual difficulty adjustment algorithm. The target hash is stored as a 256-bit compact representation identical to Bitcoin Core's encoding. Parallel mining uses Rayon for work-stealing thread parallelism across CPU cores, achieving a 3.8x speedup over single-threaded mining on an 8-core machine.
Merkle Trees and SPV Proofs: The Merkle tree implementation follows Bitcoin's leaf-duplication rule exactly (important for security correctness). Simplified Payment Verification (SPV) proofs allow a client to verify a transaction's inclusion in a block without downloading the full block, replicating the mechanism used by lightweight wallets.
Advanced Bitcoin Features: M-of-N multisig supports arbitrary signing thresholds (2-of-3, 3-of-5, etc.) with correct P2SH address encoding. BIP125 Replace-By-Fee (RBF) allows higher-fee replacements of unconfirmed transactions. Time-locked transactions enforce block height or Unix timestamp constraints on spending.
REST API and Web UI: An Axum-based REST API exposes all node functionality: broadcast transactions, query UTXO sets, inspect blocks, trigger mining. A web UI provides a visual blockchain explorer. Enterprise use cases (multisig escrow, RBF fee bumping) are documented with complete worked examples.
技术实现:UTXO模型配合RocksDB持久化,双花检测O(1),节点重启后数据保留。真实的secp256k1 ECDSA密码学,每个签名在实际椭圆曲线上数学有效。SHA-256工作量证明配合实际难度调整算法;Rayon并行挖矿实现3.8x加速。Merkle树精确遵循Bitcoin叶节点复制规则,支持SPV证明。M-of-N多重签名、BIP125 RBF、时间锁;Axum REST API和Web UI。
Documentation: 15,000+ Words That Actually Explain the Code
The mdBook documentation exceeds 15,000 words and covers every component in detail: why secp256k1 was chosen over other curves, how Bitcoin's Merkle leaf duplication creates a specific security edge case, why RocksDB column families are used to separate the UTXO set from block storage. Each chapter includes architecture diagrams, code snippets with line-level annotations, and "what could go wrong" sections that explain the security implications of deviating from the specification.
The documentation deliberately targets a reader who has heard of Bitcoin but has never read the whitepaper, guiding them from zero to a complete understanding of how a Bitcoin node works internally.
文档:超过15,000字的mdBook文档,覆盖每个组件的详细说明:为何选择secp256k1、Bitcoin的Merkle叶节点复制如何产生特定安全边缘情况、为何使用RocksDB列族分离UTXO集和区块存储。每章包含架构图、行级注释代码片段和“可能出错的地方”安全分析。
Results: 9/10 Features, 3 Platforms, Enterprise Examples
The final implementation covers 9 of 10 Bitcoin Core features: UTXO model, SHA-256 PoW, secp256k1 ECDSA, Merkle trees, SPV proofs, M-of-N multisig, BIP125 RBF, time-lock, and RocksDB persistence. Only P2P network gossip is excluded. CI/CD pipelines pass on all three major platforms. The project ships with complete multisig escrow and RBF fee-bumping worked examples that a developer could adapt for production use. Rayon parallelism delivers the 3.8x mining speedup without unsafe code — a demonstration of Rust's fearless concurrency model applied to a computationally intensive task.
结果:9/10 Bitcoin Core特性实现,三平台CI/CD全通过,附带完整企业级多重签名托管和RBF费用提升示例。Rayon并行挖矿在无unsafe代码的情况下实现3.8x加速,展示了Rust无畏并发模型在计算密集型任务中的应用。
// HIGHLIGHTS
- 9 of 10 Bitcoin Core features implemented in ~3,000 lines of idiomatic Rust (UTXO, SHA-256 PoW, secp256k1 ECDSA, Merkle SPV, M-of-N multisig, BIP125 RBF, time-lock, RocksDB persistence, REST API)
- 3.8x parallel mining speedup via Rayon work-stealing thread pool on 8-core hardware — no unsafe code
- Real secp256k1 ECDSA cryptography with valid Bitcoin address encoding (Base58Check) — no mock cryptography
- RocksDB-persisted UTXO set survives node restarts; O(1) double-spend detection
- M-of-N multisig (2-of-3, 3-of-5, arbitrary thresholds) with correct P2SH encoding
- mdBook documentation exceeding 15,000 words with architecture diagrams and security analysis
- CI/CD verified on Linux, macOS, and Windows; enterprise escrow and RBF examples included