diff --git a/relayer/crates/starknet-integration-tests/src/tests/poseidon/hades.rs b/relayer/crates/starknet-integration-tests/src/tests/poseidon/hades.rs index 43f3a62a..a4857dd5 100644 --- a/relayer/crates/starknet-integration-tests/src/tests/poseidon/hades.rs +++ b/relayer/crates/starknet-integration-tests/src/tests/poseidon/hades.rs @@ -9,29 +9,26 @@ use super::poseidon_3::{FULL_ROUNDS, MDS, PARTIAL_ROUNDS, RATE_PLUS_1}; pub const FN_NAME: &str = "Hades"; -pub const N_ROUND_CONSTANTS: usize = RATE_PLUS_1 * (FULL_ROUNDS + PARTIAL_ROUNDS); - -pub static ROUND_CONSTANTS: LazyLock<[Felt; N_ROUND_CONSTANTS]> = - LazyLock::new(|| core::array::from_fn(hades_ark)); +pub static ROUND_CONSTANTS: LazyLock<[Felt; RATE_PLUS_1 * (FULL_ROUNDS + PARTIAL_ROUNDS)]> = + LazyLock::new(|| { + core::array::from_fn(|idx| { + // https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/poseidon_utils.py#L15 + let value = format!("{}{}", FN_NAME, idx); + + let hash = { + use sha2::Digest; + let mut hasher = sha2::Sha256::new(); + hasher.update(value); + hasher.finalize() + }; + + Felt::from_bytes_be(&hash.into()) + }) + }); -pub const STARKNET_HADES_PERM_3: HadesPermutate = +pub const HADES_PERM_3: HadesPermutate = HadesPermutate { mds: MDS }; -// https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/cairo/common/poseidon_utils.py#L15 -pub fn hades_ark(idx: usize) -> Felt { - let value = format!("{}{}", FN_NAME, idx); - - use sha2::Digest; - - let hash = { - let mut hasher = sha2::Sha256::new(); - hasher.update(value); - hasher.finalize() - }; - - Felt::from_bytes_be(&hash.into()) -} - pub struct HadesPermutate { pub mds: [[i64; DIM]; DIM], } diff --git a/relayer/crates/starknet-integration-tests/src/tests/poseidon/mod.rs b/relayer/crates/starknet-integration-tests/src/tests/poseidon/mod.rs index c5fa2a12..03c1e321 100644 --- a/relayer/crates/starknet-integration-tests/src/tests/poseidon/mod.rs +++ b/relayer/crates/starknet-integration-tests/src/tests/poseidon/mod.rs @@ -1,7 +1,7 @@ pub mod hades; pub mod poseidon_3; -use hades::STARKNET_HADES_PERM_3; +use hades::HADES_PERM_3; use starknet::core::types::Felt; // References: @@ -28,7 +28,7 @@ impl Default for Poseidon3Hasher { impl Poseidon3Hasher { pub fn write(mut self, value: Felt) -> Self { if self.odd { - self.state = STARKNET_HADES_PERM_3.hades_permutation([ + self.state = HADES_PERM_3.hades_permutation([ self.state[0], self.state[1] + value, self.state[2], @@ -43,13 +43,13 @@ impl Poseidon3Hasher { pub fn finish(self) -> Felt { if self.odd { - STARKNET_HADES_PERM_3.hades_permutation([ + HADES_PERM_3.hades_permutation([ self.state[0], self.state[1] + Felt::ONE, self.state[2], ])[0] } else { - STARKNET_HADES_PERM_3.hades_permutation([ + HADES_PERM_3.hades_permutation([ self.state[0] + Felt::ONE, self.state[1], self.state[2], @@ -63,11 +63,7 @@ impl Poseidon3Hasher { for chunk in span.chunks(2) { match chunk { [x, y] => { - state = STARKNET_HADES_PERM_3.hades_permutation([ - state[0] + x, - state[1] + y, - state[2], - ]) + state = HADES_PERM_3.hades_permutation([state[0] + x, state[1] + y, state[2]]) } [x] => { return Self {