| Crates.io | zeldhash-protocol |
| lib.rs | zeldhash-protocol |
| version | 0.6.0 |
| created_at | 2025-12-12 22:44:08.968722+00 |
| updated_at | 2026-01-16 20:56:13.457991+00 |
| description | Reference Rust implementation of the ZELDHASH protocol. |
| homepage | https://zeldhash.com |
| repository | https://github.com/ouziel-slama/zeldhash-protocol |
| max_upload_size | |
| id | 1982258 |
| size | 160,350 |
A Rust implementation of the ZELDHASH (ZELD) protocol — a system that rewards Bitcoin transactions with aesthetically pleasing transaction IDs (those starting with leading zeros).
This library provides a database-agnostic and block parser-agnostic implementation of the ZELD protocol. It focuses purely on the protocol logic, allowing you to integrate it with any Bitcoin block source and any storage backend.
For the complete protocol specification, see docs/protocol.pdf.
ZeldStore traitbitcoin::Block datapre_process_block can be executed in parallel across multiple blocksprocess_block must be called sequentially, block after blockAdd to your Cargo.toml:
[dependencies]
zeldhash-protocol = "0.1"
bitcoin = "0.32"
The protocol processes blocks in two phases:
Pre-processing (pre_process_block): Extracts all ZELD-relevant data from a Bitcoin block. This phase is parallelizable — you can pre-process multiple blocks concurrently.
Processing (process_block): Updates ZELD balances in the store. This phase is sequential — blocks must be processed in order, one after another.
use zeldhash_protocol::{ZeldProtocol, ZeldConfig, ZeldNetwork, ZeldStore, Balance, UtxoKey};
// Implement your own store
struct MyStore { /* ... */ }
impl ZeldStore for MyStore {
fn get(&mut self, key: &UtxoKey) -> Balance {
// Fetch stored balance (positive = spendable, negative = spent tombstone)
}
fn set(&mut self, key: UtxoKey, value: Balance) {
// Store balance for the given UTXO key
}
}
fn main() {
// Create protocol instance with mainnet parameters
let protocol = ZeldProtocol::new(ZeldConfig::for_network(ZeldNetwork::Mainnet));
let mut store = MyStore::new();
// Fetch blocks from your Bitcoin source
let blocks: Vec<bitcoin::Block> = fetch_blocks();
// Phase 1: Pre-process blocks (can be parallelized)
let zeld_blocks: Vec<_> = blocks
.par_iter() // Using rayon for parallelism
.map(|block| protocol.pre_process_block(block))
.collect();
// Phase 2: Process blocks sequentially
for zeld_block in &zeld_blocks {
protocol.process_block(zeld_block, &mut store);
}
}
use zeldhash_protocol::{ZeldConfig, ZeldNetwork};
// Use one of the built-in network constants.
let mainnet = ZeldConfig::MAINNET;
let testnet = ZeldConfig::for_network(ZeldNetwork::Testnet4);
// Or describe a fully custom configuration.
let custom = ZeldConfig {
min_zero_count: 8,
base_reward: 8_192,
zeld_prefix: b"ZELD",
network: bitcoin::Network::Bitcoin,
};
When ZELD is earned or transferred:
Include an OP_RETURN output with:
ZELDu64 specifying exact amounts per non-OP_RETURN outputSIGHASH_ALL (or SIGHASH_DEFAULT for Taproot) for the custom distribution to apply. This ensures the distribution cannot be altered after signing. Supported script types: P2PKH, P2WPKH, P2SH-multisig, P2WSH, and P2TR.| Type | Description |
|---|---|
ZeldProtocol |
Main entry point for processing blocks |
ZeldConfig |
Protocol configuration parameters (per network) |
ZeldNetwork |
Supported Bitcoin networks for ZELD constants |
ZeldStore |
Trait for storage backend implementation |
PreProcessedZeldBlock |
Pre-processed block data |
ZeldTransaction |
Transaction with ZELD-relevant fields |
UtxoKey |
12-byte key identifying a UTXO ([u8; 12]) |
Amount |
ZELD balance type (u64) |
Balance |
Stored balance type (i64); values outside i64 will panic during processing |
Licensed under either of:
at your option.