Skip to main content

Crate lib_q_poseidon

Crate lib_q_poseidon 

Source
Expand description

Poseidon hash function optimized for zero-knowledge proofs

This crate provides a field-native implementation of the Poseidon hash function, specifically optimized for use in STARK proof systems with Complex<Mersenne31>.

§Design

Poseidon is an algebraic hash function designed for efficient implementation in zero-knowledge proof systems. Unlike traditional hashes like SHA-3, Poseidon operates directly on field elements, making it orders of magnitude more efficient in circuit constraints.

§Security

  • Uses conservative round counts based on peer-reviewed research
  • MDS matrices generated using secure methods
  • Parameters chosen for 128-bit and 256-bit security levels

§Example

use lib_q_poseidon::{Poseidon, Poseidon128};
use lib_q_stark_field::extension::Complex;
use lib_q_stark_mersenne31::Mersenne31;

type Val = Complex<Mersenne31>;

let hasher = Poseidon128::permutation();
let input = vec![Val::from(1u32), Val::from(2u32)];
let hash = hasher.hash(&input);

Structs§

Poseidon128
Poseidon-128 parameters for 128-bit security over Complex<Mersenne31>
Poseidon256
Poseidon-256 parameters for 256-bit security over Complex<Mersenne31>
PoseidonParams
Poseidon parameter configuration
PoseidonPermutation
Poseidon permutation function
PoseidonSponge
Poseidon sponge in the absorb phase (before padding).
PoseidonSpongeSqueeze
Poseidon sponge after padding: squeeze output only.

Enums§

PoseidonError
Error types for Poseidon operations

Traits§

Poseidon
High-level Poseidon hash interface

Functions§

mds_matrix_5x5
MDS matrix for state width 5 (Poseidon-128 over Complex<Mersenne31>). Cauchy construction so every square submatrix has nonzero determinant.
mds_matrix_7x7
MDS matrix for state width 7 (Poseidon-256 over Complex<Mersenne31>).
round_constants_128
Round constants for Poseidon-128 (64 rounds total: 8 full + 56 partial) State width 5 for 128-bit security over Complex<Mersenne31> (capacity 3 × ~62 bits ≥ 128).
round_constants_256
Round constants for Poseidon-256 (68 rounds total: 8 full + 60 partial) State width 7 for 256-bit security over Complex<Mersenne31> (capacity 5 × ~62 bits ≥ 256).
sbox
S-box function: x^5

Type Aliases§

PoseidonField
Field type used for Poseidon
PoseidonState
Poseidon permutation state (variable length: state_width elements)