BTC++ Riga 2025 hackathon submission
A lightning-fast Rust library for Bitcoin block height lookups using perfect hash functions, optimized for pre-BIP34 blocks (0-227,930).
- Perfect Hash Functions: Zero-collision lookups with minimal memory
- 18-bit Height Compression: Custom packing algorithm for memory efficiency
- Zero-Copy Deserialization: Using
epserdefor ultra-fast loading - Feature-Gated Design:
generate(building) andembedded(runtime) modes - Self-Contained CLI: 908KB binary with embedded oracle data
Core Rust library with perfect hash implementation for Bitcoin block height lookups.
Ultra-minimal command-line tool for instant height lookups.
Usage documentation: See delphi/README.md
- Lookup Speed: 2.5M+ lookups per second
- Memory Efficiency: 18-bit compressed heights
- Binary Size: 908KB self-contained executable
- Load Time: Instant (embedded data)
# Build the oracle data
cargo run --features generate --release
# Build the CLI tool
cd delphi
cargo build --release
# Test a lookup (Genesis block)
./target/release/delphi 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
# Output: 0This repository now includes a simple RPC-based generator that queries your local bitcoind for all pre-BIP34 block hashes and writes them to assets/prebip34.txt.
Requirements:
- A running Bitcoin Core node with RPC enabled (e.g.
-server=1) - RPC credentials via either
~/.bitcoin/.cookieor-rpcuser/-rpcpassword
Usage:
# From the repo root
# By default reads ~/.bitcoin/.cookie and connects to http://127.0.0.1:8332
cargo run --example fetch_prebip34 --release
# Custom options:
# --rpc-url RPC endpoint (default http://127.0.0.1:8332)
# --rpc-user RPC username (else reads from ~/.bitcoin/.cookie)
# --rpc-pass RPC password (else reads from ~/.bitcoin/.cookie)
# --cookie Path to cookie file (default ~/.bitcoin/.cookie)
# --concurrency Number of parallel RPC calls (default 32)
# --start-height Start height (default 0)
# --end-height End height (default 227930)
# --output Output path (default assets/prebip34.txt)
# Example with explicit credentials and higher concurrency
cargo run --example fetch_prebip34 --release -- \
--rpc-url http://127.0.0.1:8332 \
--rpc-user myuser \
--rpc-pass mypass \
--concurrency 64Once generated, you can build the oracle assets using:
cargo run --features generate --releaseNote: marking version-2 headers with an x placeholder (so they can be handled separately) yields additional space savings. Compared to the naive approach, this optimization gives about 6.4% space savings.
Important: the boundary of 227,931 (exclusive) is sourced from Bitcoin Core's pre-BIP34 definition, but the oracle generated by this repository only includes blocks with header version == 1. Blocks with version == 2 are written as x placeholders by the generator and are intentionally skipped when building the perfect-hash; handle those blocks separately if you require full coverage.
- @ubbabeck
- @bayernator
- @FelixWeis
- Claude (AI Assistant) - Code architecture, optimization, and implementation