Bitcoin Protocol Engine
Bitcoin protocol abstraction layer supporting multiple variants and protocol evolution.
For verified system status: See SYSTEM_STATUS.md in the BTCDecoded organization repository.
Provides a Bitcoin protocol abstraction layer enabling:
- Multiple Bitcoin variants (mainnet, testnet, regtest)
- Protocol evolution support
- Economic model abstraction
- Commons-specific protocol extensions (UTXO commitments, ban list sharing)
- Research-friendly interfaces
Architecture Position
Tier 3 of the 6-tier Bitcoin Commons architecture (BLVM technology stack):
1. blvm-spec (Orange Paper - mathematical foundation)
2. blvm-consensus (pure math implementation)
3. blvm-protocol (Bitcoin abstraction)
4. blvm-node (full node implementation)
5. blvm-sdk (developer toolkit)
6. blvm-commons (governance enforcement)
Features
- Protocol Variants: Mainnet, testnet, regtest support
- Network Messages: Core P2P messages and BIP152 compact blocks
- FIBRE Protocol: High-performance relay protocol with packet format definitions
- Governance P2P surfaces: Optional commons-related P2P messages and flags — see
NetworkMessage/src/and the published book protocol chapters. - Commons Extensions: UTXO commitments, filtered blocks, ban list sharing
- Service Flags: Standard and Commons-specific capability flags
- Validation Rules: Protocol-specific size limits and validation
- BIP Support: BIP152, BIP157, BIP158, BIP173/350/351
- DoS Protection: Protocol-level message size limits
Purpose
Sits between pure mathematical consensus rules (blvm-consensus) and full Bitcoin implementation (blvm-node). Provides:
Protocol Abstraction
- Multiple Variants: Support for mainnet, testnet, and regtest
- Network Parameters: Magic bytes, ports, genesis blocks, difficulty targets
- Feature Flags: SegWit, Taproot, RBF, and other protocol features
- Validation Rules: Protocol-specific size limits and validation logic
Protocol Evolution
- Version Support: Multiple protocol versions
- Feature Management: Enable/disable features based on protocol version
- Breaking Changes: Track and manage protocol evolution
Commons-Specific Extensions
- UTXO Commitments: Protocol messages for UTXO set synchronization and verification
- Filtered Blocks: Spam-filtered block relay for efficient syncing
- Ban List Sharing: Distributed ban list management
- Service Flags: Standard and Commons-specific capability flags
Core Components
Protocol Variants
- BitcoinV1: Production Bitcoin mainnet
- Testnet3: Bitcoin test network
- Regtest: Regression testing network
Network Parameters
- Magic Bytes: P2P protocol identification
- Ports: Default network ports
- Genesis Blocks: Network-specific genesis blocks
- Difficulty: Proof-of-work targets
- Halving: Block subsidy intervals
Network Messages
- Core P2P Messages: Version, VerAck, Addr, Inv, GetData, GetHeaders, Headers, Block, Tx, Ping, Pong, MemPool, FeeFilter
- Additional Core Messages: GetBlocks, GetAddr, NotFound, Reject, SendHeaders
- BIP152 (Compact Block Relay): SendCmpct, CmpctBlock, GetBlockTxn, BlockTxn
- Commons Extensions: GetUTXOSet, UTXOSet, GetFilteredBlock, FilteredBlock, GetBanList, BanList
Service Flags
- Standard Flags: NODE_NETWORK, NODE_WITNESS, NODE_COMPACT_FILTERS, NODE_NETWORK_LIMITED
- Commons Flags: NODE_UTXO_COMMITMENTS, NODE_BAN_LIST_SHARING, NODE_FIBRE, NODE_DANDELION, NODE_PACKAGE_RELAY
Validation Rules
- Size Limits: Block, transaction, and script size limits
- Feature Flags: SegWit, Taproot, RBF support
- Fee Rules: Minimum and maximum fee rates
- Protocol Context: Block height and network state
- DoS Protection: Protocol-level message size limits
Usage
Basic Protocol Engine
use ;
// Create a mainnet protocol engine
let engine = new?;
// Get network parameters
let params = engine.get_network_params;
println!;
println!;
// Check feature support
if engine.supports_feature
Configuration
use ;
// Create protocol configuration
let mut config = default;
config.service_flags.node_fibre = true;
config.commons.utxo_commitments = true;
config.validation.max_block_size = 4_000_000;
// Load from environment variables
let config = from_env;
// Get service flags from configuration
let service_flags = config.get_service_flags;
Configuration Options
The protocol configuration system provides:
- Protocol Validation: Size limits (block, transaction, script), transaction count limits, locator hash limits
- Service Flags: Control which capabilities are advertised (NODE_NETWORK, NODE_WITNESS, Commons extensions)
- Protocol Features: Enable/disable SegWit, Taproot, RBF, CTV, Compact Blocks, Compact Filters
- Fee Rates: Minimum and maximum fee rate limits
- Compact Blocks: BIP152 configuration (version preference, index limits)
- Commons Extensions: UTXO commitments, filtered blocks, ban list sharing, filter preferences
- FIBRE: Fast Internet Bitcoin Relay Engine configuration
Configuration can be loaded from:
- Environment variables (
BLVM_PROTOCOL_<SECTION>_<KEY>) - Programmatic configuration (struct initialization)
- Configuration files (via serde serialization)
Service Flags
use ;
// Check service flags
let services = NODE_NETWORK | NODE_WITNESS | NODE_FIBRE;
assert!;
assert!;
// Get all Commons flags
let commons_flags = get_commons_flags;
assert!;
assert!;
Network Message Processing
use ;
use BitcoinProtocolEngine;
let engine = new?;
let mut peer_state = new;
// Process a version message
let version_msg = Version;
let response = process_network_message?;
Commons Protocol Extensions
use ;
use NetworkMessage;
// Request UTXO set at specific height
let get_utxo = GetUTXOSet;
// Request ban list
let get_banlist = GetBanList;
BIP152 Compact Block Relay
use ;
// Negotiate compact block relay
let sendcmpct = SendCmpct;
Protocol-Specific Validation
use ;
let engine = new?;
// Validate block with protocol rules
let result = engine.validate_block?;
// Validate transaction with protocol rules
let result = engine.validate_transaction?;
Regtest Mode
use ;
// Create regtest protocol engine
let engine = new?;
// Regtest mode has fast mining for testing
assert!;
assert!;
Protocol Evolution
Supported Protocol Features
- Basic transactions and proof-of-work
- Economic model and P2P networking
- SegWit and Taproot support
- RBF (Replace-By-Fee) support
- BIP152 Compact Block Relay
- BIP157 Block Filtering
Commons Extensions
- UTXO Commitments protocol
- Filtered block relay (spam filtering)
- Ban list sharing
- FIBRE support
- Dandelion++ privacy relay
Protocol Version Support
- Multiple protocol versions supported
- Enhanced scripting capabilities
- Privacy features
- Advanced economic models
- Protocol improvements
Modules
Core Modules
network- P2P network message types and processingservice_flags- Service flags for node capabilitiescommons- Commons-specific protocol extensionsvarint- Variable-length integer encodingeconomic- Economic parameters and calculationsfeatures- Feature activation and managementvalidation- Protocol-specific validation rules
BIP Implementations
bip157- Client-side block filtering (BIP157)bip158- Compact block filters (BIP158)address- Bech32/Bech32m address encoding (BIP173/350/351)payment- Payment protocol (BIP70)fibre- FIBRE protocol definitions
Testing
# Run all tests
# Run network message tests
# Run protocol limits tests
# Run with specific protocol version
# Run with UTXO commitments
Test suite includes:
- Network message processing tests
- Protocol limits tests (DoS protection)
- BIP152 compact block relay tests
- Commons-specific message tests (UTXO commitments, filtered blocks, ban list)
- Error handling tests (malformed messages, protocol mismatches)
- Edge case tests (maximum sizes, boundary conditions)
- Service flags tests
- Varint encoding tests
- Protocol integration tests
- Validation rules tests
- Network parameters tests
- Feature registry tests
- BIP implementation tests
Security Considerations
Production Use
- Mainnet: Full consensus rules and security
- Testnet: Same rules as mainnet, different parameters
- Regtest: Relaxed rules for testing only
Development Use
- Regtest: Safe for development and testing
- Fast Mining: Configurable difficulty for testing
- Isolated: No connection to real networks
DoS Protection
- Protocol-level message size limits
- Address count limits
- Inventory item limits
- Header count limits
- Transaction count limits
Dependencies
Monorepo vs crates.io: This repo’s Cargo.toml uses path dependencies for blvm-consensus when built next to sibling repos. For a crates.io-only dependency:
[]
= "0.1.3"
blvm-consensus is pulled in transitively; ensure published versions match your crate’s Cargo.toml requirements.
All dependencies are pinned to exact versions for security. See Cargo.toml for the complete list.
Contributing
See CONTRIBUTING.md and the BTCDecoded Contribution Guide.