5 releases (1 stable)
| new 1.0.1 | Oct 30, 2025 |
|---|---|
| 0.9.5 | Sep 24, 2025 |
| 0.9.4 | Sep 24, 2025 |
| 0.9.3 | Sep 23, 2025 |
| 0.9.1 | Sep 4, 2025 |
#79 in Magic Beans
495 downloads per month
Used in 2 crates
88KB
1.5K
SLoC
qp-poseidon
Substrate-compatible Poseidon hash implementation for the Polkadot ecosystem. This crate wraps qp-poseidon-core and adds Substrate-specific functionality including codec traits and specialized storage operations.
Features
- Substrate integration: Implements required traits for use in Substrate/Polkadot projects
- Codec support: Implements
Encode,Decode, andTypeInfotraits fromparity-scale-codec - Serde support: Optional serialization support via the
serdefeature - Storage hashing: Specialized functions for Quantus Network storage operations
- Circuit compatibility: Maintains compatibility with zero-knowledge circuit implementations
- No-std support: Works in constrained environments
Usage
Add this to your Cargo.toml:
[dependencies]
qp-poseidon = { path = "path/to/qp-poseidon/crates/substrate" }
Basic Hashing
use qp_poseidon::PoseidonHasher;
// Hash bytes with circuit-compatible padding
let data = b"hello world";
let hash = PoseidonHasher::hash_padded(data);
println!("Hash: {:?}", hash);
Performance
- Optimized for Substrate's encoding/decoding patterns
- Maintains deterministic behavior across different platforms
- Memory efficient for blockchain storage operations
- Circuit-compatible padding ensures consistency with ZK proofs
Security
- Built on
qp-poseidon-core's security guarantees - Uses standard Substrate codec patterns
- Specialized storage hashing prevents collision attacks
Integration
use qp_poseidon::PoseidonHasher;
use frame_support::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {
type Hasher: sp_runtime::traits::Hash<Output = sp_core::H256>;
}
// Use PoseidonHasher as the pallet's hasher
impl pallet::Config for Runtime {
type Hasher = PoseidonHasher;
}
Related Crates
qp-poseidon-core- The underlying pure cryptographic implementationparity-scale-codec- Substrate's encoding libraryplonky3- The underlying field arithmetic library
Dependencies
~26–41MB
~638K SLoC