Skip to content

FelixWeis/height-oracle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Height Oracle - Ultra-Efficient Bitcoin Block Height Oracle

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).

🚀 Features

  • Perfect Hash Functions: Zero-collision lookups with minimal memory
  • 18-bit Height Compression: Custom packing algorithm for memory efficiency
  • Zero-Copy Deserialization: Using epserde for ultra-fast loading
  • Feature-Gated Design: generate (building) and embedded (runtime) modes
  • Self-Contained CLI: 908KB binary with embedded oracle data

📦 Components

Library (height-oracle)

Core Rust library with perfect hash implementation for Bitcoin block height lookups.

CLI Tool (delphi)

Ultra-minimal command-line tool for instant height lookups. Usage documentation: See delphi/README.md

🎯 Performance

  • Lookup Speed: 2.5M+ lookups per second
  • Memory Efficiency: 18-bit compressed heights
  • Binary Size: 908KB self-contained executable
  • Load Time: Instant (embedded data)

🏗️ Quick Start

# 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: 0

🔌 Generate assets/prebip34.txt from your local Bitcoin Core

This 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/.cookie or -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 64

Once generated, you can build the oracle assets using:

cargo run --features generate --release

Note: 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.

👥 Hackathon Team

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages