Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

  1. Pure Functions: All functions are deterministic and side-effect-free
  2. Mathematical Accuracy: Direct implementation of Orange Paper specifications
  3. 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.md in the blvm-consensus repository (sibling of this book) for production and Rayon feature flags.
  4. Exact Version Pinning: All consensus-critical dependencies pinned to exact versions
  5. Testing: Test coverage with unit tests, property-based tests, and integration tests
  6. No Consensus Rule Interpretation: Only mathematical implementation
  7. 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

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

Spec Maintenance Workflow Figure: Specification maintenance workflow showing how changes are detected, verified, and integrated.

See Also