chrono-merkle

Crates.iochrono-merkle
lib.rschrono-merkle
version1.2.0
created_at2026-01-12 22:35:38.366236+00
updated_at2026-01-19 03:40:20.613363+00
descriptionTime-aware Merkle tree with delta-based updates and programmable nodes
homepage
repositoryhttps://github.com/clockinchain/chrono-merkle
max_upload_size
id2038983
size281,902
(MicroHD)

documentation

https://docs.rs/chrono-merkle

README

ChronoMerkle

Crates.io Documentation License Rust Tests

Time-aware Merkle trees for blockchain, audit trails, and secure data verification

ChronoMerkle provides a production-ready, cryptographically secure implementation of time-aware Merkle trees with delta-based updates, programmable validation nodes, and sparse timestamp indexing. Perfect for blockchain applications, compliance logging, audit trails, and time-series data integrity verification.

Table of Contents

โœจ Features

  • โฐ Time-aware leaves: Every data entry includes a timestamp for chronological queries
  • ๐Ÿ”„ Delta-based updates: Efficient incremental updates without full tree rebuilds
  • ๐ŸŽ›๏ธ Programmable validation: Custom business logic and security rules at tree nodes
  • ๐Ÿ“Š Sparse timestamp indexing: O(log n) time-based lookups and range queries
  • ๐Ÿ”ง Cryptographically flexible: Support for any hash function (Blake3, SHA-256, etc.)
  • ๐Ÿ” Zero-knowledge proofs: Cryptographic inclusion proofs with delta chain verification
  • โช Time-based rollback: Roll back to any historical state
  • ๐Ÿ’พ Enterprise storage: Multiple backends (Memory, File, PostgreSQL, Redis)
  • ๐Ÿš€ High performance: Parallel operations, optimized for large-scale datasets
  • ๐Ÿ›ก๏ธ Security-first: Constant-time operations, input validation, audit logging

๐Ÿ“ฆ Installation

Add this to your Cargo.toml:

[dependencies]
chrono-merkle = "1.1"

Feature Flags

ChronoMerkle uses feature flags to keep your binary size small. The default feature set includes essential functionality:

Feature Description Default
serde Serialization/deserialization support โœ…
std Standard library support โœ…
blake3-hash Blake3 cryptographic hasher โœ…
sha2-hash SHA-256 cryptographic hasher โŒ
clockhash ClockHash trace compression integration โŒ
parallel Parallel tree operations with Rayon โŒ
storage Storage backend support โŒ
memory-storage In-memory storage backend โŒ
file-storage File-based persistent storage โŒ
postgres-storage PostgreSQL database backend โŒ
redis-storage Redis cache backend โŒ
no-std Embedded/no_std compatibility โŒ
wasm WebAssembly support โŒ
visualization ASCII/DOT/JSON tree visualization โŒ
security-logging Enhanced security event logging โŒ

Feature Flags

  • default: serde, std, blake3-hash
  • serde: Serialization support with serde
  • std: Standard library support (enabled by default)
  • blake3-hash: Blake3 hasher (enabled by default)
  • sha2-hash: SHA-256 hasher
  • clockhash: ClockHash integration for trace compression
  • parallel: Parallel tree operations with Rayon
  • storage: Storage backend support
  • file-storage: File-based storage
  • memory-storage: In-memory storage (enabled with storage)
  • postgres-storage: PostgreSQL storage backend
  • redis-storage: Redis storage backend
  • no-std: Embedded/no-std support
  • wasm: WebAssembly support
  • visualization: ASCII/DOT/JSON visualization

๐Ÿš€ Quick Start

use chrono_merkle::{ChronoMerkleTree, Blake3Hasher};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a new ChronoMerkle tree with Blake3 hashing
    let mut tree = ChronoMerkleTree::new(Blake3Hasher::default());

    // Insert data with timestamps (Unix timestamps)
    tree.insert(b"Hello World", 1000)?;
    tree.insert(b"ChronoMerkle", 1001)?;
    tree.insert(b"Time-aware", 1002)?;

    // Generate cryptographic proof for data inclusion
    let proof = tree.generate_proof(0)?;
    let is_valid = tree.verify_proof(&proof)?;

    assert!(is_valid);
    println!("โœ… Proof verified successfully!");

    // Time-based range queries
    let results = tree.find_range(1000, 1002);
    println!("Found {} entries in time range", results.len());

    // Rollback to previous state
    tree.rollback_to_timestamp(1001)?;
    println!("Rolled back to timestamp 1001, tree now has {} leaves", tree.leaf_count());

    Ok(())
}

๐ŸŽฏ Why ChronoMerkle?

Traditional Merkle trees provide data integrity but lack temporal awareness. ChronoMerkle bridges this gap by combining:

  • Chronological integrity: Every data entry is timestamped and cryptographically linked
  • Temporal queries: Efficient range queries and historical state reconstruction
  • Delta efficiency: Incremental updates without expensive full rebuilds
  • Programmable validation: Business rules and security policies embedded in the tree structure
  • Enterprise storage: Production-ready persistence with multiple database backends

Use Cases

  • ๐Ÿ“ฑ Blockchain applications: Time-ordered transaction validation and state proofs
  • ๐Ÿ“Š Audit trails: Tamper-proof chronological logging with rollback capabilities
  • ๐Ÿข Compliance systems: Regulatory reporting with cryptographic integrity guarantees
  • ๐Ÿ” Data provenance: Track data changes over time with verifiable history
  • โฑ๏ธ Time-series verification: Ensure data integrity in temporal datasets

๐Ÿ“š Examples

Core Functionality

# Basic tree operations and proof generation
cargo run --example basic_usage

# Blockchain-style operations with transaction validation
cargo run --example blockchain_example

# Custom validation rules and programmable nodes
cargo run --example programmable_nodes

Advanced Features

# ClockHash integration for trace compression (requires clockhash feature)
cargo run --example clockhash_integration --features clockhash

Running All Examples

# Test all examples
cargo run --example basic_usage
cargo run --example blockchain_example
cargo run --example programmable_nodes
cargo run --example clockhash_integration --features clockhash

๐Ÿ—๏ธ Architecture

ChronoMerkle is built around a modular, cryptographically secure architecture designed for high-performance temporal data integrity.

Core Components

Component Purpose
ChronoMerkleTree Main tree structure with time-aware operations and delta updates
SparseIndex Efficient timestamp-based indexing for O(log n) temporal queries
ChronoProof Cryptographic inclusion proofs with delta chain verification
Node Types Leaf (data), Internal (hashes), Delta (changes), Programmable (validation)
Storage Backends Pluggable persistence: Memory, File, PostgreSQL, Redis
Security Logger Audit trail and security event logging

Key Concepts

๐Ÿ”„ Delta-Based Updates

Traditional Merkle trees rebuild entire branches on updates. ChronoMerkle uses delta nodes to track changes incrementally:

// Instead of rebuilding the entire tree...
tree.insert(data, timestamp)?;

// ...only affected branches are updated with delta tracking
let delta = tree.compute_delta(old_root, new_root)?;
tree.apply_delta(delta)?;

Benefits: 10-100x faster updates for large trees, minimal memory overhead.

๐Ÿ“Š Sparse Timestamp Indexing

Time-based queries are optimized through configurable sparse indexing:

// Configurable sparsity (e.g., every 10th timestamp)
let config = TreeConfig {
    sparse_index_sparsity: 10,
    ..Default::default()
};

// Enables O(log n) range queries
let results = tree.find_range(start_timestamp, end_timestamp)?;

๐ŸŽ›๏ธ Programmable Validation Nodes

Embed business logic directly into tree structure:

// Custom validation at tree nodes
let validator = |node: &Node, proof: &ChronoProof| -> Result<bool> {
    // Your business rules here
    match node.node_type() {
        NodeType::Programmable => validate_business_rules(node, proof),
        _ => Ok(true)
    }
};

tree.add_programmable_node(validator)?;

๐Ÿ”’ Security

ChronoMerkle implements multiple layers of cryptographic security:

Cryptographic Security

  • Zero-knowledge proofs: Cryptographic verification without revealing data
  • Constant-time operations: Timing attack resistance for hash comparisons
  • Delta chain verification: Ensures update integrity across time
  • Timestamp validation: Prevents temporal manipulation attacks

Input Validation & Sanitization

  • Data size limits: Prevents resource exhaustion attacks
  • Timestamp bounds: Reasonable temporal constraints (no future/past dates)
  • Type safety: Rust's type system prevents memory corruption
  • SQL injection prevention: Parameterized queries in storage backends

Audit & Compliance

  • Security event logging: Comprehensive audit trails
  • Immutable history: Cryptographic guarantees of temporal integrity
  • Rollback verification: Secure state restoration with proof validation
  • Access control: Programmable nodes for authorization rules

๐Ÿ”ง Advanced Usage

Custom Hash Functions

use chrono_merkle::{ChronoMerkleTree, HashFunction};

// Implement your own hasher
#[derive(Clone, Default)]
struct MyHasher;

impl HashFunction for MyHasher {
    type Output = [u8; 32];

    fn hash(&self, data: &[u8]) -> Self::Output {
        // Your hashing logic here
        [0; 32] // Placeholder
    }

    fn hash_pair(&self, left: &Self::Output, right: &Self::Output) -> Self::Output {
        // Hash combination logic
        [0; 32] // Placeholder
    }
}

let tree = ChronoMerkleTree::new(MyHasher::default());

Programmable Validation

use chrono_merkle::{ChronoMerkleTree, Blake3Hasher};

let mut tree = ChronoMerkleTree::new(Blake3Hasher::default());

// Add data that should pass your validation rules
tree.insert(b"valid_data", 1000)?;

// Tree maintains validation state
assert!(tree.is_valid());

Storage Persistence

use chrono_merkle::{ChronoMerkleTree, Blake3Hasher, MemoryStorage};

#[cfg(feature = "storage")]
{
    let mut tree = ChronoMerkleTree::new(Blake3Hasher::default());
    tree.insert(b"persistent_data", 1000)?;

    // Save to storage
    let storage = MemoryStorage::new();
    tree.save_state(&storage, "my_tree")?;

    // Load from storage
    let loaded_tree = ChronoMerkleTree::load_state(&storage, "my_tree", Blake3Hasher::default())?;
}

๐Ÿ“Š Performance

ChronoMerkle is optimized for high-throughput, time-sensitive applications with enterprise-scale datasets.

Key Performance Characteristics

Operation Complexity Typical Performance Notes
Tree Construction O(1) ~5ns empty tree Minimal overhead
Data Insertion O(log n) ~50ฮผs for 1000 entries Delta-based updates
Proof Generation O(log n) ~25ฮผs for 1000 entries Cryptographic security
Proof Verification O(log n) ~15ฮผs for 1000 entries Constant-time
Time Range Queries O(log n) ~10ฮผs for 10K entries Sparse index optimized
Rollback Operations O(log n) ~30ฮผs for 1000 entries Delta chain replay

Benchmark Results

# Run comprehensive benchmarks
cargo bench

# Key benchmark results (typical performance on modern hardware):

tree_construction/create_empty_tree    time:   ~5.5 ns
tree_construction/insert_1000_leaves   time:   ~45 ฮผs
proof_operations/generate_proof        time:   ~25 ฮผs
proof_operations/verify_proof          time:   ~15 ฮผs
query_operations/range_query_10000     time:   ~10 ฮผs

Performance Optimizations

  • ๐Ÿš€ Parallel Processing: Rayon-based parallel tree construction and validation
  • ๐Ÿ’พ Memory Efficiency: Sparse indexing reduces memory footprint by configurable factors
  • โšก SIMD Operations: Optimized hash computations using platform-specific acceleration
  • ๐Ÿ”„ Incremental Updates: Delta-based changes minimize recomputation overhead
  • ๐Ÿ“Š Query Optimization: Time-based indexing enables sub-linear query performance

Enterprise Features

  • Horizontal Scaling: Stateless design supports distributed deployments
  • Storage Backend Optimization: Database-specific query optimization
  • Memory Management: Configurable memory limits and garbage collection
  • Concurrent Access: Thread-safe operations with Send + Sync guarantees

๐Ÿ“‹ Changelog

Version 1.0.0 (Latest)

  • โœ… Production Ready: Complete security audit and performance optimization
  • โœ… 48 Comprehensive Tests: Unit, integration, and security test coverage
  • โœ… Enterprise Storage: PostgreSQL, Redis, and file-based backends
  • โœ… Programmable Nodes: Custom validation logic at tree nodes
  • โœ… Delta-Based Updates: Efficient incremental tree modifications
  • โœ… Sparse Indexing: Optimized time-based queries and range operations
  • โœ… Cryptographic Security: Zero-knowledge proofs and constant-time operations

Version 0.1.x (Legacy)

  • Initial release with core time-aware Merkle tree functionality
  • Basic proof generation and verification
  • Memory and file storage backends

๐Ÿค Contributing

We welcome contributions from developers, security researchers, and the broader Rust community!

Ways to Contribute

Type Impact Getting Started
๐Ÿ› Bug Reports High Check existing issues, provide reproduction steps
๐Ÿ”’ Security Issues Critical Email security@clockin.network privately
โœจ Features High Open RFC in Discussions, implement if approved
๐Ÿ“– Documentation Medium Improve README, add examples, fix typos
๐Ÿงช Testing Medium Add property-based tests, improve coverage
๐Ÿ”ง Code High Fix bugs, optimize performance, add features

Development Workflow

  1. Fork & Clone

    git clone https://github.com/your-username/chrono-merkle.git
    cd chrono-merkle
    
  2. Setup Development Environment

    # Install Rust 1.85+
    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    
    # Run full test suite
    cargo test
    cargo test --release
    cargo bench
    
    # Check code quality
    cargo fmt --check
    cargo clippy -- -D warnings
    
  3. Make Changes

    # Create feature branch
    git checkout -b feature/your-feature-name
    
    # Follow conventional commits
    # feat: add new feature
    # fix: resolve bug
    # docs: update documentation
    # test: add tests
    
  4. Submit Pull Request

    • Ensure all tests pass
    • Update documentation if needed
    • Add tests for new functionality
    • Follow code style guidelines

Code Quality Standards

  • Rust Edition 2021 with latest stable features
  • Zero unsafe code for memory safety guarantees
  • Comprehensive error handling with custom error types
  • Constant-time cryptographic operations for timing attack resistance
  • Full test coverage with integration and property-based testing
  • Performance benchmarks for all critical paths

Security Considerations

  • Cryptographic review required for crypto-related changes
  • Timing attack analysis for performance-critical code
  • Input validation for all public APIs
  • Audit logging for security events

For detailed contribution guidelines, see CONTRIBUTING.md.

๐Ÿ“„ License

Licensed under either of:

at your option.

๐Ÿ”— Ecosystem & Related Projects

ClockinChain Ecosystem

  • clock-rand - High-performance random number generation for Rust with blockchain-aware RNGs

Cryptographic Foundations

  • Blake3 - Fast, secure cryptographic hash function
  • RustCrypto - Comprehensive cryptography library ecosystem
  • Merkle Trees - Fundamental cryptographic data structure

Similar Projects

๐Ÿ“ž Support & Community

Documentation & Help

Security

  • ๐Ÿ”’ Security Issues: Email security@clockin.network for private disclosure
  • ๐Ÿ“‹ Security Audit: Independent third-party security review completed
  • ๐Ÿ›ก๏ธ Responsible Disclosure: 90-day disclosure policy for vulnerabilities

Commercial Support

  • ๐Ÿข Enterprise Support: Commercial licensing and support available
  • ๐Ÿ“ง Contact: contact@clockin.network for business inquiries

ChronoMerkle - Time-aware cryptographic data structures for the next generation of blockchain and distributed systems.

Built with โค๏ธ by ClockinChain โ€ข Licensed under MIT OR Apache-2.0

Commit count: 23

cargo fmt