You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
implStarkHashforPoseidon{/// Computes the Poseidon hash of two Felts, as defined/// in <https://docs.starknet.io/documentation/architecture_and_concepts/Hashing/hash-functions/#poseidon_hash.>fnhash(felt_0:&Felt,felt_1:&Felt) -> Felt{Felt(PoseidonCairoStark252::hash(&felt_0.0,&felt_1.0))}/// 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.>fnhash_array(felts:&[Felt]) -> Felt{// Non-copy but less dangerous than transmute// https://doc.rust-lang.org/std/mem/fn.transmute.html#alternativesFelt(PoseidonCairoStark252::hash_many(unsafe{
core::slice::from_raw_parts(
felts.as_ptr()as*constFieldElement<Stark252PrimeField>,
felts.len(),)}))}}implPoseidon{/// Computes the Hades permutation over a mutable state of 3 Felts, as defined/// in <https://docs.starknet.io/documentation/architecture_and_concepts/Cryptography/hash-functions/#poseidon_array_hash>pubfnhades_permutation(state:&mut[Felt;3]){letmut state_inner = [state[0].0, state[1].0, state[2].0];PoseidonCairoStark252::hades_permutation(&mut state_inner);for i in0..3{
state[i] = Felt(state_inner[i]);}}}
This means that if you want to hash many elements you use hash_array, two elements you use hash. and for 1 single element you have to understand by yourselves that, according to poseidon specification, you must call hades_permutation(my_value, 0, 1).
As you can probably guess people don't know that and just do crazy things instead.
crates/starknet-types-core/src/hash/poseidon.rs
So the poseidon hash is defined this way.
And our API is this way:
This means that if you want to hash many elements you use
hash_array
, two elements you usehash
. and for 1 single element you have to understand by yourselves that, according to poseidon specification, you must callhades_permutation(my_value, 0, 1)
.As you can probably guess people don't know that and just do crazy things instead.
The inner labmdawork API is way more useful for developers: https://github.com/lambdaclass/lambdaworks/blob/7b5a638d4ce81f380ea5f43a22be41ef9b2d7ff2/crypto/src/hash/poseidon/mod.rs#L17
I would strongly recommend the addition of a
hash_single
method to the trait in order to make it more dev friendlyThe text was updated successfully, but these errors were encountered: