Base58 Turbo
The fastest memory-safe Base58 implementation.
base58-turbo is a production-grade library engineered for High Frequency Trading (HFT), Blockchain Nodes, and Mission-Critical Servers where CPU cycles are scarce and Undefined Behavior (UB) is unacceptable.
It aligns with modern hardware reality without sacrificing portability, utilizing optimized scalar kernels, matrix multiplication arithmetic, and vectorized zero handling.
Quick Start
Installation
[]
= "0.1"
Encoding
use BITCOIN;
Decoding
use BITCOIN;
Zero-Allocation (Stack)
For scenarios where heap allocation is too slow (e.g., hot paths), write directly to stack buffers:
use BITCOIN;
Engines
Supports multiple Base58 alphabets:
BITCOIN: Standard Bitcoin alphabet.MONERO: Monero alphabet.RIPPLE: Ripple alphabet.FLICKR: Flickr alphabet.Engine::new(&[u8; 58]): Custom alphabets.
Compatibility & Stability
Minimum Supported Rust Version (MSRV)
This crate requires Rust 1.86.0 or newer. We utilize modern Rust features to guarantee safety and performance.
Public API Stability
The public API (traits, structs, and error types) is considered Stable.
- We adhere to Semantic Versioning.
- The current API surface will remain valid and backward-compatible throughout the
0.1.xlifecycle.
Performance
base58-turbo is designed for maximum throughput, utilizing:
- Matrix Multiplication Arithmetic: Converts large chunks (25, 32, 64 bytes) using precomputed weights and 128-bit accumulation.
- Vectorized Zero Handling: Rapidly processes leading zeros using 64-bit SIMD patterns even in scalar code.
- 2-Byte Lookup Tables (LUT): Emits two characters at a time during encoding to reduce branch pressure.
- High-Radix Processing: Processes input in Base 5810 (decoding) and Base 585 (encoding) to minimize bignum divisions.
Benchmarks
| Operation | base58-turbo |
bs58 |
Speedup |
|---|---|---|---|
| Encode (32B) | 43.3 ns(705 MiB/s) | 885 ns(34.5 MiB/s) | 20.5× |
| Decode (32B) | 38.6 ns(1.06 GiB/s) | 313 ns(134 MiB/s) | 8.1× |
| Encode (64B) | 111 ns(550 MiB/s) | 3.97 µs(15.4 MiB/s) | 35.8× |
| Decode (64B) | 74.1 ns(1.11 GiB/s) | 1.25 µs(67.1 MiB/s) | 16.9× |
| Encode (128B) | 550 ns(222 MiB/s) | 17.4 µs(7.02 MiB/s) | 31.6× |
| Decode (128B) | 175 ns(952 MiB/s) | 5.09 µs(32.8 MiB/s) | 29.0× |
Safety & Verification
Achieving maximum throughput must not cost memory safety. While we leverage unsafe intrinsics and pointer arithmetic, we guarantee the absence of bugs using a "Swiss Cheese" model of verification layers.
- MIRI Verified: Validates that no Undefined Behavior (UB) occurs during execution.
- MSan Audited: MemorySanitizer confirms no logic is ever performed on uninitialized memory.
- Fuzz Tested: Continuous fuzzing with zero failures.
Feature Flags
| Feature | Default | Description |
|---|---|---|
serde |
❌ | Enables serde serialization/deserialization for Config and Engine |
std |
✅ | Enables String and Vec support. Disable for no_std |
Documentation
- Architecture & Design - Deep dive into our bignum optimizations.
- Safety & Verification - Proofs, MIRI logs, and audit strategy.
License
This project licensed under either the MIT License or the Apache License, Version 2.0 at your option.