Consensus Layer Architecture
The consensus layer is designed as a pure mathematical implementation with no side effects. Block and script logic are organized in block/ and script/ submodules. Canonical types, serialization, and crypto live in blvm-primitives and are re-exported by blvm-consensus for compatibility.
Design Principles
- Pure Functions: All functions are deterministic and side-effect-free
- Mathematical Accuracy: Direct implementation of Orange Paper specifications
- Optimization Passes: Runtime optimizations applied to the implementation (constant folding, memory layout optimization, SIMD vectorization, bounds check optimization, dead code elimination). The implementation is validated against the Orange Paper, not generated from it. See
blvm-consensus/docs/FEATURES.mdin the blvm-consensus repository (sibling of this book) for production and Rayon feature flags. - Exact Version Pinning: All consensus-critical dependencies pinned to exact versions
- Testing: Test coverage with unit tests, property-based tests, and integration tests
- No Consensus Rule Interpretation: Only mathematical implementation
- Formal Verification: BLVM Specification Lock and property-based testing ensure correctness
Core Functions
Transaction Validation
- Transaction structure and limit validation
- Input validation against UTXO set
- Script execution and verification
Block Validation
- Block connection and validation
- Transaction application to UTXO set
- Proof of work verification
Economic Model
- Block reward calculation
- Total supply computation
- Difficulty adjustment
Mempool Protocol
- Transaction mempool validation
- Standard transaction checks
- Transaction replacement (RBF) logic
Mining Protocol
- Block creation from mempool
- Block mining and nonce finding
- Block template generation
Chain Management
- Chain reorganization handling
- P2P network message processing
Advanced Features
- SegWit: Witness data validation and weight calculation (see BIP141)
- Taproot: P2TR output validation and key aggregation (see BIP341)
Optimization Passes
The implementation is validated against the Orange Paper; optimization passes optimize the implementation code (not the spec):
- Constant Folding - Pre-computed constants and constant propagation
- Memory Layout Optimization - Cache-aligned structures and compact stack frames
- SIMD Vectorization - Batch hash operations with parallel processing
- Bounds Check Optimization - Removes redundant runtime bounds checks using BLVM Specification Lock-proven bounds
- Dead Code Elimination - Removes unused code paths
- Inlining Hints - Aggressive inlining of hot functions
Mathematical Protections
Mathematical protection mechanisms ensure correctness through formal verification. See Mathematical Specifications for details.
Spec Maintenance Workflow
Figure: Specification maintenance workflow showing how changes are detected, verified, and integrated.
See Also
- Consensus Overview - Consensus layer introduction
- Formal Verification - Verification methodology and tools
- Mathematical Correctness - Verification approach and coverage
- Orange Paper - Mathematical foundation
- Protocol Architecture - Protocol layer built on consensus