@@ -8,14 +8,8 @@ use crate::{
88
99pub mod bls12_381;
1010pub mod bn254;
11- pub ( crate ) mod poseidon2_params;
12- pub mod poseidon2_sponge;
13- pub ( crate ) mod poseidon_params;
14- pub mod poseidon_sponge;
1511pub ( crate ) mod utils;
1612pub use bn254:: Fr as BnScalar ;
17- pub use poseidon2_sponge:: { Poseidon2Config , Poseidon2Sponge } ;
18- pub use poseidon_sponge:: { PoseidonConfig , PoseidonSponge } ;
1913
2014/// A `BytesN<N>` generated by a cryptographic hash function.
2115///
@@ -198,47 +192,6 @@ impl Crypto {
198192 pub fn bn254 ( & self ) -> bn254:: Bn254 {
199193 bn254:: Bn254 :: new ( self . env ( ) )
200194 }
201-
202- /// Computes a Poseidon hash matching circom's
203- /// [implementation](https://github.com/iden3/circomlib/blob/35e54ea21da3e8762557234298dbb553c175ea8d/circuits/poseidon.circom)
204- /// for input lengths up to 5 (`t ≤ 6`).
205- ///
206- /// Internally it picks the state size `t` to match the input length, i.e.
207- /// `t = N + 1` (rate = N, capacity = 1). For example, hashing 2 elements
208- /// uses t=3.
209- ///
210- /// Note: use [`poseidon_sponge::hash`] with a pre-constructed
211- /// [`PoseidonConfig`] directly if:
212- /// - You want to repeatedly hash with the same input size. Pre-constructing
213- /// the config saves the cost of re-initialization.
214- /// - You want to hash larger input sizes. The sponge will repeatedly
215- /// permute and absorb until the entire input is consumed. This is a valid
216- /// (and secure) sponge operation, even though it may not match circom's
217- /// output, which always picks a larger state size (N+1) to hash inputs in
218- /// one shot (up to t=17). If you need parameter support for larger `t`,
219- /// please file an issue.
220- pub fn poseidon_hash ( & self , field_type : Symbol , inputs : & Vec < U256 > ) -> U256 {
221- let config = PoseidonConfig :: new ( & self . env , field_type, inputs. len ( ) as u32 ) ;
222- poseidon_sponge:: hash ( & self . env , inputs, config)
223- }
224-
225- /// Computes a Poseidon2 hash matching noir's
226- /// [implementation](https://github.com/noir-lang/noir/blob/abfee1f54b20984172ba23482f4af160395cfba5/noir_stdlib/src/hash/poseidon2.nr).
227- ///
228- /// Internally it always initializes the state with `t = 4`, regardless of
229- /// input length. It alternates between absorbing and permuting until all
230- /// input elements are consumed.
231- ///
232- /// Note: use [`poseidon2_sponge::hash`] with a pre-constructed
233- /// [`Poseidon2Config`] directly if:
234- /// - You need to hash multiple times. Pre-constructing the config saves the
235- /// cost of re-initialization.
236- /// - You want to use a different state size (`t ≤ 4`).
237- pub fn poseidon2_hash ( & self , field_type : Symbol , inputs : & Vec < U256 > ) -> U256 {
238- const INTERNAL_RATE : u32 = 3 ;
239- let config = Poseidon2Config :: new ( & self . env , field_type, INTERNAL_RATE ) ;
240- poseidon2_sponge:: hash ( & self . env , inputs, config)
241- }
242195}
243196
244197/// # ⚠️ Hazardous Materials
0 commit comments