Expand description
§Poseidon Hash (Goldilocks)
Rust implementation of Poseidon2 hash function and Goldilocks field arithmetic.
§⚠️ Security Warning
This library has NOT been audited and is provided as-is. Use with caution.
- Prototype implementation focused on correctness
- Not security audited - do not use in production without proper security review
- While the implementation appears to work correctly, cryptographic software requires careful auditing
- This is an open-source contribution and not an official Lighter Protocol library
- Use at your own risk
§Overview
This crate provides essential cryptographic primitives for Zero-Knowledge proof systems:
- Goldilocks Field: A special prime field (p = 2^64 - 2^32 + 1) optimized for 64-bit CPU operations
- Poseidon2 Hash: A ZK-friendly hash function designed for low constraint counts in ZK circuits
- Fp5 Extension Field: Quintic extension field (GF(p^5)) for elliptic curve operations
§Features
- Fast field arithmetic with optimized modular reduction
- Efficient Poseidon2 hash implementation
- 40-byte field elements for cryptographic operations
- Production-grade performance and security
§Example
use poseidon_hash::{Goldilocks, hash_to_quintic_extension};
// Field arithmetic
let a = Goldilocks::from_canonical_u64(42);
let b = Goldilocks::from_canonical_u64(10);
let sum = a.add(&b);
let product = a.mul(&b);
// Poseidon2 hashing
let elements = vec![
Goldilocks::from_canonical_u64(1),
Goldilocks::from_canonical_u64(2),
Goldilocks::from_canonical_u64(3),
];
let hash = hash_to_quintic_extension(&elements);Modules§
- merkle
- Binary Merkle tree built with the Poseidon2 hash over the Goldilocks field.
Structs§
- Fp5Element
- Fp5 extension field element.
- Goldilocks
- Goldilocks field element.
Functions§
- empty_
hash_ out - Returns an empty hash output (all zeros). Equivalent to Go’s EmptyHashOut function.
- hash_
n_ to_ one - Combines multiple hash outputs into a single hash output. Equivalent to Go’s HashNToOne function.
- hash_
no_ pad - Hashes a slice of Goldilocks field elements, producing exactly 4 output elements. Equivalent to Go’s HashNoPad function.
- hash_
out_ from_ bytes_ le - Deserialises a
HashOutfrom 32 little-endian bytes. - hash_
out_ to_ bytes_ le - Serialises a
HashOutto 32 little-endian bytes. - hash_
to_ quintic_ extension - Hashes a slice of Goldilocks field elements to a single Fp5Element.
- permute
- Applies the Poseidon2 permutation to a 12-element state array.
Type Aliases§
- HashOut
- Hash output type: 4 Goldilocks elements (32 bytes) Equivalent to Go’s HashOut type