@@ -26,7 +26,7 @@ const ROUND_PARAMS: [(usize, usize, usize, usize); 8] = [
2626static POSEIDON : LazyLock < Poseidon < Fr > > = LazyLock :: new ( || Poseidon :: from ( & ROUND_PARAMS ) ) ;
2727
2828/// The Poseidon hash function over the Bn254 scalar field.
29- #[ derive( Clone , Copy , PartialEq , Eq ) ]
29+ #[ derive( Clone , Copy , PartialEq ) ]
3030pub struct PoseidonHash ;
3131
3232impl ZerokitHasher for PoseidonHash {
@@ -44,7 +44,10 @@ impl ZerokitHasher for PoseidonHash {
4444/// For example, `Hasher::<PoseidonHash>::hash_pair(left, right)`.
4545pub struct Hasher < H > ( PhantomData < H > ) ;
4646
47- impl < H : ZerokitHasher < Scalar = Fr > > Hasher < H > {
47+ impl < H > Hasher < H >
48+ where
49+ H : ZerokitHasher < Scalar = Fr > ,
50+ {
4851 /// Hashes a single field element.
4952 pub fn hash_single ( input : Fr ) -> Fr {
5053 H :: hash ( & [ input] )
@@ -61,9 +64,12 @@ impl<H: ZerokitHasher<Scalar = Fr>> Hasher<H> {
6164 }
6265}
6366
64- /// Hashes arbitrary signal to the underlying prime field.
67+ /// Hashes an arbitrary-length signal to the prime field.
68+ /// Keccak-256 digest reduced little-endian modulo the field order.
69+ ///
70+ /// Keccak-256 is used because this mapping runs outside the circuit: the circuit only
71+ /// consumes the resulting field elements (signal `x`, `epoch`, `rln_identifier`).
6572pub fn hash_to_field_le ( signal : & [ u8 ] ) -> Fr {
66- // We hash the input signal using Keccak256
6773 let mut hash = [ 0 ; 32 ] ;
6874 let mut hasher = Keccak :: v256 ( ) ;
6975 hasher. update ( signal) ;
@@ -72,9 +78,12 @@ pub fn hash_to_field_le(signal: &[u8]) -> Fr {
7278 Fr :: from_le_bytes_mod_order ( & hash)
7379}
7480
75- /// Hashes arbitrary signal to the underlying prime field.
81+ /// Hashes an arbitrary-length signal to the prime field.
82+ /// Keccak-256 digest reduced big-endian modulo the field order.
83+ ///
84+ /// Keccak-256 is used because this mapping runs outside the circuit: the circuit only
85+ /// consumes the resulting field elements (signal `x`, `epoch`, `rln_identifier`).
7686pub fn hash_to_field_be ( signal : & [ u8 ] ) -> Fr {
77- // We hash the input signal using Keccak256
7887 let mut hash = [ 0 ; 32 ] ;
7988 let mut hasher = Keccak :: v256 ( ) ;
8089 hasher. update ( signal) ;
0 commit comments