Skip to content

Commit

Permalink
fix(hash): implement suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Jan 31, 2024
1 parent df085dd commit e8e4aa0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/starknet-types-core/src/hash/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ impl StarkHash for Poseidon {
/// Computes the Poseidon hash of an array of Felts, as defined
/// in <https://docs.starknet.io/documentation/architecture_and_concepts/Cryptography/hash-functions/#poseidon_array_hash.>
fn hash_array(felts: &[Felt]) -> Felt {
// Non-copy but less dangerous than transmute
// https://doc.rust-lang.org/std/mem/fn.transmute.html#alternatives
Felt(PoseidonCairoStark252::hash_many(unsafe {
core::mem::transmute::<&[Felt], &[FieldElement<Stark252PrimeField>]>(felts)
core::slice::from_raw_parts(
felts.as_ptr() as *const FieldElement<Stark252PrimeField>,
felts.len(),
)
}))
}
}
Expand All @@ -46,7 +51,7 @@ mod tests {
}

#[test]
fn test_pedersen_hash_array() {
fn test_poseidon_hash_array() {
let a = Felt::from_hex("0xaa").unwrap();
let b = Felt::from_hex("0xbb").unwrap();
let c = Felt::from_hex("0xcc").unwrap();
Expand Down

0 comments on commit e8e4aa0

Please sign in to comment.