Documentation Index
Fetch the complete documentation index at: https://mintlify.com/provablehq/snarkvm/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thecrypto_hash module provides cryptographic hash functions designed for efficient use in zero-knowledge proof systems. The primary hash function is Poseidon, an algebraic hash optimized for ZK circuits.
Poseidon Hash
Poseidon Struct
The Poseidon hash function with fixed output size.The prime field over which the hash function operates
The rate of the sponge (number of field elements absorbed per permutation)
Methods
setup
Initializes a new Poseidon hash function with default parameters.A new Poseidon instance with default parameters for the field
evaluate
Evaluates the hash function over a list of field elements.Slice of field elements to hash
The hash output as a single field element
evaluate_many
Evaluates the hash function and returns multiple output elements.Slice of field elements to hash
Number of field elements to output
Vector of hash output field elements
evaluate_with_len
Evaluates the hash function, including the input length in the hash.Slice of field elements to hash
The hash output including length commitment
PoseidonSponge
PoseidonSponge Struct
A duplex sponge construction using the Poseidon permutation.Number of field elements absorbed/squeezed per permutation
Number of field elements in the capacity (typically 1 for 128-bit security)
AlgebraicSponge Implementation
PoseidonSponge implements theAlgebraicSponge trait for Fiat-Shamir transformations.
absorb_native_field_elements
Absorbs field elements into the sponge state.Elements to absorb (automatically converted to field elements)
squeeze_native_field_elements
Squeezes field elements from the sponge state.Number of field elements to squeeze
Squeezed field elements
absorb_nonnative_field_elements
Absorbs non-native field elements (from a different field).Non-native field elements to absorb
squeeze_nonnative_field_elements
Squeezes non-native field elements.Number of non-native field elements to squeeze
Squeezed non-native field elements
Sponge State Management
State Struct
Internal state of the Poseidon sponge.- Capacity: Hidden state providing security
- Rate: Public state for absorbing/squeezing
DuplexSpongeMode Enum
Tracks the current mode of the sponge.Advanced Methods
get_limbs_representations
Converts a non-native field element to limb representation.The field element to convert
Whether to optimize for weight or constraints
Limb representation in the base field
get_bits
Obtains random bits from the sponge.Number of random bits to generate
Random bits derived from the sponge state
Implementation Details
Permutation
The Poseidon permutation consists of:- Full rounds: S-box applied to all state elements
- Partial rounds: S-box applied to only the first state element
- MDS matrix multiplication: Mixing layer
Parameters
Poseidon parameters include:- Alpha: S-box exponent (typically 5 or 17)
- Full rounds: Number of full S-box rounds
- Partial rounds: Number of partial S-box rounds
- ARK: Round constants for domain separation
- MDS: Maximum distance separable matrix
Security
Poseidon provides:- 128-bit security with CAPACITY = 1
- Collision resistance via sponge construction
- Preimage resistance via one-way permutation
Usage in Fiat-Shamir
PoseidonSponge is used for Fiat-Shamir transformations in proof systems:See Also
- SNARK Implementations - Uses Poseidon for Fiat-Shamir
- Polynomial Commitments - Challenge generation
- FFT Operations - Polynomial arithmetic