Skip to content

Commit 4e43bfe

Browse files
authored
Remove Poseidon, Poseidon2 (#1674)
### What Remove Poseidon, Poseidon2 code from the sdk. ### Why To prepare for migrating this into a separate repo, for independent review/audit/release cadence from the regular sdk.
1 parent 4667e58 commit 4e43bfe

File tree

12 files changed

+219
-7999
lines changed

12 files changed

+219
-7999
lines changed

soroban-sdk/src/crypto.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ use crate::{
88

99
pub mod bls12_381;
1010
pub mod bn254;
11-
pub(crate) mod poseidon2_params;
12-
pub mod poseidon2_sponge;
13-
pub(crate) mod poseidon_params;
14-
pub mod poseidon_sponge;
1511
pub(crate) mod utils;
1612
pub 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

soroban-sdk/src/crypto/poseidon2_params.rs

Lines changed: 0 additions & 2161 deletions
This file was deleted.

soroban-sdk/src/crypto/poseidon2_sponge.rs

Lines changed: 0 additions & 155 deletions
This file was deleted.

0 commit comments

Comments
 (0)